Let users install a specific PHP module version

Test: amqp,apcu,gmagick,http,pecl_http,igbinary,memcache,mailparse,memcached,mongodb,mosquitto,msgpack,oauth,opencensus,parallel,pcov,pdo_sqlsrv,sqlsrv,propro,protobuf,pthreads,raphf,rdkafka,redis,solr,ssh2,uuid,xdebug,uopz,xhprof,yaml
This commit is contained in:
Michele Locati 2020-12-02 18:19:24 +01:00
parent a48eab9e71
commit 4ee43e5429
No known key found for this signature in database
GPG Key ID: 98B7CE2E7234E28B
4 changed files with 308 additions and 125 deletions

View File

@ -76,3 +76,21 @@ jobs:
with:
fetch-depth: 1
- run: docker run --rm --volume "$(pwd):/app" --workdir /app php:7.3-stretch ./scripts/test-restore-apt
test_custom_version:
name: Test installing specific versions
needs:
- check_syntax_shell
- check_syntax_php
runs-on: ubuntu-latest
strategy:
matrix:
xdebug_version:
- ''
- 2.9.8
- 3.0.0
steps:
- name: Checkout
uses: actions/checkout@v1
with:
fetch-depth: 1
- run: docker run --rm --volume "$(pwd):/app" --workdir /app php:7.4-alpine ./scripts/test-installversion "${{ matrix.xdebug_version }}"

View File

@ -9,7 +9,6 @@ The script will install all the required APT/APK packages; at the end of the scr
Supported docker images are all the Alpine/Debian versions, except for PHP 5.5 where we only support Debian 8 (jessie) (that is, `php:5.5`, `php:5.5-apache`, `php:5.5-cli`, `php:5.5-fpm`, `php:5.5-zts`).
See also the notes in the [Special requirements](#special-requirements) section.
## Usage
You have two ways to use this script within your `Dockerfile`s: you can download the script on the fly, or you can grab it from the [`mlocati/php-extension-installer` Docker Hub image](https://hub.docker.com/r/mlocati/php-extension-installer).
@ -38,6 +37,15 @@ COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr
RUN install-php-extensions gd xdebug
```
### Installing a specific version of an extension
Simply append `-<version>` to the module name.
For example:
```sh
install-php-extensions xdebug-2.9.7
```
## Supported PHP extensions
<!-- START OF EXTENSIONS TABLE -->
@ -199,7 +207,6 @@ Some extension has special requirements:
| <a name="special-requirements-for-tdlib"></a>tdlib | &bull; Not available in `alpine3.7` docker images<br />&bull; Not available in `jessie` docker images |
<!-- END OF SPECIAL REQUIREMENTS -->
## Tests
When submitting a pull request, a [GitHub Action](https://github.com/mlocati/docker-php-extension-installer/blob/master/.github/workflows/test-extensions.yml) is executed to check if affected PHP extensions actually work (see below).
@ -209,7 +216,6 @@ This is done on a scheduled basis with another [GitHub Action](https://github.co
In case of failure, a message is sent to a [Telegram Channel](https://t.me/docker_php_extension_installer).
Feel free to subscribe to it to receive failure notifications.
## How to contribute
### Formatting code
@ -266,7 +272,6 @@ Test: gd, zip, -STOP-
See [this pull request](https://github.com/mlocati/docker-php-extension-installer/pull/43) for an example.
## Do you want to really say thank you?
You can offer me a [monthly coffee](https://github.com/sponsors/mlocati) or a [one-time coffee](https://paypal.me/mlocati) :wink:

View File

@ -70,6 +70,51 @@ normalizePHPModuleName() {
printf '%s' "$normalizePHPModuleName_name"
}
# Parse a module name (and optionally version) as received via command arguments, extracting the version and normalizing it
# Example:
# xdebug-2.9.8
#
# Arguments:
# $1: the name of the module to be normalized
#
# Set these variables:
# - PROCESSED_PHP_MODULE_ARGUMENT
#
# Optionally set these variables:
# - PHP_WANTEDMODULEVERSION_<...> (where <...> is the normalized module name)
#
# Output:
# Nothing
processPHPMuduleArgument() {
PROCESSED_PHP_MODULE_ARGUMENT="${1%%-*}"
if test -n "$PROCESSED_PHP_MODULE_ARGUMENT" && test "$PROCESSED_PHP_MODULE_ARGUMENT" != "$1"; then
processPHPMuduleArgument_version="${1#*-}"
else
processPHPMuduleArgument_version=''
fi
PROCESSED_PHP_MODULE_ARGUMENT="$(normalizePHPModuleName "$PROCESSED_PHP_MODULE_ARGUMENT")"
if test -n "$processPHPMuduleArgument_version"; then
if printf '%s' "$PROCESSED_PHP_MODULE_ARGUMENT" | grep -Eq '^[a-zA-Z0-9_]+$'; then
eval PHP_WANTEDMODULEVERSION_$PROCESSED_PHP_MODULE_ARGUMENT="$processPHPMuduleArgument_version"
else
printf 'Unable to parse the following module name:\n%s\n' "$PROCESSED_PHP_MODULE_ARGUMENT" >&2
fi
fi
}
# Get the wanted PHP module version, as specified in the command line arguments.
#
# Arguments:
# $1: the name of the module to be normalized
#
# Output:
# The wanted version (if any)
getWantedPHPModuleVersion() {
if printf '%s' "$1" | grep -Eq '^[a-zA-Z0-9_]+$'; then
eval printf '%s' "\${PHP_WANTEDMODULEVERSION_$1:-}"
fi
}
# Set these variables:
# - PHP_PREINSTALLED_MODULES the normalized list of PHP modules installed before running this script
setPHPPreinstalledModules() {
@ -130,7 +175,8 @@ processCommandArguments() {
esac
fi
if test $processCommandArguments_skip -eq 0; then
processCommandArguments_name="$(normalizePHPModuleName "$1")"
processPHPMuduleArgument "$1"
processCommandArguments_name="$PROCESSED_PHP_MODULE_ARGUMENT"
if stringInList "$processCommandArguments_name" "$PHP_MODULES_TO_INSTALL"; then
printf '### WARNING Duplicated module name specified: %s ###\n' "$processCommandArguments_name" >&2
elif stringInList "$processCommandArguments_name" "$PHP_PREINSTALLED_MODULES"; then
@ -915,6 +961,9 @@ compareVersions() {
# Nothing
installBundledModule() {
printf '### INSTALLING BUNDLED MODULE %s ###\n' "$1"
if test -n "$(getWantedPHPModuleVersion "$1")"; then
printf '### WARNING the module "%s" is bundled with PHP, you can NOT specify a version for it\n' "$1" >&2
fi
case "$1" in
gd)
if test $PHP_MAJMIN_VERSION -le 506; then
@ -1104,22 +1153,27 @@ installModuleFromSource() {
# Arguments:
# $1: the handle of the PHP module
installPECLModule() {
printf '### INSTALLING PECL MODULE %s ###\n' "$1"
installPECLModule_actual="$1"
installPECLModule_module="$1"
printf '### INSTALLING PECL MODULE %s ###\n' "$installPECLModule_module"
installPECLModule_version="$(getWantedPHPModuleVersion "$installPECLModule_module")"
rm -rf "$CONFIGURE_FILE"
installPECLModule_manuallyInstalled=0
case "$1" in
case "$installPECLModule_module" in
amqp)
case "$DISTRO_VERSION" in
debian@8)
if test -z "$installPECLModule_version"; then
# in Debian Jessie we have librammitmq version 0.5.2
installPECLModule_actual="$1-1.9.3"
installPECLModule_version=1.9.3
fi
;;
esac
;;
apcu)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -le 506; then
installPECLModule_actual="$1-4.0.11"
installPECLModule_version=4.0.11
fi
fi
;;
decimal)
@ -1135,17 +1189,22 @@ installPECLModule() {
esac
;;
gmagick)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -le 506; then
installPECLModule_actual="$1-1.1.7RC3"
installPECLModule_version=1.1.7RC3
else
installPECLModule_actual="$1-beta"
installPECLModule_version=beta
fi
fi
;;
http)
installPECLModule_module=pecl_http
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -le 506; then
installPECLModule_actual="pecl_http-2.6.0"
else
installPECLModule_actual="pecl_http"
installPECLModule_version=2.6.0
fi
fi
if test $PHP_MAJMIN_VERSION -ge 700; then
if ! test -e /usr/local/lib/libidnkit.so; then
installPECLModule_src="$(getPackageSource https://jprs.co.jp/idn/idnkit-2.3.tar.bz2)"
cd -- "$installPECLModule_src"
@ -1156,26 +1215,35 @@ installPECLModule() {
fi
;;
igbinary)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -lt 700; then
installPECLModule_actual="$1-2.0.8"
installPECLModule_version=2.0.8
fi
fi
;;
memcache)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -lt 700; then
installPECLModule_actual="$1-2.2.7"
installPECLModule_version=2.2.7
fi
fi
;;
mailparse)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -lt 700; then
installPECLModule_actual="$1-2.1.6"
installPECLModule_version=2.1.6
fi
fi
;;
memcached)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -lt 700; then
installPECLModule_version=2.2.0
fi
fi
# Set the path to libmemcached install prefix
addConfigureOption 'with-libmemcached-dir' 'no'
if test $PHP_MAJMIN_VERSION -lt 700; then
installPECLModule_actual="$1-2.2.0"
else
if test -z "$installPECLModule_version" || test $(compareVersions "$installPECLModule_version" '3.0.0') -ge 0; then
# Set the path to ZLIB install prefix
addConfigureOption 'with-zlib-dir' 'no'
# Use system FastLZ library
@ -1207,31 +1275,45 @@ installPECLModule() {
addConfigureOption '-with-mongo-sasl' 'yes'
;;
mongodb)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -le 505; then
installPECLModule_actual="$1-1.5.5"
installPECLModule_version=1.5.5
elif test $PHP_MAJMIN_VERSION -le 506; then
installPECLModule_actual="$1-1.7.5"
installPECLModule_version=1.7.5
fi
fi
;;
mosquitto)
installPECLModule_actual="$1-0.4.0"
if test -z "$installPECLModule_version"; then
installPECLModule_version=0.4.0
fi
;;
msgpack)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -le 506; then
installPECLModule_actual="$1-0.5.7"
installPECLModule_version=0.5.7
fi
fi
;;
oauth)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -le 506; then
installPECLModule_actual="$1-1.2.3"
installPECLModule_version=1.2.3
fi
fi
;;
opencensus)
if test $PHP_MAJMIN_VERSION -le 702; then
installPECLModule_actual="$1-alpha"
if test -z "$installPECLModule_version"; then
installPECLModule_version=alpha
fi
else
installPECLModule_manuallyInstalled=1
if test -z "$installPECLModule_version"; then
installPECLModule_src="$(getPackageSource https://pecl.php.net/get/opencensus)"
else
installPECLModule_src="$(getPackageSource https://pecl.php.net/get/opencensus-$installPECLModule_version)"
fi
cd "$installPECLModule_src"/opencensus-*
find . -name '*.c' -type f -exec sed -i 's/\bZVAL_DESTRUCTOR\b/zval_dtor/g' {} +
phpize
@ -1241,46 +1323,63 @@ installPECLModule() {
fi
;;
parallel)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -le 701; then
installPECLModule_actual="$1-0.8.3"
installPECLModule_version=0.8.3
fi
fi
;;
pcov)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -lt 701; then
installPECLModule_actual="$1-0.9.0"
installPECLModule_version=0.9.0
fi
fi
;;
pdo_sqlsrv | sqlsrv)
if test -z "$installPECLModule_version"; then
# https://docs.microsoft.com/it-it/sql/connect/php/system-requirements-for-the-php-sql-driver?view=sql-server-2017
if test $PHP_MAJMIN_VERSION -le 700; then
installPECLModule_actual="$1-5.3.0"
installPECLModule_version=5.3.0
elif test $PHP_MAJMIN_VERSION -le 701; then
installPECLModule_actual="$1-5.6.1"
installPECLModule_version=5.6.1
fi
fi
;;
propro)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -lt 700; then
installPECLModule_actual="$1-1.0.2"
installPECLModule_version=1.0.2
fi
fi
;;
protobuf)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -lt 700; then
installPECLModule_actual="$1-3.12.4"
installPECLModule_version=3.12.4
else
installPECLModule_version=3.13.0
fi
fi
;;
pthreads)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -lt 700; then
installPECLModule_actual="$1-2.0.10"
installPECLModule_version=2.0.10
fi
fi
;;
raphf)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -lt 700; then
installPECLModule_actual="$1-1.1.2"
installPECLModule_version=1.1.2
fi
fi
;;
rdkafka)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -le 505; then
installPECLModule_actual="$1-3.0.5"
installPECLModule_version=3.0.5
else
installPECLModule_tmp=
case "$DISTRO" in
@ -1295,13 +1394,19 @@ installPECLModule() {
installPECLModule_tmp="$(getInstalledPackageVersion "$installPECLModule_tmp")"
if test -n "$installPECLModule_tmp"; then
if test $(compareVersions "$installPECLModule_tmp" '0.11.0') -lt 0; then
installPECLModule_actual="$1-3.1.3"
installPECLModule_version=3.1.3
fi
fi
fi
fi
fi
;;
redis)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -le 506; then
installPECLModule_version=4.3.0
fi
fi
# Enable igbinary serializer support?
if php --ri igbinary >/dev/null 2>/dev/null; then
addConfigureOption 'enable-redis-igbinary' 'yes'
@ -1310,9 +1415,7 @@ installPECLModule() {
fi
# Enable lzf compression support?
addConfigureOption 'enable-redis-lzf' 'yes'
if test $PHP_MAJMIN_VERSION -le 506; then
installPECLModule_actual="$1-4.3.0"
else
if test -z "$installPECLModule_version" || test $(compareVersions "$installPECLModule_version" '5.0.0') -ge 0; then
installPECLModule_machine=$(getTargetTriplet)
if ! test -e /usr/include/zstd.h || ! test -e /usr/lib/libzstd.so -o -e "/usr/lib/$installPECLModule_machine/libzstd.so"; then
installPECLModule_zstdVersion=1.4.4
@ -1333,15 +1436,19 @@ installPECLModule() {
fi
;;
solr)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -le 506; then
installPECLModule_actual="$1-2.4.0"
installPECLModule_version=2.4.0
fi
fi
;;
ssh2)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -le 506; then
installPECLModule_actual="$1-0.13"
installPECLModule_version=0.13
else
installPECLModule_actual="$1-1.2"
installPECLModule_version=1.2
fi
fi
;;
tdlib)
@ -1368,26 +1475,34 @@ installPECLModule() {
installPECLModule_manuallyInstalled=1
;;
uuid)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -le 506; then
installPECLModule_actual="$1-1.0.5"
installPECLModule_version=1.0.5
fi
fi
;;
xdebug)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -le 500; then
installPECLModule_actual="$1-2.0.5"
installPECLModule_version=2.0.5
elif test $PHP_MAJMIN_VERSION -le 503; then
installPECLModule_actual="$1-2.2.7"
installPECLModule_version=2.2.7
elif test $PHP_MAJMIN_VERSION -le 504; then
installPECLModule_actual="$1-2.4.1"
installPECLModule_version=2.4.1
elif test $PHP_MAJMIN_VERSION -le 506; then
installPECLModule_actual="$1-2.5.5"
installPECLModule_version=2.5.5
elif test $PHP_MAJMIN_VERSION -le 700; then
installPECLModule_actual="$1-2.6.1"
installPECLModule_version=2.6.1
elif test $PHP_MAJMIN_VERSION -le 701; then
installPECLModule_actual="$1-2.9.8"
elif test $PHP_MAJMIN_VERSION -ge 800; then
installPECLModule_version=2.9.8
fi
fi
if test $PHP_MAJMIN_VERSION -ge 800; then
# Workaround for picke problem - see https://github.com/FriendsOfPHP/pickle/issues/188 and https://github.com/FriendsOfPHP/pickle/issues/191
installPECLModule_src="$(getPackageSource https://codeload.github.com/xdebug/xdebug/tar.gz/3.0.0)"
if test -z "$installPECLModule_version"; then
installPECLModule_version=3.0.0
fi
installPECLModule_src="$(getPackageSource https://codeload.github.com/xdebug/xdebug/tar.gz/$installPECLModule_version)"
cd -- "$installPECLModule_src"
phpize
./configure --enable-xdebug
@ -1398,22 +1513,28 @@ installPECLModule() {
fi
;;
uopz)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -lt 700; then
installPECLModule_actual="$1-2.0.7"
installPECLModule_version=2.0.7
elif test $PHP_MAJMIN_VERSION -lt 701; then
installPECLModule_actual="$1-5.0.2"
installPECLModule_version=5.0.2
fi
fi
;;
xhprof)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -le 506; then
installPECLModule_actual="$1-0.9.4"
installPECLModule_version=0.9.4
fi
fi
;;
yaml)
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -lt 700; then
installPECLModule_actual="$1-1.3.1"
installPECLModule_version=1.3.1
elif test $PHP_MAJMIN_VERSION -lt 701; then
installPECLModule_actual="$1-2.0.4"
installPECLModule_version=2.0.4
fi
fi
;;
zookeeper)
@ -1429,34 +1550,36 @@ installPECLModule() {
fi
;;
esac
if test -z "$installPECLModule_version"; then
if test $PHP_MAJMIN_VERSION -lt 700; then
installPECLModule_actual="$1-0.5.0"
installPECLModule_version=0.5.0
elif test $PHP_MAJMIN_VERSION -gt 702; then
installPECLModule_actual="$1-0.7.2"
installPECLModule_version=0.7.2
fi
fi
;;
esac
if test $installPECLModule_manuallyInstalled -eq 0; then
if test "$1" != "$installPECLModule_actual"; then
printf ' (installing version %s)\n' "$installPECLModule_actual"
if test -n "$installPECLModule_version"; then
printf ' (installing version %s)\n' "$installPECLModule_version"
fi
installPeclPackage "$installPECLModule_actual"
installPeclPackage "$installPECLModule_module" "$installPECLModule_version"
fi
case "$1" in
case "$installPECLModule_module" in
apcu_bc)
# apcu_bc must be loaded after apcu
docker-php-ext-enable --ini-name "xx-php-ext-$1.ini" apc
docker-php-ext-enable --ini-name "xx-php-ext-$installPECLModule_module.ini" apc
;;
http)
pecl_http)
# http must be loaded after raphf and propro
docker-php-ext-enable --ini-name "xx-php-ext-$1.ini" "$1"
docker-php-ext-enable --ini-name "xx-php-ext-http.ini" http
;;
memcached)
# memcached must be loaded after msgpack
docker-php-ext-enable --ini-name "xx-php-ext-$1.ini" "$1"
docker-php-ext-enable --ini-name "xx-php-ext-$installPECLModule_module.ini" "$installPECLModule_module"
;;
*)
docker-php-ext-enable "$1"
docker-php-ext-enable "$installPECLModule_module"
;;
esac
}
@ -1504,14 +1627,20 @@ addConfigureOption() {
#
# Arguments:
# $1: the package to be installed
# $2: the package version to be installed (optional)
installPeclPackage() {
if test -z "${2:-}"; then
installPeclPackage_fullname="$1"
else
installPeclPackage_fullname="$1-$2"
fi
if ! test -f "$CONFIGURE_FILE"; then
printf '\n' >"$CONFIGURE_FILE"
fi
if test $USE_PICKLE -eq 0; then
cat "$CONFIGURE_FILE" | MAKE="make -j$(getCompilationProcessorCount $1)" pecl install "$1"
cat "$CONFIGURE_FILE" | MAKE="make -j$(getCompilationProcessorCount $1)" pecl install "$installPeclPackage_fullname"
else
MAKE="make -j$(getCompilationProcessorCount $1)" /tmp/pickle install --tmp-dir=/tmp/pickle.tmp --no-interaction --with-configure-options "$CONFIGURE_FILE" -- "$1"
MAKE="make -j$(getCompilationProcessorCount $1)" /tmp/pickle install --tmp-dir=/tmp/pickle.tmp --no-interaction --with-configure-options "$CONFIGURE_FILE" -- "$installPeclPackage_fullname"
fi
}
@ -1640,14 +1769,22 @@ for PHP_MODULE_TO_INSTALL in $PHP_MODULES_TO_INSTALL; do
MODULE_SOURCE_CFLAGS=''
case "$PHP_MODULE_TO_INSTALL" in
cmark)
MODULE_SOURCE=https://github.com/krakjoe/cmark/archive/v1.0.0.tar.gz
MODULE_VERSION="$(getWantedPHPModuleVersion "$PHP_MODULE_TO_INSTALL")"
if test -z "$MODULE_VERSION"; then
MODULE_VERSION='1.0.0'
fi
MODULE_SOURCE=https://github.com/krakjoe/cmark/archive/v$MODULE_VERSION.tar.gz
cd "$(getPackageSource https://github.com/commonmark/cmark/archive/0.28.3.tar.gz)"
make install
cd - >/dev/null
MODULE_SOURCE_CONFIGOPTIONS=--with-cmark
;;
snuffleupagus)
MODULE_SOURCE="https://codeload.github.com/jvoisin/snuffleupagus/tar.gz/v0.5.0"
MODULE_VERSION="$(getWantedPHPModuleVersion "$PHP_MODULE_TO_INSTALL")"
if test -z "$MODULE_VERSION"; then
MODULE_VERSION='0.5.0'
fi
MODULE_SOURCE=https://codeload.github.com/jvoisin/snuffleupagus/tar.gz/v$MODULE_VERSION
MODULE_SOURCE_CONFIGOPTIONS=--enable-snuffleupagus
;;
esac

23
scripts/test-installversion Executable file
View File

@ -0,0 +1,23 @@
#!/bin/sh
# Let's set a sane environment
set -o errexit
set -o nounset
WANTED_VERSION="${1:-}"
INSTALLME=xdebug
if test -n "$WANTED_VERSION"; then
INSTALLME="$INSTALLME-$1"
fi
./install-php-extensions "$INSTALLME"
INSTALLED_VERSION="$(php --ri xdebug | grep -Ei 'Version\s*=>\s*' | sed -E 's/^.*?=>\s*//')"
if test -z "$WANTED_VERSION"; then
echo 'Installing the default version worked'
elif test "$WANTED_VERSION" = "$INSTALLED_VERSION"; then
printf 'Installing specific version %s worked\n' "$WANTED_VERSION"
else
printf 'We wanted to install version %s, but we installed %s\n' "$WANTED_VERSION" "$INSTALLED_VERSION" >&2
exit 1
fi