Skip to content

Commit

Permalink
ci: Simplify dev docker images with no init overhead
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Sep 24, 2024
1 parent 492d0e8 commit a9ba4a4
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 521 deletions.
10 changes: 6 additions & 4 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,17 @@ services:

worker:
<<: *app_template
deploy:
replicas: 1
entrypoint: ["php", "/var/www/html/bin/console", "messenger:consume", "async", "--time-limit=60"]
# Need to restart worker every 10 minutes
restart: unless-stopped
entrypoint: ["php", "/var/www/html/bin/console", "messenger:consume", "async", "--time-limit=600"]

cron:
<<: *app_template
# https://github.com/dubiousjim/dcron/issues/13#issuecomment-1406937781
init: true
entrypoint: ["crond", "-f", "-L", "15"]
restart: unless-stopped
user: root
entrypoint: ["docker-cron-entrypoint"]

nginx:
image: roadiz/nginx-alpine:latest
Expand Down
13 changes: 7 additions & 6 deletions docker/php-fpm-alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ ENV COMPOSER_ALLOW_SUPERUSER=1
ENV APP_ENV=dev
ENV APP_CACHE=0
ENV APP_FFMPEG_PATH=/usr/bin/ffmpeg
ENV MYSQL_HOST=db
ENV MYSQL_PORT=3306

RUN apk add --no-cache shadow make git ffmpeg \
&& usermod -u ${USER_UID} www-data \
Expand All @@ -21,16 +19,19 @@ RUN apk add --no-cache shadow make git ffmpeg \
# Display errors
ADD php.ini /usr/local/etc/php/php.ini
ADD crontab.txt /crontab.txt
ADD wait-for-it.sh /wait-for-it.sh
ADD docker-php-entrypoint /usr/local/bin/docker-php-entrypoint
ADD docker-php-entrypoint-dev /usr/local/bin/docker-php-entrypoint
ADD docker-cron-entrypoint-dev /usr/local/bin/docker-cron-entrypoint

VOLUME /var/www/html
WORKDIR /var/www/html

RUN chown -R www-data:www-data /var/www/html/

RUN ln -s /var/www/html/bin/console /usr/local/bin/console \
&& /usr/bin/crontab -u www-data /crontab.txt \
&& chmod +x /wait-for-it.sh \
&& chmod +x /usr/local/bin/docker-php-entrypoint \
&& chmod +x /usr/local/bin/docker-cron-entrypoint \
&& chown -R www-data:www-data /var/www/html/

USER www-data

VOLUME /var/www/html
25 changes: 25 additions & 0 deletions docker/php-fpm-alpine/docker-cron-entrypoint-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
set -e

env >> /etc/environment

# cron entrypoint must be run as root as it spawns crontab for each system user
if [ "$(id -u)" -ne 0 ]; then
echo "Please run as root"
exit 1
fi

# Print env infos
echo "APP_ENV=${APP_ENV}";
echo "APP_RUNTIME_ENV=${APP_RUNTIME_ENV}";
echo "APP_DEBUG=${APP_DEBUG}";
# Debug infos
/usr/bin/sudo -E -u www-data -- bash -c "echo \"[sudo] APP_ENV=${APP_ENV}\"";
/usr/bin/sudo -E -u www-data -- bash -c "echo \"[sudo] APP_RUNTIME_ENV=${APP_RUNTIME_ENV}\"";
/usr/bin/sudo -E -u www-data -- bash -c "echo \"[sudo] APP_DEBUG=${APP_DEBUG}\"";

# DO NOT Print local env vars to .env.xxx.php file in DEV mode

# Let cron take the wheel
echo "Starting cron in foreground."
/usr/sbin/crond -f -l 8
30 changes: 0 additions & 30 deletions docker/php-fpm-alpine/docker-php-entrypoint

This file was deleted.

9 changes: 9 additions & 0 deletions docker/php-fpm-alpine/docker-php-entrypoint-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
set -e

# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- php-fpm "$@"
fi

exec "$@"
182 changes: 0 additions & 182 deletions docker/php-fpm-alpine/wait-for-it.sh

This file was deleted.

36 changes: 0 additions & 36 deletions docker/php83-fpm-alpine/Dockerfile

This file was deleted.

14 changes: 0 additions & 14 deletions docker/php83-fpm-alpine/crontab.txt

This file was deleted.

30 changes: 0 additions & 30 deletions docker/php83-fpm-alpine/docker-php-entrypoint

This file was deleted.

Loading

0 comments on commit a9ba4a4

Please sign in to comment.