Skip to content

Commit cd48561

Browse files
chore: Run Symfony Messenger worker with a Docker service
1 parent 2999aef commit cd48561

File tree

9 files changed

+99
-38
lines changed

9 files changed

+99
-38
lines changed

app/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ COPY docker/conf/cron/agentj /etc/cron.d/agentj
9090
COPY docker/conf/nginx/nginx.conf /etc/nginx/sites-enabled/default
9191
COPY docker/conf/php-fpm/www.conf /etc/php/8.2/fpm/pool.d/www.conf
9292
COPY docker/conf/supervisor/supervisord.conf /etc/supervisord.conf
93+
COPY docker/setup-env.sh /setup-env.sh
9394
COPY docker/entrypoint.sh /entrypoint.sh
95+
COPY docker/entrypoint-worker.sh /entrypoint-worker.sh
9496
COPY docker/files/amavisd-release /usr/local/bin/amavisd-release
9597

9698
EXPOSE 9000

app/Dockerfile.dev

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ COPY docker/conf/cron/agentj /etc/cron.d/agentj
5555
COPY docker/conf/nginx/nginx.conf /etc/nginx/sites-enabled/default
5656
COPY docker/conf/php-fpm/www.conf /etc/php/8.2/fpm/pool.d/www.conf
5757
COPY docker/conf/supervisor/supervisord.conf /etc/supervisord.conf
58+
COPY docker/setup-env.sh /setup-env.sh
5859
COPY docker/entrypoint.sh /entrypoint.sh
60+
COPY docker/entrypoint-worker.sh /entrypoint-worker.sh
5961
COPY docker/files/amavisd-release /usr/local/bin/amavisd-release
6062

6163
EXPOSE 9000

app/docker/conf/supervisor/supervisord.conf

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,3 @@ startsecs=0
4444
redirect_stderr=true
4545
stdout_logfile=/dev/stdout
4646
stdout_logfile_maxbytes=0
47-
48-
[program:sf-messenger-consume]
49-
command=php bin/console messenger:consume async scheduler_default --memory-limit=128M
50-
directory=/var/www/agentj
51-
user=www-data
52-
autostart=true
53-
autorestart=false
54-
redirect_stderr=true
55-
stdout_logfile=/dev/stdout
56-
stdout_logfile_maxbytes=0

app/docker/entrypoint-worker.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
set -e
3+
4+
sh /setup-env.sh
5+
6+
sed -i 's|memory_limit = 128M|memory_limit = 512M|g' /etc/php/8.2/cli/php.ini
7+
8+
cd /var/www/agentj || exit 4
9+
10+
if [ -x "$(which composer)" ] ; then
11+
echo "Installing libraries"
12+
sudo -u www-data composer install --ignore-platform-reqs --no-scripts
13+
fi
14+
15+
# Allow web server user to write Symphony logs
16+
chown -R www-data:www-data /var/www/agentj/var
17+
18+
if [ ! -d /var/log/agentj ]; then
19+
mkdir /var/log/agentj && chown -R www-data /var/log/agentj
20+
fi
21+
22+
cd /
23+
24+
exec "$@"

app/docker/entrypoint.sh

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,8 @@
11
#!/bin/sh
22
set -e
33

4-
env_file=/var/www/agentj/.env
5-
cp /var/www/agentj/.env.example $env_file
6-
sed -i "s|\$AGENTJ_VERSION|$VERSION|g" $env_file
7-
sed -i "s|\$SF_APP_ENV|$SF_APP_ENV|g" $env_file
8-
sed -i "s|\$SF_APP_SECRET|$SF_APP_SECRET|g" $env_file
9-
sed -i "s|\$SF_TOKEN_ENCRYPTION_IV|$SF_TOKEN_ENCRYPTION_IV|g" $env_file
10-
sed -i "s|\$SF_TOKEN_ENCRYPTION_SALT|$SF_TOKEN_ENCRYPTION_SALT|g" $env_file
11-
sed -i "s|\$SF_SENTRY_DSN|$SF_SENTRY_DSN|g" $env_file
12-
sed -i "s|\$DB_NAME|$DB_NAME|g" $env_file
13-
sed -i "s|\$DB_USER|$DB_USER|g" $env_file
14-
sed -i "s|\$DB_PASSWORD|$DB_PASSWORD|g" $env_file
15-
sed -i "s|\$DB_HOST|$DB_HOST|g" $env_file
16-
sed -i "s|\$APP_URL|$APP_URL|g" $env_file
17-
sed -i "s|\$SMTP_FROM|$SMTP_FROM|g" $env_file
18-
sed -i "s|\$ENABLE_AZURE_OAUTH|$ENABLE_AZURE_OAUTH|g" $env_file
19-
sed -i "s|\$OAUTH_AZURE_CLIENT_ID|$OAUTH_AZURE_CLIENT_ID|g" $env_file
20-
sed -i "s|\$OAUTH_AZURE_CLIENT_SECRET|$OAUTH_AZURE_CLIENT_SECRET|g" $env_file
21-
sed -i "s|\$ENABLE_OAUTH|$ENABLE_OAUTH|g" $env_file
22-
sed -i "s|\$OAUTH_CLIENT_ID|$OAUTH_CLIENT_ID|g" $env_file
23-
sed -i "s|\$OAUTH_CLIENT_SECRET|$OAUTH_CLIENT_SECRET|g" $env_file
24-
sed -i "s|\$OAUTH_URL_AUTHORIZE|$OAUTH_URL_AUTHORIZE|g" $env_file
25-
sed -i "s|\$OAUTH_URL_ACCESS_TOKEN|$OAUTH_URL_ACCESS_TOKEN|g" $env_file
26-
sed -i "s|\$OAUTH_URL_RESOURCE_OWNER_DETAILS|$OAUTH_URL_RESOURCE_OWNER_DETAILS|g" $env_file
27-
sed -i "s|\$OAUTH_SCOPES|$OAUTH_SCOPES|g" $env_file
28-
sed -i "s|\$OAUTH_LOGIN_LABEL|$OAUTH_LOGIN_LABEL|g" $env_file
29-
sed -i "s|\$TRUSTED_PROXIES|$TRUSTED_PROXIES|g" $env_file
30-
sed -i "s|\$TZ|$TZ|g" $env_file
31-
sed -i "s|\$DEFAULT_LOCALE|$DEFAULT_LOCALE|g" $env_file
4+
sh /setup-env.sh
5+
326
sed -i 's|memory_limit = 128M|memory_limit = 512M|g' /etc/php/8.2/cli/php.ini
337

348
cd /var/www/agentj || exit 4

app/docker/setup-env.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
env_file=/var/www/agentj/.env
6+
cp /var/www/agentj/.env.example $env_file
7+
sed -i "s|\$AGENTJ_VERSION|$VERSION|g" $env_file
8+
sed -i "s|\$SF_APP_ENV|$SF_APP_ENV|g" $env_file
9+
sed -i "s|\$SF_APP_SECRET|$SF_APP_SECRET|g" $env_file
10+
sed -i "s|\$SF_TOKEN_ENCRYPTION_IV|$SF_TOKEN_ENCRYPTION_IV|g" $env_file
11+
sed -i "s|\$SF_TOKEN_ENCRYPTION_SALT|$SF_TOKEN_ENCRYPTION_SALT|g" $env_file
12+
sed -i "s|\$SF_SENTRY_DSN|$SF_SENTRY_DSN|g" $env_file
13+
sed -i "s|\$DB_NAME|$DB_NAME|g" $env_file
14+
sed -i "s|\$DB_USER|$DB_USER|g" $env_file
15+
sed -i "s|\$DB_PASSWORD|$DB_PASSWORD|g" $env_file
16+
sed -i "s|\$DB_HOST|$DB_HOST|g" $env_file
17+
sed -i "s|\$APP_URL|$APP_URL|g" $env_file
18+
sed -i "s|\$SMTP_FROM|$SMTP_FROM|g" $env_file
19+
sed -i "s|\$ENABLE_AZURE_OAUTH|$ENABLE_AZURE_OAUTH|g" $env_file
20+
sed -i "s|\$OAUTH_AZURE_CLIENT_ID|$OAUTH_AZURE_CLIENT_ID|g" $env_file
21+
sed -i "s|\$OAUTH_AZURE_CLIENT_SECRET|$OAUTH_AZURE_CLIENT_SECRET|g" $env_file
22+
sed -i "s|\$ENABLE_OAUTH|$ENABLE_OAUTH|g" $env_file
23+
sed -i "s|\$OAUTH_CLIENT_ID|$OAUTH_CLIENT_ID|g" $env_file
24+
sed -i "s|\$OAUTH_CLIENT_SECRET|$OAUTH_CLIENT_SECRET|g" $env_file
25+
sed -i "s|\$OAUTH_URL_AUTHORIZE|$OAUTH_URL_AUTHORIZE|g" $env_file
26+
sed -i "s|\$OAUTH_URL_ACCESS_TOKEN|$OAUTH_URL_ACCESS_TOKEN|g" $env_file
27+
sed -i "s|\$OAUTH_URL_RESOURCE_OWNER_DETAILS|$OAUTH_URL_RESOURCE_OWNER_DETAILS|g" $env_file
28+
sed -i "s|\$OAUTH_SCOPES|$OAUTH_SCOPES|g" $env_file
29+
sed -i "s|\$OAUTH_LOGIN_LABEL|$OAUTH_LOGIN_LABEL|g" $env_file
30+
sed -i "s|\$TRUSTED_PROXIES|$TRUSTED_PROXIES|g" $env_file
31+
sed -i "s|\$TZ|$TZ|g" $env_file
32+
sed -i "s|\$DEFAULT_LOCALE|$DEFAULT_LOCALE|g" $env_file

compose.dev.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ services:
3030
ipv4_address: 172.28.2.1
3131
working_dir: /var/www/agentj
3232

33+
worker:
34+
build:
35+
context: app/
36+
dockerfile: Dockerfile.dev
37+
args:
38+
- UID
39+
- GID
40+
volumes:
41+
- ./app/:/var/www/agentj
42+
- ./app/var:/var/www/agentj/var
43+
- ./app/public/files:/var/www/agentj/public/files
44+
3345
watcher:
3446
image: node:18-alpine
3547
user: ${UID}:${GID}

docker-compose.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@ services:
6868
- var:/var/www/agentj/var
6969
- files:/var/www/agentj/public/files
7070

71+
worker:
72+
image: probesys38/agentj_app:$VERSION
73+
build:
74+
context: ./app
75+
command: "php /var/www/agentj/bin/console messenger:consume async scheduler_default --memory-limit=128M"
76+
entrypoint: "/entrypoint-worker.sh"
77+
restart: unless-stopped
78+
env_file:
79+
- .env
80+
depends_on:
81+
- app
82+
volumes:
83+
- var:/var/www/agentj/var
84+
- files:/var/www/agentj/public/files
85+
7186
smtp:
7287
image: probesys38/agentj_smtp:$VERSION
7388
build:

docs/administrators/deploy.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ $ docker compose up
3636
3737
You can then access the web interface to configure your email domain.
3838

39+
## Optional: Run several workers
40+
41+
If the application starts to struggle with processing the asynchronous tasks (e.g. releasing Amavis messages or sending emails), you can run more workers in parallel using this command:
42+
43+
```console
44+
$ docker compose up -d --scale worker=X
45+
```
46+
47+
Where `X` is the number of workers to run.
48+
3949
## Upgrade
4050

4151
> [!IMPORTANT]

0 commit comments

Comments
 (0)