Skip to content

Commit cd8d97d

Browse files
Merge pull request #48 from laminas/feature/php-8.1
Initial PHP 8.1 support
2 parents 5fa1858 + d8193a1 commit cd8d97d

24 files changed

+232
-188
lines changed

Dockerfile

Lines changed: 27 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -8,123 +8,31 @@ LABEL "maintainer"="https://github.com/laminas/technical-steering-committee/"
88

99
ENV COMPOSER_HOME=/usr/local/share/composer
1010

11-
RUN apt update \
12-
&& apt install -y software-properties-common curl \
13-
&& (curl -sSL https://packages.microsoft.com/keys/microsoft.asc | apt-key add -) \
14-
&& add-apt-repository -y ppa:ondrej/php \
15-
&& add-apt-repository -y https://packages.microsoft.com/ubuntu/20.04/prod \
16-
&& ACCEPT_EULA=Y apt install -y \
17-
git \
18-
jq \
19-
libxml2-utils \
20-
libzip-dev \
21-
npm \
22-
sudo \
23-
wget \
24-
yamllint \
25-
zip \
26-
msodbcsql17 \
27-
php5.6-bz2 \
28-
php5.6-cli \
29-
php5.6-curl \
30-
php5.6-dev \
31-
php5.6-fileinfo \
32-
php5.6-intl \
33-
php5.6-json \
34-
php5.6-mbstring \
35-
php5.6-phar \
36-
php5.6-readline \
37-
php5.6-sockets \
38-
php5.6-xml \
39-
php5.6-xsl \
40-
php5.6-zip \
41-
php7.0-cli \
42-
php7.0-bz2 \
43-
php7.0-curl \
44-
php7.0-dev \
45-
php7.0-fileinfo \
46-
php7.0-intl \
47-
php7.0-json \
48-
php7.0-mbstring \
49-
php7.0-phar \
50-
php7.0-readline \
51-
php7.0-sockets \
52-
php7.0-xml \
53-
php7.0-xsl \
54-
php7.0-zip \
55-
php7.1-cli \
56-
php7.1-bz2 \
57-
php7.1-curl \
58-
php7.1-dev \
59-
php7.1-fileinfo \
60-
php7.1-intl \
61-
php7.1-json \
62-
php7.1-mbstring \
63-
php7.1-phar \
64-
php7.1-readline \
65-
php7.1-sockets \
66-
php7.1-xml \
67-
php7.1-xsl \
68-
php7.1-zip \
69-
php7.2-cli \
70-
php7.2-bz2 \
71-
php7.2-curl \
72-
php7.2-dev \
73-
php7.2-fileinfo \
74-
php7.2-intl \
75-
php7.2-json \
76-
php7.2-mbstring \
77-
php7.2-phar \
78-
php7.2-readline \
79-
php7.2-sockets \
80-
php7.2-xml \
81-
php7.2-xsl \
82-
php7.2-zip \
83-
php7.3-cli \
84-
php7.3-bz2 \
85-
php7.3-curl \
86-
php7.3-dev \
87-
php7.3-fileinfo \
88-
php7.3-intl \
89-
php7.3-json \
90-
php7.3-mbstring \
91-
php7.3-phar \
92-
php7.3-readline \
93-
php7.3-sockets \
94-
php7.3-xml \
95-
php7.3-xsl \
96-
php7.3-zip \
97-
php7.4-cli \
98-
php7.4-bz2 \
99-
php7.4-curl \
100-
php7.4-dev \
101-
php7.4-fileinfo \
102-
php7.4-intl \
103-
php7.4-json \
104-
php7.4-mbstring \
105-
php7.4-phar \
106-
php7.4-readline \
107-
php7.4-sockets \
108-
php7.4-xml \
109-
php7.4-xsl \
110-
php7.4-zip \
111-
php8.0-cli \
112-
php8.0-bz2 \
113-
php8.0-curl \
114-
php8.0-dev \
115-
php8.0-fileinfo \
116-
php8.0-intl \
117-
php8.0-mbstring \
118-
php8.0-phar \
119-
php8.0-readline \
120-
php8.0-sockets \
121-
php8.0-xml \
122-
php8.0-xsl \
123-
php8.0-zip \
124-
&& apt clean \
125-
&& update-alternatives --set php /usr/bin/php7.4 \
126-
&& npm install -g markdownlint-cli2 \
127-
&& ln -s /usr/local/bin/markdownlint-cli2 /usr/local/bin/markdownlint
11+
COPY setup /setup
12+
# Base setup
13+
RUN cd /setup/ubuntu && bash setup.sh
14+
15+
# Markdownlint
16+
RUN cd /setup/markdownlint && bash setup.sh
17+
18+
# PHP
19+
RUN cd /setup/php/5.6 && bash setup.sh
20+
RUN cd /setup/php/7.0 && bash setup.sh
21+
RUN cd /setup/php/7.1 && bash setup.sh
22+
RUN cd /setup/php/7.2 && bash setup.sh
23+
RUN cd /setup/php/7.3 && bash setup.sh
24+
RUN cd /setup/php/7.4 && bash setup.sh
25+
RUN cd /setup/php/8.0 && bash setup.sh
26+
RUN cd /setup/php/8.1 && bash setup.sh
27+
28+
# Set default PHP version
29+
RUN update-alternatives --set php /usr/bin/php7.4 \
30+
&& update-alternatives --set phpize /usr/bin/phpize7.4 \
31+
&& update-alternatives --set php-config /usr/bin/php-config7.4
32+
33+
# Cleanup
34+
RUN rm -rf /setup \
35+
&& apt clean
12836

12937
# Build/install static modules that do not have packages
13038
COPY mods-available /mods-available
@@ -145,6 +53,8 @@ RUN mkdir -p /usr/local/share/composer \
14553
&& ln -s /usr/local/share/composer/vendor/bin/cs2pr /usr/local/bin/cs2pr
14654

14755
COPY scripts /scripts
56+
RUN chmod a+x /scripts/*
57+
14858
RUN /scripts/php_ini_dev_settings.sh
14959
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
15060

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ The tricks to remember are:
184184
As an example, if you wanted to run the CS checks under PHP 7.4 using locked dependencies, you could do something like the following:
185185

186186
```bash
187-
$ docker run -v $(realpath .):/github/workspace -w=/github/workspace laminas-check-runner:latest '{"php":"7.4","deps":"locked","extensions":[],"ini":["memory_limit=-1"],"command":"./vendor/bin/phpcs"}'
187+
$ docker run -v $(realpath .):/github/workspace -w=/github/workspace laminas-check-runner:latest '{"php":"7.4","dependencies":"locked","extensions":[],"ini":["memory_limit=-1"],"command":"./vendor/bin/phpcs"}'
188188
```
189189

190190
The trick to remember: the job JSON should generally be in single quotes, to allow the `"` characters used to delimit properties and strings in the JSON to not cause interpolation issues.

entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ if [ -x ".laminas-ci/pre-install.sh" ];then
143143
./.laminas-ci/pre-install.sh testuser "${PWD}" "${JOB}"
144144
fi
145145

146-
EXTENSIONS=$(echo "${JOB}" | jq -r ".extensions // [] | map(\"php${PHP}-\"+.) | join(\" \")")
146+
EXTENSIONS=$(echo "${JOB}" | jq -r ".extensions // [] | join(\" \")")
147147
INI=$(echo "${JOB}" | jq -r '.ini // [] | join("\n")')
148148
DEPS=$(echo "${JOB}" | jq -r '.dependencies // "locked"')
149149
IGNORE_PLATFORM_REQS_ON_8=$(echo "${JOB}" | jq -r 'if has("ignore_platform_reqs_8") | not then "yes" elif .ignore_platform_reqs_8 then "yes" else "no" end')

mods-install/install_swoole.sh

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -e
44

5-
SWOOLE_VERSION=4.6.7
5+
SWOOLE_VERSION=4.7.0
66

77
# Get swoole package ONCE
88
cd /tmp
@@ -19,13 +19,10 @@ for PHP_VERSION in 7.3 7.4 8.0;do
1919
./configure --enable-swoole --enable-sockets --with-php-config=php-config${PHP_VERSION}
2020
make
2121
make install
22+
23+
cp /mods-available/swoole.ini /etc/php/${PHP_VERSION}/mods-available/swoole.ini
2224
done
2325

2426
# Cleanup
2527
rm -rf /tmp/swoole-${SWOOLE_VERSION}
2628
rm /tmp/swoole-${SWOOLE_VERSION}.tgz
27-
28-
# Copy conf file to appropriate locations
29-
for PHP_VERSION in 7.3 7.4 8.0;do
30-
cp /mods-available/swoole.ini /etc/php/${PHP_VERSION}/mods-available/swoole.ini
31-
done

scripts/extensions.sh

Lines changed: 50 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,36 @@
66

77
set -e
88

9-
STATIC_EXTENSIONS=(sqlsrv swoole)
9+
function install_extensions {
10+
local PHP=$1
11+
local -a EXTENSIONS=("${@:2}")
12+
13+
case "$PHP" in
14+
8.1)
15+
echo "Cannot install extensions for the current PHP version."
16+
echo "Please use \".laminas-ci/pre-run.sh\" to setup specific extensions for PHP $PHP"
17+
echo "Additional details can be found on https://stackoverflow.com/q/8141407"
18+
echo "The following extensions were not installed: ${EXTENSIONS[*]}"
19+
;;
20+
*)
21+
install_packaged_extensions "$PHP" "${EXTENSIONS[@]}"
22+
;;
23+
esac
24+
}
1025

11-
function match_in_array {
12-
local NEEDLE="$1"
13-
local -a ARRAY_SET=("${@:2}")
14-
local item
26+
function install_packaged_extensions {
27+
local PHP=$1
28+
local -a EXTENSIONS=("${@:2}")
29+
local TO_INSTALL=""
1530

16-
for item in "${ARRAY_SET[@]}";do
17-
[[ "${item}" =~ ${NEEDLE} ]] && return 0
31+
for EXTENSION in "${EXTENSIONS[@]}"; do
32+
# Converting extension name to package name, e.g. php8.0-redis
33+
TO_INSTALL="${TO_INSTALL}php${PHP}-$EXTENSION "
1834
done
1935

20-
return 1
21-
}
22-
23-
function install_packaged_extensions {
24-
local -a EXTENSIONS=("${@:1}")
25-
local TO_INSTALL="${EXTENSIONS[*]}"
36+
if [ -z "$TO_INSTALL" ]; then
37+
return;
38+
fi
2639

2740
echo "Installing packaged extensions: ${TO_INSTALL}"
2841
apt update
@@ -34,64 +47,39 @@ function enable_static_extension {
3447
local PHP=$1
3548
local EXTENSION=$2
3649

37-
echo "Enabling ${EXTENSION} extension"
50+
echo "Enabling \"${EXTENSION}\" extension"
3851
phpenmod -v "${PHP}" -s ALL "${EXTENSION}"
3952
}
4053

41-
function enable_sqlsrv {
42-
local __result=$1
43-
local PHP=$2
44-
local -a EXTENSIONS=("${@:3}")
45-
local TO_RETURN
54+
PHP=$1
55+
declare -a EXTENSIONS=("${@:2}")
56+
# shellcheck disable=SC2196
57+
ENABLED_EXTENSIONS=$(php -m | tr '[:upper:]' '[:lower:]' | egrep -v '^[\[]' | grep -v 'zend opcache')
58+
EXTENSIONS_TO_INSTALL=()
4659

47-
if [[ ! ${PHP} =~ (7.3|7.4|8.0) ]];then
48-
echo "Skipping enabling of sqlsrv extension; not supported on PHP < 7.3"
49-
else
50-
enable_static_extension "${PHP}" sqlsrv
60+
# Loop through known statically compiled/installed extensions, and enable them.
61+
# NOTE: when developing on MacOS, remove the quotes while implementing your changes and re-add the quotes afterwards.
62+
for EXTENSION in "${EXTENSIONS[@]}"; do
63+
64+
# Check if extension is already enabled
65+
REGULAR_EXPRESSION=\\b${EXTENSION}\\b
66+
if [[ "${ENABLED_EXTENSIONS}" =~ $REGULAR_EXPRESSION ]]; then
67+
echo "Extension \"$EXTENSION\" is already enabled."
68+
continue;
5169
fi
5270

53-
TO_RETURN=$(echo "${EXTENSIONS[@]}" | sed -E -e 's/php[0-9.]+-(pdo[_-]){0,1}sqlsrv/ /g' | sed -E -e 's/\s{2,}/ /g')
54-
eval "$__result='$TO_RETURN'"
55-
}
56-
57-
function enable_swoole {
58-
local __result=$1
59-
local PHP=$2
60-
local -a EXTENSIONS=("${@:3}")
61-
local TO_RETURN
71+
# Check if extension is installable via `phpenmod`
72+
PATH_TO_EXTENSION_CONFIG="/etc/php/${PHP}/mods-available/${EXTENSION}.ini"
6273

63-
if [[ ! ${PHP} =~ (7.3|7.4|8.0) ]];then
64-
echo "Skipping enabling of swoole extension; not supported on PHP < 7.3"
65-
else
66-
enable_static_extension "${PHP}" swoole
74+
if [ -e "$PATH_TO_EXTENSION_CONFIG" ]; then
75+
enable_static_extension "$PHP" "${EXTENSION}"
76+
continue;
6777
fi
6878

69-
TO_RETURN=$(echo "${EXTENSIONS[@]}" | sed -E -e 's/php[0-9.]+-swoole/ /g' | sed -E -e 's/\s{2,}/ /g')
70-
eval "$__result='$TO_RETURN'"
71-
}
72-
73-
PHP=$1
74-
EXTENSIONS=("${@:2}")
75-
declare result ENABLE_FUNC
76-
77-
# Loop through known statically compiled/installed extensions, and enable them.
78-
# Each should update the result variable passed to it with a new list of
79-
# extensions.
80-
for EXTENSION in "${STATIC_EXTENSIONS[@]}";do
81-
if match_in_array "${EXTENSION}" "${EXTENSIONS[@]}" ; then
82-
ENABLE_FUNC="enable_${EXTENSION}"
83-
$ENABLE_FUNC result "${PHP}" "${EXTENSIONS[*]}"
84-
85-
# Validate that we don't have just whitespace in the list
86-
if [[ -z "${result// }" ]];then
87-
EXTENSIONS=()
88-
else
89-
EXTENSIONS=("${result}")
90-
fi
91-
fi
79+
EXTENSIONS_TO_INSTALL+=("$EXTENSION")
9280
done
9381

94-
# If by now the extensions list is not empty, install packaged extensions.
95-
if [[ ${#EXTENSIONS[@]} != 0 ]];then
96-
install_packaged_extensions "${EXTENSIONS[@]}"
82+
# If by now the extensions list is not empty, install missing extensions.
83+
if [[ ${#EXTENSIONS_TO_INSTALL[@]} != 0 ]]; then
84+
install_extensions "$PHP" "${EXTENSIONS_TO_INSTALL[@]}"
9785
fi

scripts/php_ini_dev_settings.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SUBSTITUTIONS+=('s/mysqlnd.collect_memory_statistics ?= ?(On|Off)/mysqlnd.collec
1313
SUBSTITUTIONS+=('s/zend.assertions ?= ?(-1|1)/zend.assertions = 1/')
1414
SUBSTITUTIONS+=('s/opcache.huge_code_pages ?= ?(0|1)/opcache.huge_code_pages = 0/')
1515

16-
for PHP_VERSION in 5.6 7.0 7.1 7.2 7.3 7.4 8.0;do
16+
for PHP_VERSION in 5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1;do
1717
INI_FILE="/etc/php/${PHP_VERSION}/cli/php.ini"
1818
for SUBSTITUTION in "${SUBSTITUTIONS[@]}";do
1919
sed --in-place -E -e "${SUBSTITUTION}" "${INI_FILE}"

setup/markdownlint/setup.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
NODE_ENV=production npm install -g markdownlint-cli2
4+
ln -s /usr/local/bin/markdownlint-cli2 /usr/local/bin/markdownlint

setup/php/5.6/dependencies

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
php5.6-bz2
2+
php5.6-cli
3+
php5.6-curl
4+
php5.6-dev
5+
php5.6-fileinfo
6+
php5.6-intl
7+
php5.6-json
8+
php5.6-mbstring
9+
php5.6-phar
10+
php5.6-readline
11+
php5.6-sockets
12+
php5.6-xml
13+
php5.6-xsl
14+
php5.6-zip

setup/php/5.6/setup.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
ACCEPT_EULA=Y xargs -a dependencies apt install -y

setup/php/7.0/dependencies

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
php7.0-cli
2+
php7.0-bz2
3+
php7.0-curl
4+
php7.0-dev
5+
php7.0-fileinfo
6+
php7.0-intl
7+
php7.0-json
8+
php7.0-mbstring
9+
php7.0-phar
10+
php7.0-readline
11+
php7.0-sockets
12+
php7.0-xml
13+
php7.0-xsl
14+
php7.0-zip

0 commit comments

Comments
 (0)