mirror of
https://github.com/danog/php.git
synced 2024-11-26 20:04:58 +01:00
Remove extracted php src (#256)
* Remove php src the right way for lightweight containers. * Adapt docker-php-ext-* scripts to check exts against /available-exts generated file. * Improve docker-php-source script - swap spaces to tabs to match - use gnu tar for `--strip-components` - cache known extension list in `/usr/src/` - remove extra output * Changes per tianon's comments
This commit is contained in:
parent
8f978dd1f2
commit
1a4763005a
@ -12,7 +12,9 @@ ENV PHPIZE_DEPS \
|
||||
re2c
|
||||
RUN apk add --no-cache --virtual .persistent-deps \
|
||||
ca-certificates \
|
||||
curl
|
||||
curl \
|
||||
tar \
|
||||
xz
|
||||
|
||||
# ensure www-data user exists
|
||||
RUN set -x \
|
||||
@ -36,27 +38,32 @@ ENV PHP_FILENAME %%PHP_FILENAME%%
|
||||
ENV PHP_SHA256 %%PHP_SHA256%%
|
||||
|
||||
RUN set -xe \
|
||||
&& apk add --no-cache --virtual .build-deps \
|
||||
$PHPIZE_DEPS \
|
||||
curl-dev \
|
||||
&& apk add --no-cache --virtual .fetch-deps \
|
||||
gnupg \
|
||||
libedit-dev \
|
||||
libxml2-dev \
|
||||
openssl-dev \
|
||||
sqlite-dev \
|
||||
&& curl -fSL "http://php.net/get/$PHP_FILENAME/from/this/mirror" -o "$PHP_FILENAME" \
|
||||
&& echo "$PHP_SHA256 *$PHP_FILENAME" | sha256sum -c - \
|
||||
&& curl -fSL "http://php.net/get/$PHP_FILENAME.asc/from/this/mirror" -o "$PHP_FILENAME.asc" \
|
||||
&& mkdir -p /usr/src \
|
||||
&& cd /usr/src/ \
|
||||
&& curl -fSL "http://php.net/get/$PHP_FILENAME/from/this/mirror" -o php.tar.xz \
|
||||
&& echo "$PHP_SHA256 *php.tar.xz" | sha256sum -c - \
|
||||
&& curl -fSL "http://php.net/get/$PHP_FILENAME.asc/from/this/mirror" -o php.tar.xz.asc \
|
||||
&& export GNUPGHOME="$(mktemp -d)" \
|
||||
&& for key in $GPG_KEYS; do \
|
||||
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
|
||||
done \
|
||||
&& gpg --batch --verify "$PHP_FILENAME.asc" "$PHP_FILENAME" \
|
||||
&& rm -r "$GNUPGHOME" "$PHP_FILENAME.asc" \
|
||||
&& mkdir -p /usr/src \
|
||||
&& tar -Jxf "$PHP_FILENAME" -C /usr/src \
|
||||
&& mv "/usr/src/php-$PHP_VERSION" /usr/src/php \
|
||||
&& rm "$PHP_FILENAME" \
|
||||
&& gpg --batch --verify php.tar.xz.asc php.tar.xz \
|
||||
&& rm -r "$GNUPGHOME" \
|
||||
&& apk del .fetch-deps
|
||||
|
||||
COPY docker-php-source /usr/local/bin/
|
||||
|
||||
RUN set -xe \
|
||||
&& apk add --no-cache --virtual .build-deps \
|
||||
$PHPIZE_DEPS \
|
||||
curl-dev \
|
||||
libedit-dev \
|
||||
libxml2-dev \
|
||||
openssl-dev \
|
||||
sqlite-dev \
|
||||
&& docker-php-source extract \
|
||||
&& cd /usr/src/php \
|
||||
&& ./configure \
|
||||
--with-config-file-path="$PHP_INI_DIR" \
|
||||
@ -83,7 +90,8 @@ RUN set -xe \
|
||||
| sort -u \
|
||||
)" \
|
||||
&& apk add --no-cache --virtual .php-rundeps $runDeps \
|
||||
&& apk del .build-deps
|
||||
&& apk del .build-deps \
|
||||
&& docker-php-source delete
|
||||
|
||||
COPY docker-php-ext-* /usr/local/bin/
|
||||
|
||||
|
@ -17,6 +17,7 @@ RUN apt-get update && apt-get install -y \
|
||||
libedit2 \
|
||||
libsqlite3-0 \
|
||||
libxml2 \
|
||||
xz-utils \
|
||||
--no-install-recommends && rm -r /var/lib/apt/lists/*
|
||||
|
||||
ENV PHP_INI_DIR /usr/local/etc/php
|
||||
@ -31,6 +32,20 @@ ENV PHP_VERSION %%PHP_VERSION%%
|
||||
ENV PHP_FILENAME %%PHP_FILENAME%%
|
||||
ENV PHP_SHA256 %%PHP_SHA256%%
|
||||
|
||||
RUN set -xe \
|
||||
&& cd /usr/src/ \
|
||||
&& curl -fSL "http://php.net/get/$PHP_FILENAME/from/this/mirror" -o php.tar.xz \
|
||||
&& echo "$PHP_SHA256 *php.tar.xz" | sha256sum -c - \
|
||||
&& curl -fSL "http://php.net/get/$PHP_FILENAME.asc/from/this/mirror" -o php.tar.xz.asc \
|
||||
&& export GNUPGHOME="$(mktemp -d)" \
|
||||
&& for key in $GPG_KEYS; do \
|
||||
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
|
||||
done \
|
||||
&& gpg --batch --verify php.tar.xz.asc php.tar.xz \
|
||||
&& rm -r "$GNUPGHOME"
|
||||
|
||||
COPY docker-php-source /usr/local/bin/
|
||||
|
||||
RUN set -xe \
|
||||
&& buildDeps=" \
|
||||
$PHP_EXTRA_BUILD_DEPS \
|
||||
@ -39,21 +54,9 @@ RUN set -xe \
|
||||
libsqlite3-dev \
|
||||
libssl-dev \
|
||||
libxml2-dev \
|
||||
xz-utils \
|
||||
" \
|
||||
&& apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \
|
||||
&& curl -fSL "http://php.net/get/$PHP_FILENAME/from/this/mirror" -o "$PHP_FILENAME" \
|
||||
&& echo "$PHP_SHA256 *$PHP_FILENAME" | sha256sum -c - \
|
||||
&& curl -fSL "http://php.net/get/$PHP_FILENAME.asc/from/this/mirror" -o "$PHP_FILENAME.asc" \
|
||||
&& export GNUPGHOME="$(mktemp -d)" \
|
||||
&& for key in $GPG_KEYS; do \
|
||||
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
|
||||
done \
|
||||
&& gpg --batch --verify "$PHP_FILENAME.asc" "$PHP_FILENAME" \
|
||||
&& rm -r "$GNUPGHOME" "$PHP_FILENAME.asc" \
|
||||
&& mkdir -p /usr/src/php \
|
||||
&& tar -xf "$PHP_FILENAME" -C /usr/src/php --strip-components=1 \
|
||||
&& rm "$PHP_FILENAME" \
|
||||
&& docker-php-source extract \
|
||||
&& cd /usr/src/php \
|
||||
&& ./configure \
|
||||
--with-config-file-path="$PHP_INI_DIR" \
|
||||
@ -72,7 +75,8 @@ RUN set -xe \
|
||||
&& make install \
|
||||
&& { find /usr/local/bin /usr/local/sbin -type f -executable -exec strip --strip-all '{}' + || true; } \
|
||||
&& make clean \
|
||||
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false -o APT::AutoRemove::SuggestsImportant=false $buildDeps
|
||||
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $buildDeps \
|
||||
&& docker-php-source delete
|
||||
|
||||
COPY docker-php-ext-* /usr/local/bin/
|
||||
|
||||
|
@ -2,13 +2,12 @@
|
||||
set -e
|
||||
|
||||
ext="$1"
|
||||
extDir="/usr/src/php/ext/$ext"
|
||||
if [ -z "$ext" ] || ! [ -d "$extDir" ]; then
|
||||
if [ -z "$ext" ] || ! grep -qE "^$ext$" /usr/src/php-available-exts; then
|
||||
echo >&2 "usage: $0 ext-name [configure flags]"
|
||||
echo >&2 " ie: $0 gd --with-jpeg-dir=/usr/local/something"
|
||||
echo >&2
|
||||
echo >&2 'Possible values for ext-name:'
|
||||
echo >&2 $(find /usr/src/php/ext -mindepth 2 -maxdepth 2 -type f -name 'config.m4' | cut -d/ -f6 | sort)
|
||||
echo $(cat /usr/src/php-available-exts)
|
||||
exit 1
|
||||
fi
|
||||
shift
|
||||
@ -28,7 +27,9 @@ if [ "$pm" = 'apk' ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
docker-php-source extract
|
||||
|
||||
set -x
|
||||
cd "$extDir"
|
||||
cd "/usr/src/php/ext/$ext"
|
||||
phpize
|
||||
./configure "$@"
|
||||
|
@ -1,8 +1,6 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
cd /usr/src/php/ext
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 [-jN] ext-name [ext-name ...]"
|
||||
echo " ie: $0 gd mysqli"
|
||||
@ -12,7 +10,7 @@ usage() {
|
||||
echo 'if custom ./configure arguments are necessary, see docker-php-ext-configure'
|
||||
echo
|
||||
echo 'Possible values for ext-name:'
|
||||
echo $(find /usr/src/php/ext -mindepth 2 -maxdepth 2 -type f -name 'config.m4' | cut -d/ -f6 | sort)
|
||||
echo $(cat /usr/src/php-available-exts)
|
||||
}
|
||||
|
||||
opts="$(getopt -o 'h?j:' --long 'help,jobs:' -- "$@" || { usage >&2 && false; })"
|
||||
@ -41,8 +39,8 @@ for ext; do
|
||||
if [ -z "$ext" ]; then
|
||||
continue
|
||||
fi
|
||||
if [ ! -d "$ext" ]; then
|
||||
echo >&2 "error: $(pwd -P)/$ext does not exist"
|
||||
if ! grep -qE "^$ext$" /usr/src/php-available-exts; then
|
||||
echo >&2 "error: /usr/src/php/ext/$ext does not exist"
|
||||
echo >&2
|
||||
usage >&2
|
||||
exit 1
|
||||
@ -72,6 +70,9 @@ if [ "$pm" = 'apk' ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
docker-php-source extract
|
||||
cd /usr/src/php/ext
|
||||
|
||||
for ext in $exts; do
|
||||
(
|
||||
cd "$ext"
|
||||
@ -90,3 +91,4 @@ done
|
||||
if [ "$pm" = 'apk' ] && [ -n "$apkDel" ]; then
|
||||
apk del $apkDel
|
||||
fi
|
||||
docker-php-source delete
|
||||
|
44
docker-php-source
Executable file
44
docker-php-source
Executable file
@ -0,0 +1,44 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
dir=/usr/src/php
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 COMMAND"
|
||||
echo
|
||||
echo "Manage php source tarball lifecycle."
|
||||
echo
|
||||
echo "Commands:"
|
||||
echo " extract extract php source tarball into directory $dir if not already done."
|
||||
echo " delete delete extracted php source located into $dir if not already done."
|
||||
echo
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
extract)
|
||||
if [ -e "$dir" -a ! -d "$dir" ] ; then
|
||||
echo >&2 "$dir exists and is not a directory"
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -d "$dir" ]; then
|
||||
mkdir -p "$dir"
|
||||
tar -Jxf /usr/src/php.tar.xz -C "$dir" --strip-components=1
|
||||
|
||||
if [ ! -f /usr/src/php-available-exts ]; then
|
||||
find "$dir/ext" \
|
||||
-mindepth 2 \
|
||||
-maxdepth 2 \
|
||||
-type f \
|
||||
-name 'config.m4' \
|
||||
| xargs -n1 dirname | xargs -n1 basename | sort \
|
||||
> /usr/src/php-available-exts
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
delete)
|
||||
rm -rf "$dir"
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@ -68,11 +68,13 @@ for version in "${versions[@]}"; do
|
||||
|
||||
cp -v Dockerfile-debian.template "$version/Dockerfile"
|
||||
cp -v docker-php-ext-* "$version/"
|
||||
cp -v docker-php-source "$version/"
|
||||
dockerfiles+=( "$version/Dockerfile" )
|
||||
|
||||
if [ -d "$version/alpine" ]; then
|
||||
cp -v Dockerfile-alpine.template "$version/alpine/Dockerfile"
|
||||
cp -v docker-php-ext-* "$version/alpine/"
|
||||
cp -v docker-php-source "$version/alpine/"
|
||||
dockerfiles+=( "$version/alpine/Dockerfile" )
|
||||
fi
|
||||
|
||||
@ -98,6 +100,7 @@ for version in "${versions[@]}"; do
|
||||
ia && ac == 1 { system("cat '$variant'-Dockerfile-block-" ab) }
|
||||
' "$base" > "$version/$target/Dockerfile"
|
||||
cp -v docker-php-ext-* "$version/$target/"
|
||||
cp -v docker-php-source "$version/$target/"
|
||||
dockerfiles+=( "$version/$target/Dockerfile" )
|
||||
done
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user