Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support clear_env variable by PHP_CLEAR_ENV #406

Merged
merged 4 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 8.0/Dockerfile.rhel9
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ ENV PHP_CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/php/ \
PHP_FPM_CONF_D_PATH=/etc/php-fpm.d \
PHP_FPM_CONF_FILE=www.conf \
PHP_FPM_RUN_DIR=/run/php-fpm \
PHP_CLEAR_ENV=ON \
PHP_MAIN_FPM_CONF_FILE=/etc/php-fpm.conf \
PHP_FPM_LOG_PATH=/var/log/php-fpm \
HTTPD_CONFIGURATION_PATH=${APP_ROOT}/etc/conf.d \
Expand Down
3 changes: 3 additions & 0 deletions 8.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ The following environment variables set their equivalent property value in the p
* **PHP_MEMORY_LIMIT**
* Memory Limit
* Default: 128M
* **PHP_CLEAR_ENV**
* Sets to clear environment in FPM workers. See [FPM_CONFIGURATION](https://www.php.net/manual/en/install.fpm.configuration.php).
* Default: ON
* **SESSION_NAME**
* Name of the session
* Default: PHPSESSID
Expand Down
4 changes: 4 additions & 0 deletions 8.0/root/usr/libexec/container-setup
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ if [ "x$PLATFORM" == "xel9" ] || [ "x$PLATFORM" == "xfedora" ]; then
chmod -R a+rwx ${PHP_FPM_LOG_PATH}
chown -R 1001:0 ${PHP_FPM_LOG_PATH}
fi
if [ "${PHP_CLEAR_ENV:-ON}" == "OFF" ]; then
echo "Setting clear_env to no in assemble script"
sed -e 's/^[;]*\s*clear_env\s*=.*$/clear_env = no/' -i ${PHP_FPM_CONF_D_PATH}/${PHP_FPM_CONF_FILE}
fi
fi

mkdir -p ${PHP_CONTAINER_SCRIPTS_PATH}/pre-init
Expand Down
5 changes: 4 additions & 1 deletion 8.0/root/usr/share/container-scripts/php/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ config_general() {
if [ -d "/run/php-fpm" ]; then
sed -i -E "/php_value\[session.save_path\]/d" ${PHP_FPM_CONF_D_PATH}/${PHP_FPM_CONF_FILE}
sed -e '/catch_workers_output/d' -e '/error_log/d' -i ${PHP_FPM_CONF_D_PATH}/${PHP_FPM_CONF_FILE}
sed -e 's/^(clear_env)\s+.*/clear_env = no/' -i ${PHP_FPM_CONF_D_PATH}/${PHP_FPM_CONF_FILE}
if [ "${PHP_CLEAR_ENV:-ON}" == "OFF" ]; then
echo "Setting clear_env to no in config_general"
sed -e 's/^[;]*\s*clear_env\s*=.*$/clear_env = no/' -i ${PHP_FPM_CONF_D_PATH}/${PHP_FPM_CONF_FILE}
fi
else
sed -i '/php_value session.save_/d' ${HTTPD_MAIN_CONF_D_PATH}/${PHP_HTTPD_CONF_FILE}
fi
Expand Down
5 changes: 5 additions & 0 deletions 8.0/s2i/bin/assemble
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ if [ -f composer.json ]; then
fi
fi

if [ "${PHP_CLEAR_ENV:-ON}" == "OFF" ]; then
echo "Setting clear_env to no in assemble script"
sed -e 's/^[;]*\s*clear_env\s*=.*$/clear_env = no/' -i ${PHP_FPM_CONF_D_PATH}/${PHP_FPM_CONF_FILE}
fi

# post-assemble files
process_extending_files ./php-post-assemble/ ${PHP_CONTAINER_SCRIPTS_PATH}/post-assemble/

Expand Down
4 changes: 4 additions & 0 deletions 8.0/s2i/bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ if [ "x$PLATFORM" == "xel9" ] || [ "x$PLATFORM" == "xfedora" ]; then
chmod -R a+rwx ${PHP_FPM_LOG_PATH}
chown -R 1001:0 ${PHP_FPM_LOG_PATH}
fi
if [ "${PHP_CLEAR_ENV:-ON}" == "OFF" ]; then
echo "Setting clear_env to no in run script."
sed -e 's/^[;]*\s*clear_env\s*=.*$/clear_env = no/' -i ${PHP_FPM_CONF_D_PATH}/${PHP_FPM_CONF_FILE}
fi

fi

Expand Down
1 change: 1 addition & 0 deletions 8.1/Dockerfile.rhel9
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ ENV PHP_CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/php/ \
PHP_FPM_CONF_D_PATH=/etc/php-fpm.d \
PHP_FPM_CONF_FILE=www.conf \
PHP_FPM_RUN_DIR=/run/php-fpm \
PHP_CLEAR_ENV=ON \
PHP_MAIN_FPM_CONF_FILE=/etc/php-fpm.conf \
PHP_FPM_LOG_PATH=/var/log/php-fpm \
HTTPD_CONFIGURATION_PATH=${APP_ROOT}/etc/conf.d \
Expand Down
5 changes: 4 additions & 1 deletion 8.1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ The following environment variables set their equivalent property value in the p
* **PHP_MEMORY_LIMIT**
* Memory Limit
* Default: 128M
* **PHP_CLEAR_ENV**
* Sets to clear environment in FPM workers. See [FPM_CONFIGURATION](https://www.php.net/manual/en/install.fpm.configuration.php).
* Default: ON
* **SESSION_NAME**
* Name of the session
* Default: PHPSESSID
Expand Down Expand Up @@ -221,7 +224,7 @@ You can also override the entire directory used to load the PHP configuration by
* Sets the path to the php.ini file
* **PHP_INI_SCAN_DIR**
* Path to scan for additional ini configuration files

You can override the Apache [MPM prefork](https://httpd.apache.org/docs/2.4/mod/mpm_common.html)
settings to increase the performance for of the PHP application. In case you set
some Cgroup limits, the image will attempt to automatically set the
Expand Down
4 changes: 4 additions & 0 deletions 8.1/root/usr/libexec/container-setup
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ if [ "x$PLATFORM" == "xel9" ] || [ "x$PLATFORM" == "xfedora" ]; then
chmod -R a+rwx ${PHP_FPM_LOG_PATH}
chown -R 1001:0 ${PHP_FPM_LOG_PATH}
fi
if [ "${PHP_CLEAR_ENV:-ON}" == "OFF" ]; then
sed -e 's/^[;]*\s*clear_env\s*=.*$/clear_env = no/' -i ${PHP_FPM_CONF_D_PATH}/${PHP_FPM_CONF_FILE}
fi

fi

mkdir -p ${PHP_CONTAINER_SCRIPTS_PATH}/pre-init
Expand Down
4 changes: 3 additions & 1 deletion 8.1/root/usr/share/container-scripts/php/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ config_general() {
if [ -d "/run/php-fpm" ]; then
sed -i -E "/php_value\[session.save_path\]/d" ${PHP_FPM_CONF_D_PATH}/${PHP_FPM_CONF_FILE}
sed -e '/catch_workers_output/d' -e '/error_log/d' -i ${PHP_FPM_CONF_D_PATH}/${PHP_FPM_CONF_FILE}
sed -e 's/^(clear_env)\s+.*/clear_env = no/' -i ${PHP_FPM_CONF_D_PATH}/${PHP_FPM_CONF_FILE}
if [ "${PHP_CLEAR_ENV:-ON}" == "OFF" ]; then
sed -e 's/^[;]*\s*clear_env\s*=.*$/clear_env = no/' -i ${PHP_FPM_CONF_D_PATH}/${PHP_FPM_CONF_FILE}
fi
else
sed -i '/php_value session.save_/d' ${HTTPD_MAIN_CONF_D_PATH}/${PHP_HTTPD_CONF_FILE}
fi
Expand Down
5 changes: 5 additions & 0 deletions 8.1/s2i/bin/assemble
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ if [ -f composer.json ]; then
fi
fi

if [ "${PHP_CLEAR_ENV:-ON}" == "OFF" ]; then
echo "Setting clear_env to no in assemble script"
sed -e 's/^[;]*\s*clear_env\s*=.*$/clear_env = no/' -i ${PHP_FPM_CONF_D_PATH}/${PHP_FPM_CONF_FILE}
fi

# post-assemble files
process_extending_files ./php-post-assemble/ ${PHP_CONTAINER_SCRIPTS_PATH}/post-assemble/

Expand Down
5 changes: 4 additions & 1 deletion 8.1/s2i/bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ if [ "x$PLATFORM" == "xel9" ] || [ "x$PLATFORM" == "xfedora" ]; then
chmod -R a+rwx ${PHP_FPM_LOG_PATH}
chown -R 1001:0 ${PHP_FPM_LOG_PATH}
fi

if [ "${PHP_CLEAR_ENV:-ON}" == "OFF" ]; then
echo "Setting clear_env to no in assemble script"
sed -e 's/^[;]*\s*clear_env\s*=.*$/clear_env = no/' -i ${PHP_FPM_CONF_D_PATH}/${PHP_FPM_CONF_FILE}
fi
fi

# pre-start files
Expand Down
1 change: 1 addition & 0 deletions 8.2/Dockerfile.rhel9
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ ENV PHP_CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/php/ \
PHP_FPM_CONF_D_PATH=/etc/php-fpm.d \
PHP_FPM_CONF_FILE=www.conf \
PHP_FPM_RUN_DIR=/run/php-fpm \
PHP_CLEAR_ENV=ON \
PHP_MAIN_FPM_CONF_FILE=/etc/php-fpm.conf \
PHP_FPM_LOG_PATH=/var/log/php-fpm \
HTTPD_CONFIGURATION_PATH=${APP_ROOT}/etc/conf.d \
Expand Down
3 changes: 3 additions & 0 deletions 8.2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ The following environment variables set their equivalent property value in the p
* **PHP_MEMORY_LIMIT**
* Memory Limit
* Default: 128M
* **PHP_CLEAR_ENV**
* Sets to clear environment in FPM workers. See [FPM_CONFIGURATION](https://www.php.net/manual/en/install.fpm.configuration.php).
* Default: ON
* **SESSION_NAME**
* Name of the session
* Default: PHPSESSID
Expand Down
4 changes: 4 additions & 0 deletions 8.2/root/usr/libexec/container-setup
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ if [ "x$PLATFORM" == "xel9" ] || [ "x$PLATFORM" == "xfedora" ]; then
chmod -R a+rwx ${PHP_FPM_LOG_PATH}
chown -R 1001:0 ${PHP_FPM_LOG_PATH}
fi
if [ "${PHP_CLEAR_ENV:-ON}" == "OFF" ]; then
echo "Setting clear_env to no in assemble script"
sed -e 's/^[;]*\s*clear_env\s*=.*$/clear_env = no/' -i ${PHP_FPM_CONF_D_PATH}/${PHP_FPM_CONF_FILE}
fi
fi

mkdir -p ${PHP_CONTAINER_SCRIPTS_PATH}/pre-init
Expand Down
5 changes: 4 additions & 1 deletion 8.2/root/usr/share/container-scripts/php/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ config_general() {
if [ -d "/run/php-fpm" ]; then
sed -i -E "/php_value\[session.save_path\]/d" ${PHP_FPM_CONF_D_PATH}/${PHP_FPM_CONF_FILE}
sed -e '/catch_workers_output/d' -e '/error_log/d' -i ${PHP_FPM_CONF_D_PATH}/${PHP_FPM_CONF_FILE}
sed -e 's/^(clear_env)\s+.*/clear_env = no/' -i ${PHP_FPM_CONF_D_PATH}/${PHP_FPM_CONF_FILE}
if [ "${PHP_CLEAR_ENV:-ON}" == "OFF" ]; then
echo "Setting clear_env to no in assemble script"
sed -e 's/^[;]*\s*clear_env\s*=.*$/clear_env = no/' -i ${PHP_FPM_CONF_D_PATH}/${PHP_FPM_CONF_FILE}
fi
else
sed -i '/php_value session.save_/d' ${HTTPD_MAIN_CONF_D_PATH}/${PHP_HTTPD_CONF_FILE}
fi
Expand Down
5 changes: 5 additions & 0 deletions 8.2/s2i/bin/assemble
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ if [ -f composer.json ]; then
fi
fi

if [ "${PHP_CLEAR_ENV:-ON}" == "OFF" ]; then
echo "Setting clear_env to no in assemble script"
sed -e 's/^[;]*\s*clear_env\s*=.*$/clear_env = no/' -i ${PHP_FPM_CONF_D_PATH}/${PHP_FPM_CONF_FILE}
fi

# post-assemble files
process_extending_files ./php-post-assemble/ ${PHP_CONTAINER_SCRIPTS_PATH}/post-assemble/

Expand Down
5 changes: 4 additions & 1 deletion 8.2/s2i/bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ if [ "x$PLATFORM" == "xel9" ] || [ "x$PLATFORM" == "xfedora" ]; then
chmod -R a+rwx ${PHP_FPM_LOG_PATH}
chown -R 1001:0 ${PHP_FPM_LOG_PATH}
fi

if [ "${PHP_CLEAR_ENV:-ON}" == "OFF" ]; then
echo "Setting clear_env to no in assemble script"
sed -e 's/^[;]*\s*clear_env\s*=.*$/clear_env = no/' -i ${PHP_FPM_CONF_D_PATH}/${PHP_FPM_CONF_FILE}
fi
fi

# pre-start files
Expand Down
32 changes: 29 additions & 3 deletions test/run
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
test -n "${IMAGE_NAME-}" || false 'make sure $IMAGE_NAME is defined'
test -n "${VERSION-}" || false 'make sure $VERSION is defined'


TEST_LIST="\
test_s2i_usage
test_docker_run_usage
Expand All @@ -20,6 +21,10 @@ ct_npm_works
test_build_from_dockerfile
"

TEST_CLEAR_ENV="\
clear_env_set
"

# TODO: Make command compatible for Mac users
test_dir="$(readlink -f $(dirname "${BASH_SOURCE[0]}"))"
image_dir=$(readlink -f ${test_dir}/..)
Expand All @@ -46,7 +51,7 @@ container_ip() {
}

run_s2i_build() {
ct_s2i_build_as_df file://${test_dir}/test-app ${IMAGE_NAME} ${IMAGE_NAME}-testapp ${s2i_args} $(ct_build_s2i_npm_variables)
ct_s2i_build_as_df file://${test_dir}/test-app ${IMAGE_NAME} ${IMAGE_NAME}-testapp ${s2i_args} $(ct_build_s2i_npm_variables) $1
}

prepare() {
Expand Down Expand Up @@ -157,8 +162,19 @@ test_config_writeable() {
docker run --rm "${IMAGE_NAME}" /bin/bash -c "${run_cmd}"
}

test_clear_env_setup() {
local run_cmd="[ -f /etc/php-fpm.d/www.conf ] && grep \"^clear_env = no\" /etc/php-fpm.d/www.conf"

info "Checking if clear_env = no is set in /etc/php-fpm.d/www.conf file."
docker run --rm "${IMAGE_NAME}-testapp" /bin/bash -c "${run_cmd}"
}

clear_env_set() {
PHP_CLEAR_ENV=OFF test_application
}


test_application() {
set -x
cid_file=$CID_FILE_DIR/$(mktemp -u -p . --suffix .cid)
# Verify that the HTTP connection can be established to test application container
run_test_application &
Expand All @@ -181,6 +197,11 @@ test_application() {

test_config_writeable
ct_check_testcase_result $?

if [ "${OS}" == "rhel9" ] && [ "${PHP_CLEAR_ENV:-ON}" == "OFF" ]; then
test_clear_env_setup
ct_check_testcase_result $?
fi
}

test_application_user() {
Expand Down Expand Up @@ -229,9 +250,14 @@ ct_init
# Since we built the candidate image locally, we don't want S2I attempt to pull
# it from Docker hub
s2i_args="--pull-policy=never"

#
prepare
run_s2i_build
ct_check_testcase_result $?

TEST_SET=${TESTS:-$TEST_LIST} ct_run_tests_from_testset "php_tests"

run_s2i_build "-e PHP_CLEAR_ENV=OFF"
ct_check_testcase_result $?

TEST_SET=${TESTS:-$TEST_CLEAR_ENV} ct_run_tests_from_testset "clear_env_set"