diff --git a/Dockerfiles/base/data/php-fpm.d/pool.conf b/Dockerfiles/base/data/php-fpm.d/pool.conf index 1ed4f1a..0d2f199 100644 --- a/Dockerfiles/base/data/php-fpm.d/pool.conf +++ b/Dockerfiles/base/data/php-fpm.d/pool.conf @@ -1,18 +1,5 @@ [www] -; User and Group -user = devilbox -group = devilbox - -; Ensure to listen here -listen = 9000 - -; Keep env variables set by docker -clear_env = no - -; Ensure worker stdout and stderr are sent to the main error log. -catch_workers_output = yes - ; Pool config pm = dynamic pm.max_children = 5 diff --git a/Dockerfiles/prod/Dockerfile-5.4 b/Dockerfiles/prod/Dockerfile-5.4 index 53bad65..8ae6806 100644 --- a/Dockerfiles/prod/Dockerfile-5.4 +++ b/Dockerfiles/prod/Dockerfile-5.4 @@ -58,6 +58,7 @@ COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf ### Volumes ### VOLUME /etc/php-custom.d +VOLUME /etc/php-fpm-custom.d VOLUME /etc/php-modules.d VOLUME /var/log/php VOLUME /var/mail diff --git a/Dockerfiles/prod/Dockerfile-5.5 b/Dockerfiles/prod/Dockerfile-5.5 index 530b615..df204b8 100644 --- a/Dockerfiles/prod/Dockerfile-5.5 +++ b/Dockerfiles/prod/Dockerfile-5.5 @@ -58,6 +58,7 @@ COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf ### Volumes ### VOLUME /etc/php-custom.d +VOLUME /etc/php-fpm-custom.d VOLUME /etc/php-modules.d VOLUME /var/log/php VOLUME /var/mail diff --git a/Dockerfiles/prod/Dockerfile-5.6 b/Dockerfiles/prod/Dockerfile-5.6 index e84ac60..c920672 100644 --- a/Dockerfiles/prod/Dockerfile-5.6 +++ b/Dockerfiles/prod/Dockerfile-5.6 @@ -58,6 +58,7 @@ COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf ### Volumes ### VOLUME /etc/php-custom.d +VOLUME /etc/php-fpm-custom.d VOLUME /etc/php-modules.d VOLUME /var/log/php VOLUME /var/mail diff --git a/Dockerfiles/prod/Dockerfile-7.0 b/Dockerfiles/prod/Dockerfile-7.0 index 6992be6..6d61515 100644 --- a/Dockerfiles/prod/Dockerfile-7.0 +++ b/Dockerfiles/prod/Dockerfile-7.0 @@ -58,6 +58,7 @@ COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf ### Volumes ### VOLUME /etc/php-custom.d +VOLUME /etc/php-fpm-custom.d VOLUME /etc/php-modules.d VOLUME /var/log/php VOLUME /var/mail diff --git a/Dockerfiles/prod/Dockerfile-7.1 b/Dockerfiles/prod/Dockerfile-7.1 index e44ca40..ee4d98b 100644 --- a/Dockerfiles/prod/Dockerfile-7.1 +++ b/Dockerfiles/prod/Dockerfile-7.1 @@ -58,6 +58,7 @@ COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf ### Volumes ### VOLUME /etc/php-custom.d +VOLUME /etc/php-fpm-custom.d VOLUME /etc/php-modules.d VOLUME /var/log/php VOLUME /var/mail diff --git a/Dockerfiles/prod/Dockerfile-7.2 b/Dockerfiles/prod/Dockerfile-7.2 index 40f6f2c..bae41cd 100644 --- a/Dockerfiles/prod/Dockerfile-7.2 +++ b/Dockerfiles/prod/Dockerfile-7.2 @@ -58,6 +58,7 @@ COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf ### Volumes ### VOLUME /etc/php-custom.d +VOLUME /etc/php-fpm-custom.d VOLUME /etc/php-modules.d VOLUME /var/log/php VOLUME /var/mail diff --git a/Dockerfiles/prod/data/docker-entrypoint.d/36-custom-php-fpm-files.sh b/Dockerfiles/prod/data/docker-entrypoint.d/36-custom-php-fpm-files.sh new file mode 100755 index 0000000..6536bed --- /dev/null +++ b/Dockerfiles/prod/data/docker-entrypoint.d/36-custom-php-fpm-files.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +set -e +set -u +set -o pipefail + + +############################################################ +# Functions +############################################################ + +### +### Copy PHP-FPM *.conf files from source to destination with prefix +### +copy_fpm_files() { + local fpm_src="${1}" + local fpm_dst="${2}" + local debug="${3}" + + if [ ! -d "${fpm_src}" ]; then + run "mkdir -p ${fpm_src}" "${debug}" + fi + fpm_files="$( find "${fpm_src}" -type f -iname '*.conf' )" + + # loop over them line by line + IFS=' + ' + for fpm_f in ${fpm_files}; do + fpm_name="$( basename "${fpm_f}" )" + log "info" "PHP-FOM.conf: ${fpm_name} -> ${fpm_dst}/zzz-devilbox-${fpm_name}" "${debug}" + run "cp ${fpm_f} ${fpm_dst}/zzz-devilbox-${fpm_name}" "${debug}" + done + run "find ${fpm_dst} -type f -iname '*.conf' -exec chmod 0644 \"{}\" \;" "${debug}" +} + + +############################################################ +# Sanity Checks +############################################################ + +if ! command -v find >/dev/null 2>&1; then + echo "find not found, but required." + exit 1 +fi +if ! command -v basename >/dev/null 2>&1; then + echo "basename not found, but required." + exit 1 +fi diff --git a/Dockerfiles/prod/data/docker-entrypoint.sh b/Dockerfiles/prod/data/docker-entrypoint.sh index 0929549..130cdad 100755 --- a/Dockerfiles/prod/data/docker-entrypoint.sh +++ b/Dockerfiles/prod/data/docker-entrypoint.sh @@ -21,6 +21,9 @@ CONFIG_DIR="/docker-entrypoint.d" # php.ini.d directory PHP_INI_DIR="/usr/local/etc/php/conf.d" +# php-fpm conf.d directory +PHP_FPM_DIR="/usr/local/etc/php-fpm.d" + # This is the log file for any mail related functions PHP_MAIL_LOG="/var/log/mail.log" @@ -33,6 +36,9 @@ FPM_LOG_DIR="/var/log/php" # Custom ini dir (to be copied to actual ini dir) PHP_CUST_INI_DIR="/etc/php-custom.d" +# Custom PHP-FPM dir (to be copied to actual FPM conf dir) +PHP_CUST_FPM_DIR="/etc/php-fpm-custom.d" + # Supervisord config directory SUPERVISOR_CONFD="/etc/supervisor/conf.d" @@ -140,6 +146,12 @@ supervisor_add_service "php-fpm" "/usr/local/sbin/php-fpm" "${SUPERVISOR_CONFD} copy_ini_files "${PHP_CUST_INI_DIR}" "${PHP_INI_DIR}" "${DEBUG_LEVEL}" +### +### Copy custom PHP-FPM *.conf files +### +copy_fpm_files "${PHP_CUST_FPM_DIR}" "${PHP_FPM_DIR}" "${DEBUG_LEVEL}" + + ### ### Startup ### diff --git a/Dockerfiles/work/Dockerfile-5.4 b/Dockerfiles/work/Dockerfile-5.4 index c5706fc..c0e1ad8 100644 --- a/Dockerfiles/work/Dockerfile-5.4 +++ b/Dockerfiles/work/Dockerfile-5.4 @@ -303,6 +303,7 @@ COPY ./data/sudo-devilbox /etc/sudoers.d/devilbox ### VOLUME /etc/bash-custom.d VOLUME /etc/php-custom.d +VOLUME /etc/php-fpm-custom.d VOLUME /etc/php-modules.d VOLUME /shared/backups VOLUME /var/log/php diff --git a/Dockerfiles/work/Dockerfile-5.5 b/Dockerfiles/work/Dockerfile-5.5 index c64d3ed..9ec2860 100644 --- a/Dockerfiles/work/Dockerfile-5.5 +++ b/Dockerfiles/work/Dockerfile-5.5 @@ -307,6 +307,7 @@ COPY ./data/sudo-devilbox /etc/sudoers.d/devilbox ### VOLUME /etc/bash-custom.d VOLUME /etc/php-custom.d +VOLUME /etc/php-fpm-custom.d VOLUME /etc/php-modules.d VOLUME /shared/backups VOLUME /var/log/php diff --git a/Dockerfiles/work/Dockerfile-5.6 b/Dockerfiles/work/Dockerfile-5.6 index c23ecce..9942a87 100644 --- a/Dockerfiles/work/Dockerfile-5.6 +++ b/Dockerfiles/work/Dockerfile-5.6 @@ -307,6 +307,7 @@ COPY ./data/sudo-devilbox /etc/sudoers.d/devilbox ### VOLUME /etc/bash-custom.d VOLUME /etc/php-custom.d +VOLUME /etc/php-fpm-custom.d VOLUME /etc/php-modules.d VOLUME /shared/backups VOLUME /var/log/php diff --git a/Dockerfiles/work/Dockerfile-7.0 b/Dockerfiles/work/Dockerfile-7.0 index 2ff108e..49cf24c 100644 --- a/Dockerfiles/work/Dockerfile-7.0 +++ b/Dockerfiles/work/Dockerfile-7.0 @@ -307,6 +307,7 @@ COPY ./data/sudo-devilbox /etc/sudoers.d/devilbox ### VOLUME /etc/bash-custom.d VOLUME /etc/php-custom.d +VOLUME /etc/php-fpm-custom.d VOLUME /etc/php-modules.d VOLUME /shared/backups VOLUME /var/log/php diff --git a/Dockerfiles/work/Dockerfile-7.1 b/Dockerfiles/work/Dockerfile-7.1 index 1853520..20ea6fc 100644 --- a/Dockerfiles/work/Dockerfile-7.1 +++ b/Dockerfiles/work/Dockerfile-7.1 @@ -307,6 +307,7 @@ COPY ./data/sudo-devilbox /etc/sudoers.d/devilbox ### VOLUME /etc/bash-custom.d VOLUME /etc/php-custom.d +VOLUME /etc/php-fpm-custom.d VOLUME /etc/php-modules.d VOLUME /shared/backups VOLUME /var/log/php diff --git a/Dockerfiles/work/Dockerfile-7.2 b/Dockerfiles/work/Dockerfile-7.2 index e67d69c..ff4e05b 100644 --- a/Dockerfiles/work/Dockerfile-7.2 +++ b/Dockerfiles/work/Dockerfile-7.2 @@ -307,6 +307,7 @@ COPY ./data/sudo-devilbox /etc/sudoers.d/devilbox ### VOLUME /etc/bash-custom.d VOLUME /etc/php-custom.d +VOLUME /etc/php-fpm-custom.d VOLUME /etc/php-modules.d VOLUME /shared/backups VOLUME /var/log/php diff --git a/Dockerfiles/work/data/docker-entrypoint.sh b/Dockerfiles/work/data/docker-entrypoint.sh index 19a3d5b..cc13262 100755 --- a/Dockerfiles/work/data/docker-entrypoint.sh +++ b/Dockerfiles/work/data/docker-entrypoint.sh @@ -21,6 +21,9 @@ CONFIG_DIR="/docker-entrypoint.d" # php.ini.d directory PHP_INI_DIR="/usr/local/etc/php/conf.d" +# php-fpm conf.d directory +PHP_FPM_DIR="/usr/local/etc/php-fpm.d" + # This is the log file for any mail related functions PHP_MAIL_LOG="/var/log/mail.log" @@ -33,6 +36,9 @@ FPM_LOG_DIR="/var/log/php" # Custom ini dir (to be copied to actual ini dir) PHP_CUST_INI_DIR="/etc/php-custom.d" +# Custom PHP-FPM dir (to be copied to actual FPM conf dir) +PHP_CUST_FPM_DIR="/etc/php-fpm-custom.d" + # Supervisord config directory SUPERVISOR_CONFD="/etc/supervisor/conf.d" @@ -140,6 +146,12 @@ supervisor_add_service "php-fpm" "/usr/local/sbin/php-fpm" "${SUPERVISOR_CONFD} copy_ini_files "${PHP_CUST_INI_DIR}" "${PHP_INI_DIR}" "${DEBUG_LEVEL}" +### +### Copy custom PHP-FPM *.conf files +### +copy_fpm_files "${PHP_CUST_FPM_DIR}" "${PHP_FPM_DIR}" "${DEBUG_LEVEL}" + + ### ### mysqldump-secure ### diff --git a/README.md b/README.md index 6e12d84..afb0348 100644 --- a/README.md +++ b/README.md @@ -97,16 +97,20 @@ Have a look at the following table to see all offered volumes for each Docker im Image - Volumes + Volumes Description - prod

work + prod

work /etc/php-custom.d Mount this directory into your host computer and add custom \*.ini files in order to alter php behaviour. + + /etc/php-fpm-custom.d + Mount this directory into your host computer and add custom PHP-FOM \*.conf files in order to alter PHP-FPM behaviour. + /etc/php-modules.d Mount this directory into your host computer and add custo \*.so files in order to add your php modules.

Note:Your should then also provide a custom \*.ini file in order to actually load your custom provided module. diff --git a/build/ansible/DOCKERFILES/Dockerfile-prod.j2 b/build/ansible/DOCKERFILES/Dockerfile-prod.j2 index 1015382..95bb84a 100644 --- a/build/ansible/DOCKERFILES/Dockerfile-prod.j2 +++ b/build/ansible/DOCKERFILES/Dockerfile-prod.j2 @@ -60,6 +60,7 @@ COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf ### Volumes ### VOLUME /etc/php-custom.d +VOLUME /etc/php-fpm-custom.d VOLUME /etc/php-modules.d VOLUME /var/log/php VOLUME /var/mail diff --git a/build/ansible/DOCKERFILES/Dockerfile-work.j2 b/build/ansible/DOCKERFILES/Dockerfile-work.j2 index 3e4c5f2..e546ca5 100644 --- a/build/ansible/DOCKERFILES/Dockerfile-work.j2 +++ b/build/ansible/DOCKERFILES/Dockerfile-work.j2 @@ -194,6 +194,7 @@ COPY ./data/sudo-devilbox /etc/sudoers.d/devilbox ### VOLUME /etc/bash-custom.d VOLUME /etc/php-custom.d +VOLUME /etc/php-fpm-custom.d VOLUME /etc/php-modules.d VOLUME /shared/backups VOLUME /var/log/php diff --git a/tests/base/04-test-run_nginx.sh b/tests/base/04-test-run_nginx.sh index 83d0ab6..cc73539 100755 --- a/tests/base/04-test-run_nginx.sh +++ b/tests/base/04-test-run_nginx.sh @@ -71,8 +71,8 @@ run "sleep 10" ### ### Check correct PHP-FPM user ### -if ! docker_exec "${did}" "ps aux | grep 'php-fpm: pool' | grep -v grep | awk '{ print \$1 }' | head -1 | grep devilbox"; then - docker_exec "${did}" "ps aux" +if ! docker_exec "${did}" "ps auxw | grep 'php-fpm: pool' | grep -v grep | awk '{ print \$1 }' | head -1 | grep devilbox"; then + docker_exec "${did}" "ps auxw" # Shutdown docker_stop "${ndid}" || true @@ -82,8 +82,8 @@ if ! docker_exec "${did}" "ps aux | grep 'php-fpm: pool' | grep -v grep | awk '{ echo "Failed" exit 1 fi -if ! docker_exec "${did}" "ps aux | grep 'php-fpm: pool' | grep -v grep | awk '{ print \$1 }' | tail -1 | grep devilbox"; then - docker_exec "${did}" "ps aux" +if ! docker_exec "${did}" "ps auxw | grep 'php-fpm: pool' | grep -v grep | awk '{ print \$1 }' | tail -1 | grep devilbox"; then + docker_exec "${did}" "ps auxw" # Shutdown docker_stop "${ndid}" || true diff --git a/tests/prod/06-test-mount-custom_fpm_conf.sh b/tests/prod/06-test-mount-custom_fpm_conf.sh new file mode 100755 index 0000000..9eb34c0 --- /dev/null +++ b/tests/prod/06-test-mount-custom_fpm_conf.sh @@ -0,0 +1,181 @@ +#!/usr/bin/env bash + +set -e +set -u +set -o pipefail + +CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)" + +IMAGE="${1}" +VERSION="${2}" +FLAVOUR="${3}" + +# shellcheck disable=SC1090 +. "${CWD}/../.lib.sh" + + + +############################################################ +# Tests +############################################################ + +### +### Test Nginx with PHP-FPM +### +WWW_PORT="23254" +DOC_ROOT_HOST="$( mktemp -d )" +DOC_ROOT_CONT="/var/www/default" + +CONFIG_HOST="$( mktemp -d )" +CONFIG_CONT="/etc/nginx/conf.d" + +PHP_CNF_HOST="$( mktemp -d )" +PHP_CNF_CONT="/etc/php-fpm-custom.d" + +CONTAINER="nginx:stable" + +echo "php_admin_value[post_max_size] = 17M" > "${PHP_CNF_HOST}/post.conf" +echo " "${DOC_ROOT_HOST}/index.php" + +# Fix mount permissions +chmod 0777 "${CONFIG_HOST}" +chmod 0777 "${PHP_CNF_HOST}" +chmod 0777 "${DOC_ROOT_HOST}" +chmod 0644 "${DOC_ROOT_HOST}/index.php" + +# Pull container +run "docker pull ${CONTAINER}" + +# Start PHP-FPM +did="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "-e DEBUG_ENTRYPOINT=2 -e NEW_UID=$(id -u) -e NEW_GID=$(id -g) -v ${DOC_ROOT_HOST}:${DOC_ROOT_CONT} -v ${PHP_CNF_HOST}:${PHP_CNF_CONT}" )" +name="$( docker_name "${did}" )" + +# Nginx.conf +{ + echo "server {" + echo " server_name _;" + echo " listen 80;" + echo " root ${DOC_ROOT_CONT};" + echo " index index.php;" + echo " location ~* \.php\$ {" + echo " fastcgi_index index.php;" + echo " fastcgi_pass ${name}:9000;" + echo " include fastcgi_params;" + echo " fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;" + echo " fastcgi_param SCRIPT_NAME \$fastcgi_script_name;" + echo " }" + echo "}" +} > "${CONFIG_HOST}/php.conf" + + +# Start Nginx +ndid="$( docker_run "${CONTAINER}" "-v ${DOC_ROOT_HOST}:${DOC_ROOT_CONT} -v ${CONFIG_HOST}:${CONFIG_CONT} -p ${WWW_PORT}:80 --link ${name}" )" + +# Wait for both containers to be up and running +run "sleep 10" + +# Check entrypoint +if ! run "docker logs ${did} | grep 'post.conf'"; then + docker_logs "${ndid}" || true + docker_logs "${did}" || true + docker_stop "${ndid}" || true + docker_stop "${did}" || true + rm -rf "${DOC_ROOT_HOST}" + rm -rf "${CONFIG_HOST}" + rm -rf "${PHP_CNF_HOST}" + echo "Failed" + exit 1 +fi + +# Check PHP connectivity +if ! run "curl -q -4 http://127.0.0.1:${WWW_PORT}/index.php >/dev/null 2>&1"; then + # Info + run "netstat -tuln" + run "curl -4 http://127.0.0.1:${WWW_PORT}/index.php" || true + run "curl -6 http://127.0.0.1:${WWW_PORT}/index.php" || true + run "docker ps --no-trunc" + docker_exec "${ndid}" "nginx -t" + + # Show logs + docker_logs "${ndid}" || true + docker_logs "${did}" || true + + # Ensure file is available + docker_exec "${ndid}" "ls -la ${DOC_ROOT_CONT}/" + docker_exec "${did}" "ls -la ${DOC_ROOT_CONT}/" + + docker_exec "${ndid}" "cat ${DOC_ROOT_CONT}/index.php" + docker_exec "${did}" "cat ${DOC_ROOT_CONT}/index.php" + + # Nginx configuration + docker_exec "${ndid}" "cat ${CONFIG_CONT}/php.conf" + + # Shutdown + docker_stop "${ndid}" || true + docker_stop "${did}" || true + rm -rf "${DOC_ROOT_HOST}" + rm -rf "${CONFIG_HOST}" + rm -rf "${PHP_CNF_HOST}" + echo "Failed" + exit 1 +fi + +# Check modified php-fpm.conf +if ! docker_exec "${did}" "php -r \"echo ini_get('post_max_size');\" | grep '17M'"; then + # Info + docker_exec "${did}" "php -r \"echo ini_get('post_max_size');\"" + + # Show logs + docker_logs "${ndid}" || true + docker_logs "${did}" || true + + # Shutdown + docker_stop "${ndid}" || true + docker_stop "${did}" || true + rm -rf "${DOC_ROOT_HOST}" + rm -rf "${CONFIG_HOST}" + rm -rf "${PHP_CNF_HOST}" + echo "Failed" + exit 1 +fi + +# Check modified php-fpm.conf +if ! run "curl -q -4 http://127.0.0.1:${WWW_PORT}/index.php 2>/dev/null | grep post_max_size | grep '17M'"; then + # Info + run "netstat -tuln" + run "curl -4 http://127.0.0.1:${WWW_PORT}/index.php" || true + run "curl -6 http://127.0.0.1:${WWW_PORT}/index.php" || true + run "docker ps --no-trunc" + docker_exec "${ndid}" "nginx -t" + + # Show logs + docker_logs "${ndid}" || true + docker_logs "${did}" || true + + # Ensure file is available + docker_exec "${ndid}" "ls -la ${DOC_ROOT_CONT}/" + docker_exec "${did}" "ls -la ${DOC_ROOT_CONT}/" + + docker_exec "${ndid}" "cat ${DOC_ROOT_CONT}/index.php" + docker_exec "${did}" "cat ${DOC_ROOT_CONT}/index.php" + + # Nginx configuration + docker_exec "${ndid}" "cat ${CONFIG_CONT}/php.conf" + + # Shutdown + docker_stop "${ndid}" || true + docker_stop "${did}" || true + rm -rf "${DOC_ROOT_HOST}" + rm -rf "${CONFIG_HOST}" + rm -rf "${PHP_CNF_HOST}" + echo "Failed" + exit 1 +fi + + +# Cleanup +docker_stop "${did}" +docker_stop "${ndid}" +rm -rf "${DOC_ROOT_HOST}" +rm -rf "${CONFIG_HOST}" +rm -rf "${PHP_CNF_HOST}"