From d4da0caa0780466321f6a7b8aefa5bedf3318527 Mon Sep 17 00:00:00 2001 From: eroncero Date: Mon, 18 Aug 2025 21:07:59 +0200 Subject: [PATCH] Works if you run it manually in the container --- docker-compose.template.yaml | 2 +- .../project/entrypoint/copy-config.sh | 54 ++++++++++++------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/docker-compose.template.yaml b/docker-compose.template.yaml index f13dab6..18bd249 100644 --- a/docker-compose.template.yaml +++ b/docker-compose.template.yaml @@ -27,7 +27,7 @@ services: environment: - PHP_VERSIONS=${PHP_VERSIONS} # Inherits from .env volumes: - - ./mnt/place-config/etc/php/8.2:/mnt/place-config/etc/php/8.2 # Config ready to be copied into the container. + - ./mnt/place-config/etc/php:/mnt/place-config/etc/php # Config ready to be copied into the container. - ./multi-php-fpm-srv/run/php:/run/php - ./mariadb-srv/run/mysql:/run/mysqld # php-mysql should be able connecting to the MariaDB socket. diff --git a/multi-php-fpm-srv/project/entrypoint/copy-config.sh b/multi-php-fpm-srv/project/entrypoint/copy-config.sh index c6c853c..c929c5e 100644 --- a/multi-php-fpm-srv/project/entrypoint/copy-config.sh +++ b/multi-php-fpm-srv/project/entrypoint/copy-config.sh @@ -5,34 +5,52 @@ set -euo pipefail SRC_BASE="/mnt/place-config/etc/php" DEST_BASE="/etc/php" -# Determine which PHP versions to process -[ -z "${PHP_VERSIONS:-}" ] && [ -z "${BUILDTIME_PHP_VER_INST:-}" ] && exit 0 -VERSIONS_TO_PROCESS="${PHP_VERSIONS:-$BUILDTIME_PHP_VER_INST}" +# Use both environment variables if they exist +VERSIONS_TO_PROCESS="$(echo "${PHP_VERSIONS:-} ${BUILDTIME_PHP_VER_INST:-}" | xargs -n1 | sort -u | xargs)" -echo "Processing PHP versions: ${VERSIONS_TO_PROCESS}" +if [ -z "$VERSIONS_TO_PROCESS" ]; then + echo "ā„¹ļø No PHP versions specified in environment variables" + exit 0 +fi + +echo "šŸ” Processing PHP versions: $VERSIONS_TO_PROCESS" for version in $VERSIONS_TO_PROCESS; do src_dir="${SRC_BASE}/${version}/fpm/pool.d" dest_dir="${DEST_BASE}/${version}/fpm/pool.d" - # Skip if source doesn't exist - [ ! -d "$src_dir" ] && continue + echo -e "\nšŸ“¦ Checking PHP ${version}..." + + # Verify source directory exists + if [ ! -d "$src_dir" ]; then + echo " āš ļø Source directory not found: $src_dir" + continue + fi + + # Count .conf files + conf_files=("$src_dir"/*.conf) + if [ ${#conf_files[@]} -eq 0 ]; then + echo " āœ… No .conf files to copy (directory empty)" + continue + fi # Process each .conf file - find "$src_dir" -maxdepth 1 -name '*.conf' -print0 | while IFS= read -r -d '' conf_file; do + copied=0 + for conf_file in "${conf_files[@]}"; do + if [ ! -f "$conf_file" ]; then + continue + fi + filename=$(basename "$conf_file") - echo "Copying: ${filename} (PHP ${version})" + echo " āž¤ Copying: $filename" - cp -f "$conf_file" "$dest_dir/" - chmod 644 "${dest_dir}/${filename}" - chown root:root "${dest_dir}/${filename}" - - # Verify copy - cmp -s "$conf_file" "${dest_dir}/${filename}" || { - echo "ERROR: Copy verification failed for ${filename}" - exit 1 - } + cp -f "$conf_file" "$dest_dir/" && \ + chmod 644 "${dest_dir}/${filename}" && \ + chown root:root "${dest_dir}/${filename}" && \ + copied=$((copied + 1)) done + + echo " āœ” Copied $copied files for PHP $version" done -echo "Configuration copy completed successfully" +echo -e "\nāœ… Configuration copy completed"