Skip to content

Initial PHP 8.1 support #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 27 additions & 117 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,123 +8,31 @@ LABEL "maintainer"="https://github.com/laminas/technical-steering-committee/"

ENV COMPOSER_HOME=/usr/local/share/composer

RUN apt update \
&& apt install -y software-properties-common curl \
&& (curl -sSL https://packages.microsoft.com/keys/microsoft.asc | apt-key add -) \
&& add-apt-repository -y ppa:ondrej/php \
&& add-apt-repository -y https://packages.microsoft.com/ubuntu/20.04/prod \
&& ACCEPT_EULA=Y apt install -y \
git \
jq \
libxml2-utils \
libzip-dev \
npm \
sudo \
wget \
yamllint \
zip \
msodbcsql17 \
php5.6-bz2 \
php5.6-cli \
php5.6-curl \
php5.6-dev \
php5.6-fileinfo \
php5.6-intl \
php5.6-json \
php5.6-mbstring \
php5.6-phar \
php5.6-readline \
php5.6-sockets \
php5.6-xml \
php5.6-xsl \
php5.6-zip \
php7.0-cli \
php7.0-bz2 \
php7.0-curl \
php7.0-dev \
php7.0-fileinfo \
php7.0-intl \
php7.0-json \
php7.0-mbstring \
php7.0-phar \
php7.0-readline \
php7.0-sockets \
php7.0-xml \
php7.0-xsl \
php7.0-zip \
php7.1-cli \
php7.1-bz2 \
php7.1-curl \
php7.1-dev \
php7.1-fileinfo \
php7.1-intl \
php7.1-json \
php7.1-mbstring \
php7.1-phar \
php7.1-readline \
php7.1-sockets \
php7.1-xml \
php7.1-xsl \
php7.1-zip \
php7.2-cli \
php7.2-bz2 \
php7.2-curl \
php7.2-dev \
php7.2-fileinfo \
php7.2-intl \
php7.2-json \
php7.2-mbstring \
php7.2-phar \
php7.2-readline \
php7.2-sockets \
php7.2-xml \
php7.2-xsl \
php7.2-zip \
php7.3-cli \
php7.3-bz2 \
php7.3-curl \
php7.3-dev \
php7.3-fileinfo \
php7.3-intl \
php7.3-json \
php7.3-mbstring \
php7.3-phar \
php7.3-readline \
php7.3-sockets \
php7.3-xml \
php7.3-xsl \
php7.3-zip \
php7.4-cli \
php7.4-bz2 \
php7.4-curl \
php7.4-dev \
php7.4-fileinfo \
php7.4-intl \
php7.4-json \
php7.4-mbstring \
php7.4-phar \
php7.4-readline \
php7.4-sockets \
php7.4-xml \
php7.4-xsl \
php7.4-zip \
php8.0-cli \
php8.0-bz2 \
php8.0-curl \
php8.0-dev \
php8.0-fileinfo \
php8.0-intl \
php8.0-mbstring \
php8.0-phar \
php8.0-readline \
php8.0-sockets \
php8.0-xml \
php8.0-xsl \
php8.0-zip \
&& apt clean \
&& update-alternatives --set php /usr/bin/php7.4 \
&& npm install -g markdownlint-cli2 \
&& ln -s /usr/local/bin/markdownlint-cli2 /usr/local/bin/markdownlint
COPY setup /setup
# Base setup
RUN cd /setup/ubuntu && bash setup.sh

# Markdownlint
RUN cd /setup/markdownlint && bash setup.sh

# PHP
RUN cd /setup/php/5.6 && bash setup.sh
RUN cd /setup/php/7.0 && bash setup.sh
RUN cd /setup/php/7.1 && bash setup.sh
RUN cd /setup/php/7.2 && bash setup.sh
RUN cd /setup/php/7.3 && bash setup.sh
RUN cd /setup/php/7.4 && bash setup.sh
RUN cd /setup/php/8.0 && bash setup.sh
RUN cd /setup/php/8.1 && bash setup.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this break-down, as it means that we likely won't need to rebuild most layers unless a change actually occurs to an individual script. That said, I see one potential issue being that forcing a rebuild to pick up a new bugfix release may be harder.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is indeed an issue.
I will think about it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy

GitHub will remove any cache entries that have not been accessed in over 7 days.

Maybe we won't have any issues due to this fact?


# Set default PHP version
RUN update-alternatives --set php /usr/bin/php7.4 \
&& update-alternatives --set phpize /usr/bin/phpize7.4 \
&& update-alternatives --set php-config /usr/bin/php-config7.4

# Cleanup
RUN rm -rf /setup \
&& apt clean

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

COPY scripts /scripts
RUN chmod a+x /scripts/*

RUN /scripts/php_ini_dev_settings.sh
COPY entrypoint.sh /usr/local/bin/entrypoint.sh

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ The tricks to remember are:
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:

```bash
$ 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"}'
$ 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"}'
```

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.
Expand Down
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ if [ -x ".laminas-ci/pre-install.sh" ];then
./.laminas-ci/pre-install.sh testuser "${PWD}" "${JOB}"
fi

EXTENSIONS=$(echo "${JOB}" | jq -r ".extensions // [] | map(\"php${PHP}-\"+.) | join(\" \")")
EXTENSIONS=$(echo "${JOB}" | jq -r ".extensions // [] | join(\" \")")
INI=$(echo "${JOB}" | jq -r '.ini // [] | join("\n")')
DEPS=$(echo "${JOB}" | jq -r '.dependencies // "locked"')
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')
Expand Down
9 changes: 3 additions & 6 deletions mods-install/install_swoole.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

SWOOLE_VERSION=4.6.7
SWOOLE_VERSION=4.7.0

# Get swoole package ONCE
cd /tmp
Expand All @@ -19,13 +19,10 @@ for PHP_VERSION in 7.3 7.4 8.0;do
./configure --enable-swoole --enable-sockets --with-php-config=php-config${PHP_VERSION}
make
make install

cp /mods-available/swoole.ini /etc/php/${PHP_VERSION}/mods-available/swoole.ini
done

# Cleanup
rm -rf /tmp/swoole-${SWOOLE_VERSION}
rm /tmp/swoole-${SWOOLE_VERSION}.tgz

# Copy conf file to appropriate locations
for PHP_VERSION in 7.3 7.4 8.0;do
cp /mods-available/swoole.ini /etc/php/${PHP_VERSION}/mods-available/swoole.ini
done
112 changes: 50 additions & 62 deletions scripts/extensions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,36 @@

set -e

STATIC_EXTENSIONS=(sqlsrv swoole)
function install_extensions {
local PHP=$1
local -a EXTENSIONS=("${@:2}")

case "$PHP" in
8.1)
echo "Cannot install extensions for the current PHP version."
echo "Please use \".laminas-ci/pre-run.sh\" to setup specific extensions for PHP $PHP"
echo "Additional details can be found on https://stackoverflow.com/q/8141407"
echo "The following extensions were not installed: ${EXTENSIONS[*]}"
;;
*)
install_packaged_extensions "$PHP" "${EXTENSIONS[@]}"
;;
esac
}

function match_in_array {
local NEEDLE="$1"
local -a ARRAY_SET=("${@:2}")
local item
function install_packaged_extensions {
local PHP=$1
local -a EXTENSIONS=("${@:2}")
local TO_INSTALL=""

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

return 1
}

function install_packaged_extensions {
local -a EXTENSIONS=("${@:1}")
local TO_INSTALL="${EXTENSIONS[*]}"
if [ -z "$TO_INSTALL" ]; then
return;
fi

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

echo "Enabling ${EXTENSION} extension"
echo "Enabling \"${EXTENSION}\" extension"
phpenmod -v "${PHP}" -s ALL "${EXTENSION}"
}

function enable_sqlsrv {
local __result=$1
local PHP=$2
local -a EXTENSIONS=("${@:3}")
local TO_RETURN
PHP=$1
declare -a EXTENSIONS=("${@:2}")
# shellcheck disable=SC2196
ENABLED_EXTENSIONS=$(php -m | tr '[:upper:]' '[:lower:]' | egrep -v '^[\[]' | grep -v 'zend opcache')
EXTENSIONS_TO_INSTALL=()

if [[ ! ${PHP} =~ (7.3|7.4|8.0) ]];then
echo "Skipping enabling of sqlsrv extension; not supported on PHP < 7.3"
else
enable_static_extension "${PHP}" sqlsrv
# Loop through known statically compiled/installed extensions, and enable them.
# NOTE: when developing on MacOS, remove the quotes while implementing your changes and re-add the quotes afterwards.
for EXTENSION in "${EXTENSIONS[@]}"; do

# Check if extension is already enabled
REGULAR_EXPRESSION=\\b${EXTENSION}\\b
if [[ "${ENABLED_EXTENSIONS}" =~ $REGULAR_EXPRESSION ]]; then
echo "Extension \"$EXTENSION\" is already enabled."
continue;
fi

TO_RETURN=$(echo "${EXTENSIONS[@]}" | sed -E -e 's/php[0-9.]+-(pdo[_-]){0,1}sqlsrv/ /g' | sed -E -e 's/\s{2,}/ /g')
eval "$__result='$TO_RETURN'"
}

function enable_swoole {
local __result=$1
local PHP=$2
local -a EXTENSIONS=("${@:3}")
local TO_RETURN
# Check if extension is installable via `phpenmod`
PATH_TO_EXTENSION_CONFIG="/etc/php/${PHP}/mods-available/${EXTENSION}.ini"

if [[ ! ${PHP} =~ (7.3|7.4|8.0) ]];then
echo "Skipping enabling of swoole extension; not supported on PHP < 7.3"
else
enable_static_extension "${PHP}" swoole
if [ -e "$PATH_TO_EXTENSION_CONFIG" ]; then
enable_static_extension "$PHP" "${EXTENSION}"
continue;
fi

TO_RETURN=$(echo "${EXTENSIONS[@]}" | sed -E -e 's/php[0-9.]+-swoole/ /g' | sed -E -e 's/\s{2,}/ /g')
eval "$__result='$TO_RETURN'"
}

PHP=$1
EXTENSIONS=("${@:2}")
declare result ENABLE_FUNC

# Loop through known statically compiled/installed extensions, and enable them.
# Each should update the result variable passed to it with a new list of
# extensions.
for EXTENSION in "${STATIC_EXTENSIONS[@]}";do
if match_in_array "${EXTENSION}" "${EXTENSIONS[@]}" ; then
ENABLE_FUNC="enable_${EXTENSION}"
$ENABLE_FUNC result "${PHP}" "${EXTENSIONS[*]}"

# Validate that we don't have just whitespace in the list
if [[ -z "${result// }" ]];then
EXTENSIONS=()
else
EXTENSIONS=("${result}")
fi
fi
EXTENSIONS_TO_INSTALL+=("$EXTENSION")
done

# If by now the extensions list is not empty, install packaged extensions.
if [[ ${#EXTENSIONS[@]} != 0 ]];then
install_packaged_extensions "${EXTENSIONS[@]}"
# If by now the extensions list is not empty, install missing extensions.
if [[ ${#EXTENSIONS_TO_INSTALL[@]} != 0 ]]; then
install_extensions "$PHP" "${EXTENSIONS_TO_INSTALL[@]}"
fi
2 changes: 1 addition & 1 deletion scripts/php_ini_dev_settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SUBSTITUTIONS+=('s/mysqlnd.collect_memory_statistics ?= ?(On|Off)/mysqlnd.collec
SUBSTITUTIONS+=('s/zend.assertions ?= ?(-1|1)/zend.assertions = 1/')
SUBSTITUTIONS+=('s/opcache.huge_code_pages ?= ?(0|1)/opcache.huge_code_pages = 0/')

for PHP_VERSION in 5.6 7.0 7.1 7.2 7.3 7.4 8.0;do
for PHP_VERSION in 5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1;do
INI_FILE="/etc/php/${PHP_VERSION}/cli/php.ini"
for SUBSTITUTION in "${SUBSTITUTIONS[@]}";do
sed --in-place -E -e "${SUBSTITUTION}" "${INI_FILE}"
Expand Down
4 changes: 4 additions & 0 deletions setup/markdownlint/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

NODE_ENV=production npm install -g markdownlint-cli2
ln -s /usr/local/bin/markdownlint-cli2 /usr/local/bin/markdownlint
14 changes: 14 additions & 0 deletions setup/php/5.6/dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
php5.6-bz2
php5.6-cli
php5.6-curl
php5.6-dev
php5.6-fileinfo
php5.6-intl
php5.6-json
php5.6-mbstring
php5.6-phar
php5.6-readline
php5.6-sockets
php5.6-xml
php5.6-xsl
php5.6-zip
3 changes: 3 additions & 0 deletions setup/php/5.6/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

ACCEPT_EULA=Y xargs -a dependencies apt install -y
14 changes: 14 additions & 0 deletions setup/php/7.0/dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
php7.0-cli
php7.0-bz2
php7.0-curl
php7.0-dev
php7.0-fileinfo
php7.0-intl
php7.0-json
php7.0-mbstring
php7.0-phar
php7.0-readline
php7.0-sockets
php7.0-xml
php7.0-xsl
php7.0-zip
3 changes: 3 additions & 0 deletions setup/php/7.0/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

ACCEPT_EULA=Y xargs -a dependencies apt install -y
Loading