Skip to content

Commit e1ab9ff

Browse files
committed
Merge pull request #176 from ncopa/php-alpine
add php:7.0-alpine
2 parents b367866 + 647490f commit e1ab9ff

16 files changed

+954
-0
lines changed

5.6/alpine/Dockerfile

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
FROM alpine:3.3
2+
3+
ENV PHP_INI_DIR /usr/local/etc/php
4+
RUN mkdir -p $PHP_INI_DIR/conf.d
5+
6+
ENV PHP_VERSION 5.6.19
7+
ENV PHP_FILENAME php-5.6.19.tar.xz
8+
ENV PHP_SHA256 2a24a3f84971680ac0a4c71050067de4f76ee235aa4a041fae21bfa69975c168
9+
10+
##<autogenerated>##
11+
##</autogenerated>##
12+
13+
# --enable-mysqlnd is included below because it's harder to compile after the fact the extensions are (since it's a plugin for several extensions, not an extension in itself)
14+
ENV GPG_KEYS 0BD78B5F97500D450838F95DFE857D9A90D90EC1 6E4F6AB321FDC07F2C332E3AC2BF0BC433CFC8B3
15+
RUN set -xe \
16+
&& apk add --no-cache --virtual .build-deps \
17+
autoconf \
18+
curl-dev \
19+
file \
20+
gcc \
21+
gnupg \
22+
libc-dev \
23+
libedit-dev \
24+
libxml2-dev \
25+
make \
26+
openssl-dev \
27+
pkgconf \
28+
re2c \
29+
sqlite-dev \
30+
&& for key in $GPG_KEYS; do \
31+
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
32+
done \
33+
&& curl -fSL "http://php.net/get/$PHP_FILENAME/from/this/mirror" -o "$PHP_FILENAME" \
34+
&& echo "$PHP_SHA256 *$PHP_FILENAME" | sha256sum -c - \
35+
&& curl -fSL "http://php.net/get/$PHP_FILENAME.asc/from/this/mirror" -o "$PHP_FILENAME.asc" \
36+
&& gpg --batch --verify "$PHP_FILENAME.asc" "$PHP_FILENAME" \
37+
&& mkdir -p /usr/src \
38+
&& tar -Jxf "$PHP_FILENAME" -C /usr/src \
39+
&& mv /usr/src/php-$PHP_VERSION /usr/src/php \
40+
&& rm "$PHP_FILENAME"* \
41+
&& cd /usr/src/php \
42+
&& ./configure \
43+
--with-config-file-path="$PHP_INI_DIR" \
44+
--with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \
45+
$PHP_EXTRA_CONFIGURE_ARGS \
46+
--disable-cgi \
47+
--enable-mysqlnd \
48+
--with-curl \
49+
--with-openssl \
50+
--with-libedit \
51+
--with-zlib \
52+
&& make -j"$(getconf _NPROCESSORS_ONLN)" \
53+
&& make install \
54+
&& { find /usr/local/bin /usr/local/sbin -type f -perm +0111 -exec strip --strip-all '{}' + || true; } \
55+
&& make clean \
56+
&& runDeps="$( \
57+
scanelf --needed --nobanner --recursive /usr/local \
58+
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
59+
| sort -u \
60+
| xargs -r apk info --installed \
61+
| sort -u \
62+
)" \
63+
&& apk add --virtual .php-rundeps $runDeps \
64+
&& apk del .build-deps
65+
66+
COPY docker-php-ext-* /usr/local/bin/
67+
68+
##<autogenerated>##
69+
CMD ["php", "-a"]
70+
##</autogenerated>##

5.6/alpine/docker-php-ext-configure

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
set -e
3+
4+
ext="$1"
5+
extDir="/usr/src/php/ext/$ext"
6+
if [ -z "$ext" ] || ! [ -d "$extDir" ]; then
7+
echo >&2 "usage: $0 ext-name [configure flags]"
8+
echo >&2 " ie: $0 gd --with-jpeg-dir=/usr/local/something"
9+
echo >&2
10+
echo >&2 'Possible values for ext-name:'
11+
echo >&2 $(find /usr/src/php/ext -mindepth 2 -maxdepth 2 -type f -name 'config.m4' | cut -d/ -f6 | sort)
12+
exit 1
13+
fi
14+
shift
15+
16+
set -x
17+
cd "$extDir"
18+
phpize
19+
./configure "$@"

5.6/alpine/docker-php-ext-enable

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/sh
2+
set -e
3+
4+
cd "$(php -r 'echo ini_get("extension_dir");')"
5+
6+
usage() {
7+
echo "usage: $0 module-name [module-name ...]"
8+
echo " ie: $0 gd mysqli"
9+
echo " $0 pdo pdo_mysql"
10+
echo
11+
echo 'Possible values for module-name:'
12+
echo $(find -maxdepth 1 -type f -name '*.so' -exec basename '{}' ';' | sort)
13+
}
14+
15+
modules=""
16+
for module; do
17+
if [ -z "$module" ]; then
18+
continue
19+
fi
20+
if [ -f "$module.so" ] && ! [ -f "$module" ]; then
21+
# allow ".so" to be optional
22+
module="$module.so"
23+
fi
24+
if ! [ -f "$module" ]; then
25+
echo >&2 "error: $(readlink -f "$module") does not exist"
26+
echo >&2
27+
usage >&2
28+
exit 1
29+
fi
30+
modules="$modules $module"
31+
done
32+
33+
if [ -z "$modules" ]; then
34+
usage >&2
35+
exit 1
36+
fi
37+
38+
for module in ${modules}; do
39+
if grep -q zend_extension_entry "$module"; then
40+
# https://wiki.php.net/internals/extensions#loading_zend_extensions
41+
line="zend_extension=$(readlink -f "$module")"
42+
else
43+
line="extension=$module"
44+
fi
45+
46+
ext="$(basename "$module")"
47+
ext="${ext%.*}"
48+
if php -r 'exit(extension_loaded("'"$ext"'") ? 0 : 1);'; then
49+
# this isn't perfect, but it's better than nothing
50+
# (for example, 'opcache.so' presents inside PHP as 'Zend OPcache', not 'opcache')
51+
echo >&2
52+
echo >&2 "warning: $ext ($module) is already loaded!"
53+
echo >&2
54+
continue
55+
fi
56+
57+
ini="/usr/local/etc/php/conf.d/docker-php-ext-$ext.ini"
58+
if ! grep -q "$line" "$ini" 2>/dev/null; then
59+
echo "$line" >> "$ini"
60+
fi
61+
done

5.6/alpine/docker-php-ext-install

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/sh
2+
set -e
3+
4+
cd /usr/src/php/ext
5+
6+
usage() {
7+
echo "usage: $0 [-jN] ext-name [ext-name ...]"
8+
echo " ie: $0 gd mysqli"
9+
echo " $0 pdo pdo_mysql"
10+
echo " $0 -j5 gd mbstring mysqli pdo pdo_mysql shmop"
11+
echo
12+
echo 'if custom ./configure arguments are necessary, see docker-php-ext-configure'
13+
echo
14+
echo 'Possible values for ext-name:'
15+
echo $(find /usr/src/php/ext -mindepth 2 -maxdepth 2 -type f -name 'config.m4' | cut -d/ -f6 | sort)
16+
}
17+
18+
opts="$(getopt -o 'h?j:' --long 'help,jobs:' -- "$@" || { usage >&2 && false; })"
19+
eval set -- "$opts"
20+
21+
j=1
22+
while true; do
23+
flag="$1"
24+
shift
25+
case "$flag" in
26+
--help|-h|'-?') usage && exit 0 ;;
27+
--jobs|-j) j="$1" && shift ;;
28+
--) break ;;
29+
*)
30+
{
31+
echo "error: unknown flag: $flag"
32+
usage
33+
} >&2
34+
exit 1
35+
;;
36+
esac
37+
done
38+
39+
exts=
40+
for ext; do
41+
if [ -z "$ext" ]; then
42+
continue
43+
fi
44+
if [ ! -d "$ext" ]; then
45+
echo >&2 "error: $(pwd -P)/$ext does not exist"
46+
echo >&2
47+
usage >&2
48+
exit 1
49+
fi
50+
exts="$exts $ext"
51+
done
52+
53+
if [ -z "$exts" ]; then
54+
usage >&2
55+
exit 1
56+
fi
57+
58+
for ext in $exts; do
59+
(
60+
cd "$ext"
61+
[ -e Makefile ] || docker-php-ext-configure "$ext"
62+
make -j"$j"
63+
make -j"$j" install
64+
ls modules/*.so | cut -d/ -f2 | xargs -r docker-php-ext-enable
65+
make -j"$j" clean
66+
)
67+
done

5.6/fpm/alpine/Dockerfile

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
FROM alpine:3.3
2+
3+
ENV PHP_INI_DIR /usr/local/etc/php
4+
RUN mkdir -p $PHP_INI_DIR/conf.d
5+
6+
ENV PHP_VERSION 5.6.18
7+
ENV PHP_FILENAME php-5.6.18.tar.xz
8+
ENV PHP_SHA256 54dd9106c3469bc7028644d72ac140af00655420bbaaf4a742a64e9ed02ec1b0
9+
10+
11+
##<autogenerated>##
12+
ENV PHP_EXTRA_CONFIGURE_ARGS --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data
13+
##</autogenerated>##
14+
15+
# --enable-mysqlnd is included below because it's harder to compile after the fact the extensions are (since it's a plugin for several extensions, not an extension in itself)
16+
ENV GPG_KEYS 0BD78B5F97500D450838F95DFE857D9A90D90EC1 6E4F6AB321FDC07F2C332E3AC2BF0BC433CFC8B3
17+
RUN addgroup -g 82 -S www-data \
18+
&& adduser -u 82 -D -S -G www-data www-data
19+
RUN set -xe \
20+
&& apk add --no-cache --virtual .build-deps \
21+
autoconf \
22+
curl-dev \
23+
file \
24+
gcc \
25+
gnupg \
26+
libc-dev \
27+
libedit-dev \
28+
libxml2-dev \
29+
make \
30+
openssl-dev \
31+
pkgconf \
32+
re2c \
33+
sqlite-dev \
34+
&& for key in $GPG_KEYS; do \
35+
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
36+
done \
37+
&& curl -fSL "http://php.net/get/$PHP_FILENAME/from/this/mirror" -o "$PHP_FILENAME" \
38+
&& echo "$PHP_SHA256 *$PHP_FILENAME" | sha256sum -c - \
39+
&& curl -fSL "http://php.net/get/$PHP_FILENAME.asc/from/this/mirror" -o "$PHP_FILENAME.asc" \
40+
&& gpg --batch --verify "$PHP_FILENAME.asc" "$PHP_FILENAME" \
41+
&& mkdir -p /usr/src \
42+
&& tar -Jxf "$PHP_FILENAME" -C /usr/src \
43+
&& mv /usr/src/php-$PHP_VERSION /usr/src/php \
44+
&& rm "$PHP_FILENAME"* \
45+
&& cd /usr/src/php \
46+
&& ./configure \
47+
--with-config-file-path="$PHP_INI_DIR" \
48+
--with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \
49+
$PHP_EXTRA_CONFIGURE_ARGS \
50+
--disable-cgi \
51+
--enable-mysqlnd \
52+
--with-curl \
53+
--with-openssl \
54+
--with-libedit \
55+
--with-zlib \
56+
&& make -j"$(getconf _NPROCESSORS_ONLN)" \
57+
&& make install \
58+
&& { find /usr/local/bin /usr/local/sbin -type f -perm +0111 -exec strip --strip-all '{}' + || true; } \
59+
&& make clean \
60+
&& runDeps="$( \
61+
scanelf --needed --nobanner --recursive /usr/local \
62+
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
63+
| sort -u \
64+
| xargs -r apk info --installed \
65+
| sort -u \
66+
)" \
67+
&& apk add --virtual .php-rundeps $runDeps \
68+
&& apk del .build-deps
69+
70+
COPY docker-php-ext-* /usr/local/bin/
71+
72+
##<autogenerated>##
73+
WORKDIR /var/www/html
74+
75+
RUN set -ex \
76+
&& cd /usr/local/etc \
77+
&& if [ -d php-fpm.d ]; then \
78+
# for some reason, upstream's php-fpm.conf.default has "include=NONE/etc/php-fpm.d/*.conf"
79+
sed 's!=NONE/!=!g' php-fpm.conf.default | tee php-fpm.conf > /dev/null; \
80+
cp php-fpm.d/www.conf.default php-fpm.d/www.conf; \
81+
else \
82+
# PHP 5.x don't use "include=" by default, so we'll create our own simple config that mimics PHP 7+ for consistency
83+
mkdir php-fpm.d; \
84+
cp php-fpm.conf.default php-fpm.d/www.conf; \
85+
{ \
86+
echo '[global]'; \
87+
echo 'include=etc/php-fpm.d/*.conf'; \
88+
} | tee php-fpm.conf; \
89+
fi \
90+
&& { \
91+
echo '[global]'; \
92+
echo 'error_log = /proc/self/fd/2'; \
93+
echo; \
94+
echo '[www]'; \
95+
echo '; if we send this to /proc/self/fd/1, it never appears'; \
96+
echo 'access.log = /proc/self/fd/2'; \
97+
echo; \
98+
echo 'clear_env = no'; \
99+
echo; \
100+
echo '; Ensure worker stdout and stderr are sent to the main error log.'; \
101+
echo 'catch_workers_output = yes'; \
102+
} | tee php-fpm.d/docker.conf \
103+
&& { \
104+
echo '[global]'; \
105+
echo 'daemonize = no'; \
106+
echo; \
107+
echo '[www]'; \
108+
echo 'listen = [::]:9000'; \
109+
} | tee php-fpm.d/zz-docker.conf
110+
111+
EXPOSE 9000
112+
CMD ["php-fpm"]
113+
##</autogenerated>##
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
set -e
3+
4+
ext="$1"
5+
extDir="/usr/src/php/ext/$ext"
6+
if [ -z "$ext" ] || ! [ -d "$extDir" ]; then
7+
echo >&2 "usage: $0 ext-name [configure flags]"
8+
echo >&2 " ie: $0 gd --with-jpeg-dir=/usr/local/something"
9+
echo >&2
10+
echo >&2 'Possible values for ext-name:'
11+
echo >&2 $(find /usr/src/php/ext -mindepth 2 -maxdepth 2 -type f -name 'config.m4' | cut -d/ -f6 | sort)
12+
exit 1
13+
fi
14+
shift
15+
16+
set -x
17+
cd "$extDir"
18+
phpize
19+
./configure "$@"

0 commit comments

Comments
 (0)