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

Commit 88fa932

Browse files
committed
Merge pull request #77 from jdeathe/issue/76
CLOSES #76: Merge in upstream changes from 1.4.5 tag.
2 parents ad29c0b + 6af86a3 commit 88fa932

File tree

9 files changed

+127
-66
lines changed

9 files changed

+127
-66
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# CentOS-6, Apache 2.2, PHP 5.3, PHP Memcached 1.0, PHP APC 3.1.
55
#
66
# =============================================================================
7-
FROM jdeathe/centos-ssh-apache-php:centos-6-1.4.4
7+
FROM jdeathe/centos-ssh-apache-php:centos-6-1.4.5
88

99
MAINTAINER James Deathe <james.deathe@gmail.com>
1010

README.md

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ Run up a container named ```apache-php.app-1.1.1``` from the docker image ```jde
3535
$ docker run -d \
3636
--name apache-php.app-1.1.1 \
3737
-p 8080:80 \
38-
--env "SERVICE_UNIT_APP_GROUP=app-1" \
39-
--env "SERVICE_UNIT_LOCAL_ID=1" \
40-
--env "SERVICE_UNIT_INSTANCE=1" \
4138
--env "APACHE_SERVER_NAME=app-1.local" \
42-
--env "PHP_OPTIONS_DATE_TIMEZONE=UTC" \
4339
-v /var/www \
4440
jdeathe/centos-ssh-apache-php-fcgi:latest
4541
```
@@ -198,9 +194,6 @@ $ docker stop apache-php.app-1.1.1 && \
198194
$ docker run -d \
199195
--name apache-php.app-1.1.1 \
200196
-p 8080:80 \
201-
--env "SERVICE_UNIT_INSTANCE=app-1" \
202-
--env "SERVICE_UNIT_LOCAL_ID=1" \
203-
--env "SERVICE_UNIT_INSTANCE=1" \
204197
--env "APACHE_CONTENT_ROOT=/var/www/app-1" \
205198
--env "APACHE_CUSTOM_LOG_FORMAT=combined" \
206199
--env "APACHE_CUSTOM_LOG_LOCATION=/var/www/app-1/var/log/apache_access_log" \
@@ -215,6 +208,7 @@ $ docker run -d \
215208
--env "APACHE_SERVER_NAME=app-1.local" \
216209
--env "APACHE_SYSTEM_USER=app" \
217210
--env "PHP_OPTIONS_DATE_TIMEZONE=UTC" \
211+
--env "SERVICE_UID=app-1.1.1" \
218212
-v volume-data.apache-php.app-1.1.1:/var/www \
219213
jdeathe/centos-ssh-apache-php-fcgi:latest
220214
```
@@ -229,12 +223,10 @@ $ docker stop apache-php.app-1.1.1 && \
229223
$ docker run -d \
230224
--name apache-php.app-1.1.1 \
231225
-p 8080:80 \
232-
--env "SERVICE_UNIT_INSTANCE=app-1" \
233-
--env "SERVICE_UNIT_LOCAL_ID=1" \
234-
--env "SERVICE_UNIT_INSTANCE=1" \
235226
--env "APACHE_SERVER_ALIAS=app-1" \
236227
--env "APACHE_SERVER_NAME=app-1.local" \
237228
--env "PHP_OPTIONS_DATE_TIMEZONE=UTC" \
229+
--env "SERVICE_UID=app-1.1.1" \
238230
--volumes-from volume-config.apache-php.app-1.1.1 \
239231
-v volume-data.apache-php.app-1.1.1:/var/www \
240232
jdeathe/centos-ssh-apache-php-fcgi:latest
@@ -248,30 +240,26 @@ $ docker logs apache-php.app-1.1.1
248240

249241
The output of the logs should show the Apache modules being loaded and auto-generated password for the Apache user and group, (if not try again after a few seconds).
250242

251-
#### Runtime Environment Variables
243+
#### Environment Variables
252244

253-
There are several environmental variables defined at runtime these allow the operator to customise the running container which may become necessary when running several on the same docker host, when clustering docker hosts or to simply set the timezone.
254-
255-
##### SERVICE_UNIT_INSTANCE, SERVICE_UNIT_LOCAL_ID & SERVICE_UNIT_INSTANCE
245+
##### APACHE_SERVER_NAME & APACHE_SERVER_ALIAS
256246

257-
The ```SERVICE_UNIT_INSTANCE```, ```SERVICE_UNIT_LOCAL_ID``` and ```SERVICE_UNIT_INSTANCE``` environmental variables are used to set a response header named ```X-Service-Uid``` that lets you identify the container that is serving the content. This is useful when you have many containers running on a single host using different ports (i.e with different ```SERVICE_UNIT_LOCAL_ID``` values) or if you are running a cluster and need to identify which host the content is served from (i.e with different ```SERVICE_UNIT_INSTANCE``` values). The three values should map to the last 3 dotted values of the container name; in our case that is "app-1.1.1"
247+
The ```APACHE_SERVER_NAME``` and ```APACHE_SERVER_ALIAS``` environmental variables are used to set the VirtualHost ```ServerName``` and ```ServerAlias``` values respectively. In the following example the running container would respond to the host names ```app-1.local``` or ```app-1```:
258248

259249
```
260250
...
261-
--env "SERVICE_UNIT_APP_GROUP=app-1" \
262-
--env "SERVICE_UNIT_LOCAL_ID=1" \
263-
--env "SERVICE_UNIT_INSTANCE=1" \
251+
--env "APACHE_SERVER_ALIAS=app-1" \
252+
--env "APACHE_SERVER_NAME=app-1.local" \
264253
...
265254
```
266255

267-
##### APACHE_SERVER_NAME & APACHE_SERVER_ALIAS
256+
##### APACHE_CONTENT_ROOT
268257

269-
The ```APACHE_SERVER_NAME``` and ```APACHE_SERVER_ALIAS``` environmental variables are used to set the VirtualHost ```ServerName``` and ```ServerAlias``` values respectively. In the following example the running container would respond to the host names ```app-1.local``` or ```app-1```:
258+
The home directory of the service user and parent directory of the Apache DocumentRoot is /var/www/app by default but can be changed if necessary using the ```APACHE_CONTENT_ROOT``` environment variable.
270259

271260
```
272261
...
273-
--env "APACHE_SERVER_ALIAS=app-1" \
274-
--env "APACHE_SERVER_NAME=app-1.local" \
262+
--env "APACHE_CONTENT_ROOT=/var/www/app-1" \
275263
...
276264
```
277265

@@ -288,7 +276,7 @@ The Apache CustomLog can be defined using ```APACHE_CUSTOM_LOG_LOCATION``` to se
288276
...
289277
```
290278

291-
##### APACHE_ERROR_LOG_LOCATION && APACHE_ERROR_LOG_LEVEL
279+
##### APACHE_ERROR_LOG_LOCATION & APACHE_ERROR_LOG_LEVEL
292280

293281
The Apache ErrorLog can be defined using ```APACHE_ERROR_LOG_LOCATION``` to set a file | pipe location and ```APACHE_ERROR_LOG_LEVEL``` to specify the required LogLevel value.
294282

@@ -363,23 +351,23 @@ The Apache process is run by the User and Group defined by ```APACHE_RUN_USER```
363351
...
364352
```
365353

366-
##### APACHE_CONTENT_ROOT
354+
##### APACHE_PUBLIC_DIRECTORY
367355

368-
The home directory of the service user and parent directory of the Apache DocumentRoot is /var/www/app by default but can be changed if necessary using the ```APACHE_CONTENT_ROOT``` environment variable.
356+
The public directory is relative to the ```APACHE_CONTENT_ROOT``` and together they form the Apache DocumentRoot path. The default value is `public_html` and should not be changed unless changes are made to the source of the app to include an alternative public directory such as `web` or `public`.
369357

370358
```
371359
...
372-
--env "APACHE_CONTENT_ROOT=/var/www/app-1" \
360+
--env "APACHE_PUBLIC_DIRECTORY=web" \
373361
...
374362
```
375363

376-
##### APACHE_PUBLIC_DIRECTORY
364+
##### APACHE_SYSTEM_USER
377365

378-
The public directory is relative to the ```APACHE_CONTENT_ROOT``` and together they form the Apache DocumentRoot path. The default value is `public_html` and should not be changed unless changes are made to the source of the app to include an alternative public directory such as `web` or `public`.
366+
Use the ```APACHE_SYSTEM_USER``` environment variable to define a custom service username.
379367

380368
```
381369
...
382-
--env "APACHE_PUBLIC_DIRECTORY=web" \
370+
--env "APACHE_SYSTEM_USER=app-1" \
383371
...
384372
```
385373

@@ -395,13 +383,13 @@ To set the timezone for the UK and account for British Summer Time you would use
395383
...
396384
```
397385

398-
##### APACHE_SYSTEM_USER
386+
##### SERVICE_UID
399387

400-
Use the ```APACHE_SYSTEM_USER``` environment variable to define a custom service username.
388+
The ```SERVICE_UID``` environmental variable is used to set a response header named ```X-Service-Uid``` that lets you identify the container that is serving the content. This is useful when you have many containers running on a single host using different ports or if you are running a cluster and need to identify which host the content is served from. The default value is set to the Service Unit's App Group Name, Local ID and Instance ID.
401389

402390
```
403391
...
404-
--env "APACHE_SYSTEM_USER=app-1" \
392+
--env "SERVICE_UID=app-1.1.1" \
405393
...
406394
```
407395

apache-php.app-1.1.1@8080.service

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Environment="APACHE_ERROR_LOG_LEVEL=warn"
4545
Environment="APACHE_EXTENDED_STATUS_ENABLED=false"
4646
Environment="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"
4747
Environment="APACHE_MOD_SSL_ENABLED=false"
48+
Environment="APACHE_OPERATING_MODE=production"
4849
Environment="APACHE_PUBLIC_DIRECTORY=public_html"
4950
Environment="APACHE_RUN_GROUP=app-www"
5051
Environment="APACHE_RUN_USER=app-www"
@@ -109,12 +110,10 @@ ExecStart=/bin/sudo /bin/bash -c \
109110
--name %p \
110111
-p %i:80 \
111112
-p 8580:8443 \
112-
--env \"SERVICE_UNIT_APP_GROUP=${SERVICE_UNIT_APP_GROUP}\" \
113-
--env \"SERVICE_UNIT_LOCAL_ID=${SERVICE_UNIT_LOCAL_ID}\" \
114-
--env \"SERVICE_UNIT_INSTANCE=${SERVICE_UNIT_INSTANCE}\" \
115113
--env \"APACHE_SERVER_ALIAS=${APACHE_SERVER_ALIAS}\" \
116114
--env \"APACHE_SERVER_NAME=${APACHE_SERVER_NAME}\" \
117115
--env \"PHP_OPTIONS_DATE_TIMEZONE=${PHP_OPTIONS_DATE_TIMEZONE}\" \
116+
--env \"SERVICE_UID=${SERVICE_UNIT_APP_GROUP}.${SERVICE_UNIT_LOCAL_ID}.${SERVICE_UNIT_INSTANCE}\" \
118117
--volumes-from volume-config.%p \
119118
-v ${VOLUME_DATA_NAME}:${APACHE_SERVER_HOME} \
120119
${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}; \
@@ -123,9 +122,6 @@ ExecStart=/bin/sudo /bin/bash -c \
123122
--name %p \
124123
-p %i:80 \
125124
-p 8580:8443 \
126-
--env \"SERVICE_UNIT_APP_GROUP=${SERVICE_UNIT_APP_GROUP}\" \
127-
--env \"SERVICE_UNIT_LOCAL_ID=${SERVICE_UNIT_LOCAL_ID}\" \
128-
--env \"SERVICE_UNIT_INSTANCE=${SERVICE_UNIT_INSTANCE}\" \
129125
--env \"APACHE_CONTENT_ROOT=${APACHE_CONTENT_ROOT}\" \
130126
--env \"APACHE_CUSTOM_LOG_FORMAT=${APACHE_CUSTOM_LOG_FORMAT}\" \
131127
--env \"APACHE_CUSTOM_LOG_LOCATION=${APACHE_CUSTOM_LOG_LOCATION}\" \
@@ -142,6 +138,7 @@ ExecStart=/bin/sudo /bin/bash -c \
142138
--env \"APACHE_SYSTEM_USER=${APACHE_SYSTEM_USER}\" \
143139
--env \"HTTPD=${HTTPD}\" \
144140
--env \"PHP_OPTIONS_DATE_TIMEZONE=${PHP_OPTIONS_DATE_TIMEZONE}\" \
141+
--env \"SERVICE_UID=${SERVICE_UNIT_APP_GROUP}.${SERVICE_UNIT_LOCAL_ID}.${SERVICE_UNIT_INSTANCE}\" \
145142
-v ${VOLUME_DATA_NAME}:${APACHE_SERVER_HOME} \
146143
${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}; \
147144
fi"

etc/apache-bootstrap

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,87 @@ enable_apache_modules ()
5252
local MODULES_ENABLED=""
5353
local SED_COMMAND=""
5454

55+
# Available DSO Modules
56+
declare -a MODULE_IDENTFIERS=(
57+
'auth_basic_module'
58+
'auth_digest_module'
59+
'authn_file_module'
60+
'authn_alias_module'
61+
'authn_anon_module'
62+
'authn_dbm_module'
63+
'authn_default_module'
64+
'authz_host_module'
65+
'authz_user_module'
66+
'authz_owner_module'
67+
'authz_groupfile_module'
68+
'authz_dbm_module'
69+
'authz_default_module'
70+
'ldap_module'
71+
'authnz_ldap_module'
72+
'include_module'
73+
'log_config_module'
74+
'logio_module'
75+
'env_module'
76+
'ext_filter_module'
77+
'mime_magic_module'
78+
'expires_module'
79+
'deflate_module'
80+
'headers_module'
81+
'usertrack_module'
82+
'setenvif_module'
83+
'mime_module'
84+
'dav_module'
85+
'status_module'
86+
'autoindex_module'
87+
'info_module'
88+
'dav_fs_module'
89+
'vhost_alias_module'
90+
'negotiation_module'
91+
'dir_module'
92+
'actions_module'
93+
'speling_module'
94+
'userdir_module'
95+
'alias_module'
96+
'substitute_module'
97+
'rewrite_module'
98+
'proxy_module'
99+
'proxy_balancer_module'
100+
'proxy_ftp_module'
101+
'proxy_http_module'
102+
'proxy_ajp_module'
103+
'proxy_connect_module'
104+
'cache_module'
105+
'suexec_module'
106+
'disk_cache_module'
107+
'cgi_module'
108+
'version_module'
109+
'reqtimeout_module'
110+
'asis_module'
111+
'authn_dbd_module'
112+
'cern_meta_module'
113+
'cgid_module'
114+
'dbd_module'
115+
'dumpio_module'
116+
'filter_module'
117+
'ident_module'
118+
'log_forensic_module'
119+
'unique_id_module'
120+
)
121+
55122
if [[ -n ${MODULES} ]]; then
56-
for MODULE in ${MODULES}; do
57-
MODULES_ENABLED+=" - ${MODULE}\n"
58-
SED_COMMAND+=" -e \"s~^#LoadModule ${MODULE} ~LoadModule ${MODULE} ~g\""
123+
for MODULE_IDENTFIER in ${MODULES}; do
124+
# Prevent invalid or unavailable module identifiers
125+
if [[ " ${MODULE_IDENTFIERS[@]} " =~ " ${MODULE_IDENTFIER} " ]]; then
126+
MODULES_ENABLED+=" - ${MODULE_IDENTFIER}\n"
127+
SED_COMMAND+="$(
128+
printf -- " -e 's~^#LoadModule %s ~LoadModule %s ~g'" \
129+
${MODULE_IDENTFIER} ${MODULE_IDENTFIER}
130+
)"
131+
fi
59132
done
60133

61134
if [[ -n ${SED_COMMAND} ]]; then
62-
sed -i ${SED_COMMAND} /etc/httpd/conf/httpd.conf
135+
eval "$(printf 'sed -i %s /etc/httpd/conf/httpd.conf' "${SED_COMMAND}")"
63136
fi
64137

65138
printf -- "%b" "${MODULES_ENABLED}"
@@ -354,12 +427,12 @@ HTTPD=${HTTPD:-${HTTPD_MPM_PREFORK}}
354427
if [[ ${HTTPD} == ${HTTPD_MPM_PREFORK} ]]; then
355428
echo "Apache Server MPM: Prefork"
356429
sed -i \
357-
-e "s~HTTPD=${HTTPD_MPM_WORKER}~#HTTPD=${HTTPD_MPM_WORKER}~g" \
430+
-e "s~^HTTPD=${HTTPD_MPM_WORKER}~#HTTPD=${HTTPD_MPM_WORKER}~g" \
358431
/etc/sysconfig/httpd
359432
elif [[ ${HTTPD} == ${HTTPD_MPM_WORKER} ]]; then
360433
echo "Apache Server MPM: Worker"
361434
sed -i \
362-
-e "s~#HTTPD=${HTTPD_MPM_WORKER}~HTTPD=${HTTPD_MPM_WORKER}~g" \
435+
-e "s~^#HTTPD=${HTTPD_MPM_WORKER}~HTTPD=${HTTPD_MPM_WORKER}~g" \
363436
/etc/sysconfig/httpd
364437
else
365438
echo "ERROR: Apache Server MPM (${HTTPD}) unknown."

etc/services-config/httpd/apache-bootstrap.conf

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ APACHE_LOAD_MODULES_DEFAULT="
1111
alias_module
1212
"
1313

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-
1814
APACHE_CONTENT_ROOT="${APACHE_CONTENT_ROOT:-/var/www/app}"
1915
APACHE_CUSTOM_LOG_FORMAT="${APACHE_CUSTOM_LOG_FORMAT:-combined}"
2016
APACHE_CUSTOM_LOG_LOCATION="${APACHE_CUSTOM_LOG_LOCATION:-${APACHE_CONTENT_ROOT}/var/log/apache_access_log}"
@@ -23,11 +19,13 @@ APACHE_ERROR_LOG_LEVEL="${APACHE_ERROR_LOG_LEVEL:-warn}"
2319
APACHE_EXTENDED_STATUS_ENABLED="${APACHE_EXTENDED_STATUS_ENABLED:-false}"
2420
APACHE_LOAD_MODULES="${APACHE_LOAD_MODULES:-${APACHE_LOAD_MODULES_DEFAULT}}"
2521
APACHE_MOD_SSL_ENABLED="${APACHE_MOD_SSL_ENABLED:-false}"
22+
APACHE_OPERATING_MODE="${APACHE_OPERATING_MODE:-production}"
2623
APACHE_PUBLIC_DIRECTORY="${APACHE_PUBLIC_DIRECTORY:-public_html}"
2724
APACHE_RUN_GROUP="${APACHE_RUN_GROUP:-app-www}"
2825
APACHE_RUN_USER="${APACHE_RUN_USER:-app-www}"
2926
APACHE_SERVER_ALIAS="${APACHE_SERVER_ALIAS:-}"
30-
APACHE_SERVER_NAME="${APACHE_SERVER_NAME:-${SERVICE_UNIT_APP_GROUP}.local}"
27+
APACHE_SERVER_NAME="${APACHE_SERVER_NAME:-app-1.local}"
3128
APACHE_SYSTEM_USER="${APACHE_SYSTEM_USER:-app}"
3229
HTTPD="${HTTPD:-/usr/sbin/httpd}"
33-
PHP_OPTIONS_DATE_TIMEZONE="${PHP_OPTIONS_DATE_TIMEZONE:-UTC}"
30+
PHP_OPTIONS_DATE_TIMEZONE="${PHP_OPTIONS_DATE_TIMEZONE:-UTC}"
31+
SERVICE_UID="${SERVICE_UID:-}"

etc/services-config/supervisor/supervisord.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ stdout_events_enabled = true
3434

3535
[program:httpd]
3636
priority = 100
37-
command = /bin/bash -c "/bin/sleep 1 && %(ENV_HTTPD)s -c \"ErrorLog /dev/stdout\" -DFOREGROUND"
37+
command = /bin/bash -c "/bin/sleep 1 && %(ENV_HTTPD)s -c \"ErrorLog /dev/stdout\" -DFOREGROUND -D %(ENV_APACHE_OPERATING_MODE)s"
3838
redirect_stderr = true
3939
stdout_logfile = /var/log/httpd/error_log
4040
stdout_events_enabled = true

run.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ APACHE_ERROR_LOG_LOCATION=${APACHE_CONTENT_ROOT}/var/log/apache_error_log
7272
APACHE_ERROR_LOG_LEVEL=warn
7373
APACHE_EXTENDED_STATUS_ENABLED=false
7474
APACHE_LOAD_MODULES="${APACHE_LOAD_MODULES_DEFAULT}"
75+
APACHE_OPERATING_MODE=production
7576
APACHE_MOD_SSL_ENABLED=false
7677
APACHE_PUBLIC_DIRECTORY=public_html
7778
APACHE_RUN_GROUP=app-www
@@ -81,6 +82,7 @@ APACHE_SERVER_NAME=app-1.local
8182
APACHE_SYSTEM_USER=app
8283
HTTPD=/usr/sbin/httpd.worker
8384
PHP_OPTIONS_DATE_TIMEZONE=UTC
85+
SERVICE_UID=${SERVICE_UNIT_APP_GROUP}.${SERVICE_UNIT_LOCAL_ID}.${SERVICE_UNIT_INSTANCE}
8486

8587
# Linked container
8688
DOCKER_LINK_NAME_DB_MYSQL=mysql.${SERVICE_UNIT_SHARED_GROUP}.1.1

run.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ docker run \
168168
--env "APACHE_SYSTEM_USER=${APACHE_SYSTEM_USER}" \
169169
--env "HTTPD=${HTTPD}" \
170170
--env "PHP_OPTIONS_DATE_TIMEZONE=${PHP_OPTIONS_DATE_TIMEZONE}" \
171+
--env "SERVICE_UID=${SERVICE_UID}" \
171172
${DOCKER_VOLUMES_FROM:-} \
172173
${DOCKER_IMAGE_REPOSITORY_NAME}${@:+ -c }"${@}"
173174
)
@@ -201,6 +202,7 @@ docker run \
201202
# --env "APACHE_SYSTEM_USER=app" \
202203
# --env "HTTPD=/usr/sbin/httpd.worker" \
203204
# --env "PHP_OPTIONS_DATE_TIMEZONE=Europe/London" \
205+
# --env "SERVICE_UID=app-1.1.1" \
204206
# ${DOCKER_VOLUMES_FROM:-} \
205207
# ${DOCKER_IMAGE_REPOSITORY_NAME}${@:+ -c }"${@}"
206208
# )

0 commit comments

Comments
 (0)