Skip to content

Commit 0bd17ea

Browse files
committed
Add explicit "cli" variants for wp-cli
See also: - https://make.wordpress.org/core/2016/12/28/supporting-the-future-of-wp-cli/ - https://make.wordpress.org/cli/2017/01/03/lets-do-this/ The expected usage for these images is something like the following: docker run -it --rm \ --volumes-from some-wordpress \ --network container:some-wordpress \ wordpress:cli user list
1 parent 3a1ca61 commit 0bd17ea

11 files changed

+452
-2
lines changed

.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ env:
55
- VARIANT=php5.6/apache
66
- VARIANT=php5.6/fpm
77
- VARIANT=php5.6/fpm-alpine
8+
- VARIANT=php5.6/cli
89
- VARIANT=php7.0/apache
910
- VARIANT=php7.0/fpm
1011
- VARIANT=php7.0/fpm-alpine
12+
- VARIANT=php7.0/cli
1113
- VARIANT=php7.1/apache
1214
- VARIANT=php7.1/fpm
1315
- VARIANT=php7.1/fpm-alpine
16+
- VARIANT=php7.1/cli
1417

1518
install:
1619
- git clone https://github.com/docker-library/official-images.git ~/official-images

Dockerfile-cli.template

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
FROM php:%%PHP_VERSION%%-alpine
2+
3+
# install the PHP extensions we need
4+
RUN set -ex; \
5+
\
6+
apk add --no-cache --virtual .build-deps \
7+
libjpeg-turbo-dev \
8+
libpng-dev \
9+
; \
10+
\
11+
docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \
12+
docker-php-ext-install gd mysqli opcache; \
13+
\
14+
runDeps="$( \
15+
scanelf --needed --nobanner --recursive \
16+
/usr/local/lib/php/extensions \
17+
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
18+
| sort -u \
19+
| xargs -r apk info --installed \
20+
| sort -u \
21+
)"; \
22+
apk add --virtual .wordpress-phpexts-rundeps $runDeps; \
23+
apk del .build-deps
24+
25+
# set recommended PHP.ini settings
26+
# see https://secure.php.net/manual/en/opcache.installation.php
27+
RUN { \
28+
echo 'opcache.memory_consumption=128'; \
29+
echo 'opcache.interned_strings_buffer=8'; \
30+
echo 'opcache.max_accelerated_files=4000'; \
31+
echo 'opcache.revalidate_freq=2'; \
32+
echo 'opcache.fast_shutdown=1'; \
33+
echo 'opcache.enable_cli=1'; \
34+
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
35+
36+
# install wp-cli dependencies
37+
RUN apk add --no-cache \
38+
less \
39+
mysql-client
40+
41+
RUN set -ex; \
42+
mkdir -p /var/www/html; \
43+
chown -R www-data:www-data /var/www/html
44+
WORKDIR /var/www/html
45+
VOLUME /var/www/html
46+
47+
# pub 2048R/2F6B6B7F 2016-01-07
48+
# Key fingerprint = 3B91 9162 5F3B 1F1B F5DD 3B47 673A 0204 2F6B 6B7F
49+
# uid Daniel Bachhuber <daniel@handbuilt.co>
50+
# sub 2048R/45F9CDE2 2016-01-07
51+
ENV WORDPRESS_CLI_GPG_KEY 3B9191625F3B1F1BF5DD3B47673A02042F6B6B7F
52+
53+
ENV WORDPRESS_CLI_VERSION %%WORDPRESS_CLI_VERSION%%
54+
ENV WORDPRESS_CLI_SHA512 %%WORDPRESS_CLI_SHA512%%
55+
56+
RUN set -ex; \
57+
\
58+
apk add --no-cache --virtual .fetch-deps \
59+
gnupg \
60+
; \
61+
\
62+
curl -o /usr/local/bin/wp.gpg -fSL "https://github.com/wp-cli/wp-cli/releases/download/v${WORDPRESS_CLI_VERSION}/wp-cli-${WORDPRESS_CLI_VERSION}.phar.gpg"; \
63+
\
64+
export GNUPGHOME="$(mktemp -d)"; \
65+
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$WORDPRESS_CLI_GPG_KEY"; \
66+
gpg --batch --decrypt --output /usr/local/bin/wp /usr/local/bin/wp.gpg; \
67+
rm -r "$GNUPGHOME" /usr/local/bin/wp.gpg; \
68+
\
69+
echo "$WORDPRESS_CLI_SHA512 */usr/local/bin/wp" | sha512sum -c -; \
70+
chmod +x /usr/local/bin/wp; \
71+
\
72+
apk del .fetch-deps; \
73+
\
74+
wp --allow-root --version
75+
76+
COPY docker-entrypoint.sh /usr/local/bin/
77+
78+
ENTRYPOINT ["docker-entrypoint.sh"]
79+
USER www-data
80+
CMD ["wp", "shell"]

cli-entrypoint.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
set -euo pipefail
3+
4+
# first arg is `-f` or `--some-option`
5+
if [ "${1#-}" != "$1" ]; then
6+
set -- wp "$@"
7+
fi
8+
9+
# if our command is a valid wp-cli subcommand, let's invoke it through wp-cli instead
10+
# (this allows for "docker run wordpress:cli help", etc)
11+
if wp --path=/dev/null help "$1" > /dev/null 2>&1; then
12+
set -- wp "$@"
13+
fi
14+
15+
exec "$@"

generate-stackbrew-library.sh

+50
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,53 @@ for phpVersion in "${phpVersions[@]}"; do
104104
EOE
105105
done
106106
done
107+
108+
echo
109+
echo '# Now, wp-cli variants (which do _not_ include WordPress, so no WordPress version number -- only wp-cli version)'
110+
111+
for phpVersion in "${phpVersions[@]}"; do
112+
variant='cli'
113+
114+
dir="$phpVersion/$variant"
115+
[ -f "$dir/Dockerfile" ] || continue
116+
117+
commit="$(dirCommit "$dir")"
118+
119+
fullVersion="$(git show "$commit":"$dir/Dockerfile" | awk '$1 == "ENV" && $2 == "WORDPRESS_CLI_VERSION" { print $3; exit }')"
120+
121+
versionAliases=()
122+
while [ "${fullVersion%[.-]*}" != "$fullVersion" ]; do
123+
versionAliases+=( $fullVersion )
124+
fullVersion="${fullVersion%[.-]*}"
125+
done
126+
versionAliases+=(
127+
$fullVersion
128+
latest
129+
)
130+
131+
phpVersionAliases=( "${versionAliases[@]/#/$phpVersion-}" )
132+
phpVersionAliases=( "${phpVersionAliases[@]//-latest/}" )
133+
134+
variantAliases=( "${versionAliases[@]/#/$variant-}" )
135+
variantAliases=( "${variantAliases[@]//-latest/}" )
136+
137+
phpVersionVariantAliases=( "${versionAliases[@]/#/$phpVersion-$variant-}" )
138+
phpVersionVariantAliases=( "${phpVersionVariantAliases[@]//-latest/}" )
139+
140+
fullAliases=()
141+
142+
if [ "$phpVersion" = "$defaultPhpVersion" ]; then
143+
fullAliases+=( "${variantAliases[@]}" )
144+
fi
145+
146+
fullAliases+=(
147+
"${phpVersionVariantAliases[@]}"
148+
)
149+
150+
echo
151+
cat <<-EOE
152+
Tags: $(join ', ' "${fullAliases[@]}")
153+
GitCommit: $commit
154+
Directory: $dir
155+
EOE
156+
done

php5.6/cli/Dockerfile

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
FROM php:5.6-alpine
2+
3+
# install the PHP extensions we need
4+
RUN set -ex; \
5+
\
6+
apk add --no-cache --virtual .build-deps \
7+
libjpeg-turbo-dev \
8+
libpng-dev \
9+
; \
10+
\
11+
docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \
12+
docker-php-ext-install gd mysqli opcache; \
13+
\
14+
runDeps="$( \
15+
scanelf --needed --nobanner --recursive \
16+
/usr/local/lib/php/extensions \
17+
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
18+
| sort -u \
19+
| xargs -r apk info --installed \
20+
| sort -u \
21+
)"; \
22+
apk add --virtual .wordpress-phpexts-rundeps $runDeps; \
23+
apk del .build-deps
24+
25+
# set recommended PHP.ini settings
26+
# see https://secure.php.net/manual/en/opcache.installation.php
27+
RUN { \
28+
echo 'opcache.memory_consumption=128'; \
29+
echo 'opcache.interned_strings_buffer=8'; \
30+
echo 'opcache.max_accelerated_files=4000'; \
31+
echo 'opcache.revalidate_freq=2'; \
32+
echo 'opcache.fast_shutdown=1'; \
33+
echo 'opcache.enable_cli=1'; \
34+
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
35+
36+
# install wp-cli dependencies
37+
RUN apk add --no-cache \
38+
less \
39+
mysql-client
40+
41+
RUN set -ex; \
42+
mkdir -p /var/www/html; \
43+
chown -R www-data:www-data /var/www/html
44+
WORKDIR /var/www/html
45+
VOLUME /var/www/html
46+
47+
# pub 2048R/2F6B6B7F 2016-01-07
48+
# Key fingerprint = 3B91 9162 5F3B 1F1B F5DD 3B47 673A 0204 2F6B 6B7F
49+
# uid Daniel Bachhuber <daniel@handbuilt.co>
50+
# sub 2048R/45F9CDE2 2016-01-07
51+
ENV WORDPRESS_CLI_GPG_KEY 3B9191625F3B1F1BF5DD3B47673A02042F6B6B7F
52+
53+
ENV WORDPRESS_CLI_VERSION 1.1.0
54+
ENV WORDPRESS_CLI_SHA512 1fb4a3800441fc5188dac73efc6ca865076772ef698189ded379c53947d1fec30311e84eb4371455d415ef2cbb33d7593240fdf7b7f206277a12cfa8596d4b51
55+
56+
RUN set -ex; \
57+
\
58+
apk add --no-cache --virtual .fetch-deps \
59+
gnupg \
60+
; \
61+
\
62+
curl -o /usr/local/bin/wp.gpg -fSL "https://github.com/wp-cli/wp-cli/releases/download/v${WORDPRESS_CLI_VERSION}/wp-cli-${WORDPRESS_CLI_VERSION}.phar.gpg"; \
63+
\
64+
export GNUPGHOME="$(mktemp -d)"; \
65+
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$WORDPRESS_CLI_GPG_KEY"; \
66+
gpg --batch --decrypt --output /usr/local/bin/wp /usr/local/bin/wp.gpg; \
67+
rm -r "$GNUPGHOME" /usr/local/bin/wp.gpg; \
68+
\
69+
echo "$WORDPRESS_CLI_SHA512 */usr/local/bin/wp" | sha512sum -c -; \
70+
chmod +x /usr/local/bin/wp; \
71+
\
72+
apk del .fetch-deps; \
73+
\
74+
wp --allow-root --version
75+
76+
COPY docker-entrypoint.sh /usr/local/bin/
77+
78+
ENTRYPOINT ["docker-entrypoint.sh"]
79+
USER www-data
80+
CMD ["wp", "shell"]

php5.6/cli/docker-entrypoint.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
set -euo pipefail
3+
4+
# first arg is `-f` or `--some-option`
5+
if [ "${1#-}" != "$1" ]; then
6+
set -- wp "$@"
7+
fi
8+
9+
# if our command is a valid wp-cli subcommand, let's invoke it through wp-cli instead
10+
# (this allows for "docker run wordpress:cli help", etc)
11+
if wp --path=/dev/null help "$1" > /dev/null 2>&1; then
12+
set -- wp "$@"
13+
fi
14+
15+
exec "$@"

php7.0/cli/Dockerfile

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
FROM php:7.0-alpine
2+
3+
# install the PHP extensions we need
4+
RUN set -ex; \
5+
\
6+
apk add --no-cache --virtual .build-deps \
7+
libjpeg-turbo-dev \
8+
libpng-dev \
9+
; \
10+
\
11+
docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \
12+
docker-php-ext-install gd mysqli opcache; \
13+
\
14+
runDeps="$( \
15+
scanelf --needed --nobanner --recursive \
16+
/usr/local/lib/php/extensions \
17+
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
18+
| sort -u \
19+
| xargs -r apk info --installed \
20+
| sort -u \
21+
)"; \
22+
apk add --virtual .wordpress-phpexts-rundeps $runDeps; \
23+
apk del .build-deps
24+
25+
# set recommended PHP.ini settings
26+
# see https://secure.php.net/manual/en/opcache.installation.php
27+
RUN { \
28+
echo 'opcache.memory_consumption=128'; \
29+
echo 'opcache.interned_strings_buffer=8'; \
30+
echo 'opcache.max_accelerated_files=4000'; \
31+
echo 'opcache.revalidate_freq=2'; \
32+
echo 'opcache.fast_shutdown=1'; \
33+
echo 'opcache.enable_cli=1'; \
34+
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
35+
36+
# install wp-cli dependencies
37+
RUN apk add --no-cache \
38+
less \
39+
mysql-client
40+
41+
RUN set -ex; \
42+
mkdir -p /var/www/html; \
43+
chown -R www-data:www-data /var/www/html
44+
WORKDIR /var/www/html
45+
VOLUME /var/www/html
46+
47+
# pub 2048R/2F6B6B7F 2016-01-07
48+
# Key fingerprint = 3B91 9162 5F3B 1F1B F5DD 3B47 673A 0204 2F6B 6B7F
49+
# uid Daniel Bachhuber <daniel@handbuilt.co>
50+
# sub 2048R/45F9CDE2 2016-01-07
51+
ENV WORDPRESS_CLI_GPG_KEY 3B9191625F3B1F1BF5DD3B47673A02042F6B6B7F
52+
53+
ENV WORDPRESS_CLI_VERSION 1.1.0
54+
ENV WORDPRESS_CLI_SHA512 1fb4a3800441fc5188dac73efc6ca865076772ef698189ded379c53947d1fec30311e84eb4371455d415ef2cbb33d7593240fdf7b7f206277a12cfa8596d4b51
55+
56+
RUN set -ex; \
57+
\
58+
apk add --no-cache --virtual .fetch-deps \
59+
gnupg \
60+
; \
61+
\
62+
curl -o /usr/local/bin/wp.gpg -fSL "https://github.com/wp-cli/wp-cli/releases/download/v${WORDPRESS_CLI_VERSION}/wp-cli-${WORDPRESS_CLI_VERSION}.phar.gpg"; \
63+
\
64+
export GNUPGHOME="$(mktemp -d)"; \
65+
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$WORDPRESS_CLI_GPG_KEY"; \
66+
gpg --batch --decrypt --output /usr/local/bin/wp /usr/local/bin/wp.gpg; \
67+
rm -r "$GNUPGHOME" /usr/local/bin/wp.gpg; \
68+
\
69+
echo "$WORDPRESS_CLI_SHA512 */usr/local/bin/wp" | sha512sum -c -; \
70+
chmod +x /usr/local/bin/wp; \
71+
\
72+
apk del .fetch-deps; \
73+
\
74+
wp --allow-root --version
75+
76+
COPY docker-entrypoint.sh /usr/local/bin/
77+
78+
ENTRYPOINT ["docker-entrypoint.sh"]
79+
USER www-data
80+
CMD ["wp", "shell"]

php7.0/cli/docker-entrypoint.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
set -euo pipefail
3+
4+
# first arg is `-f` or `--some-option`
5+
if [ "${1#-}" != "$1" ]; then
6+
set -- wp "$@"
7+
fi
8+
9+
# if our command is a valid wp-cli subcommand, let's invoke it through wp-cli instead
10+
# (this allows for "docker run wordpress:cli help", etc)
11+
if wp --path=/dev/null help "$1" > /dev/null 2>&1; then
12+
set -- wp "$@"
13+
fi
14+
15+
exec "$@"

0 commit comments

Comments
 (0)