diff --git a/.env b/.env index 186751e..4af6d1a 100644 --- a/.env +++ b/.env @@ -14,7 +14,7 @@ # https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration # Main user is 1000 on Linux -USER_UID=1000 +UID=1000 PUBLIC_NGINX_PORT=8781 PUBLIC_VARNISH_PORT=8784 PUBLIC_PMA_PORT=8782 diff --git a/Dockerfile b/Dockerfile index 0279b73..5f7d5d0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,9 @@ ARG PHP_VERSION=8.3.14 ARG MYSQL_VERSION=8.0.40 +ARG NGINX_VERSION=1.27.2 ARG SOLR_VERSION=9 ARG VARNISH_VERSION=7.1 -ARG USER_UID=1000 +ARG UID=1000 ####### # PHP # @@ -12,7 +13,7 @@ FROM php:${PHP_VERSION}-fpm-bookworm AS php LABEL org.opencontainers.image.authors="ambroise@rezo-zero.com" -ARG USER_UID +ARG UID ARG COMPOSER_VERSION=2.8.1 ARG PHP_EXTENSION_INSTALLER_VERSION=2.6.0 @@ -24,8 +25,6 @@ ENV APP_FFMPEG_PATH=/usr/bin/ffmpeg ENV MYSQL_HOST=db ENV MYSQL_PORT=3306 -HEALTHCHECK --start-period=30s --interval=1m --timeout=6s CMD bin/console monitor:health -q - COPY --link docker/php/crontab.txt /crontab.txt COPY --link docker/php/wait-for-it.sh /wait-for-it.sh COPY --link docker/php/fpm.d/www.conf ${PHP_INI_DIR}-fpm.d/zz-www.conf @@ -42,13 +41,17 @@ apt-get --quiet --yes --no-install-recommends --verbose-versions install \ ffmpeg rm -rf /var/lib/apt/lists/* -usermod -u ${USER_UID} www-data -groupmod -g ${USER_UID} www-data -echo "www-data ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/www-data +# User +addgroup --gid ${UID} php +adduser --home /home/php --shell /bin/bash --uid ${UID} --gecos php --ingroup php --disabled-password php +echo "php ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/php -/usr/bin/crontab -u www-data /crontab.txt +# App +install --verbose --owner php --group php --mode 0755 --directory /app + +/usr/bin/crontab -u php /crontab.txt chmod +x /wait-for-it.sh -chown -R www-data:www-data /var/www/html +chown -R php:php /app # Php extensions curl -sSLf https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions \ @@ -75,7 +78,7 @@ install-php-extensions \ redis-${PHP_EXTENSION_REDIS_VERSION} EOF -WORKDIR /var/www/html +WORKDIR /app ################### # PHP Development # @@ -105,12 +108,12 @@ apt-get --quiet --yes --purge --autoremove upgrade apt-get --quiet --yes --no-install-recommends --verbose-versions install make rm -rf /var/lib/apt/lists/* # Prepare folder to install composer credentials -install --owner=www-data --group=www-data --mode=755 --directory /var/www/.composer +install --owner=php --group=php --mode=755 --directory /home/php/.composer EOF -VOLUME /var/www/html +VOLUME /app -USER www-data +USER php # If you depend on private Gitlab repositories, you must use a deploy token and username #RUN composer config --global gitlab-token.gitlab.rezo-zero.com ${COMPOSER_DEPLOY_TOKEN_USER} ${COMPOSER_DEPLOY_TOKEN} @@ -138,17 +141,17 @@ COPY --link docker/php/conf.d/php.prod.ini ${PHP_INI_DIR}/conf.d/zz-app.ini COPY --link --chmod=755 docker/php/docker-php-entrypoint /usr/local/bin/docker-php-entrypoint COPY --link --chmod=755 docker/php/docker-cron-entrypoint /usr/local/bin/docker-cron-entrypoint -USER www-data +USER php # Composer -COPY --link --chown=www-data:www-data composer.* symfony.* ./ +COPY --link --chown=php:php composer.* symfony.* ./ RUN < /etc/sudoers.d/nginx + +# App +install --verbose --owner nginx --group nginx --mode 0755 --directory /app +EOF + +ENV NGINX_ENTRYPOINT_QUIET_LOGS=1 +# Config +COPY --link docker/nginx/nginx.conf /etc/nginx/nginx.conf +COPY --link docker/nginx/redirections.conf /etc/nginx/redirections.conf +COPY --link docker/nginx/mime.types /etc/nginx/mime.types +COPY --link docker/nginx/conf.d/_gzip.conf /etc/nginx/conf.d/_gzip.conf +COPY --link docker/nginx/conf.d/_security.conf /etc/nginx/conf.d/_security.conf +COPY --link docker/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf + +WORKDIR /app + + + +############## +# Nginx DEV # +############## + +FROM nginx AS nginx-dev + +# Silence entrypoint logs + +# Declare a volume for development +VOLUME /app + + + +############## +# Nginx PROD # +############## + +FROM nginx AS nginx-prod +# Copy public files from API +COPY --link --from=php-prod --chown=${USER_UID}:${USER_UID} /app/public /app/public +# Only enable healthcheck in production when the app is ready to serve requests on root path +# This could prevent Traefik or an ingress controller to route traffic to the app +#HEALTHCHECK --start-period=1m30s --interval=1m --timeout=6s CMD curl --fail -I http://localhost ######### # MySQL # @@ -183,14 +246,14 @@ FROM mysql:${MYSQL_VERSION} AS mysql LABEL org.opencontainers.image.authors="ambroise@rezo-zero.com" -ARG USER_UID +ARG UID SHELL ["/bin/bash", "-e", "-o", "pipefail", "-c"] RUN <