Skip to content

Commit 637afb5

Browse files
committed
Refactoring for template usage and updates since the original PR
1 parent d0f0731 commit 637afb5

19 files changed

+541
-157
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ services: docker
44
env:
55
- VARIANT=php5.6/apache
66
- VARIANT=php5.6/fpm
7+
- VARIANT=php5.6/fpm-alpine
78
- VARIANT=php7.0/apache
89
- VARIANT=php7.0/fpm
10+
- VARIANT=php7.0/fpm-alpine
911

1012
install:
1113
- git clone https://github.com/docker-library/official-images.git ~/official-images

Dockerfile-alpine.template

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
FROM php:%%PHP_VERSION%%-%%VARIANT%%
2+
3+
# docker-entrypoint.sh dependencies
4+
RUN apk add --no-cache \
5+
# in theory, docker-entrypoint.sh is POSIX-compliant, but priority is a working, consistent image
6+
bash \
7+
# BusyBox sed is not sufficient for some of our sed expressions
8+
sed
9+
10+
# install the PHP extensions we need
11+
RUN set -ex; \
12+
\
13+
apk add --no-cache --virtual .build-deps \
14+
libjpeg-turbo-dev \
15+
libpng-dev \
16+
; \
17+
\
18+
docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \
19+
docker-php-ext-install gd mysqli opcache; \
20+
\
21+
runDeps="$( \
22+
scanelf --needed --nobanner --recursive \
23+
/usr/local/lib/php/extensions \
24+
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
25+
| sort -u \
26+
| xargs -r apk info --installed \
27+
| sort -u \
28+
)"; \
29+
apk add --virtual .wordpress-phpexts-rundeps $runDeps; \
30+
apk del .build-deps
31+
32+
# set recommended PHP.ini settings
33+
# see https://secure.php.net/manual/en/opcache.installation.php
34+
RUN { \
35+
echo 'opcache.memory_consumption=128'; \
36+
echo 'opcache.interned_strings_buffer=8'; \
37+
echo 'opcache.max_accelerated_files=4000'; \
38+
echo 'opcache.revalidate_freq=2'; \
39+
echo 'opcache.fast_shutdown=1'; \
40+
echo 'opcache.enable_cli=1'; \
41+
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
42+
%%VARIANT_EXTRAS%%
43+
VOLUME /var/www/html
44+
45+
ENV WORDPRESS_VERSION %%WORDPRESS_VERSION%%
46+
ENV WORDPRESS_SHA1 %%WORDPRESS_SHA1%%
47+
48+
RUN set -ex; \
49+
curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz"; \
50+
echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c -; \
51+
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
52+
tar -xzf wordpress.tar.gz -C /usr/src/; \
53+
rm wordpress.tar.gz; \
54+
chown -R www-data:www-data /usr/src/wordpress
55+
56+
COPY docker-entrypoint.sh /usr/local/bin/
57+
58+
ENTRYPOINT ["docker-entrypoint.sh"]
59+
CMD ["%%CMD%%"]
Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
FROM php:%%PHP_VERSION%%-%%VARIANT%%
22

33
# install the PHP extensions we need
4-
RUN apt-get update && apt-get install -y libpng12-dev libjpeg-dev && rm -rf /var/lib/apt/lists/* \
5-
&& docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \
6-
&& docker-php-ext-install gd mysqli opcache
4+
RUN set -ex; \
5+
\
6+
apt-get update; \
7+
apt-get install -y \
8+
libjpeg-dev \
9+
libpng12-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
716

817
# set recommended PHP.ini settings
918
# see https://secure.php.net/manual/en/opcache.installation.php
@@ -21,17 +30,15 @@ VOLUME /var/www/html
2130
ENV WORDPRESS_VERSION %%WORDPRESS_VERSION%%
2231
ENV WORDPRESS_SHA1 %%WORDPRESS_SHA1%%
2332

24-
RUN set -x \
25-
&& curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz" \
26-
&& echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
33+
RUN set -ex; \
34+
curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz"; \
35+
echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c -; \
2736
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
28-
&& tar -xzf wordpress.tar.gz -C /usr/src/ \
29-
&& rm wordpress.tar.gz \
30-
&& chown -R www-data:www-data /usr/src/wordpress
37+
tar -xzf wordpress.tar.gz -C /usr/src/; \
38+
rm wordpress.tar.gz; \
39+
chown -R www-data:www-data /usr/src/wordpress
3140

3241
COPY docker-entrypoint.sh /usr/local/bin/
33-
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
3442

35-
# ENTRYPOINT resets CMD
3643
ENTRYPOINT ["docker-entrypoint.sh"]
3744
CMD ["%%CMD%%"]

docker-entrypoint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
set -eu
2+
set -euo pipefail
33

44
# usage: file_env VAR [DEFAULT]
55
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
@@ -135,7 +135,7 @@ EOPHP
135135
# if not specified, let's generate a random value
136136
current_set="$(sed -rn -e "s/define\((([\'\"])$unique\2\s*,\s*)(['\"])(.*)\3\);/\4/p" wp-config.php)"
137137
if [ "$current_set" = 'put your unique phrase here' ]; then
138-
set_config "$unique" "$(head -c1M /dev/urandom | sha1sum | cut -d' ' -f1)"
138+
set_config "$unique" "$(head -c1m /dev/urandom | sha1sum | cut -d' ' -f1)"
139139
fi
140140
fi
141141
done

fpm/alpine/Dockerfile

Lines changed: 0 additions & 49 deletions
This file was deleted.

generate-stackbrew-library.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ join() {
4848
}
4949

5050
for phpVersion in "${phpVersions[@]}"; do
51-
for variant in apache fpm; do
51+
for variant in apache fpm fpm-alpine; do
5252
dir="$phpVersion/$variant"
5353
[ -f "$dir/Dockerfile" ] || continue
5454

php5.6/apache/Dockerfile

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
FROM php:5.6-apache
22

33
# install the PHP extensions we need
4-
RUN apt-get update && apt-get install -y libpng12-dev libjpeg-dev && rm -rf /var/lib/apt/lists/* \
5-
&& docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \
6-
&& docker-php-ext-install gd mysqli opcache
4+
RUN set -ex; \
5+
\
6+
apt-get update; \
7+
apt-get install -y \
8+
libjpeg-dev \
9+
libpng12-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
716

817
# set recommended PHP.ini settings
918
# see https://secure.php.net/manual/en/opcache.installation.php
@@ -23,17 +32,15 @@ VOLUME /var/www/html
2332
ENV WORDPRESS_VERSION 4.7
2433
ENV WORDPRESS_SHA1 1e14144c4db71421dc4ed22f94c3914dfc3b7020
2534

26-
RUN set -x \
27-
&& curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz" \
28-
&& echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
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 -; \
2938
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
30-
&& tar -xzf wordpress.tar.gz -C /usr/src/ \
31-
&& rm wordpress.tar.gz \
32-
&& chown -R www-data:www-data /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
3342

3443
COPY docker-entrypoint.sh /usr/local/bin/
35-
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
3644

37-
# ENTRYPOINT resets CMD
3845
ENTRYPOINT ["docker-entrypoint.sh"]
3946
CMD ["apache2-foreground"]

php5.6/apache/docker-entrypoint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
set -eu
2+
set -euo pipefail
33

44
# usage: file_env VAR [DEFAULT]
55
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
@@ -135,7 +135,7 @@ EOPHP
135135
# if not specified, let's generate a random value
136136
current_set="$(sed -rn -e "s/define\((([\'\"])$unique\2\s*,\s*)(['\"])(.*)\3\);/\4/p" wp-config.php)"
137137
if [ "$current_set" = 'put your unique phrase here' ]; then
138-
set_config "$unique" "$(head -c1M /dev/urandom | sha1sum | cut -d' ' -f1)"
138+
set_config "$unique" "$(head -c1m /dev/urandom | sha1sum | cut -d' ' -f1)"
139139
fi
140140
fi
141141
done

php5.6/fpm-alpine/Dockerfile

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
FROM php:5.6-fpm-alpine
2+
3+
# docker-entrypoint.sh dependencies
4+
RUN apk add --no-cache \
5+
# in theory, docker-entrypoint.sh is POSIX-compliant, but priority is a working, consistent image
6+
bash \
7+
# BusyBox sed is not sufficient for some of our sed expressions
8+
sed
9+
10+
# install the PHP extensions we need
11+
RUN set -ex; \
12+
\
13+
apk add --no-cache --virtual .build-deps \
14+
libjpeg-turbo-dev \
15+
libpng-dev \
16+
; \
17+
\
18+
docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \
19+
docker-php-ext-install gd mysqli opcache; \
20+
\
21+
runDeps="$( \
22+
scanelf --needed --nobanner --recursive \
23+
/usr/local/lib/php/extensions \
24+
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
25+
| sort -u \
26+
| xargs -r apk info --installed \
27+
| sort -u \
28+
)"; \
29+
apk add --virtual .wordpress-phpexts-rundeps $runDeps; \
30+
apk del .build-deps
31+
32+
# set recommended PHP.ini settings
33+
# see https://secure.php.net/manual/en/opcache.installation.php
34+
RUN { \
35+
echo 'opcache.memory_consumption=128'; \
36+
echo 'opcache.interned_strings_buffer=8'; \
37+
echo 'opcache.max_accelerated_files=4000'; \
38+
echo 'opcache.revalidate_freq=2'; \
39+
echo 'opcache.fast_shutdown=1'; \
40+
echo 'opcache.enable_cli=1'; \
41+
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
42+
43+
VOLUME /var/www/html
44+
45+
ENV WORDPRESS_VERSION 4.7
46+
ENV WORDPRESS_SHA1 1e14144c4db71421dc4ed22f94c3914dfc3b7020
47+
48+
RUN set -ex; \
49+
curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz"; \
50+
echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c -; \
51+
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
52+
tar -xzf wordpress.tar.gz -C /usr/src/; \
53+
rm wordpress.tar.gz; \
54+
chown -R www-data:www-data /usr/src/wordpress
55+
56+
COPY docker-entrypoint.sh /usr/local/bin/
57+
58+
ENTRYPOINT ["docker-entrypoint.sh"]
59+
CMD ["php-fpm"]

0 commit comments

Comments
 (0)