Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit 7154889

Browse files
committed
ISSUE 29: Add config via environment variables.
1 parent d57ec78 commit 7154889

File tree

4 files changed

+172
-136
lines changed

4 files changed

+172
-136
lines changed

build.sh

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env bash
22

33
# Change working directory
4-
DIR_PATH="$( if [ "$( echo "${0%/*}" )" != "$( echo "${0}" )" ] ; then cd "$( echo "${0%/*}" )"; fi; pwd )"
5-
if [[ $DIR_PATH == */* ]] && [[ $DIR_PATH != "$( pwd )" ]] ; then
6-
cd $DIR_PATH
4+
DIR_PATH="$( if [[ $( echo "${0%/*}" ) != $( echo "${0}" ) ]]; then cd "$( echo "${0%/*}" )"; fi; pwd )"
5+
if [[ ${DIR_PATH} == */* ]] && [[ ${DIR_PATH} != $( pwd ) ]]; then
6+
cd ${DIR_PATH}
77
fi
88

9-
NO_CACHE="$1"
9+
NO_CACHE=$1
1010

1111
source build.conf
1212

@@ -16,28 +16,27 @@ show_docker_image ()
1616
local NAME_PARTS=(${NAME//:/ })
1717

1818
# Set 'latest' tag if no tag requested
19-
if [ ${#NAME_PARTS[@]} == 1 ]; then
19+
if [[ ${#NAME_PARTS[@]} == 1 ]]; then
2020
NAME_PARTS[1]='latest'
2121
fi
2222

2323
docker images | grep -e "^${NAME_PARTS[0]}[ ]\{1,\}${NAME_PARTS[1]}"
2424
}
2525

26-
echo Building ${DOCKER_IMAGE_REPOSITORY_NAME}...
26+
echo "Building ${DOCKER_IMAGE_REPOSITORY_NAME}"
2727

2828
# Allow cache to be bypassed
29-
if [ "$NO_CACHE" == "true" ]; then
29+
if [[ ${NO_CACHE} == "true" ]]; then
3030
echo " ---> Skipping cache"
3131
else
3232
NO_CACHE="false"
3333
fi
3434

3535
# Build from working directory
36-
docker build --no-cache=$NO_CACHE -t ${DOCKER_IMAGE_REPOSITORY_NAME} .
37-
36+
docker build --no-cache=${NO_CACHE} -t ${DOCKER_IMAGE_REPOSITORY_NAME} .
3837

3938
# Display the last docker image
4039
echo "Docker image:"
4140
show_docker_image ${DOCKER_IMAGE_REPOSITORY_NAME}
4241

43-
echo " ---> Build complete"
42+
echo " ---> Build complete"

etc/apache-bootstrap

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,42 @@ get_password ()
77
echo $(head -n 4096 /dev/urandom | tr -cd '[:alnum:]' | head -c ${1})
88
}
99

10+
APP_HOME_DIR_TEMPLATE="/var/www/.app-skel"
11+
12+
OPTS_APACHE_SERVER_NAME="${APACHE_SERVER_NAME:-$(hostname)}"
13+
OPTS_APACHE_MOD_SSL_ENABLED="${APACHE_MOD_SSL_ENABLED:-false}"
14+
OPTS_APACHE_LOAD_MODULES="${APACHE_LOAD_MODULES:-authz_user_module log_config_module expires_module deflate_module headers_module setenvif_module mime_module status_module dir_module alias_module reqtimeout_module}"
15+
OPTS_APP_HOME_DIR="${APP_HOME_DIR:-/var/www/app}"
1016
OPTS_SERVICE_USER="${SERVICE_USER:-app}"
1117
OPTS_SERVICE_USER_GROUP="${SERVICE_USER_GROUP:-app-www}"
12-
OPTS_SERVICE_USER_PASSWORD="${SERVICE_USER_PASSWORD:-$(get_password 8)}"
1318
OPTS_SERVICE_USER_GROUP_PASSWORD="${SERVICE_USER_GROUP_PASSWORD:-$(get_password 8)}"
19+
OPTS_SERVICE_USER_PASSWORD="${SERVICE_USER_PASSWORD:-$(get_password 8)}"
1420
OPTS_SUEXECUSERGROUP="${SUEXECUSERGROUP:-false}"
1521

16-
OPTS_APACHE_SERVER_NAME="${APACHE_SERVER_NAME:-$(hostname)}"
17-
OPTS_APACHE_MOD_SSL_ENABLED="${APACHE_MOD_SSL_ENABLED:-false}"
18-
19-
if [[ ! -d ${APP_HOME_DIR} ]] && [[ -d ${APP_HOME_DIR_TEMPLATE} ]]; then
20-
echo Recreate the ${APP_HOME_DIR} directory...
21-
mkdir -p ${APP_HOME_DIR}
22+
if [[ ! -d ${OPTS_APP_HOME_DIR} ]] && [[ -d ${OPTS_APP_HOME_DIR_TEMPLATE} ]]; then
23+
echo "Recreate the ${OPTS_APP_HOME_DIR} directory."
24+
mkdir -p ${OPTS_APP_HOME_DIR}
2225
fi
2326

24-
if [[ ! -n $(find ${APP_HOME_DIR} -maxdepth 1 -type f) ]] && [[ -d ${APP_HOME_DIR_TEMPLATE} ]]; then
25-
echo Home directory ${APP_HOME_DIR} exists but is empty - populate it using ${APP_HOME_DIR_TEMPLATE}...
26-
cp -rf ${APP_HOME_DIR_TEMPLATE}/. ${APP_HOME_DIR}/
27+
if [[ -z $(find ${OPTS_APP_HOME_DIR} -maxdepth 1 -type f) ]] && [[ -d ${APP_HOME_DIR_TEMPLATE} ]]; then
28+
echo "Home directory ${OPTS_APP_HOME_DIR} is empty - populate it using ${APP_HOME_DIR_TEMPLATE}."
29+
cp -rf ${APP_HOME_DIR_TEMPLATE}/. ${OPTS_APP_HOME_DIR}/
2730
fi
2831

2932
# Document root directory is required
30-
if [[ ! -d ${APP_HOME_DIR}/public_html ]]; then
31-
echo ERROR: ${APP_HOME_DIR}/public_html not found.
33+
if [[ ! -d ${OPTS_APP_HOME_DIR}/public_html ]]; then
34+
echo "ERROR: ${OPTS_APP_HOME_DIR}/public_html not found."
3235
exit 1
3336
fi
3437

38+
if [[ ${OPTS_APP_HOME_DIR} != /var/www/app ]]; then
39+
unlink /home/app && ln -s ${OPTS_APP_HOME_DIR} /home/app
40+
fi
41+
3542
# If users need to change the vhost.conf the SSL version can be rebuilt if it is deleted
36-
if [[ ${OPTS_APACHE_MOD_SSL_ENABLED} == "true" ]] && [[ ! -f ${APP_HOME_DIR}/vhost-ssl.conf ]] && [[ -f ${APP_HOME_DIR}/vhost.conf ]]; then
37-
echo Rebuilding the SSL VirtualHost configuration...
38-
cp -pf ${APP_HOME_DIR}/vhost.conf ${APP_HOME_DIR}/vhost-ssl.conf
43+
if [[ ${OPTS_APACHE_MOD_SSL_ENABLED} == "true" ]] && [[ ! -f ${OPTS_APP_HOME_DIR}/vhost-ssl.conf ]] && [[ -f ${OPTS_APP_HOME_DIR}/vhost.conf ]]; then
44+
echo "Rebuilding the SSL VirtualHost configuration."
45+
cp -pf ${OPTS_APP_HOME_DIR}/vhost.conf ${OPTS_APP_HOME_DIR}/vhost-ssl.conf
3946

4047
# Enable the SSL VirtualHosts configuration
4148
sed -i \
@@ -47,70 +54,72 @@ if [[ ${OPTS_APACHE_MOD_SSL_ENABLED} == "true" ]] && [[ ! -f ${APP_HOME_DIR}/vho
4754
-e 's~#SSLCipherSuite \(.*\)$~SSLCipherSuite \1~g' \
4855
-e 's~#SSLCertificateFile \(.*\)$~SSLCertificateFile \1~g' \
4956
-e 's~#SSLCertificateKeyFile \(.*\)$~SSLCertificateKeyFile \1~g' \
50-
${APP_HOME_DIR}/vhost-ssl.conf
57+
${OPTS_APP_HOME_DIR}/vhost-ssl.conf
5158
fi
5259

5360
# Enable/Disable SSL support
54-
if [[ ${OPTS_APACHE_MOD_SSL_ENABLED} == "true" ]]; then
55-
echo Enabling SSL support...
61+
if [[ ${OPTS_APACHE_MOD_SSL_ENABLED} == true ]]; then
62+
echo "Enabling SSL support."
5663
cat /etc/httpd/conf.d/ssl.conf.off > /etc/httpd/conf.d/ssl.conf
5764

5865
sed -i \
5966
-e 's~^#NameVirtualHost \*:443$~NameVirtualHost \*:443~g' \
60-
-e 's~^#Include ${APP_HOME_DIR}/vhost-ssl.conf$~Include ${APP_HOME_DIR}/vhost-ssl.conf~g' \
67+
-e 's~^#Include ${OPTS_APP_HOME_DIR}/vhost-ssl.conf$~Include ${OPTS_APP_HOME_DIR}/vhost-ssl.conf~g' \
6168
/etc/httpd/conf/httpd.conf
6269

6370
if [[ ! -f /etc/services-config/ssl/private/localhost.key ]] || [[ ! -f /etc/services-config/ssl/certs/localhost.crt ]]; then
64-
echo Generating new certificate...
65-
openssl req -x509 -nodes -newkey rsa:4096 \
66-
-days 365 \
67-
-subj "/C=--/ST=STATE/L=LOCALITY/O=ORGANIZATION/CN=${OPTS_APACHE_SERVER_NAME}" \
68-
-keyout /etc/services-config/ssl/private/localhost.key \
69-
-out /etc/services-config/ssl/certs/localhost.crt
71+
echo "Generating new certificate."
72+
openssl req \
73+
-x509 \
74+
-nodes \
75+
-newkey rsa:4096 \
76+
-days 365 \
77+
-subj "/C=--/ST=STATE/L=LOCALITY/O=ORGANIZATION/CN=${OPTS_APACHE_SERVER_NAME}" \
78+
-keyout /etc/services-config/ssl/private/localhost.key \
79+
-out /etc/services-config/ssl/certs/localhost.crt
7080
fi
7181

7282
openssl x509 -in /etc/services-config/ssl/certs/localhost.crt -text
7383
else
74-
echo Disabling SSL support...
84+
echo "Disabling SSL support."
7585
> /etc/httpd/conf.d/ssl.conf
7686

7787
sed -i \
7888
-e 's~^NameVirtualHost \*:443$~#NameVirtualHost \*:443~g' \
79-
-e 's~^Include ${APP_HOME_DIR}/vhost-ssl.conf$~#Include ${APP_HOME_DIR}/vhost-ssl.conf~g' \
89+
-e 's~^Include ${OPTS_APP_HOME_DIR}/vhost-ssl.conf$~#Include ${OPTS_APP_HOME_DIR}/vhost-ssl.conf~g' \
8090
/etc/httpd/conf/httpd.conf
8191
fi
8292

8393
# Set the service user / service group user
84-
if getent passwd app && [[ ${OPTS_SERVICE_USER} != "app" ]]; then
94+
if getent passwd app && [[ ${OPTS_SERVICE_USER} != app ]]; then
8595
usermod -l ${OPTS_SERVICE_USER} app
8696
fi
8797

88-
if getent passwd app-www && [[ ${OPTS_SERVICE_USER_GROUP} != "app-www" ]]; then
98+
if getent passwd app-www && [[ ${OPTS_SERVICE_USER_GROUP} != app-www ]]; then
8999
usermod -l ${OPTS_SERVICE_USER_GROUP} app-www
90100
fi
91101

92102
# Set the Apache (run) service user/group
93-
if [[ ${OPTS_SUEXECUSERGROUP} == "true" ]]; then
103+
if [[ ${OPTS_SUEXECUSERGROUP} == true ]]; then
94104
sed -i -e "s~^User .*$~User ${OPTS_SERVICE_USER_GROUP}~g" \
95105
-e "s~^Group .*$~Group ${OPTS_SERVICE_USER_GROUP}~g" /etc/httpd/conf/httpd.conf
96-
sed -i -e 's~#SuexecUserGroup \(.*\)$~SuexecUserGroup \1~g' ${APP_HOME_DIR}/vhost.conf
97-
sed -i -e 's~#SuexecUserGroup \(.*\)$~SuexecUserGroup \1~g' ${APP_HOME_DIR}/vhost-ssl.conf
106+
sed -i -e 's~#SuexecUserGroup \(.*\)$~SuexecUserGroup \1~g' ${OPTS_APP_HOME_DIR}/vhost.conf
107+
sed -i -e 's~#SuexecUserGroup \(.*\)$~SuexecUserGroup \1~g' ${OPTS_APP_HOME_DIR}/vhost-ssl.conf
98108
chown -R 502:502 /var/{www/app-bin,run/mod_fcgid}
99109
else
100110
sed -i -e "s~^User .*$~User apache~g" \
101111
-e "s~^Group .*$~Group apache~g" /etc/httpd/conf/httpd.conf
102-
sed -i -e 's~\([^#]\)SuexecUserGroup \(.*\)$~\1#SuexecUserGroup \2~g' ${APP_HOME_DIR}/vhost.conf
103-
sed -i -e 's~\([^#]\)SuexecUserGroup \(.*\)$~\1#SuexecUserGroup \2~g' ${APP_HOME_DIR}/vhost-ssl.conf
112+
sed -i -e 's~\([^#]\)SuexecUserGroup \(.*\)$~\1#SuexecUserGroup \2~g' ${OPTS_APP_HOME_DIR}/vhost.conf
113+
sed -i -e 's~\([^#]\)SuexecUserGroup \(.*\)$~\1#SuexecUserGroup \2~g' ${OPTS_APP_HOME_DIR}/vhost-ssl.conf
104114
chown -R apache:apache /var/{www/app-bin,run/mod_fcgid}
105115
fi
106116

107117
# Update any existing instances of php-wrapper path in the Virtual Host
108-
sed -i -e 's~app/bin/php-wrapper~app-bin/php-wrapper~g' ${APP_HOME_DIR}/vhost.conf
109-
sed -i -e 's~app/bin/php-wrapper~app-bin/php-wrapper~g' ${APP_HOME_DIR}/vhost-ssl.conf
118+
sed -i -e 's~app/bin/php-wrapper~app-bin/php-wrapper~g' ${OPTS_APP_HOME_DIR}/vhost.conf
119+
sed -i -e 's~app/bin/php-wrapper~app-bin/php-wrapper~g' ${OPTS_APP_HOME_DIR}/vhost-ssl.conf
110120

111-
echo Loading Apache modules...
112-
for MODULE in ${APACHE_LOAD_MODULES}
113-
do
121+
echo "Loading Apache modules."
122+
for MODULE in ${APACHE_LOAD_MODULES}; do
114123
echo " - ${MODULE}"
115124
sed -i \
116125
-e "s~^#LoadModule ${MODULE} ~LoadModule ${MODULE} ~g" \
Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1-
APP_HOME_DIR=/var/www/app
2-
APP_HOME_DIR_TEMPLATE=/var/www/.app-skel
3-
SERVICE_USER=app
4-
SERVICE_USER_GROUP=app-www
5-
SERVICE_USER_PASSWORD=
6-
SERVICE_USER_GROUP_PASSWORD=
7-
SUEXECUSERGROUP=false
8-
APACHE_MOD_SSL_ENABLED=false
9-
APACHE_LOAD_MODULES="
10-
authz_user_module
11-
log_config_module
12-
expires_module
13-
deflate_module
14-
headers_module
15-
setenvif_module
16-
mime_module
17-
status_module
18-
dir_module
19-
alias_module
20-
"
1+
APACHE_LOAD_MODULES_DEFAULT="
2+
authz_user_module
3+
log_config_module
4+
expires_module
5+
deflate_module
6+
headers_module
7+
setenvif_module
8+
mime_module
9+
status_module
10+
dir_module
11+
alias_module
12+
"
13+
14+
SERVICE_UNIT_APP_GROUP="${SERVICE_UNIT_APP_GROUP:-app-1}"
15+
SERVICE_UNIT_LOCAL_ID="${SERVICE_UNIT_LOCAL_ID:-1}"
16+
SERVICE_UNIT_INSTANCE="${SERVICE_UNIT_INSTANCE:-1}"
17+
18+
APACHE_SERVER_ALIAS="${APACHE_SERVER_ALIAS:-}"
19+
APACHE_SERVER_NAME="${APACHE_SERVER_NAME:-${SERVICE_UNIT_APP_GROUP}.local}"
20+
APACHE_LOAD_MODULES="${APACHE_LOAD_MODULES:-${APACHE_LOAD_MODULES_DEFAULT}}"
21+
APACHE_MOD_SSL_ENABLED="${APACHE_MOD_SSL_ENABLED:-false}"
22+
APP_HOME_DIR="${APP_HOME_DIR:-/var/www/app}"
23+
DATE_TIMEZONE="${DATE_TIMEZONE:-UTC}"
24+
SERVICE_USER="${SERVICE_USER:-app}"
25+
SERVICE_USER_GROUP="${SERVICE_USER_GROUP:-app-www}"
26+
SERVICE_USER_GROUP_PASSWORD=""
27+
SERVICE_USER_PASSWORD="${SERVICE_USER_PASSWORD:-}"
28+
SUEXECUSERGROUP="${SUEXECUSERGROUP:-false}"

0 commit comments

Comments
 (0)