Skip to content

Commit 436d749

Browse files
committed
Using kool/php as base
1 parent 7f56e72 commit 436d749

53 files changed

Lines changed: 5249 additions & 717 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/docker.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,29 @@ jobs:
1616
- name: Build image
1717
run: |
1818
docker build --pull -t kooldev/wordpress:${{ matrix.version }} ${{ matrix.version }}
19+
docker build --pull -t kooldev/wordpress:${{ matrix.version }}-prod ${{ matrix.version }}-prod
1920
docker build -t kooldev/wordpress:${{ matrix.version }}-nginx ${{ matrix.version }}-nginx
21+
docker build -t kooldev/wordpress:${{ matrix.version }}-nginx-prod ${{ matrix.version }}-nginx-prod
2022
2123
- name: Test docker images PHP executable
2224
run: |
2325
docker run kooldev/wordpress:${{ matrix.version }} php -v
26+
docker run kooldev/wordpress:${{ matrix.version }}-prod php -v
27+
2428
docker run kooldev/wordpress:${{ matrix.version }}-nginx php -v
29+
docker run kooldev/wordpress:${{ matrix.version }}-nginx nginx -v
30+
docker run kooldev/wordpress:${{ matrix.version }}-nginx supervisord version
31+
32+
docker run kooldev/wordpress:${{ matrix.version }}-nginx-prod php -v
33+
docker run kooldev/wordpress:${{ matrix.version }}-nginx-prod nginx -v
34+
docker run kooldev/wordpress:${{ matrix.version }}-nginx-prod supervisord version
2535
2636
- name: Test docker images wordpress code
2737
run: |
2838
docker run kooldev/wordpress:${{ matrix.version }} php /usr/src/wordpress/index.php
39+
docker run kooldev/wordpress:${{ matrix.version }}-prod php /usr/src/wordpress/index.php
2940
docker run kooldev/wordpress:${{ matrix.version }}-nginx php /usr/src/wordpress/index.php
41+
docker run kooldev/wordpress:${{ matrix.version }}-nginx-prod php /usr/src/wordpress/index.php
3042
3143
- name: Push to Hub
3244
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
@@ -36,4 +48,6 @@ jobs:
3648
run: |
3749
echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin
3850
docker push kooldev/wordpress:${{ matrix.version }}
51+
docker push kooldev/wordpress:${{ matrix.version }}-prod
3952
docker push kooldev/wordpress:${{ matrix.version }}-nginx
53+
docker push kooldev/wordpress:${{ matrix.version }}-nginx-prod

7.1-nginx-prod/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM wordpress:php7.1-fpm-alpine as wordpress
2+
FROM kooldev/php:7.1-nginx-prod
3+
4+
ENV NGINX_ROOT=/app
5+
6+
COPY --from=wordpress --chown=kool:kool /usr/src/wordpress /kool/wordpress
7+
COPY --from=wordpress --chown=kool:kool /var/www/html/wp-content /app/wp-content
8+
COPY entrypoint /kool/entrypoint
9+
10+
RUN chmod -R 777 wp-content && chmod +x /kool/entrypoint

7.1-nginx-prod/entrypoint

Lines changed: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,288 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# usage: file_env VAR [DEFAULT]
5+
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
6+
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
7+
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
8+
file_env() {
9+
local var="$1"
10+
local fileVar="${var}_FILE"
11+
local def="${2:-}"
12+
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
13+
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
14+
exit 1
15+
fi
16+
local val="$def"
17+
if [ "${!var:-}" ]; then
18+
val="${!var}"
19+
elif [ "${!fileVar:-}" ]; then
20+
val="$(< "${!fileVar}")"
21+
fi
22+
export "$var"="$val"
23+
unset "$fileVar"
24+
}
25+
26+
if [ "$1" == php-fpm ] || [ "$1" == supervisord ]; then
27+
if [ "$(id -u)" = '0' ]; then
28+
user='kool'
29+
group='kool'
30+
else
31+
user="$(id -u)"
32+
group="$(id -g)"
33+
fi
34+
35+
if [ ! -e index.php ] && [ ! -e wp-includes/version.php ]; then
36+
# if the directory exists and WordPress doesn't appear to be installed AND the permissions of it are root:root, let's chown it (likely a Docker-created directory)
37+
if [ "$(id -u)" = '0' ] && [ "$(stat -c '%u:%g' .)" = '0:0' ]; then
38+
chown "$user:$group" .
39+
fi
40+
41+
echo >&2 "WordPress not found in $PWD - copying now..."
42+
if [ -n "$(find -mindepth 1 -maxdepth 1 -not -name wp-content)" ]; then
43+
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
44+
fi
45+
sourceTarArgs=(
46+
--create
47+
--file -
48+
--directory /kool/wordpress
49+
--owner "$user" --group "$group"
50+
)
51+
targetTarArgs=(
52+
--extract
53+
--file -
54+
)
55+
if [ "$user" != '0' ]; then
56+
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
57+
targetTarArgs+=( --no-overwrite-dir )
58+
fi
59+
# loop over "pluggable" content in the source, and if it already exists in the destination, skip it
60+
# https://github.com/docker-library/wordpress/issues/506 ("wp-content" persisted, "akismet" updated, WordPress container restarted/recreated, "akismet" downgraded)
61+
for contentDir in /kool/wordpress/wp-content/*/*/; do
62+
contentDir="${contentDir%/}"
63+
[ -d "$contentDir" ] || continue
64+
contentPath="${contentDir#/kool/wordpress/}" # "wp-content/plugins/akismet", etc.
65+
if [ -d "$PWD/$contentPath" ]; then
66+
echo >&2 "WARNING: '$PWD/$contentPath' exists! (not copying the WordPress version)"
67+
sourceTarArgs+=( --exclude "./$contentPath" )
68+
fi
69+
done
70+
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
71+
echo >&2 "Complete! WordPress has been successfully copied to $PWD"
72+
if [ ! -e .htaccess ]; then
73+
# NOTE: The "Indexes" option is disabled in the php:apache base image
74+
cat > .htaccess <<-'EOF'
75+
# BEGIN WordPress
76+
<IfModule mod_rewrite.c>
77+
RewriteEngine On
78+
RewriteBase /
79+
RewriteRule ^index\.php$ - [L]
80+
RewriteCond %{REQUEST_FILENAME} !-f
81+
RewriteCond %{REQUEST_FILENAME} !-d
82+
RewriteRule . /index.php [L]
83+
</IfModule>
84+
# END WordPress
85+
EOF
86+
chown "$user:$group" .htaccess
87+
fi
88+
fi
89+
90+
# allow any of these "Authentication Unique Keys and Salts." to be specified via
91+
# environment variables with a "WORDPRESS_" prefix (ie, "WORDPRESS_AUTH_KEY")
92+
uniqueEnvs=(
93+
AUTH_KEY
94+
SECURE_AUTH_KEY
95+
LOGGED_IN_KEY
96+
NONCE_KEY
97+
AUTH_SALT
98+
SECURE_AUTH_SALT
99+
LOGGED_IN_SALT
100+
NONCE_SALT
101+
)
102+
envs=(
103+
WORDPRESS_DB_HOST
104+
WORDPRESS_DB_USER
105+
WORDPRESS_DB_PASSWORD
106+
WORDPRESS_DB_NAME
107+
WORDPRESS_DB_CHARSET
108+
WORDPRESS_DB_COLLATE
109+
"${uniqueEnvs[@]/#/WORDPRESS_}"
110+
WORDPRESS_TABLE_PREFIX
111+
WORDPRESS_DEBUG
112+
WORDPRESS_CONFIG_EXTRA
113+
)
114+
haveConfig=
115+
for e in "${envs[@]}"; do
116+
file_env "$e"
117+
if [ -z "$haveConfig" ] && [ -n "${!e}" ]; then
118+
haveConfig=1
119+
fi
120+
done
121+
122+
# linking backwards-compatibility
123+
if [ -n "${!MYSQL_ENV_MYSQL_*}" ]; then
124+
haveConfig=1
125+
# host defaults to "mysql" below if unspecified
126+
: "${WORDPRESS_DB_USER:=${MYSQL_ENV_MYSQL_USER:-root}}"
127+
if [ "$WORDPRESS_DB_USER" = 'root' ]; then
128+
: "${WORDPRESS_DB_PASSWORD:=${MYSQL_ENV_MYSQL_ROOT_PASSWORD:-}}"
129+
else
130+
: "${WORDPRESS_DB_PASSWORD:=${MYSQL_ENV_MYSQL_PASSWORD:-}}"
131+
fi
132+
: "${WORDPRESS_DB_NAME:=${MYSQL_ENV_MYSQL_DATABASE:-}}"
133+
fi
134+
135+
# only touch "wp-config.php" if we have environment-supplied configuration values
136+
if [ "$haveConfig" ]; then
137+
: "${WORDPRESS_DB_HOST:=mysql}"
138+
: "${WORDPRESS_DB_USER:=root}"
139+
: "${WORDPRESS_DB_PASSWORD:=}"
140+
: "${WORDPRESS_DB_NAME:=wordpress}"
141+
: "${WORDPRESS_DB_CHARSET:=utf8}"
142+
: "${WORDPRESS_DB_COLLATE:=}"
143+
144+
# version 4.4.1 decided to switch to windows line endings, that breaks our seds and awks
145+
# https://github.com/docker-library/wordpress/issues/116
146+
# https://github.com/WordPress/WordPress/commit/1acedc542fba2482bab88ec70d4bea4b997a92e4
147+
sed -ri -e 's/\r$//' wp-config*
148+
149+
if [ ! -e wp-config.php ]; then
150+
awk '
151+
/^\/\*.*stop editing.*\*\/$/ && c == 0 {
152+
c = 1
153+
system("cat")
154+
if (ENVIRON["WORDPRESS_CONFIG_EXTRA"]) {
155+
print "// WORDPRESS_CONFIG_EXTRA"
156+
print ENVIRON["WORDPRESS_CONFIG_EXTRA"] "\n"
157+
}
158+
}
159+
{ print }
160+
' wp-config-sample.php > wp-config.php <<'EOPHP'
161+
// If we're behind a proxy server and using HTTPS, we need to alert WordPress of that fact
162+
// see also http://codex.wordpress.org/Administration_Over_SSL#Using_a_Reverse_Proxy
163+
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
164+
$_SERVER['HTTPS'] = 'on';
165+
}
166+
167+
EOPHP
168+
chown "$user:$group" wp-config.php
169+
elif [ -e wp-config.php ] && [ -n "$WORDPRESS_CONFIG_EXTRA" ] && [[ "$(< wp-config.php)" != *"$WORDPRESS_CONFIG_EXTRA"* ]]; then
170+
# (if the config file already contains the requested PHP code, don't print a warning)
171+
echo >&2
172+
echo >&2 'WARNING: environment variable "WORDPRESS_CONFIG_EXTRA" is set, but "wp-config.php" already exists'
173+
echo >&2 ' The contents of this variable will _not_ be inserted into the existing "wp-config.php" file.'
174+
echo >&2 ' (see https://github.com/docker-library/wordpress/issues/333 for more details)'
175+
echo >&2
176+
fi
177+
178+
# see http://stackoverflow.com/a/2705678/433558
179+
sed_escape_lhs() {
180+
echo "$@" | sed -e 's/[]\/$*.^|[]/\\&/g'
181+
}
182+
sed_escape_rhs() {
183+
echo "$@" | sed -e 's/[\/&]/\\&/g'
184+
}
185+
php_escape() {
186+
local escaped="$(php -r 'var_export(('"$2"') $argv[1]);' -- "$1")"
187+
if [ "$2" = 'string' ] && [ "${escaped:0:1}" = "'" ]; then
188+
escaped="${escaped//$'\n'/"' + \"\\n\" + '"}"
189+
fi
190+
echo "$escaped"
191+
}
192+
set_config() {
193+
key="$1"
194+
value="$2"
195+
var_type="${3:-string}"
196+
start="(['\"])$(sed_escape_lhs "$key")\2\s*,"
197+
end="\);"
198+
if [ "${key:0:1}" = '$' ]; then
199+
start="^(\s*)$(sed_escape_lhs "$key")\s*="
200+
end=";"
201+
fi
202+
sed -ri -e "s/($start\s*).*($end)$/\1$(sed_escape_rhs "$(php_escape "$value" "$var_type")")\3/" wp-config.php
203+
}
204+
205+
set_config 'DB_HOST' "$WORDPRESS_DB_HOST"
206+
set_config 'DB_USER' "$WORDPRESS_DB_USER"
207+
set_config 'DB_PASSWORD' "$WORDPRESS_DB_PASSWORD"
208+
set_config 'DB_NAME' "$WORDPRESS_DB_NAME"
209+
set_config 'DB_CHARSET' "$WORDPRESS_DB_CHARSET"
210+
set_config 'DB_COLLATE' "$WORDPRESS_DB_COLLATE"
211+
212+
for unique in "${uniqueEnvs[@]}"; do
213+
uniqVar="WORDPRESS_$unique"
214+
if [ -n "${!uniqVar}" ]; then
215+
set_config "$unique" "${!uniqVar}"
216+
else
217+
# if not specified, let's generate a random value
218+
currentVal="$(sed -rn -e "s/define\(\s*(([\'\"])$unique\2\s*,\s*)(['\"])(.*)\3\s*\);/\4/p" wp-config.php)"
219+
if [ "$currentVal" = 'put your unique phrase here' ]; then
220+
set_config "$unique" "$(head -c1m /dev/urandom | sha1sum | cut -d' ' -f1)"
221+
fi
222+
fi
223+
done
224+
225+
if [ "$WORDPRESS_TABLE_PREFIX" ]; then
226+
set_config '$table_prefix' "$WORDPRESS_TABLE_PREFIX"
227+
fi
228+
229+
if [ "$WORDPRESS_DEBUG" ]; then
230+
set_config 'WP_DEBUG' 1 boolean
231+
fi
232+
233+
if ! TERM=dumb php -- <<'EOPHP'
234+
<?php
235+
// database might not exist, so let's try creating it (just to be safe)
236+
237+
$stderr = fopen('php://stderr', 'w');
238+
239+
// https://codex.wordpress.org/Editing_wp-config.php#MySQL_Alternate_Port
240+
// "hostname:port"
241+
// https://codex.wordpress.org/Editing_wp-config.php#MySQL_Sockets_or_Pipes
242+
// "hostname:unix-socket-path"
243+
list($host, $socket) = explode(':', getenv('WORDPRESS_DB_HOST'), 2);
244+
$port = 0;
245+
if (is_numeric($socket)) {
246+
$port = (int) $socket;
247+
$socket = null;
248+
}
249+
$user = getenv('WORDPRESS_DB_USER');
250+
$pass = getenv('WORDPRESS_DB_PASSWORD');
251+
$dbName = getenv('WORDPRESS_DB_NAME');
252+
253+
$maxTries = 10;
254+
do {
255+
$mysql = new mysqli($host, $user, $pass, '', $port, $socket);
256+
if ($mysql->connect_error) {
257+
fwrite($stderr, "\n" . 'MySQL Connection Error: (' . $mysql->connect_errno . ') ' . $mysql->connect_error . "\n");
258+
--$maxTries;
259+
if ($maxTries <= 0) {
260+
exit(1);
261+
}
262+
sleep(3);
263+
}
264+
} while ($mysql->connect_error);
265+
266+
if (!$mysql->query('CREATE DATABASE IF NOT EXISTS `' . $mysql->real_escape_string($dbName) . '`')) {
267+
fwrite($stderr, "\n" . 'MySQL "CREATE DATABASE" Error: ' . $mysql->error . "\n");
268+
$mysql->close();
269+
exit(1);
270+
}
271+
272+
$mysql->close();
273+
EOPHP
274+
then
275+
echo >&2
276+
echo >&2 "WARNING: unable to establish a database connection to '$WORDPRESS_DB_HOST'"
277+
echo >&2 ' continuing anyways (which might have unexpected results)'
278+
echo >&2
279+
fi
280+
fi
281+
282+
# now that we're definitely done writing configuration, let's clear out the relevant envrionment variables (so that stray "phpinfo()" calls don't leak secrets from our code)
283+
for e in "${envs[@]}"; do
284+
unset "$e"
285+
done
286+
fi
287+
288+
exec "$@"

7.1-nginx/Dockerfile

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
1-
FROM kooldev/wordpress:7.1
1+
FROM wordpress:php7.1-fpm-alpine as wordpress
2+
FROM kooldev/php:7.1-nginx
23

3-
ENV PHP_FPM_LISTEN=/run/php-fpm.sock \
4-
NGINX_LISTEN=80 \
5-
NGINX_ROOT=/var/www/html \
6-
NGINX_CLIENT_MAX_BODY_SIZE=25M \
7-
NGINX_PHP_FPM=unix:/run/php-fpm.sock \
8-
NGINX_FASTCGI_READ_TIMEOUT=60s
4+
ENV NGINX_ROOT=/app
95

10-
RUN curl -L https://github.com/ochinchina/supervisord/releases/download/v0.6.3/supervisord_static_0.6.3_linux_amd64 -o /usr/local/bin/supervisord \
11-
&& chmod +x /usr/local/bin/supervisord \
12-
&& apk add --no-cache nginx \
13-
&& sed -i "s|^listen\ \=.*|listen\ \= $PHP_FPM_LISTEN|g" /usr/local/etc/php-fpm.d/zz-docker.conf \
14-
&& echo "listen.owner = kool" >> /usr/local/etc/php-fpm.d/zz-docker.conf \
15-
&& echo "listen.group = kool" >> /usr/local/etc/php-fpm.d/zz-docker.conf \
16-
&& echo "listen.mode = 0666" >> /usr/local/etc/php-fpm.d/zz-docker.conf \
17-
&& sed -i "s|^user .*|user\ kool;|g" /etc/nginx/nginx.conf
6+
COPY --from=wordpress --chown=kool:kool /usr/src/wordpress /kool/wordpress
7+
COPY --from=wordpress --chown=kool:kool /var/www/html/wp-content /app/wp-content
8+
COPY entrypoint /kool/entrypoint
189

19-
COPY supervisor.conf /kool/supervisor.conf
20-
COPY default.tmpl /kool/default.tmpl
21-
22-
EXPOSE 80
23-
24-
ENTRYPOINT [ "dockerize", "-template", "/kool/kool.tmpl:/usr/local/etc/php/conf.d/kool.ini", "-template", "/kool/default.tmpl:/etc/nginx/conf.d/default.conf", "docker-entrypoint.sh" ]
25-
CMD [ "supervisord", "-c", "/kool/supervisor.conf" ]
10+
RUN chmod -R 777 wp-content && chmod +x /kool/entrypoint

0 commit comments

Comments
 (0)