Skip to content

Commit

Permalink
feat: Generate Supervisor configuration in entrypoint scripts and add…
Browse files Browse the repository at this point in the history
… configuration script
  • Loading branch information
MrAnyx committed Jan 4, 2025
1 parent 61acc40 commit 30b0a88
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
12 changes: 10 additions & 2 deletions .docker/entrypoint.dev.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
12 changes: 10 additions & 2 deletions .docker/entrypoint.prod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
8 changes: 0 additions & 8 deletions .docker/supervisord.conf
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
[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
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
Expand Down
14 changes: 14 additions & 0 deletions .docker/supervisord/generate-supervisord-config.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
EXPOSE 80

0 comments on commit 30b0a88

Please sign in to comment.