Skip to content

Commit ba9254a

Browse files
committed
Include the same changes in 70 and 56 versions
1 parent 5765d72 commit ba9254a

File tree

16 files changed

+430
-0
lines changed

16 files changed

+430
-0
lines changed

Diff for: 5.6/root/usr/libexec/container-setup

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# In order to drop the root user, we have to make some directories world
6+
# writeable as OpenShift default security model is to run the container under
7+
# random UID.
8+
9+
source ${PHP_CONTAINER_SCRIPTS_PATH}/common.sh
10+
11+
# compatibility symlinks so we hide SCL paths
12+
if [ -v SCL_ENABLED ] ; then
13+
# /opt/rh/httpd24/root/etc/httpd will be symlink to /etc/httpd
14+
mv /opt/rh/httpd24/root/etc/httpd /etc/httpd
15+
ln -s /etc/httpd /opt/rh/httpd24/root/etc/httpd
16+
17+
# /opt/rh/httpd24/root/var/run/httpd will be symlink to /var/run/httpd
18+
mv /opt/rh/httpd24/root/var/run/httpd /var/run/httpd
19+
ln -s /var/run/httpd /opt/rh/httpd24/root/var/run/httpd
20+
21+
# /opt/rh/httpd24/root/var/www will be symlink to /var/www
22+
rm -rf /var/www
23+
mv ${HTTPD_DATA_ORIG_PATH} /var/www
24+
ln -s /var/www ${HTTPD_DATA_ORIG_PATH}
25+
else
26+
rm -f /opt/app-root/etc/scl_enable
27+
fi
28+
29+
mkdir -p ${HTTPD_CONFIGURATION_PATH}
30+
chmod -R a+rwx ${HTTPD_MAIN_CONF_PATH}
31+
chmod -R a+rwx ${HTTPD_MAIN_CONF_D_PATH}
32+
chmod -R ug+r /etc/pki/tls/certs/localhost.crt
33+
chmod -R ug+r /etc/pki/tls/private/localhost.key
34+
chown -R 1000:0 /etc/pki/tls/certs/localhost.crt
35+
chown -R 1000:0 /etc/pki/tls/private/localhost.key
36+
mkdir -p ${APP_ROOT}/etc
37+
chmod -R a+rwx ${APP_ROOT}/etc
38+
chmod -R a+rwx ${HTTPD_VAR_RUN}
39+
chown -R 1001:0 ${APP_ROOT}
40+
mkdir /tmp/sessions
41+
chown -R 1000:0 /tmp/sessions
42+
chown -R 1001:0 ${HTTPD_DATA_PATH}
43+
chmod -R a+rwx ${PHP_SYSCONF_PATH}
44+
45+
mkdir -p ${PHP_CONTAINER_SCRIPTS_PATH}/pre-init
46+
47+
config_general
48+

Diff for: 5.6/root/usr/share/container-scripts/php/common.sh

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
config_httpd_conf() {
2+
sed -i "s/^Listen 80/Listen 0.0.0.0:8080/" ${HTTPD_MAIN_CONF_PATH}/httpd.conf
3+
sed -i "s/^User apache/User default/" ${HTTPD_MAIN_CONF_PATH}/httpd.conf
4+
sed -i "s/^Group apache/Group root/" ${HTTPD_MAIN_CONF_PATH}/httpd.conf
5+
sed -i "s%^DocumentRoot \"${HTTPD_DATA_ORIG_PATH}/html\"%#DocumentRoot \"${APP_DATA}\"%" ${HTTPD_MAIN_CONF_PATH}/httpd.conf
6+
sed -i "s%^<Directory \"${HTTPD_DATA_ORIG_PATH}/html\"%<Directory \"${APP_DATA}\"%" ${HTTPD_MAIN_CONF_PATH}/httpd.conf
7+
sed -i "s%^<Directory \"${HTTPD_VAR_PATH}/html\"%<Directory \"${APP_DATA}\"%" ${HTTPD_MAIN_CONF_PATH}/httpd.conf
8+
sed -i "s%^ErrorLog \"logs/error_log\"%ErrorLog \"|/usr/bin/cat\"%" ${HTTPD_MAIN_CONF_PATH}/httpd.conf
9+
sed -i "s%CustomLog \"logs/access_log\"%CustomLog \"|/usr/bin/cat\"%" ${HTTPD_MAIN_CONF_PATH}/httpd.conf
10+
sed -i "151s%AllowOverride None%AllowOverride All%" ${HTTPD_MAIN_CONF_PATH}/httpd.conf
11+
}
12+
13+
config_ssl_conf() {
14+
sed -i -E "s/^Listen 443/Listen 0.0.0.0:8443/" ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf
15+
sed -i -E "s/_default_:443/_default_:8443/" ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf
16+
sed -i -E "s!^(\s*CustomLog)\s+\S+!\1 |/usr/bin/cat!" ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf
17+
sed -i -E "s!^(\s*TransferLog)\s+\S+!\1 |/usr/bin/cat!" ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf
18+
sed -i -E "s!^(\s*ErrorLog)\s+\S+!\1 |/usr/bin/cat!" ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf
19+
}
20+
21+
config_general() {
22+
config_httpd_conf
23+
config_ssl_conf
24+
sed -i '/php_value session.save_path/d' ${HTTPD_MAIN_CONF_D_PATH}/${PHP_HTTPD_CONF_FILE}
25+
head -n151 ${HTTPD_MAIN_CONF_PATH}/httpd.conf | tail -n1 | grep "AllowOverride All" || exit 1
26+
echo "IncludeOptional ${APP_ROOT}/etc/conf.d/*.conf" >> ${HTTPD_MAIN_CONF_PATH}/httpd.conf
27+
}
28+
29+
function log_info {
30+
echo "---> `date +%T` $@"
31+
}
32+
33+
function log_and_run {
34+
log_info "Running $@"
35+
"$@"
36+
}
37+
38+
function log_volume_info {
39+
CONTAINER_DEBUG=${CONTAINER_DEBUG:-}
40+
if [[ "${CONTAINER_DEBUG,,}" != "true" ]]; then
41+
return
42+
fi
43+
44+
log_info "Volume info for $@:"
45+
set +e
46+
log_and_run mount
47+
while [ $# -gt 0 ]; do
48+
log_and_run ls -alZ $1
49+
shift
50+
done
51+
set -e
52+
}
53+
54+
# get_matched_files finds file for image extending
55+
function get_matched_files() {
56+
local custom_dir default_dir
57+
custom_dir="$1"
58+
default_dir="$2"
59+
files_matched="$3"
60+
find "$default_dir" -maxdepth 1 -type f -name "$files_matched" -printf "%f\n"
61+
[ -d "$custom_dir" ] && find "$custom_dir" -maxdepth 1 -type f -name "$files_matched" -printf "%f\n"
62+
}
63+
64+
# process_extending_files process extending files in $1 and $2 directories
65+
# - source all *.sh files
66+
# (if there are files with same name source only file from $1)
67+
function process_extending_files() {
68+
local custom_dir default_dir
69+
custom_dir=$1
70+
default_dir=$2
71+
72+
while read filename ; do
73+
echo "=> sourcing $filename ..."
74+
# Custom file is prefered
75+
if [ -f $custom_dir/$filename ]; then
76+
source $custom_dir/$filename
77+
elif [ -f $default_dir/$filename ]; then
78+
source $default_dir/$filename
79+
fi
80+
done <<<"$(get_matched_files "$custom_dir" "$default_dir" '*.sh' | sort -u)"
81+
}
82+
83+
# process extending config files in $1 and $2 directories
84+
# - expand variables in *.conf and copy the files into /opt/app-root/etc/httpd.d directory
85+
# (if there are files with same name source only file from $1)
86+
function process_extending_config_files() {
87+
local custom_dir default_dir
88+
custom_dir=$1
89+
default_dir=$2
90+
91+
while read filename ; do
92+
echo "=> sourcing $filename ..."
93+
# Custom file is prefered
94+
if [ -f $custom_dir/$filename ]; then
95+
envsubst < $custom_dir/$filename > ${HTTPD_CONFIGURATION_PATH}/$filename
96+
elif [ -f $default_dir/$filename ]; then
97+
envsubst < $default_dir/$filename > ${HTTPD_CONFIGURATION_PATH}/$filename
98+
fi
99+
done <<<"$(get_matched_files "$custom_dir" "$default_dir" '*.conf' | sort -u)"
100+
}
101+
102+
# Copy config files from application to the location where httd expects them
103+
# Param sets the directory where to look for files
104+
# This function was taken from httpd container
105+
process_config_files() {
106+
local dir=${1:-.}
107+
if [ -d ${dir}/httpd-cfg ]; then
108+
echo "---> Copying httpd configuration files..."
109+
if [ "$(ls -A ${dir}/httpd-cfg/*.conf)" ]; then
110+
cp -v ${dir}/httpd-cfg/*.conf "${HTTPD_CONFIGURATION_PATH}"/
111+
rm -rf ${dir}/httpd-cfg
112+
fi
113+
fi
114+
}
115+
116+
# Copy SSL files provided in application source
117+
# This function was taken from httpd container
118+
process_ssl_certs() {
119+
local dir=${1:-.}
120+
if [ -d ${dir}/httpd-ssl/private ] && [ -d ${dir}/httpd-ssl/certs ]; then
121+
echo "---> Looking for SSL certs for httpd..."
122+
cp -r ${dir}/httpd-ssl ${APP_ROOT}
123+
local ssl_cert="$(ls -A ${APP_ROOT}/httpd-ssl/certs/*.pem | head -n 1)"
124+
local ssl_private="$(ls -A ${APP_ROOT}/httpd-ssl/private/*.pem | head -n 1)"
125+
if [ -f "${ssl_cert}" ] && [ -f "${ssl_private}" ]; then
126+
echo "---> Setting SSL certs for httpd..."
127+
sed -i -e "s|^SSLCertificateFile .*$|SSLCertificateFile ${ssl_cert}|" ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf
128+
sed -i -e "s|^SSLCertificateKeyFile .*$|SSLCertificateKeyFile ${ssl_private}|" ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf
129+
fi
130+
rm -rf ${dir}/httpd-ssl
131+
fi
132+
}
133+
134+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DocumentRoot "/opt/app-root/src${DOCUMENTROOT}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<IfModule mpm_prefork_module>
2+
# This value should mirror what is set in MinSpareServers.
3+
StartServers ${HTTPD_START_SERVERS}
4+
MinSpareServers ${HTTPD_START_SERVERS}
5+
MaxSpareServers ${HTTPD_MAX_SPARE_SERVERS}
6+
# The MaxRequestWorkers directive sets the limit on the number of simultaneous requests that will be served.
7+
# The default value, when no Cgroup limits are set is 256.
8+
MaxRequestWorkers ${HTTPD_MAX_REQUEST_WORKERS}
9+
ServerLimit ${HTTPD_MAX_REQUEST_WORKERS}
10+
MaxRequestsPerChild 4000
11+
MaxKeepAliveRequests 100
12+
</IfModule>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# additional arbitrary httpd configuration provided by user using s2i
2+
3+
log_info 'Processing additional arbitrary httpd configuration provided by s2i ...'
4+
5+
process_extending_config_files ${APP_DATA}/httpd-cfg/ ${PHP_CONTAINER_SCRIPTS_PATH}/httpd-cnf/
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source ${PHP_CONTAINER_SCRIPTS_PATH}/common.sh
2+
3+
# Copy SSL files provided in application source
4+
process_ssl_certs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# additional arbitrary httpd configuration provided by user using s2i
2+
3+
log_info 'Processing additional arbitrary httpd configuration provided by s2i ...'
4+
5+
process_extending_config_files ${APP_DATA}/httpd-cfg/ ${PHP_CONTAINER_SCRIPTS_PATH}/httpd-cnf/
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source ${PHP_CONTAINER_SCRIPTS_PATH}/common.sh
2+
3+
# Copy SSL files provided in application source
4+
process_ssl_certs ${APP_ROOT}/src

Diff for: 7.0/root/usr/libexec/container-setup

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# In order to drop the root user, we have to make some directories world
6+
# writeable as OpenShift default security model is to run the container under
7+
# random UID.
8+
9+
source ${PHP_CONTAINER_SCRIPTS_PATH}/common.sh
10+
11+
# compatibility symlinks so we hide SCL paths
12+
if [ -v SCL_ENABLED ] ; then
13+
# /opt/rh/httpd24/root/etc/httpd will be symlink to /etc/httpd
14+
mv /opt/rh/httpd24/root/etc/httpd /etc/httpd
15+
ln -s /etc/httpd /opt/rh/httpd24/root/etc/httpd
16+
17+
# /opt/rh/httpd24/root/var/run/httpd will be symlink to /var/run/httpd
18+
mv /opt/rh/httpd24/root/var/run/httpd /var/run/httpd
19+
ln -s /var/run/httpd /opt/rh/httpd24/root/var/run/httpd
20+
21+
# /opt/rh/httpd24/root/var/www will be symlink to /var/www
22+
rm -rf /var/www
23+
mv ${HTTPD_DATA_ORIG_PATH} /var/www
24+
ln -s /var/www ${HTTPD_DATA_ORIG_PATH}
25+
else
26+
rm -f /opt/app-root/etc/scl_enable
27+
fi
28+
29+
mkdir -p ${HTTPD_CONFIGURATION_PATH}
30+
chmod -R a+rwx ${HTTPD_MAIN_CONF_PATH}
31+
chmod -R a+rwx ${HTTPD_MAIN_CONF_D_PATH}
32+
chmod -R ug+r /etc/pki/tls/certs/localhost.crt
33+
chmod -R ug+r /etc/pki/tls/private/localhost.key
34+
chown -R 1000:0 /etc/pki/tls/certs/localhost.crt
35+
chown -R 1000:0 /etc/pki/tls/private/localhost.key
36+
mkdir -p ${APP_ROOT}/etc
37+
chmod -R a+rwx ${APP_ROOT}/etc
38+
chmod -R a+rwx ${HTTPD_VAR_RUN}
39+
chown -R 1001:0 ${APP_ROOT}
40+
mkdir /tmp/sessions
41+
chown -R 1000:0 /tmp/sessions
42+
chown -R 1001:0 ${HTTPD_DATA_PATH}
43+
chmod -R a+rwx ${PHP_SYSCONF_PATH}
44+
45+
mkdir -p ${PHP_CONTAINER_SCRIPTS_PATH}/pre-init
46+
47+
config_general
48+

0 commit comments

Comments
 (0)