From b8d2ed65ec9616df2a482e798443d33efe42fcc8 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Fri, 25 Oct 2019 20:38:06 +0200 Subject: [PATCH] feat(docker): use supervisord (#3129) --- CHANGELOG.md | 1 + scripts/docker/apache/Dockerfile | 10 +++++--- scripts/docker/apache/supervisord.conf | 30 ++++++++++++++++++++++ scripts/docker/apache2-foreground | 5 ---- scripts/docker/entrypoint.sh | 9 +------ scripts/docker/fpm/Dockerfile | 6 +++-- scripts/docker/fpm/supervisord.conf | 30 ++++++++++++++++++++++ scripts/docker/php-apache/Dockerfile | 6 +++-- scripts/docker/php-apache/supervisord.conf | 30 ++++++++++++++++++++++ 9 files changed, 106 insertions(+), 21 deletions(-) create mode 100644 scripts/docker/apache/supervisord.conf create mode 100644 scripts/docker/fpm/supervisord.conf create mode 100644 scripts/docker/php-apache/supervisord.conf diff --git a/CHANGELOG.md b/CHANGELOG.md index 61e4b08b6..972886dce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Enhancements: +* Use supervisor in docker images * Use JawsDB by default on heroku instances * Add pluralization forms for non-english-like-plural languages, for vue.js translations diff --git a/scripts/docker/apache/Dockerfile b/scripts/docker/apache/Dockerfile index 7887df4b3..c2a309af6 100644 --- a/scripts/docker/apache/Dockerfile +++ b/scripts/docker/apache/Dockerfile @@ -18,7 +18,7 @@ LABEL org.label-schema.build-date=$BUILD_DATE \ RUN apk update && apk upgrade RUN apk add --virtual .build-deps \ curl openssl bash -RUN apk add netcat-openbsd \ +RUN apk add supervisor netcat-openbsd \ #- base php7 php7-intl php7-openssl php7-ctype \ php7-zip php7-zlib \ @@ -114,7 +114,7 @@ RUN set -ex && \ cd /etc/periodic/hourly/ && \ { \ echo '#!/bin/sh'; \ - echo '/usr/bin/php /var/www/monica/artisan schedule:run -v'; \ + echo '/usr/bin/php /var/www/monica/artisan schedule:run -v > /proc/1/fd/1 2> /proc/1/fd/2'; \ } | tee monica && \ chmod a+x monica @@ -127,10 +127,12 @@ ENTRYPOINT ["entrypoint.sh"] # Apache2 RUN apk add apache2 php7-apache2 -COPY scripts/docker/apache2-foreground /usr/local/sbin/ +COPY scripts/docker/apache2-foreground /usr/local/bin/ COPY scripts/docker/000-default.conf /etc/apache2/conf.d/ RUN echo 'LoadModule rewrite_module modules/mod_rewrite.so' > /etc/apache2/conf.d/rewrite.conf RUN echo 'ServerName "monica"' > /etc/apache2/conf.d/hostname.conf EXPOSE 80 -CMD ["apache2-foreground"] + +COPY scripts/docker/apache/supervisord.conf /etc/supervisord.conf +CMD ["supervisord", "-c /etc/supervisord.conf"] diff --git a/scripts/docker/apache/supervisord.conf b/scripts/docker/apache/supervisord.conf new file mode 100644 index 000000000..e1902a234 --- /dev/null +++ b/scripts/docker/apache/supervisord.conf @@ -0,0 +1,30 @@ +[supervisord] +nodaemon=true +user=root + +[program:cron] +command=/usr/sbin/crond -f -l 0 +autostart=true +autorestart=true + +[program:queue] +process_name=%(program_name)s_%(process_num)02d +command=/usr/bin/php /var/www/monica/artisan queue:work --sleep=10 --timeout=0 --tries=3 --queue=default,migration +numprocs=1 +stdout_logfile=/proc/1/fd/1 +stdout_logfile_maxbytes=0 +stderr_logfile=/proc/1/fd/2 +stderr_logfile_maxbytes=0 +autostart=true +autorestart=true +startretries=0 + +[program:httpd] +process_name=%(program_name)s_%(process_num)02d +command=/usr/local/bin/apache2-foreground +stdout_logfile=/proc/1/fd/1 +stdout_logfile_maxbytes=0 +stderr_logfile=/proc/1/fd/2 +stderr_logfile_maxbytes=0 +autostart=true +autorestart=true diff --git a/scripts/docker/apache2-foreground b/scripts/docker/apache2-foreground index 6b2470735..549977483 100755 --- a/scripts/docker/apache2-foreground +++ b/scripts/docker/apache2-foreground @@ -1,10 +1,5 @@ #!/bin/sh -# Run fpm -if [ -f /etc/apache2/conf-enabled/php7.3-fpm.conf ]; then - service php7.3-fpm start -fi - # Run apache2 mkdir -p /run/apache2 rm -f /run/apache2/httpd.pid diff --git a/scripts/docker/entrypoint.sh b/scripts/docker/entrypoint.sh index 4345f7737..8d6418838 100755 --- a/scripts/docker/entrypoint.sh +++ b/scripts/docker/entrypoint.sh @@ -23,7 +23,7 @@ waitfordb() { sleep 3 } -if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm7" ]; then +if expr "$1" : "supervisord" 1>/dev/null; then MONICADIR=/var/www/monica ARTISAN="php ${MONICADIR}/artisan" @@ -61,13 +61,6 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm7" ]; then echo "! Please be careful to backup /var/www/monica/storage/oauth-public.key and /var/www/monica/storage/oauth-private.key files !" fi - # Run cron - if [ -f "/usr/sbin/crond" ]; then - crond -b -l 0 -L /dev/stdout - elif [ -f "/etc/init.d/cron" ]; then - service cron start - fi - fi exec $@ diff --git a/scripts/docker/fpm/Dockerfile b/scripts/docker/fpm/Dockerfile index 2b9542398..1d3900371 100644 --- a/scripts/docker/fpm/Dockerfile +++ b/scripts/docker/fpm/Dockerfile @@ -114,7 +114,7 @@ RUN set -ex && \ cd /etc/periodic/hourly/ && \ { \ echo '#!/bin/sh'; \ - echo '/usr/bin/php /var/www/monica/artisan schedule:run -v'; \ + echo '/usr/bin/php /var/www/monica/artisan schedule:run -v > /proc/1/fd/1 2> /proc/1/fd/2'; \ } | tee monica && \ chmod a+x monica @@ -152,4 +152,6 @@ RUN set -ex && \ STOPSIGNAL SIGQUIT EXPOSE 9000 -CMD ["php-fpm7"] + +COPY scripts/docker/fpm/supervisord.conf /etc/supervisord.conf +CMD ["supervisord", "-c /etc/supervisord.conf"] diff --git a/scripts/docker/fpm/supervisord.conf b/scripts/docker/fpm/supervisord.conf new file mode 100644 index 000000000..4025ec745 --- /dev/null +++ b/scripts/docker/fpm/supervisord.conf @@ -0,0 +1,30 @@ +[supervisord] +nodaemon=true +user=root + +[program:cron] +command=/usr/sbin/crond -f -l 0 +autostart=true +autorestart=true + +[program:queue] +process_name=%(program_name)s_%(process_num)02d +command=/usr/bin/php /var/www/monica/artisan queue:work --sleep=10 --timeout=0 --tries=3 --queue=default,migration +numprocs=1 +stdout_logfile=/proc/1/fd/1 +stdout_logfile_maxbytes=0 +stderr_logfile=/proc/1/fd/2 +stderr_logfile_maxbytes=0 +autostart=true +autorestart=true +startretries=0 + +[program:fpm] +process_name=%(program_name)s_%(process_num)02d +command=/usr/bin/php-fpm7 +stdout_logfile=/proc/1/fd/1 +stdout_logfile_maxbytes=0 +stderr_logfile=/proc/1/fd/2 +stderr_logfile_maxbytes=0 +autostart=true +autorestart=true diff --git a/scripts/docker/php-apache/Dockerfile b/scripts/docker/php-apache/Dockerfile index 7c41eeab7..912b11f69 100644 --- a/scripts/docker/php-apache/Dockerfile +++ b/scripts/docker/php-apache/Dockerfile @@ -114,7 +114,7 @@ RUN set -ex && \ cd /etc/cron.hourly && \ { \ echo '#!/bin/sh'; \ - echo '/usr/bin/php /var/www/monica/artisan schedule:run -v'; \ + echo '/usr/bin/php /var/www/monica/artisan schedule:run -v > /proc/1/fd/1 2> /proc/1/fd/2'; \ } | tee monica && \ chmod a+x monica @@ -129,4 +129,6 @@ RUN a2enconf hostname RUN a2enmod rewrite cache headers EXPOSE 80 -CMD ["apache2-foreground"] + +COPY scripts/docker/php-apache/supervisord.conf /etc/supervisord.conf +CMD ["supervisord", "-c /etc/supervisord.conf"] diff --git a/scripts/docker/php-apache/supervisord.conf b/scripts/docker/php-apache/supervisord.conf new file mode 100644 index 000000000..5944ac483 --- /dev/null +++ b/scripts/docker/php-apache/supervisord.conf @@ -0,0 +1,30 @@ +[supervisord] +nodaemon=true +user=root + +[program:cron] +command=/usr/sbin/cron -f -L 0 +autostart=true +autorestart=true + +[program:queue] +process_name=%(program_name)s_%(process_num)02d +command=/usr/bin/php /var/www/monica/artisan queue:work --sleep=10 --timeout=0 --tries=3 --queue=default,migration +numprocs=1 +stdout_logfile=/proc/1/fd/1 +stdout_logfile_maxbytes=0 +stderr_logfile=/proc/1/fd/2 +stderr_logfile_maxbytes=0 +autostart=true +autorestart=true +startretries=0 + +[program:apache] +process_name=%(program_name)s_%(process_num)02d +command=/usr/local/bin/apache2-foreground +stdout_logfile=/proc/1/fd/1 +stdout_logfile_maxbytes=0 +stderr_logfile=/proc/1/fd/2 +stderr_logfile_maxbytes=0 +autostart=true +autorestart=true