Skip to content

Instantly share code, notes, and snippets.

@thedomeffm
Last active May 12, 2023 06:22
Show Gist options
  • Save thedomeffm/4e98fa8db1b4b271628ea3f9de67f4c9 to your computer and use it in GitHub Desktop.
Save thedomeffm/4e98fa8db1b4b271628ea3f9de67f4c9 to your computer and use it in GitHub Desktop.
Symfony Messenger | Digitalocean App Platform | Dockerfile | Supervisor
FROM composer:2.5 AS build
WORKDIR /application
ENV APP_ENV=prod
COPY . .
RUN composer install --no-dev --no-scripts --ignore-platform-reqs --optimize-autoloader
FROM php:8.1-cli-bullseye
WORKDIR /application
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get -y --no-install-recommends install -y \
apt-transport-https \
ca-certificates \
libicu-dev \
libicu-dev \
libpng-dev \
libzip-dev \
software-properties-common \
wget \
zlib1g-dev \
curl \
git \
openssl \
unzip \
supervisor \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /etc/cron.*/*
RUN docker-php-ext-install -j$(nproc) intl \
&& docker-php-ext-install -j$(nproc) opcache \
&& docker-php-ext-install -j$(nproc) zip \
&& docker-php-ext-install -j$(nproc) pdo_mysql \
&& docker-php-ext-install -j$(nproc) pcntl
COPY entrypoint.sh /entrypoint.sh
COPY --from=build /application /application
RUN chmod +x /entrypoint.sh \
&& mv supervisord.conf /etc/supervisor/supervisord.conf \
&& mv worker.conf /etc/supervisor/conf.d/app.conf \
&& ls -la /etc/supervisor/conf.d
RUN APP_ENV=prod APP_DEBUG=0 php bin/console cache:clear
ENTRYPOINT ["/entrypoint.sh"]
CMD ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]
#!/bin/sh
env >> /etc/environment
# execute CMD
echo "$@"
exec "$@"
[unix_http_server]
file=/tmp/supervisor.sock
chmod=0700
[supervisord]
nodaemon=true
logfile=/tmp/supervisord.log
pidfile=/tmp/supervisord.pid
[rpcinterface:supervisor]
supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock
[include]
files = /etc/supervisor/conf.d/*.conf
[program:worker]
command=php /application/bin/console messenger:consume async --time-limit=360 --limit=10 --memory-limit=256M
autorestart=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true
@thedomeffm
Copy link
Author

Security or performance is not an important specification for this worker because it is running in "worker" mode - not connected to the internet.

@wweevv-johndpope
Copy link

missing entrypoint.sh
I have a designer who is recommending using bedrock + roots - I'm investigating - I have aws + lightsail ($5 / mth) currently all working -
what do you recommend ? switch to digital ocean? I need terminal access + ssl / letsencrypt.

@thedomeffm
Copy link
Author

@wweevv-johndpope I've added the entrypoint.sh


I do not want to make blanket recommendations. All providers have their advantages and disadvantages.

AWS Lightsail is a cheap service, but as soon as you switch to the more professional solutions (especially for databases), it gets really expensive.

DigitalOcean App Platform takes care of SSL (if you connect your domain correctly) and you have access to a terminal.
Oh, and you don't need a Dockerfile at App Platform for most projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment