Skip to content

Commit

Permalink
build: added deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaile committed May 8, 2024
1 parent ba87571 commit 172f87d
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 24 deletions.
21 changes: 21 additions & 0 deletions .env.prod.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
APP_ENV=production
APP_KEY=
APP_DEBUG=false
APP_TIMEZONE=Europe/Rome
APP_URL=http://localhost

BCRYPT_ROUNDS=12

LOG_LEVEL=debug
LOG_CHANNEL=errorlog
LOG_DEPRECATIONS_CHANNEL=errorlog

DB_CONNECTION=sqlite
DB_DATABASE=/var/www/html/storage/database.sqlite

FILESYSTEM_DISK=local
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=
AWS_BUCKET=
AWS_ENDPOINT=
3 changes: 2 additions & 1 deletion containers/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ ADD --chmod=777 \
--checksum=sha256:206a8f9b2177703fc5aa924d85ad6c72e82413e2d09635b4c9c82a1b65b5b3d5 \
https://github.com/eficode/wait-for/releases/download/v2.2.4/wait-for /usr/local/bin/wait-for
# configure entrypoints and image
COPY --chmod=777 containers/php/entrypoint.sh /usr/local/sbin/entrypoint
RUN echo "* * * * * cd /var/www/html && php artisan schedule:run >> /dev/null 2>&1" > /etc/crontabs/www-data \
&& echo "access.log = /dev/null" >> /usr/local/etc/php-fpm.d/zz-docker.conf
ENTRYPOINT ["entrypoint"]
Expand All @@ -26,6 +25,7 @@ RUN apk add --no-cache \
&& install-php-extensions xdebug \
&& mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" \
&& echo "ALL ALL=(ALL:ALL) NOPASSWD: ALL" > "/etc/sudoers.d/password_less_sudo"
COPY --chmod=777 containers/php/entrypoint-dev.sh /usr/local/sbin/entrypoint
ARG UID
ARG GID
RUN usermod -u "$UID" www-data \
Expand All @@ -37,6 +37,7 @@ USER www-data
FROM base as production
RUN install-php-extensions opcache \
&& mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
COPY --chmod=777 containers/php/entrypoint.sh /usr/local/sbin/entrypoint
COPY containers/php/config/conf.d/opcache.ini /usr/local/etc/php/conf.d/opcache.ini
ARG COMPOSER_ALLOW_SUPERUSER=1
COPY composer.json .
Expand Down
18 changes: 18 additions & 0 deletions containers/php/entrypoint-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env sh

set -e

if [ -f '.env' ]; then
. .env
fi

if [ "$1" = "php-fpm" ]; then
composer install
php artisan migrate --force
elif [ "$1" = "scheduler" ]; then
set -- crond -f
elif [ "$1" = "worker" ]; then
set -- php artisan queue:work --tries=3 --timeout=1800
fi

exec "$@"
19 changes: 10 additions & 9 deletions containers/php/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ if [ -f '.env' ]; then
. .env
fi

if [ "$1" = 'php-fpm' ]; then
if [ "$APP_ENV" = "local" ]; then
composer install
else
php artisan optimize
fi
php artisan optimize

if [ "$1" = "php-fpm" ]; then
# migrate database
php artisan migrate --force
chown -R www-data:www-data storage
elif [ "$1" = 'crond' ] || [ "$3" = 'queue:work' ] || [ "$3" = 'queue:listen' ]; then
wait-for "${PHP_HOST:?Missing PHP_HOST}:${PHP_PORT:?Missing PHP_PORT}" -t 60
elif [ "$1" = "scheduler" ]; then
# remove scheduler command, replace the $@
set -- crond -f
elif [ "$1" = "worker" ]; then
# remove worker command, replace the $@
set -- su -s /bin/sh -c "php artisan queue:work --tries=3 --timeout=1800" www-data
fi

exec "$@"
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name: parceler-prod
services:
nginx:
image: ghcr.io/nethesis/parceler-nginx:latest
Expand All @@ -14,25 +15,20 @@ services:
- storage:/var/www/html
- /etc/localtime:/etc/localtime:ro
env_file:
- .env.production
- .env
worker:
image: ghcr.io/nethesis/parceler-php:latest
extends:
service: php
stop_signal: SIGKILL
user: www-data
command: php artisan queue:work --tries=3 --timeout=1800
volumes:
- storage:/var/www/html
- /etc/localtime:/etc/localtime:ro
command: worker
environment:
PHP_HOST: php
PHP_PORT: 9000
scheduler:
image: ghcr.io/nethesis/parceler-php:latest
extends:
service: php
stop_signal: SIGKILL
command: crond -f
volumes:
- storage:/var/www/html
- /etc/localtime:/etc/localtime:ro
command: scheduler
environment:
PHP_HOST: php
PHP_PORT: 9000
Expand Down
17 changes: 17 additions & 0 deletions deploy/quadlet/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env sh

set -e

INSTALL_PATH=${INSTALL_PATH:-"$HOME/.config/containers/systemd"}
# Ensure the directory exists
mkdir -p "${INSTALL_PATH}"
# Install the service files
install -Dm644 parceler.pod "${INSTALL_PATH}/parceler.pod"
install -Dm644 storage.volume "${INSTALL_PATH}/storage.volume"
install -Dm644 php.container "${INSTALL_PATH}/php.container"
install -Dm644 nginx.container "${INSTALL_PATH}/nginx.container"
install -Dm644 scheduler.container "${INSTALL_PATH}/scheduler.container"
install -Dm644 worker.container "${INSTALL_PATH}/worker.container"
# Reload the systemd user service
systemctl --user daemon-reload
systemctl --user reload-or-restart parceler-pod
7 changes: 7 additions & 0 deletions deploy/quadlet/nginx.container
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Container]
Pod=parceler.pod
Image=ghcr.io/nethesis/parceler-nginx:latest
ContainerName=parceler-nginx
Volume=/etc/localtime:/etc/localtime:ro
Environment=FPM_HOST=parceler-php
Environment=FPM_PORT=9000
9 changes: 9 additions & 0 deletions deploy/quadlet/parceler.pod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Pod]
PodName=parceler
PublishPort=8080:80

[Service]
Restart=always

[Install]
WantedBy=default.target
7 changes: 7 additions & 0 deletions deploy/quadlet/php.container
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Container]
Pod=parceler.pod
Image=ghcr.io/nethesis/parceler-php:latest
ContainerName=parceler-php
Volume=/etc/localtime:/etc/localtime:ro
Volume=storage.volume:/var/www/html
EnvironmentFile=%S/parceler.env
8 changes: 8 additions & 0 deletions deploy/quadlet/scheduler.container
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Container]
Pod=parceler.pod
Image=ghcr.io/nethesis/parceler-php:latest
ContainerName=parceler-scheduler
Volume=/etc/localtime:/etc/localtime:ro
Volume=storage.volume:/var/www/html
Exec=scheduler
EnvironmentFile=%S/parceler.env
1 change: 1 addition & 0 deletions deploy/quadlet/storage.volume
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Volume]
8 changes: 8 additions & 0 deletions deploy/quadlet/worker.container
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Container]
Pod=parceler.pod
Image=ghcr.io/nethesis/parceler-php:latest
ContainerName=parceler-worker
Volume=/etc/localtime:/etc/localtime:ro
Volume=storage.volume:/var/www/html
Exec=worker
EnvironmentFile=%S/parceler.env
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ services:
extends:
service: php
stop_signal: SIGKILL
command: php artisan queue:listen --tries=3 --timeout=1800
command: worker
environment:
PHP_HOST: php
PHP_PORT: 9000
scheduler:
extends:
service: php
stop_signal: SIGKILL
command: crond -f
command: scheduler
environment:
PHP_HOST: php
PHP_PORT: 9000

0 comments on commit 172f87d

Please sign in to comment.