From 800c42b038f8aa886848f0c5977303c23f0a68f0 Mon Sep 17 00:00:00 2001 From: Jonas Kaninda Date: Sat, 6 Jan 2024 12:15:51 +0100 Subject: [PATCH] Update php version, fix permission issue --- .gitignore | 2 +- README.md | 3 +- build.sh | 2 +- docker-compose.yml | 29 ------------------- example/docker-compose.yml | 3 +- src/docker/7.2/Dockerfile | 18 +++++++----- src/docker/7.3/Dockerfile | 16 +++++++---- src/docker/7.4/Dockerfile | 18 ++++++------ src/docker/8.0/Dockerfile | 18 ++++++------ src/docker/8.1/Dockerfile | 18 +++++++----- src/docker/8.1/Dockerfile.alpine | 6 ++-- src/docker/8.2/Dockerfile | 18 ++++++------ src/docker/8.2/Dockerfile.alpine | 6 ++-- src/docker/8.3/Dockerfile | 21 ++++++++------ src/docker/8.3/Dockerfile.alpine | 6 ++-- src/entrypoint.sh | 49 ++++++++++++++++++-------------- src/supervisor/supervisord.conf | 9 +++--- tests/compose.yaml | 1 + 18 files changed, 125 insertions(+), 118 deletions(-) delete mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore index e24a1a4..260c12b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ /.history -laravel +laravel \ No newline at end of file diff --git a/README.md b/README.md index 36120fc..4ace567 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,8 @@ services: php-fpm: image: jkaninda/laravel-php-fpm:latest container_name: php-fpm - restart: unless-stopped + restart: unless-stopped + user: www-data #Use www-data user production usage volumes: #Project root - ./:/var/www/html diff --git a/build.sh b/build.sh index d980654..94b1177 100755 --- a/build.sh +++ b/build.sh @@ -11,7 +11,7 @@ then docker build -f src/docker/${tag}/Dockerfile -t jkaninda/laravel-php-fpm:$tag . else echo 'Build latest' - docker build -f src/docker/8.2/Dockerfile -t jkaninda/laravel-php-fpm:$tag . + docker build -f src/docker/8.3/Dockerfile -t jkaninda/laravel-php-fpm:$tag . fi diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 5ada036..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,29 +0,0 @@ -version: '3' -services: - php-fpm: - image: jkaninda/laravel-php-fpm:8.3 - container_name: php-fpm - restart: unless-stopped - volumes: - #Project root - - ./laravel:/var/www/html - networks: - - web #if you're using networks between containers - #Nginx server - nginx-server: - image: jkaninda/nginx-fpm:alpine - container_name: nginx-server - restart: unless-stopped - ports: - - 80:80 - volumes: - - ./laravel:/var/www/html - environment: - - DOCUMENT_ROOT=/var/www/html/public - - CLIENT_MAX_BODY_SIZE=20M - - PHP_FPM_HOST=php-fpm:9000 - networks: - - web -networks: - web: - external: false diff --git a/example/docker-compose.yml b/example/docker-compose.yml index 233ac2c..83949eb 100644 --- a/example/docker-compose.yml +++ b/example/docker-compose.yml @@ -3,7 +3,8 @@ services: php-fpm: image: jkaninda/laravel-php-fpm container_name: php-fpm - restart: unless-stopped + restart: unless-stopped + user: www-data #Use www-data user production usage volumes: #Project root - ./:/var/www/html diff --git a/src/docker/7.2/Dockerfile b/src/docker/7.2/Dockerfile index 0cc33c1..caf9250 100644 --- a/src/docker/7.2/Dockerfile +++ b/src/docker/7.2/Dockerfile @@ -3,6 +3,10 @@ ARG WORKDIR=/var/www/html ENV DOCUMENT_ROOT=${WORKDIR} ENV LARAVEL_PROCS_NUMBER=1 ENV NODE_VERSION=16.x +ARG GROUP_ID=1000 +ARG USER_ID=1000 +ENV USER_NAME=www-data +ARG GROUP_NAME=www-data # Install system dependencies RUN apt-get update && apt-get install -y \ git \ @@ -83,12 +87,12 @@ RUN ln -s /usr/local/bin/entrypoint.sh / ENTRYPOINT ["entrypoint.sh"] - - -RUN usermod -u 1000 www-data -RUN groupmod -g 1000 www-data - -RUN chmod -R 755 $WORKDIR -RUN chown -R www-data:www-data $WORKDIR +RUN usermod -u ${USER_ID} ${USER_NAME} +RUN groupmod -g ${USER_ID} ${GROUP_NAME} +RUN chown -R ${USER_NAME}:${GROUP_NAME} /var/www && \ + chown -R ${USER_NAME}:${GROUP_NAME} /var/log/ && \ + chown -R ${USER_NAME}:${GROUP_NAME} /etc/supervisor/conf.d/ && \ + chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/ + EXPOSE 9000 CMD [ "entrypoint" ] diff --git a/src/docker/7.3/Dockerfile b/src/docker/7.3/Dockerfile index dbadef9..9b3b3a4 100644 --- a/src/docker/7.3/Dockerfile +++ b/src/docker/7.3/Dockerfile @@ -3,6 +3,10 @@ ARG WORKDIR=/var/www/html ENV DOCUMENT_ROOT=${WORKDIR} ENV LARAVEL_PROCS_NUMBER=1 ENV NODE_VERSION=16.x +ARG GROUP_ID=1000 +ARG USER_ID=1000 +ENV USER_NAME=www-data +ARG GROUP_NAME=www-data # Install system dependencies RUN apt-get update && apt-get install -y \ git \ @@ -83,12 +87,12 @@ RUN ln -s /usr/local/bin/entrypoint.sh / ENTRYPOINT ["entrypoint.sh"] +RUN usermod -u ${USER_ID} ${USER_NAME} +RUN groupmod -g ${USER_ID} ${GROUP_NAME} +RUN chown -R ${USER_NAME}:${GROUP_NAME} /var/www && \ + chown -R ${USER_NAME}:${GROUP_NAME} /var/log/ && \ + chown -R ${USER_NAME}:${GROUP_NAME} /etc/supervisor/conf.d/ && \ + chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/ - -RUN usermod -u 1000 www-data -RUN groupmod -g 1000 www-data - -RUN chmod -R 755 $WORKDIR -RUN chown -R www-data:www-data $WORKDIR EXPOSE 9000 CMD [ "entrypoint" ] diff --git a/src/docker/7.4/Dockerfile b/src/docker/7.4/Dockerfile index 7651d22..3185ac0 100644 --- a/src/docker/7.4/Dockerfile +++ b/src/docker/7.4/Dockerfile @@ -3,8 +3,10 @@ ARG WORKDIR=/var/www/html ENV DOCUMENT_ROOT=${WORKDIR} ENV LARAVEL_PROCS_NUMBER=1 ENV NODE_VERSION=16.x -ARG HOST_UID=1000 -ENV USER=www-data +ARG GROUP_ID=1000 +ARG USER_ID=1000 +ENV USER_NAME=www-data +ARG GROUP_NAME=www-data # Install system dependencies RUN apt-get update && apt-get install -y \ git \ @@ -86,12 +88,12 @@ RUN ln -s /usr/local/bin/entrypoint.sh / ENTRYPOINT ["entrypoint.sh"] +RUN usermod -u ${USER_ID} ${USER_NAME} +RUN groupmod -g ${USER_ID} ${GROUP_NAME} +RUN chown -R ${USER_NAME}:${GROUP_NAME} /var/www && \ + chown -R ${USER_NAME}:${GROUP_NAME} /var/log/ && \ + chown -R ${USER_NAME}:${GROUP_NAME} /etc/supervisor/conf.d/ && \ + chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/ - -RUN usermod -u ${HOST_UID} www-data -RUN groupmod -g ${HOST_UID} www-data - -RUN chmod -R 755 $WORKDIR -RUN chown -R www-data:www-data $WORKDIR EXPOSE 9000 CMD [ "entrypoint" ] diff --git a/src/docker/8.0/Dockerfile b/src/docker/8.0/Dockerfile index 16b73fd..517d537 100644 --- a/src/docker/8.0/Dockerfile +++ b/src/docker/8.0/Dockerfile @@ -3,8 +3,10 @@ ARG WORKDIR=/var/www/html ENV DOCUMENT_ROOT=${WORKDIR} ENV LARAVEL_PROCS_NUMBER=1 ENV NODE_VERSION=16.x -ARG HOST_UID=1000 -ENV USER=www-data +ARG GROUP_ID=1000 +ARG USER_ID=1000 +ENV USER_NAME=www-data +ARG GROUP_NAME=www-data # Install system dependencies RUN apt-get update && apt-get install -y \ git \ @@ -86,12 +88,12 @@ RUN ln -s /usr/local/bin/entrypoint.sh / ENTRYPOINT ["entrypoint.sh"] +RUN usermod -u ${USER_ID} ${USER_NAME} +RUN groupmod -g ${USER_ID} ${GROUP_NAME} +RUN chown -R ${USER_NAME}:${GROUP_NAME} /var/www && \ + chown -R ${USER_NAME}:${GROUP_NAME} /var/log/ && \ + chown -R ${USER_NAME}:${GROUP_NAME} /etc/supervisor/conf.d/ && \ + chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/ - -RUN usermod -u ${HOST_UID} www-data -RUN groupmod -g ${HOST_UID} www-data - -RUN chmod -R 755 $WORKDIR -RUN chown -R www-data:www-data $WORKDIR EXPOSE 9000 CMD [ "entrypoint" ] diff --git a/src/docker/8.1/Dockerfile b/src/docker/8.1/Dockerfile index 50a1ce0..861fe60 100644 --- a/src/docker/8.1/Dockerfile +++ b/src/docker/8.1/Dockerfile @@ -3,8 +3,10 @@ ARG WORKDIR=/var/www/html ENV DOCUMENT_ROOT=${WORKDIR} ENV LARAVEL_PROCS_NUMBER=1 ENV NODE_VERSION=17.x -ARG HOST_UID=1000 -ENV USER=www-data +ARG GROUP_ID=1000 +ARG USER_ID=1000 +ENV USER_NAME=www-data +ARG GROUP_NAME=www-data # Install system dependencies RUN apt-get update && apt-get install -y \ git \ @@ -85,13 +87,15 @@ COPY src/entrypoint.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/entrypoint.sh RUN ln -s /usr/local/bin/entrypoint.sh / -ENTRYPOINT ["entrypoint.sh"] +ENTRYPOINT ["entrypoint.sh"] -RUN usermod -u ${HOST_UID} www-data -RUN groupmod -g ${HOST_UID} www-data +RUN usermod -u ${USER_ID} ${USER_NAME} +RUN groupmod -g ${USER_ID} ${GROUP_NAME} +RUN chown -R ${USER_NAME}:${GROUP_NAME} /var/www && \ + chown -R ${USER_NAME}:${GROUP_NAME} /var/log/ && \ + chown -R ${USER_NAME}:${GROUP_NAME} /etc/supervisor/conf.d/ && \ + chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/ -RUN chmod -R 755 $WORKDIR -RUN chown -R www-data:www-data $WORKDIR EXPOSE 9000 CMD [ "entrypoint" ] diff --git a/src/docker/8.1/Dockerfile.alpine b/src/docker/8.1/Dockerfile.alpine index c582050..c8d6c12 100644 --- a/src/docker/8.1/Dockerfile.alpine +++ b/src/docker/8.1/Dockerfile.alpine @@ -2,8 +2,10 @@ FROM php:8.1-fpm-alpine ARG WORKDIR=/var/www/html ENV DOCUMENT_ROOT=${WORKDIR} ENV LARAVEL_PROCS_NUMBER=1 -ARG HOST_UID=1000 -ENV USER=www-data +ARG GROUP_ID=1000 +ARG USER_ID=1000 +ENV USER_NAME=www-data +ARG GROUP_NAME=www-data # Install the PHP pdo_mysql extention RUN docker-php-ext-install pdo_mysql diff --git a/src/docker/8.2/Dockerfile b/src/docker/8.2/Dockerfile index 4713f16..a9d7f56 100644 --- a/src/docker/8.2/Dockerfile +++ b/src/docker/8.2/Dockerfile @@ -3,8 +3,10 @@ ARG WORKDIR=/var/www/html ENV DOCUMENT_ROOT=${WORKDIR} ENV LARAVEL_PROCS_NUMBER=1 ENV NODE_MAJOR=20 -ARG HOST_UID=1000 -ENV USER=www-data +ARG GROUP_ID=1000 +ARG USER_ID=1000 +ENV USER_NAME=www-data +ARG GROUP_NAME=www-data # Install system dependencies RUN apt-get update && apt-get install -y \ git \ @@ -88,12 +90,12 @@ RUN ln -s /usr/local/bin/entrypoint.sh / ENTRYPOINT ["entrypoint.sh"] +RUN usermod -u ${USER_ID} ${USER_NAME} +RUN groupmod -g ${USER_ID} ${GROUP_NAME} +RUN chown -R ${USER_NAME}:${GROUP_NAME} /var/www && \ + chown -R ${USER_NAME}:${GROUP_NAME} /var/log/ && \ + chown -R ${USER_NAME}:${GROUP_NAME} /etc/supervisor/conf.d/ && \ + chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/ - -RUN usermod -u ${HOST_UID} www-data -RUN groupmod -g ${HOST_UID} www-data - -RUN chmod -R 755 $WORKDIR -RUN chown -R www-data:www-data $WORKDIR EXPOSE 9000 CMD [ "entrypoint" ] diff --git a/src/docker/8.2/Dockerfile.alpine b/src/docker/8.2/Dockerfile.alpine index 32dd264..f2990d5 100644 --- a/src/docker/8.2/Dockerfile.alpine +++ b/src/docker/8.2/Dockerfile.alpine @@ -2,8 +2,10 @@ FROM php:8.2-fpm-alpine ARG WORKDIR=/var/www/html ENV DOCUMENT_ROOT=${WORKDIR} ENV LARAVEL_PROCS_NUMBER=1 -ARG HOST_UID=1000 -ENV USER=www-data +ARG GROUP_ID=1000 +ARG USER_ID=1000 +ENV USER_NAME=www-data +ARG GROUP_NAME=www-data # Install the PHP pdo_mysql extention RUN docker-php-ext-install pdo_mysql diff --git a/src/docker/8.3/Dockerfile b/src/docker/8.3/Dockerfile index f852fd2..c973bf5 100644 --- a/src/docker/8.3/Dockerfile +++ b/src/docker/8.3/Dockerfile @@ -1,10 +1,12 @@ -FROM php:8.3.0-fpm +FROM php:8.3.1-fpm ARG WORKDIR=/var/www/html ENV DOCUMENT_ROOT=${WORKDIR} ENV LARAVEL_PROCS_NUMBER=1 ENV NODE_MAJOR=20 -ARG HOST_UID=1000 -ENV USER=www-data +ARG GROUP_ID=1000 +ARG USER_ID=1000 +ENV USER_NAME=www-data +ARG GROUP_NAME=www-data # Install system dependencies RUN apt-get update && apt-get install -y \ git \ @@ -86,14 +88,15 @@ COPY src/entrypoint.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/entrypoint.sh RUN ln -s /usr/local/bin/entrypoint.sh / -ENTRYPOINT ["entrypoint.sh"] - +ENTRYPOINT ["entrypoint.sh"] -RUN usermod -u ${HOST_UID} www-data -RUN groupmod -g ${HOST_UID} www-data +RUN usermod -u ${USER_ID} ${USER_NAME} +RUN groupmod -g ${USER_ID} ${GROUP_NAME} +RUN chown -R ${USER_NAME}:${GROUP_NAME} /var/www && \ + chown -R ${USER_NAME}:${GROUP_NAME} /var/log/ && \ + chown -R ${USER_NAME}:${GROUP_NAME} /etc/supervisor/conf.d/ && \ + chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/ -RUN chmod -R 755 $WORKDIR -RUN chown -R www-data:www-data $WORKDIR EXPOSE 9000 CMD [ "entrypoint" ] diff --git a/src/docker/8.3/Dockerfile.alpine b/src/docker/8.3/Dockerfile.alpine index 8a87db6..c1061d4 100644 --- a/src/docker/8.3/Dockerfile.alpine +++ b/src/docker/8.3/Dockerfile.alpine @@ -2,8 +2,10 @@ FROM php:8.3-fpm-alpine ARG WORKDIR=/var/www/html ENV DOCUMENT_ROOT=${WORKDIR} ENV LARAVEL_PROCS_NUMBER=1 -ARG HOST_UID=1000 -ENV USER=www-data +ARG GROUP_ID=1000 +ARG USER_ID=1000 +ENV USER_NAME=www-data +ARG GROUP_NAME=www-data # Install the PHP pdo_mysql extention RUN docker-php-ext-install pdo_mysql diff --git a/src/entrypoint.sh b/src/entrypoint.sh index 47568e3..ab1af68 100644 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -1,16 +1,27 @@ -#!/bin/sh -Red='\033[0;31m' # Red -Green='\033[0;32m' # Green +#!/bin/bash + echo "" echo "***********************************************************" echo " Starting LARAVEL PHP-FPM Container " echo "***********************************************************" set -e - +info() { + { set +x; } 2> /dev/null + echo '[INFO] ' "$@" +} +warning() { + { set +x; } 2> /dev/null + echo '[WARNING] ' "$@" +} +fatal() { + { set +x; } 2> /dev/null + echo '[ERROR] ' "$@" >&2 + exit 1 +} ## Check if the artisan file exists if [ -f /var/www/html/artisan ]; then - echo "${Green} artisan file found, creating laravel supervisor config..." + info "Artisan file found, creating laravel supervisor config..." ##Create Laravel Scheduler process TASK=/etc/supervisor/conf.d/laravel-worker.conf touch $TASK @@ -21,7 +32,7 @@ if [ -f /var/www/html/artisan ]; then autostart=true autorestart=true numprocs=1 - user=www-data + user=$USER_NAME stdout_logfile=/var/log/laravel_scheduler.out.log redirect_stderr=true @@ -31,36 +42,32 @@ if [ -f /var/www/html/artisan ]; then autostart=true autorestart=true numprocs=$LARAVEL_PROCS_NUMBER - user=www-data + user=$USER_NAME redirect_stderr=true stdout_logfile=/var/log/laravel_worker.log EOF -echo "${Green} Laravel supervisor config created" +info "Laravel supervisor config created" else - echo "${Red} artisan file not found" + info "artisan file not found" fi ## Check if the supervisor config file exists if [ -f /var/www/html/conf/worker/supervisor.conf ]; then - echo "additional supervisor config found" + info "additional supervisor config found" cp /var/www/html/conf/worker/supervisor.conf /etc/supervisor/conf.d/supervisor.conf else - echo "${Red} Supervisor.conf not found" - echo "${Green} If you want to add more supervisor configs, create config file in /var/www/html/conf/worker/supervisor.conf" - echo "${Green} Start supervisor with default config..." + info "Supervisor.conf not found" + info "If you want to add more supervisor configs, create config file in /var/www/html/conf/worker/supervisor.conf" + info "Start supervisor with default config..." fi ## Check if php.ini file exists if [ -f /var/www/html/conf/php/php.ini ]; then cp /var/www/html/conf/php/php.ini $PHP_INI_DIR/conf.d/ - echo "Custom php.ini file found and copied in $PHP_INI_DIR/conf.d/" + info "Custom php.ini file found and copied in $PHP_INI_DIR/conf.d/" else - echo "Custom php.ini file not found" - echo "If you want to add a custom php.ini file, you add it in /var/www/html/conf/php/php.ini" + info "Custom php.ini file not found" + info "If you want to add a custom php.ini file, you add it in /var/www/html/conf/php/php.ini" fi -echo "" -echo "**********************************" -echo " Starting Supervisord... " -echo "***********************************" supervisord -c /etc/supervisor/supervisord.conf - +exec "$@" \ No newline at end of file diff --git a/src/supervisor/supervisord.conf b/src/supervisor/supervisord.conf index f528f16..bcdfaa7 100644 --- a/src/supervisor/supervisord.conf +++ b/src/supervisor/supervisord.conf @@ -1,9 +1,8 @@ [supervisord] nodaemon=true -user=root +#user=root +user=%(ENV_USER_NAME)s logfile=/var/log/supervisor/supervisord.log -pidfile=/var/run/supervisord.pid - [program:php-fpm] command=/usr/local/sbin/php-fpm @@ -12,8 +11,8 @@ autostart=true autorestart=true stderr_logfile=/var/log/php-fpm_consumer.err.log stdout_logfile=/var/log/php-fpm_consumer.out.log -user=root -priority=100 +user=www-data +priority=1 [include] diff --git a/tests/compose.yaml b/tests/compose.yaml index 053d2d4..53b658b 100644 --- a/tests/compose.yaml +++ b/tests/compose.yaml @@ -15,6 +15,7 @@ services: image: jkaninda/laravel-php-fpm:latest container_name: php-fpm restart: unless-stopped + user: www-data #Use www-data user production usage depends_on: - mysql environment: