diff --git a/assets/entrypoint.sh b/assets/entrypoint.sh index 5e49a2b..76a5928 100755 --- a/assets/entrypoint.sh +++ b/assets/entrypoint.sh @@ -16,7 +16,7 @@ then echo " |___/ " echo echo "Image: $DOCKER_IMAGE" - echo "Build Date: `cat /etc/build-date`" + echo "Build Date: $(cat /etc/build-date)" echo fi @@ -24,35 +24,51 @@ fi if [[ -f /usr/bin/php ]] then # Getting PHP INI Paths - PHPINI=`php -i | grep "Loaded Configuration File" | awk -F" => " '{print $2}'` - PHPMODULES=`php -i | grep "Scan this dir" | awk -F" => " '{print $2}'` + PHPMODULES=$(php -i | grep "Scan this dir" | awk -F" => " '{print $2}') PHPCUSTOM=/etc/php/conf.d - # Disable modules - for VAR in `printenv | grep DISABLEMODULE | grep -E '(true|yes|1)' | cut -d= -f1 | cut -d_ -f2- | awk '{print tolower($0)}'` - do - if [[ -f "$PHPMODULES/*$VAR.ini" ]] + # Errors are always shown and stop the container; VERBOSE only shows the modules disabled. + # A module already disabled (e.g. after a restart) is not an error. + MODULE_OUTPUT=/dev/null + ${VERBOSE_MODE} && MODULE_OUTPUT=/dev/stdout + + # Keep only these modules (and the ones they require): PHP_ENABLED_MODULES="pdo_mysql,mbstring" + read -r -a ENABLED_MODULES <<< "${PHP_ENABLED_MODULES//,/ }" + if [[ ${#ENABLED_MODULES[@]} -gt 0 ]] + then + if ! /usr/local/bin/php-disable-module --all-except "${ENABLED_MODULES[@]}" > "$MODULE_OUTPUT" then - ${VERBOSE_MODE} && echo "Disabling Module $VAR ..." - rm "$PHPMODULES/*$VAR.ini" - elif [[ -f "$PHPMODULES/$VAR.ini" ]] + echo "PHP_ENABLED_MODULES=\"$PHP_ENABLED_MODULES\" failed (see above), stopping the container." >&2 + exit 1 + fi + fi + + # Disable modules (and the ones that require them): PHP_DISABLE_MODULES="yaml,memcached" + read -r -a DISABLE_MODULES <<< "${PHP_DISABLE_MODULES//,/ }" + if [[ ${#DISABLE_MODULES[@]} -gt 0 ]] + then + if ! /usr/local/bin/php-disable-module "${DISABLE_MODULES[@]}" > "$MODULE_OUTPUT" then - ${VERBOSE_MODE} && echo "Disabling Module $VAR ..." - rm "$PHPMODULES/$VAR.ini" - else - ${VERBOSE_MODE} && echo "Module not found $VAR" + echo "PHP_DISABLE_MODULES=\"$PHP_DISABLE_MODULES\" failed (see above), stopping the container." >&2 + exit 1 fi - done - ${VERBOSE_MODE} && echo + fi - # List available modules - if [[ "$VERBOSE" == "true" ]] + # Deprecated: DISABLEMODULE_=true, will be removed in a future release. It does not stop + # the container on an error, as it did not before. + mapfile -t DEPRECATED_MODULES < <(printenv | grep -E '^DISABLEMODULE_[^=]+=(true|yes|1)$' | cut -d= -f1 | cut -d_ -f2- | awk '{print tolower($0)}') + if [[ ${#DEPRECATED_MODULES[@]} -gt 0 ]] then + echo "DISABLEMODULE_ is deprecated, use PHP_DISABLE_MODULES=\"$(IFS=,; echo "${DEPRECATED_MODULES[*]}")\"" >&2 + /usr/local/bin/php-disable-module "${DEPRECATED_MODULES[@]}" > "$MODULE_OUTPUT" + fi + + # List the enabled modules + if ${VERBOSE_MODE} + then + echo echo "Available Modules:" - for VAR in `ls $PHPMODULES/ | sort` - do - echo $VAR | awk -F"." '{printf $1; printf " "}' - done + /usr/local/bin/php-disable-module --list | tr '\n' ' ' echo fi @@ -63,7 +79,7 @@ then fi # Copy Custom Config - cp $PHPCUSTOM/*.ini $PHPMODULES/ 2>/dev/null || : + cp "$PHPCUSTOM"/*.ini "$PHPMODULES"/ 2>/dev/null || : fi exec "$@" diff --git a/assets/index.html b/assets/index.html index e74cad4..48cec0c 100644 --- a/assets/index.html +++ b/assets/index.html @@ -231,12 +231,27 @@

Environment Configurat
-
DISABLEMODULE_[name]
+
PHP_DISABLE_MODULES
-

Disable specific PHP modules at runtime to optimize performance.

+

Comma separated list of PHP modules to disable at runtime to optimize performance.

Default: All modules enabled

-
docker run -e DISABLEMODULE_DOM=true -e DISABLEMODULE_XSL=true @@DOCKER_IMAGE@@
+
docker run -e PHP_DISABLE_MODULES="dom,xsl" @@DOCKER_IMAGE@@
+ +
+
+
+ +
+
PHP_ENABLED_MODULES
+
+

Comma separated list of PHP modules to keep enabled at runtime; all the others are disabled. The modules they require are kept too.

+

Default: All modules enabled

+
+
docker run -e PHP_ENABLED_MODULES="pdo_mysql,mbstring" @@DOCKER_IMAGE@@