Skip to content

Commit

Permalink
feat: Refactor Supervisor configuration generation and update environ…
Browse files Browse the repository at this point in the history
…ment variables handling
  • Loading branch information
MrAnyx committed Jan 4, 2025
1 parent 2e744cd commit 1c051c0
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 26 deletions.
10 changes: 2 additions & 8 deletions .docker/entrypoint.dev.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
#!/bin/bash
set -e

# Generate Supervisor configuration
echo "Generating Supervisor configuration..."
SUPERVISORD_CONF="/etc/supervisor/conf.d/supervisord.conf"
ENV_VARS=$(printenv | awk -F= '{print $1"=\""$2"\","}' | tr -d '\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
exec /usr/local/bin/generate-supervisord-config.sh

# Update and start supervisor service
echo "Starting supervisor..."
Expand Down
11 changes: 1 addition & 10 deletions .docker/entrypoint.prod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,8 @@ 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 | awk -F= '{print $1"=\""$2"\","}' | tr -d '\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
exec /usr/local/bin/generate-supervisord-config.sh

# Update and start supervisor service
echo "Starting supervisor..."
Expand Down
10 changes: 4 additions & 6 deletions .docker/supervisord/generate-supervisord-config.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/bin/bash

# Original supervisord configuration template
# Generate Supervisor configuration
echo "Generating Supervisor configuration..."
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
ENV_VARS=$(printenv | awk -F= '{print $1"=\""$2"\","}' | tr -d '\n' | sed 's/,$//')
echo "" >> $SUPERVISORD_CONF
echo "[supervisord]" >> $SUPERVISORD_CONF
echo "nodaemon=true" >> $SUPERVISORD_CONF
echo "logfile=/dev/null" >> $SUPERVISORD_CONF
Expand Down
6 changes: 4 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ APP_SECRET=ChangeMe
MAILER_DSN=smtp://mailer:25
CORS_ALLOW_ORIGIN=*
NOREPLY_SENDER=noreply@example.com
DATABASE_URL=postgresql://user:password@database:5432/meeio?serverVersion=16.4&charset=utf8
MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
DATABASE_URL=postgresql://user:password@database:5432/meeio
DATABASE_CHARSET=utf8
DATABASE_VERSION=16.4
MESSENGER_TRANSPORT_DSN=doctrine://default
LOCK_DSN=flock
# TRUSTED_PROXIES=127.0.0.1,REMOTE_ADDR
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RUN install-php-extensions @composer
ENV COMPOSER_ALLOW_SUPERUSER=1
COPY ./.docker/apache/apache.conf /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite
COPY -chmod=755 ./.docker/supervisord/generate-supervisord-config.sh /usr/local/bin/generate-supervisord-config.sh
COPY ./.docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ]

Expand Down
2 changes: 2 additions & 0 deletions config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
doctrine:
dbal:
url: "%env(resolve:DATABASE_URL)%"
server_version: "%env(resolve:DATABASE_VERSION)%"
charset: "%env(resolve:DATABASE_CHARSET)%"

# To be able to validate the database schema with the entities without having error in the doctrine_migration_version table
# schema_filter: ~^(?!doctrine_migration_versions)~
Expand Down
2 changes: 2 additions & 0 deletions config/packages/messenger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ framework:
# https://symfony.com/doc/current/messenger.html#transport-configuration
async:
dsn: "%env(MESSENGER_TRANSPORT_DSN)%"
options:
auto_setup: false
retry_strategy:
max_retries: 5
delay: 3000
Expand Down

0 comments on commit 1c051c0

Please sign in to comment.