Skip to content

Commit f9ef96e

Browse files
authored
Merge pull request docker-library#178 from infosiftr/multi-version
Introduce templates and a PHP 7.0-based variant
2 parents 163f643 + 7d40c42 commit f9ef96e

12 files changed

+574
-55
lines changed

.travis.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ language: bash
22
services: docker
33

44
env:
5-
- VARIANT=apache
6-
- VARIANT=fpm
5+
- VARIANT=php5.6/apache
6+
- VARIANT=php5.6/fpm
7+
- VARIANT=php7.0/apache
8+
- VARIANT=php7.0/fpm
79

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

1113
before_script:
1214
- env | sort
1315
- cd "$VARIANT"
14-
- image="wordpress:$VARIANT"
16+
- slash='/'; image="wordpress:${VARIANT//$slash/-}"
1517

1618
script:
1719
- docker build -t "$image" .

Dockerfile.template

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
FROM php:%%PHP_VERSION%%-%%VARIANT%%
2+
3+
# 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
7+
8+
# set recommended PHP.ini settings
9+
# see https://secure.php.net/manual/en/opcache.installation.php
10+
RUN { \
11+
echo 'opcache.memory_consumption=128'; \
12+
echo 'opcache.interned_strings_buffer=8'; \
13+
echo 'opcache.max_accelerated_files=4000'; \
14+
echo 'opcache.revalidate_freq=2'; \
15+
echo 'opcache.fast_shutdown=1'; \
16+
echo 'opcache.enable_cli=1'; \
17+
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
18+
%%VARIANT_EXTRAS%%
19+
VOLUME /var/www/html
20+
21+
ENV WORDPRESS_VERSION %%WORDPRESS_VERSION%%
22+
ENV WORDPRESS_SHA1 %%WORDPRESS_SHA1%%
23+
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 - \
27+
# 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
31+
32+
COPY docker-entrypoint.sh /usr/local/bin/
33+
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
34+
35+
# ENTRYPOINT resets CMD
36+
ENTRYPOINT ["docker-entrypoint.sh"]
37+
CMD ["%%CMD%%"]

generate-stackbrew-library.sh

Lines changed: 59 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
#!/bin/bash
22
set -eu
33

4+
defaultPhpVersion='php5.6'
5+
defaultVariant='apache'
6+
47
self="$(basename "$BASH_SOURCE")"
58
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
69

10+
phpVersions=( "$@" )
11+
if [ ${#phpVersions[@]} -eq 0 ]; then
12+
phpVersions=( php*.*/ )
13+
fi
14+
phpVersions=( "${phpVersions[@]%/}" )
15+
716
# get the most recent commit which modified any of "$@"
817
fileCommit() {
918
git log -1 --format='format:%H' HEAD -- "$@"
@@ -41,35 +50,59 @@ join() {
4150
echo "${out#$sep}"
4251
}
4352

44-
for variant in apache fpm; do
45-
commit="$(dirCommit "$variant")"
53+
for phpVersion in "${phpVersions[@]}"; do
54+
for variant in apache fpm; do
55+
dir="$phpVersion/$variant"
56+
[ -f "$dir/Dockerfile" ] || continue
4657

47-
fullVersion="$(git show "$commit":"$variant/Dockerfile" | awk '$1 == "ENV" && $2 == "WORDPRESS_VERSION" { print $3; exit }')"
48-
if [[ "$fullVersion" != *.*.* && "$fullVersion" == *.* ]]; then
49-
fullVersion+='.0'
50-
fi
58+
commit="$(dirCommit "$dir")"
5159

52-
versionAliases=()
53-
while [ "${fullVersion%.*}" != "$fullVersion" ]; do
54-
versionAliases+=( $fullVersion )
55-
fullVersion="${fullVersion%.*}"
56-
done
57-
versionAliases+=(
58-
$fullVersion
59-
latest
60-
)
60+
fullVersion="$(git show "$commit":"$dir/Dockerfile" | awk '$1 == "ENV" && $2 == "WORDPRESS_VERSION" { print $3; exit }')"
61+
if [[ "$fullVersion" != *.*.* && "$fullVersion" == *.* ]]; then
62+
fullVersion+='.0'
63+
fi
64+
65+
versionAliases=()
66+
while [ "${fullVersion%[.-]*}" != "$fullVersion" ]; do
67+
versionAliases+=( $fullVersion )
68+
fullVersion="${fullVersion%[.-]*}"
69+
done
70+
versionAliases+=(
71+
$fullVersion
72+
latest
73+
)
74+
75+
phpVersionAliases=( "${versionAliases[@]/%/-$phpVersion}" )
76+
phpVersionAliases=( "${phpVersionAliases[@]//latest-/}" )
6177

62-
variantAliases=( "${versionAliases[@]/%/-$variant}" )
63-
variantAliases=( "${variantAliases[@]//latest-/}" )
78+
variantAliases=( "${versionAliases[@]/%/-$variant}" )
79+
variantAliases=( "${variantAliases[@]//latest-/}" )
6480

65-
if [ "$variant" = 'apache' ]; then
66-
variantAliases+=( "${versionAliases[@]}" )
67-
fi
81+
phpVersionVariantAliases=( "${versionAliases[@]/%/-$phpVersion-$variant}" )
82+
phpVersionVariantAliases=( "${phpVersionVariantAliases[@]//latest-/}" )
6883

69-
echo
70-
cat <<-EOE
71-
Tags: $(join ', ' "${variantAliases[@]}")
72-
GitCommit: $commit
73-
Directory: $variant
74-
EOE
84+
fullAliases=()
85+
86+
if [ "$phpVersion" = "$defaultPhpVersion" ]; then
87+
fullAliases+=( "${variantAliases[@]}" )
88+
89+
if [ "$variant" = "$defaultVariant" ]; then
90+
fullAliases+=( "${versionAliases[@]}" )
91+
fi
92+
fi
93+
if [ "$variant" = "$defaultVariant" ]; then
94+
fullAliases+=( "${phpVersionAliases[@]}" )
95+
fi
96+
97+
fullAliases+=(
98+
"${phpVersionVariantAliases[@]}"
99+
)
100+
101+
echo
102+
cat <<-EOE
103+
Tags: $(join ', ' "${fullAliases[@]}")
104+
GitCommit: $commit
105+
Directory: $dir
106+
EOE
107+
done
75108
done

apache/Dockerfile renamed to php5.6/apache/Dockerfile

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

3-
RUN a2enmod rewrite expires
4-
53
# install the PHP extensions we need
64
RUN apt-get update && apt-get install -y libpng12-dev libjpeg-dev && rm -rf /var/lib/apt/lists/* \
75
&& docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \
@@ -18,20 +16,24 @@ RUN { \
1816
echo 'opcache.enable_cli=1'; \
1917
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
2018

19+
RUN a2enmod rewrite expires
20+
2121
VOLUME /var/www/html
2222

2323
ENV WORDPRESS_VERSION 4.6.1
2424
ENV WORDPRESS_SHA1 027e065d30a64720624a7404a1820e6c6fff1202
2525

26-
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
27-
RUN curl -o wordpress.tar.gz -SL https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz \
26+
RUN set -x \
27+
&& curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz" \
2828
&& echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
29+
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
2930
&& tar -xzf wordpress.tar.gz -C /usr/src/ \
3031
&& rm wordpress.tar.gz \
3132
&& chown -R www-data:www-data /usr/src/wordpress
3233

33-
COPY docker-entrypoint.sh /entrypoint.sh
34+
COPY docker-entrypoint.sh /usr/local/bin/
35+
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
3436

35-
# grr, ENTRYPOINT resets CMD now
36-
ENTRYPOINT ["/entrypoint.sh"]
37+
# ENTRYPOINT resets CMD
38+
ENTRYPOINT ["docker-entrypoint.sh"]
3739
CMD ["apache2-foreground"]
File renamed without changes.

fpm/Dockerfile renamed to php5.6/fpm/Dockerfile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ VOLUME /var/www/html
2121
ENV WORDPRESS_VERSION 4.6.1
2222
ENV WORDPRESS_SHA1 027e065d30a64720624a7404a1820e6c6fff1202
2323

24-
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
25-
RUN curl -o wordpress.tar.gz -SL https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz \
24+
RUN set -x \
25+
&& curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz" \
2626
&& echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
27+
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
2728
&& tar -xzf wordpress.tar.gz -C /usr/src/ \
2829
&& rm wordpress.tar.gz \
2930
&& chown -R www-data:www-data /usr/src/wordpress
3031

31-
COPY docker-entrypoint.sh /entrypoint.sh
32+
COPY docker-entrypoint.sh /usr/local/bin/
33+
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
3234

33-
# grr, ENTRYPOINT resets CMD now
34-
ENTRYPOINT ["/entrypoint.sh"]
35+
# ENTRYPOINT resets CMD
36+
ENTRYPOINT ["docker-entrypoint.sh"]
3537
CMD ["php-fpm"]
File renamed without changes.

php7.0/apache/Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM php:7.0-apache
2+
3+
# 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
7+
8+
# set recommended PHP.ini settings
9+
# see https://secure.php.net/manual/en/opcache.installation.php
10+
RUN { \
11+
echo 'opcache.memory_consumption=128'; \
12+
echo 'opcache.interned_strings_buffer=8'; \
13+
echo 'opcache.max_accelerated_files=4000'; \
14+
echo 'opcache.revalidate_freq=2'; \
15+
echo 'opcache.fast_shutdown=1'; \
16+
echo 'opcache.enable_cli=1'; \
17+
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
18+
19+
RUN a2enmod rewrite expires
20+
21+
VOLUME /var/www/html
22+
23+
ENV WORDPRESS_VERSION 4.6.1
24+
ENV WORDPRESS_SHA1 027e065d30a64720624a7404a1820e6c6fff1202
25+
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 - \
29+
# 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
33+
34+
COPY docker-entrypoint.sh /usr/local/bin/
35+
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
36+
37+
# ENTRYPOINT resets CMD
38+
ENTRYPOINT ["docker-entrypoint.sh"]
39+
CMD ["apache2-foreground"]

0 commit comments

Comments
 (0)