Skip to content

Commit 1e1456c

Browse files
authored
Merge pull request docker-library#259 from infosiftr/php7.2
Add php7.2 variants
2 parents 88b4aa3 + 1e6d4be commit 1e1456c

14 files changed

+919
-5
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ env:
1414
- VARIANT=php7.1/fpm
1515
- VARIANT=php7.1/fpm-alpine
1616
- VARIANT=php7.1/cli
17+
- VARIANT=php7.2/apache
18+
- VARIANT=php7.2/fpm
19+
- VARIANT=php7.2/fpm-alpine
20+
- VARIANT=php7.2/cli
1721

1822
install:
1923
- git clone https://github.com/docker-library/official-images.git ~/official-images

Dockerfile-cli.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ RUN set -ex; \
6262
export GNUPGHOME="$(mktemp -d)"; \
6363
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$WORDPRESS_CLI_GPG_KEY"; \
6464
gpg --batch --decrypt --output /usr/local/bin/wp /usr/local/bin/wp.gpg; \
65-
rm -r "$GNUPGHOME" /usr/local/bin/wp.gpg; \
65+
rm -rf "$GNUPGHOME" /usr/local/bin/wp.gpg; \
6666
\
6767
echo "$WORDPRESS_CLI_SHA512 */usr/local/bin/wp" | sha512sum -c -; \
6868
chmod +x /usr/local/bin/wp; \

generate-stackbrew-library.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/bash
22
set -eu
33

4-
defaultPhpVersion='php5.6'
4+
# https://wordpress.org/about/requirements/
5+
defaultPhpVersion='php7.2'
56
defaultVariant='apache'
67

78
self="$(basename "$BASH_SOURCE")"

php5.6/cli/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ RUN set -ex; \
6262
export GNUPGHOME="$(mktemp -d)"; \
6363
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$WORDPRESS_CLI_GPG_KEY"; \
6464
gpg --batch --decrypt --output /usr/local/bin/wp /usr/local/bin/wp.gpg; \
65-
rm -r "$GNUPGHOME" /usr/local/bin/wp.gpg; \
65+
rm -rf "$GNUPGHOME" /usr/local/bin/wp.gpg; \
6666
\
6767
echo "$WORDPRESS_CLI_SHA512 */usr/local/bin/wp" | sha512sum -c -; \
6868
chmod +x /usr/local/bin/wp; \

php7.0/cli/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ RUN set -ex; \
6262
export GNUPGHOME="$(mktemp -d)"; \
6363
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$WORDPRESS_CLI_GPG_KEY"; \
6464
gpg --batch --decrypt --output /usr/local/bin/wp /usr/local/bin/wp.gpg; \
65-
rm -r "$GNUPGHOME" /usr/local/bin/wp.gpg; \
65+
rm -rf "$GNUPGHOME" /usr/local/bin/wp.gpg; \
6666
\
6767
echo "$WORDPRESS_CLI_SHA512 */usr/local/bin/wp" | sha512sum -c -; \
6868
chmod +x /usr/local/bin/wp; \

php7.1/cli/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ RUN set -ex; \
6262
export GNUPGHOME="$(mktemp -d)"; \
6363
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$WORDPRESS_CLI_GPG_KEY"; \
6464
gpg --batch --decrypt --output /usr/local/bin/wp /usr/local/bin/wp.gpg; \
65-
rm -r "$GNUPGHOME" /usr/local/bin/wp.gpg; \
65+
rm -rf "$GNUPGHOME" /usr/local/bin/wp.gpg; \
6666
\
6767
echo "$WORDPRESS_CLI_SHA512 */usr/local/bin/wp" | sha512sum -c -; \
6868
chmod +x /usr/local/bin/wp; \

php7.2/apache/Dockerfile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
FROM php:7.2-apache
2+
3+
# install the PHP extensions we need
4+
RUN set -ex; \
5+
\
6+
apt-get update; \
7+
apt-get install -y \
8+
libjpeg-dev \
9+
libpng-dev \
10+
; \
11+
rm -rf /var/lib/apt/lists/*; \
12+
\
13+
docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \
14+
docker-php-ext-install gd mysqli opcache
15+
# TODO consider removing the *-dev deps and only keeping the necessary lib* packages
16+
17+
# set recommended PHP.ini settings
18+
# see https://secure.php.net/manual/en/opcache.installation.php
19+
RUN { \
20+
echo 'opcache.memory_consumption=128'; \
21+
echo 'opcache.interned_strings_buffer=8'; \
22+
echo 'opcache.max_accelerated_files=4000'; \
23+
echo 'opcache.revalidate_freq=2'; \
24+
echo 'opcache.fast_shutdown=1'; \
25+
echo 'opcache.enable_cli=1'; \
26+
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
27+
28+
RUN a2enmod rewrite expires
29+
30+
VOLUME /var/www/html
31+
32+
ENV WORDPRESS_VERSION 4.9.1
33+
ENV WORDPRESS_SHA1 892d2c23b9d458ec3d44de59b753adb41012e903
34+
35+
RUN set -ex; \
36+
curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz"; \
37+
echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c -; \
38+
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
39+
tar -xzf wordpress.tar.gz -C /usr/src/; \
40+
rm wordpress.tar.gz; \
41+
chown -R www-data:www-data /usr/src/wordpress
42+
43+
COPY docker-entrypoint.sh /usr/local/bin/
44+
45+
ENTRYPOINT ["docker-entrypoint.sh"]
46+
CMD ["apache2-foreground"]

php7.2/apache/docker-entrypoint.sh

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
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" == apache2* ]] || [ "$1" == php-fpm ]; then
27+
if ! [ -e index.php -a -e wp-includes/version.php ]; then
28+
echo >&2 "WordPress not found in $PWD - copying now..."
29+
if [ "$(ls -A)" ]; then
30+
echo >&2 "WARNING: $PWD is not empty - press Ctrl+C now if this is an error!"
31+
( set -x; ls -A; sleep 10 )
32+
fi
33+
tar cf - --one-file-system -C /usr/src/wordpress . | tar xf -
34+
echo >&2 "Complete! WordPress has been successfully copied to $PWD"
35+
if [ ! -e .htaccess ]; then
36+
# NOTE: The "Indexes" option is disabled in the php:apache base image
37+
cat > .htaccess <<-'EOF'
38+
# BEGIN WordPress
39+
<IfModule mod_rewrite.c>
40+
RewriteEngine On
41+
RewriteBase /
42+
RewriteRule ^index\.php$ - [L]
43+
RewriteCond %{REQUEST_FILENAME} !-f
44+
RewriteCond %{REQUEST_FILENAME} !-d
45+
RewriteRule . /index.php [L]
46+
</IfModule>
47+
# END WordPress
48+
EOF
49+
chown www-data:www-data .htaccess
50+
fi
51+
fi
52+
53+
# TODO handle WordPress upgrades magically in the same way, but only if wp-includes/version.php's $wp_version is less than /usr/src/wordpress/wp-includes/version.php's $wp_version
54+
55+
# allow any of these "Authentication Unique Keys and Salts." to be specified via
56+
# environment variables with a "WORDPRESS_" prefix (ie, "WORDPRESS_AUTH_KEY")
57+
uniqueEnvs=(
58+
AUTH_KEY
59+
SECURE_AUTH_KEY
60+
LOGGED_IN_KEY
61+
NONCE_KEY
62+
AUTH_SALT
63+
SECURE_AUTH_SALT
64+
LOGGED_IN_SALT
65+
NONCE_SALT
66+
)
67+
envs=(
68+
WORDPRESS_DB_HOST
69+
WORDPRESS_DB_USER
70+
WORDPRESS_DB_PASSWORD
71+
WORDPRESS_DB_NAME
72+
"${uniqueEnvs[@]/#/WORDPRESS_}"
73+
WORDPRESS_TABLE_PREFIX
74+
WORDPRESS_DEBUG
75+
)
76+
haveConfig=
77+
for e in "${envs[@]}"; do
78+
file_env "$e"
79+
if [ -z "$haveConfig" ] && [ -n "${!e}" ]; then
80+
haveConfig=1
81+
fi
82+
done
83+
84+
# linking backwards-compatibility
85+
if [ -n "${!MYSQL_ENV_MYSQL_*}" ]; then
86+
haveConfig=1
87+
# host defaults to "mysql" below if unspecified
88+
: "${WORDPRESS_DB_USER:=${MYSQL_ENV_MYSQL_USER:-root}}"
89+
if [ "$WORDPRESS_DB_USER" = 'root' ]; then
90+
: "${WORDPRESS_DB_PASSWORD:=${MYSQL_ENV_MYSQL_ROOT_PASSWORD:-}}"
91+
else
92+
: "${WORDPRESS_DB_PASSWORD:=${MYSQL_ENV_MYSQL_PASSWORD:-}}"
93+
fi
94+
: "${WORDPRESS_DB_NAME:=${MYSQL_ENV_MYSQL_DATABASE:-}}"
95+
fi
96+
97+
# only touch "wp-config.php" if we have environment-supplied configuration values
98+
if [ "$haveConfig" ]; then
99+
: "${WORDPRESS_DB_HOST:=mysql}"
100+
: "${WORDPRESS_DB_USER:=root}"
101+
: "${WORDPRESS_DB_PASSWORD:=}"
102+
: "${WORDPRESS_DB_NAME:=wordpress}"
103+
104+
# version 4.4.1 decided to switch to windows line endings, that breaks our seds and awks
105+
# https://github.com/docker-library/wordpress/issues/116
106+
# https://github.com/WordPress/WordPress/commit/1acedc542fba2482bab88ec70d4bea4b997a92e4
107+
sed -ri -e 's/\r$//' wp-config*
108+
109+
if [ ! -e wp-config.php ]; then
110+
awk '/^\/\*.*stop editing.*\*\/$/ && c == 0 { c = 1; system("cat") } { print }' wp-config-sample.php > wp-config.php <<'EOPHP'
111+
// If we're behind a proxy server and using HTTPS, we need to alert Wordpress of that fact
112+
// see also http://codex.wordpress.org/Administration_Over_SSL#Using_a_Reverse_Proxy
113+
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
114+
$_SERVER['HTTPS'] = 'on';
115+
}
116+
117+
EOPHP
118+
chown www-data:www-data wp-config.php
119+
fi
120+
121+
# see http://stackoverflow.com/a/2705678/433558
122+
sed_escape_lhs() {
123+
echo "$@" | sed -e 's/[]\/$*.^|[]/\\&/g'
124+
}
125+
sed_escape_rhs() {
126+
echo "$@" | sed -e 's/[\/&]/\\&/g'
127+
}
128+
php_escape() {
129+
local escaped="$(php -r 'var_export(('"$2"') $argv[1]);' -- "$1")"
130+
if [ "$2" = 'string' ] && [ "${escaped:0:1}" = "'" ]; then
131+
escaped="${escaped//$'\n'/"' + \"\\n\" + '"}"
132+
fi
133+
echo "$escaped"
134+
}
135+
set_config() {
136+
key="$1"
137+
value="$2"
138+
var_type="${3:-string}"
139+
start="(['\"])$(sed_escape_lhs "$key")\2\s*,"
140+
end="\);"
141+
if [ "${key:0:1}" = '$' ]; then
142+
start="^(\s*)$(sed_escape_lhs "$key")\s*="
143+
end=";"
144+
fi
145+
sed -ri -e "s/($start\s*).*($end)$/\1$(sed_escape_rhs "$(php_escape "$value" "$var_type")")\3/" wp-config.php
146+
}
147+
148+
set_config 'DB_HOST' "$WORDPRESS_DB_HOST"
149+
set_config 'DB_USER' "$WORDPRESS_DB_USER"
150+
set_config 'DB_PASSWORD' "$WORDPRESS_DB_PASSWORD"
151+
set_config 'DB_NAME' "$WORDPRESS_DB_NAME"
152+
153+
for unique in "${uniqueEnvs[@]}"; do
154+
uniqVar="WORDPRESS_$unique"
155+
if [ -n "${!uniqVar}" ]; then
156+
set_config "$unique" "${!uniqVar}"
157+
else
158+
# if not specified, let's generate a random value
159+
currentVal="$(sed -rn -e "s/define\((([\'\"])$unique\2\s*,\s*)(['\"])(.*)\3\);/\4/p" wp-config.php)"
160+
if [ "$currentVal" = 'put your unique phrase here' ]; then
161+
set_config "$unique" "$(head -c1m /dev/urandom | sha1sum | cut -d' ' -f1)"
162+
fi
163+
fi
164+
done
165+
166+
if [ "$WORDPRESS_TABLE_PREFIX" ]; then
167+
set_config '$table_prefix' "$WORDPRESS_TABLE_PREFIX"
168+
fi
169+
170+
if [ "$WORDPRESS_DEBUG" ]; then
171+
set_config 'WP_DEBUG' 1 boolean
172+
fi
173+
174+
TERM=dumb php -- <<'EOPHP'
175+
<?php
176+
// database might not exist, so let's try creating it (just to be safe)
177+
178+
$stderr = fopen('php://stderr', 'w');
179+
180+
// https://codex.wordpress.org/Editing_wp-config.php#MySQL_Alternate_Port
181+
// "hostname:port"
182+
// https://codex.wordpress.org/Editing_wp-config.php#MySQL_Sockets_or_Pipes
183+
// "hostname:unix-socket-path"
184+
list($host, $socket) = explode(':', getenv('WORDPRESS_DB_HOST'), 2);
185+
$port = 0;
186+
if (is_numeric($socket)) {
187+
$port = (int) $socket;
188+
$socket = null;
189+
}
190+
$user = getenv('WORDPRESS_DB_USER');
191+
$pass = getenv('WORDPRESS_DB_PASSWORD');
192+
$dbName = getenv('WORDPRESS_DB_NAME');
193+
194+
$maxTries = 10;
195+
do {
196+
$mysql = new mysqli($host, $user, $pass, '', $port, $socket);
197+
if ($mysql->connect_error) {
198+
fwrite($stderr, "\n" . 'MySQL Connection Error: (' . $mysql->connect_errno . ') ' . $mysql->connect_error . "\n");
199+
--$maxTries;
200+
if ($maxTries <= 0) {
201+
exit(1);
202+
}
203+
sleep(3);
204+
}
205+
} while ($mysql->connect_error);
206+
207+
if (!$mysql->query('CREATE DATABASE IF NOT EXISTS `' . $mysql->real_escape_string($dbName) . '`')) {
208+
fwrite($stderr, "\n" . 'MySQL "CREATE DATABASE" Error: ' . $mysql->error . "\n");
209+
$mysql->close();
210+
exit(1);
211+
}
212+
213+
$mysql->close();
214+
EOPHP
215+
fi
216+
217+
# 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)
218+
for e in "${envs[@]}"; do
219+
unset "$e"
220+
done
221+
fi
222+
223+
exec "$@"

0 commit comments

Comments
 (0)