From 30b0a885a1729cf3cc5af8584ecf2629ab44a193 Mon Sep 17 00:00:00 2001 From: MrAnyx Date: Sat, 4 Jan 2025 15:37:35 +0000 Subject: [PATCH] feat: Generate Supervisor configuration in entrypoint scripts and add configuration script --- .docker/entrypoint.dev.sh | 12 ++++++++++-- .docker/entrypoint.prod.sh | 12 ++++++++++-- .docker/supervisord.conf | 8 -------- .docker/supervisord/generate-supervisord-config.sh | 14 ++++++++++++++ Dockerfile | 2 +- 5 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 .docker/supervisord/generate-supervisord-config.sh diff --git a/.docker/entrypoint.dev.sh b/.docker/entrypoint.dev.sh index ef5a1c6..9c5b65f 100644 --- a/.docker/entrypoint.dev.sh +++ b/.docker/entrypoint.dev.sh @@ -1,11 +1,19 @@ #!/bin/bash set -e +echo "Generating Supervisor configuration..." +SUPERVISORD_CONF="/etc/supervisor/conf.d/supervisord.conf" +ENV_VARS=$(printenv | sed 's/^\(.*\)$/\1/' | tr '\n' ',' | sed 's/,$//') +echo "" >> $SUPERVISORD_CONF +echo "[supervisord]" >> $SUPERVISORD_CONF +echo "nodaemon=true" >> $SUPERVISORD_CONF +echo "logfile=/dev/null" >> $SUPERVISORD_CONF +echo "logfile_maxbytes=0" >> $SUPERVISORD_CONF +echo "environment=${ENV_VARS}" >> $SUPERVISORD_CONF + # Update and start supervisor service echo "Starting supervisor..." service supervisor start supervisorctl reread supervisorctl update supervisorctl restart all - -exec docker-php-entrypoint "$@" \ No newline at end of file diff --git a/.docker/entrypoint.prod.sh b/.docker/entrypoint.prod.sh index 332c615..0f46bdd 100644 --- a/.docker/entrypoint.prod.sh +++ b/.docker/entrypoint.prod.sh @@ -5,11 +5,19 @@ set -e echo "Running database migrations..." php bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration +# Generate Supervisor configuration +echo "Generating Supervisor configuration..." +SUPERVISORD_CONF="/etc/supervisor/conf.d/supervisord.conf" +ENV_VARS=$(printenv | sed 's/^\(.*\)$/\1/' | tr '\n' ',' | sed 's/,$//') +echo "[supervisord]" >> $SUPERVISORD_CONF +echo "nodaemon=true" >> $SUPERVISORD_CONF +echo "logfile=/dev/null" >> $SUPERVISORD_CONF +echo "logfile_maxbytes=0" >> $SUPERVISORD_CONF +echo "environment=${ENV_VARS}" >> $SUPERVISORD_CONF + # Update and start supervisor service echo "Starting supervisor..." service supervisor start supervisorctl reread supervisorctl update supervisorctl restart all - -exec docker-php-entrypoint "$@" \ No newline at end of file diff --git a/.docker/supervisord.conf b/.docker/supervisord.conf index 3dfc1f3..8db28d6 100644 --- a/.docker/supervisord.conf +++ b/.docker/supervisord.conf @@ -1,9 +1,3 @@ -[supervisord] -nodaemon=true -logfile=/dev/null -logfile_maxbytes=0 -environment=APP_ENV="%(APP_ENV)s",APP_SECRET="%(ENV_APP_SECRET)s",MAILER_DSN="%(ENV_MAILER_DSN)s",CORS_ALLOW_ORIGIN="%(ENV_CORS_ALLOW_ORIGIN)s",NOREPLY_SENDER="%(ENV_NOREPLY_SENDER)s",DATABASE_URL="%(ENV_DATABASE_URL)s",MESSENGER_TRANSPORT_DSN="%(ENV_MESSENGER_TRANSPORT_DSN)s",LOCK_DSN="%(ENV_LOCK_DSN)s" - [program:env] command=env stdout_logfile=/dev/stdout @@ -11,9 +5,7 @@ stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 autorestart=false -startsecs=0 autostart=true -startretries=10 [program:apache] command=apache2-foreground diff --git a/.docker/supervisord/generate-supervisord-config.sh b/.docker/supervisord/generate-supervisord-config.sh new file mode 100644 index 0000000..a570264 --- /dev/null +++ b/.docker/supervisord/generate-supervisord-config.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Original supervisord configuration template +SUPERVISORD_CONF="/etc/supervisor/conf.d/supervisord.conf" + +# Get all host environment variables and format them for supervisord +ENV_VARS=$(printenv | sed 's/^\(.*\)$/\1/' | tr '\n' ',' | sed 's/,$//') + +# Create the final supervisord configuration +echo "[supervisord]" >> $SUPERVISORD_CONF +echo "nodaemon=true" >> $SUPERVISORD_CONF +echo "logfile=/dev/null" >> $SUPERVISORD_CONF +echo "logfile_maxbytes=0" >> $SUPERVISORD_CONF +echo "environment=${ENV_VARS}" >> $SUPERVISORD_CONF diff --git a/Dockerfile b/Dockerfile index 872d339..00d283b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,4 +30,4 @@ RUN composer install --no-dev --optimize-autoloader --no-interaction RUN php bin/console cache:clear && php bin/console cache:warmup RUN composer dump-env prod --empty RUN chown -R www-data:www-data ./var -EXPOSE 80 \ No newline at end of file +EXPOSE 80