Skip to content

Commit 27c65bb

Browse files
committed
Add docker-php-* scripts for new images
1 parent 53040bf commit 27c65bb

File tree

105 files changed

+7308
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+7308
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# first arg is `-f` or `--some-option`
5+
if [ "${1#-}" != "$1" ]; then
6+
set -- php "$@"
7+
fi
8+
9+
exec "$@"
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# prefer user supplied CFLAGS, but default to our PHP_CFLAGS
5+
: ${CFLAGS:=$PHP_CFLAGS}
6+
: ${CPPFLAGS:=$PHP_CPPFLAGS}
7+
: ${LDFLAGS:=$PHP_LDFLAGS}
8+
export CFLAGS CPPFLAGS LDFLAGS
9+
10+
srcExists=
11+
if [ -d /usr/src/php ]; then
12+
srcExists=1
13+
fi
14+
docker-php-source extract
15+
if [ -z "$srcExists" ]; then
16+
touch /usr/src/php/.docker-delete-me
17+
fi
18+
19+
cd /usr/src/php/ext
20+
21+
usage() {
22+
echo "usage: $0 ext-name [configure flags]"
23+
echo " ie: $0 gd --with-jpeg-dir=/usr/local/something"
24+
echo
25+
echo 'Possible values for ext-name:'
26+
find . \
27+
-mindepth 2 \
28+
-maxdepth 2 \
29+
-type f \
30+
-name 'config.m4' \
31+
| xargs -n1 dirname \
32+
| xargs -n1 basename \
33+
| sort \
34+
| xargs
35+
echo
36+
echo 'Some of the above modules are already compiled into PHP; please check'
37+
echo 'the output of "php -i" to see which modules are already loaded.'
38+
}
39+
40+
ext="$1"
41+
if [ -z "$ext" ] || [ ! -d "$ext" ]; then
42+
usage >&2
43+
exit 1
44+
fi
45+
shift
46+
47+
pm='unknown'
48+
if [ -e /lib/apk/db/installed ]; then
49+
pm='apk'
50+
fi
51+
52+
if [ "$pm" = 'apk' ]; then
53+
if \
54+
[ -n "$PHPIZE_DEPS" ] \
55+
&& ! apk info --installed .phpize-deps > /dev/null \
56+
&& ! apk info --installed .phpize-deps-configure > /dev/null \
57+
; then
58+
apk add --no-cache --virtual .phpize-deps-configure $PHPIZE_DEPS
59+
fi
60+
fi
61+
62+
if command -v dpkg-architecture > /dev/null; then
63+
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"
64+
set -- --build="$gnuArch" "$@"
65+
fi
66+
67+
cd "$ext"
68+
phpize
69+
./configure "$@"
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/bin/sh
2+
set -e
3+
4+
extDir="$(php -r 'echo ini_get("extension_dir");')"
5+
cd "$extDir"
6+
7+
usage() {
8+
echo "usage: $0 [options] module-name [module-name ...]"
9+
echo " ie: $0 gd mysqli"
10+
echo " $0 pdo pdo_mysql"
11+
echo " $0 --ini-name 0-apc.ini apcu apc"
12+
echo
13+
echo 'Possible values for module-name:'
14+
find -maxdepth 1 \
15+
-type f \
16+
-name '*.so' \
17+
-exec basename '{}' ';' \
18+
| sort \
19+
| xargs
20+
echo
21+
echo 'Some of the above modules are already compiled into PHP; please check'
22+
echo 'the output of "php -i" to see which modules are already loaded.'
23+
}
24+
25+
opts="$(getopt -o 'h?' --long 'help,ini-name:' -- "$@" || { usage >&2 && false; })"
26+
eval set -- "$opts"
27+
28+
iniName=
29+
while true; do
30+
flag="$1"
31+
shift
32+
case "$flag" in
33+
--help|-h|'-?') usage && exit 0 ;;
34+
--ini-name) iniName="$1" && shift ;;
35+
--) break ;;
36+
*)
37+
{
38+
echo "error: unknown flag: $flag"
39+
usage
40+
} >&2
41+
exit 1
42+
;;
43+
esac
44+
done
45+
46+
modules=
47+
for module; do
48+
if [ -z "$module" ]; then
49+
continue
50+
fi
51+
if [ -f "$module.so" ] && ! [ -f "$module" ]; then
52+
# allow ".so" to be optional
53+
module="$module.so"
54+
fi
55+
if ! [ -f "$module" ]; then
56+
echo >&2 "error: '$module' does not exist"
57+
echo >&2
58+
usage >&2
59+
exit 1
60+
fi
61+
modules="$modules $module"
62+
done
63+
64+
if [ -z "$modules" ]; then
65+
usage >&2
66+
exit 1
67+
fi
68+
69+
pm='unknown'
70+
if [ -e /lib/apk/db/installed ]; then
71+
pm='apk'
72+
fi
73+
74+
apkDel=
75+
if [ "$pm" = 'apk' ]; then
76+
if \
77+
[ -n "$PHPIZE_DEPS" ] \
78+
&& ! apk info --installed .phpize-deps > /dev/null \
79+
&& ! apk info --installed .phpize-deps-configure > /dev/null \
80+
; then
81+
apk add --no-cache --virtual '.docker-php-ext-enable-deps' binutils
82+
apkDel='.docker-php-ext-enable-deps'
83+
fi
84+
fi
85+
86+
for module in $modules; do
87+
if readelf --wide --syms "$module" | grep -q ' zend_extension_entry$'; then
88+
# https://wiki.php.net/internals/extensions#loading_zend_extensions
89+
absModule="$(readlink -f "$module")"
90+
line="zend_extension=$absModule"
91+
else
92+
line="extension=$module"
93+
fi
94+
95+
ext="$(basename "$module")"
96+
ext="${ext%.*}"
97+
if php -r 'exit(extension_loaded("'"$ext"'") ? 0 : 1);'; then
98+
# this isn't perfect, but it's better than nothing
99+
# (for example, 'opcache.so' presents inside PHP as 'Zend OPcache', not 'opcache')
100+
echo >&2
101+
echo >&2 "warning: $ext ($module) is already loaded!"
102+
echo >&2
103+
continue
104+
fi
105+
106+
ini="/usr/local/etc/php/conf.d/${iniName:-"docker-php-ext-$ext.ini"}"
107+
if ! grep -q "$line" "$ini" 2>/dev/null; then
108+
echo "$line" >> "$ini"
109+
fi
110+
done
111+
112+
if [ "$pm" = 'apk' ] && [ -n "$apkDel" ]; then
113+
apk del $apkDel
114+
fi
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# prefer user supplied CFLAGS, but default to our PHP_CFLAGS
5+
: ${CFLAGS:=$PHP_CFLAGS}
6+
: ${CPPFLAGS:=$PHP_CPPFLAGS}
7+
: ${LDFLAGS:=$PHP_LDFLAGS}
8+
export CFLAGS CPPFLAGS LDFLAGS
9+
10+
srcExists=
11+
if [ -d /usr/src/php ]; then
12+
srcExists=1
13+
fi
14+
docker-php-source extract
15+
if [ -z "$srcExists" ]; then
16+
touch /usr/src/php/.docker-delete-me
17+
fi
18+
19+
cd /usr/src/php/ext
20+
21+
usage() {
22+
echo "usage: $0 [-jN] ext-name [ext-name ...]"
23+
echo " ie: $0 gd mysqli"
24+
echo " $0 pdo pdo_mysql"
25+
echo " $0 -j5 gd mbstring mysqli pdo pdo_mysql shmop"
26+
echo
27+
echo 'if custom ./configure arguments are necessary, see docker-php-ext-configure'
28+
echo
29+
echo 'Possible values for ext-name:'
30+
find . \
31+
-mindepth 2 \
32+
-maxdepth 2 \
33+
-type f \
34+
-name 'config.m4' \
35+
| xargs -n1 dirname \
36+
| xargs -n1 basename \
37+
| sort \
38+
| xargs
39+
echo
40+
echo 'Some of the above modules are already compiled into PHP; please check'
41+
echo 'the output of "php -i" to see which modules are already loaded.'
42+
}
43+
44+
opts="$(getopt -o 'h?j:' --long 'help,jobs:' -- "$@" || { usage >&2 && false; })"
45+
eval set -- "$opts"
46+
47+
j=1
48+
while true; do
49+
flag="$1"
50+
shift
51+
case "$flag" in
52+
--help|-h|'-?') usage && exit 0 ;;
53+
--jobs|-j) j="$1" && shift ;;
54+
--) break ;;
55+
*)
56+
{
57+
echo "error: unknown flag: $flag"
58+
usage
59+
} >&2
60+
exit 1
61+
;;
62+
esac
63+
done
64+
65+
exts=
66+
for ext; do
67+
if [ -z "$ext" ]; then
68+
continue
69+
fi
70+
if [ ! -d "$ext" ]; then
71+
echo >&2 "error: $PWD/$ext does not exist"
72+
echo >&2
73+
usage >&2
74+
exit 1
75+
fi
76+
exts="$exts $ext"
77+
done
78+
79+
if [ -z "$exts" ]; then
80+
usage >&2
81+
exit 1
82+
fi
83+
84+
pm='unknown'
85+
if [ -e /lib/apk/db/installed ]; then
86+
pm='apk'
87+
fi
88+
89+
apkDel=
90+
if [ "$pm" = 'apk' ]; then
91+
if [ -n "$PHPIZE_DEPS" ]; then
92+
if apk info --installed .phpize-deps-configure > /dev/null; then
93+
apkDel='.phpize-deps-configure'
94+
elif ! apk info --installed .phpize-deps > /dev/null; then
95+
apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS
96+
apkDel='.phpize-deps'
97+
fi
98+
fi
99+
fi
100+
101+
popDir="$PWD"
102+
for ext in $exts; do
103+
cd "$ext"
104+
[ -e Makefile ] || docker-php-ext-configure "$ext"
105+
make -j"$j"
106+
make -j"$j" install
107+
find modules \
108+
-maxdepth 1 \
109+
-name '*.so' \
110+
-exec basename '{}' ';' \
111+
| xargs -r docker-php-ext-enable
112+
make -j"$j" clean
113+
cd "$popDir"
114+
done
115+
116+
if [ "$pm" = 'apk' ] && [ -n "$apkDel" ]; then
117+
apk del $apkDel
118+
fi
119+
120+
if [ -e /usr/src/php/.docker-delete-me ]; then
121+
docker-php-source delete
122+
fi

5.6/alpine3.7/cli/docker-php-source

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/sh
2+
set -e
3+
4+
dir=/usr/src/php
5+
6+
usage() {
7+
echo "usage: $0 COMMAND"
8+
echo
9+
echo "Manage php source tarball lifecycle."
10+
echo
11+
echo "Commands:"
12+
echo " extract extract php source tarball into directory $dir if not already done."
13+
echo " delete delete extracted php source located into $dir if not already done."
14+
echo
15+
}
16+
17+
case "$1" in
18+
extract)
19+
mkdir -p "$dir"
20+
if [ ! -f "$dir/.docker-extracted" ]; then
21+
tar -Jxf /usr/src/php.tar.xz -C "$dir" --strip-components=1
22+
touch "$dir/.docker-extracted"
23+
fi
24+
;;
25+
26+
delete)
27+
rm -rf "$dir"
28+
;;
29+
30+
*)
31+
usage
32+
exit 1
33+
;;
34+
esac
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# first arg is `-f` or `--some-option`
5+
if [ "${1#-}" != "$1" ]; then
6+
set -- php-fpm "$@"
7+
fi
8+
9+
exec "$@"

0 commit comments

Comments
 (0)