Skip to content

Commit

Permalink
Add docker support
Browse files Browse the repository at this point in the history
  • Loading branch information
SerafimArts committed Mar 16, 2024
1 parent ba29924 commit 714a0ef
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 6 deletions.
3 changes: 0 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@ trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2

[docker-compose.yml]
indent_size = 4
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
APP_URL=http://laravel.localhost

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
Expand Down
11 changes: 11 additions & 0 deletions Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
laravel.localhost {
tls internal
root * /home/laravel/laravel.su/public

php_fastcgi php:9000 {
root /home/laravel/laravel.su/public
}

file_server
encode gzip
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"license": "CC BY-NC-SA 4.0",
"require": {
"php": ">=8.1",
"php": "^8.3",
"cagilo/cagilo": "^3.2",
"doctrine/dbal": "^3.7",
"esplora/spire": "0.0.1",
Expand Down
2 changes: 1 addition & 1 deletion config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
|
*/

'default' => env('DB_CONNECTION', 'mysql'),
'default' => env('DB_CONNECTION', 'sqlite'),

/*
|--------------------------------------------------------------------------
Expand Down
40 changes: 40 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: "3.8"

services:
caddy:
image: caddy:2.7-alpine
container_name: laravelsu-caddy
restart: unless-stopped
working_dir: /home/laravel/laravel.su
env_file:
- path: .env
required: false
ports:
- "${LARAVEL_SU_HTTP_PUBLIC_PORT:-80}:80"
- "${LARAVEL_SU_HTTPS_PUBLIC_PORT:-443}:443"
- "${LARAVEL_SU_HTTPS_PUBLIC_PORT:-443}:443/udp"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- .:/home/laravel/laravel.su
depends_on:
- php
networks:
- laravel_su

php:
build: docker/php
container_name: laravelsu-php
working_dir: /home/laravel/laravel.su
env_file:
- path: .env
required: false
volumes:
- .:/home/laravel/laravel.su
- ./docker/php/php.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- laravel_su

networks:
laravel_su:
name: laravel_su
driver: bridge
74 changes: 74 additions & 0 deletions docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
FROM php:8.3-fpm

WORKDIR "/home/laravel/laravel.su"

# Fix debconf warnings upon build
ARG DEBIAN_FRONTEND=noninteractive

# ------------------------------------------------------------------------------
# Install Dependencies
# ------------------------------------------------------------------------------

RUN apt-get update \
&& pecl channel-update pecl.php.net \
&& apt-get -y --no-install-recommends install \
libsqlite3-dev \
libzip-dev \
libicu-dev \
libpq-dev \
unzip \
git \
curl

# ------------------------------------------------------------------------------
# Install PHP
# ------------------------------------------------------------------------------

# Composer
RUN curl -sS https://getcomposer.org/installer | \
php -- --install-dir=/usr/local/bin --filename=composer

# APCU
RUN pecl install apcu \
&& docker-php-ext-enable apcu

# INTL
RUN docker-php-ext-install intl \
&& docker-php-ext-enable intl

# PDO PostgreSQL
RUN docker-php-ext-install pdo_sqlite \
&& docker-php-ext-enable pdo_sqlite

# Zip
RUN docker-php-ext-install zip \
&& docker-php-ext-enable zip

# Opcache
RUN docker-php-ext-install opcache

# Sockets
RUN docker-php-ext-install sockets

# ------------------------------------------------------------------------------
# Cleanup Dependencies
# ------------------------------------------------------------------------------

RUN apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* \
&& ln -sf /usr/share/zoneinfo/Etc/UTC /etc/localtime

# ------------------------------------------------------------------------------
# Copy Runtime Files
# ------------------------------------------------------------------------------

COPY --chown=root:root boot.sh /etc/init.d/boot.sh
RUN chmod +x /etc/init.d/boot.sh

# ------------------------------------------------------------------------------
# Execute Server
# ------------------------------------------------------------------------------

RUN useradd -u 1000 -m laravel
USER laravel

ENTRYPOINT ["/etc/init.d/boot.sh"]
44 changes: 44 additions & 0 deletions docker/php/boot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
set -e

echo " > Prepare server APP_ENV=${APP_ENV}"

echo "$ copy .env.example .env"
cp -n /home/laravel/laravel.su/.env.example /home/laravel/laravel.su/.env

# NON Production Environment
if [[ ${APP_ENV} != *"production"* ]];
then
# --------------------------------------------------------------------------
# Additional installation of DEV dependencies
# --------------------------------------------------------------------------
echo "$ touch database/database.sqlite"
touch /home/laravel/laravel.su/database/database.sqlite

echo "$ composer install -n -v"
composer install -n -v

echo "$ artisan key:generate"
php /home/laravel/laravel.su/artisan key:generate

echo "$ artisan migrate"
php /home/laravel/laravel.su/artisan migrate
fi

# ----------------------------------------------------------------------------
# Warmup
# ----------------------------------------------------------------------------

echo "$ artisan cache:clear"
php /home/laravel/laravel.su/artisan cache:clear

echo "$ artisan config:clear"
php /home/laravel/laravel.su/artisan config:clear

# ------------------------------------------------------------------------------
# Execute Server
# ------------------------------------------------------------------------------

echo "Ready (APP_ENV=${APP_ENV}, APP_DEBUG=${APP_DEBUG})"

exec php-fpm
25 changes: 25 additions & 0 deletions docker/php/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[PHP]
; Maximum allowed size for uploaded files.
; https://php.net/upload-max-filesize
upload_max_filesize = 100M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; https://php.net/post-max-size
post_max_size = 100M

[Date]
; Defines the default timezone used by the date functions
; https://php.net/date.timezone
date.timezone = UTC

[opcache]
; Determines if Zend OPCache is enabled
opcache.enable=1

; Determines if Zend OPCache is enabled for the CLI version of PHP
opcache.enable_cli=1

0 comments on commit 714a0ef

Please sign in to comment.