Skip to content

Make extension installation and enablement modular #41

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
Show file tree
Hide file tree
Changes from 2 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
26 changes: 5 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,10 @@ RUN apt update \
&& npm install -g markdownlint-cli2 \
&& ln -s /usr/local/bin/markdownlint-cli2 /usr/local/bin/markdownlint

# Install sqlsrv modules for PHP 7.3 - 8.0 (none available on Ubuntu 2.0.4 prior to that)
RUN (curl -L https://github.com/microsoft/msphpsql/releases/download/v5.9.0/Ubuntu2004-7.3.tar | tar xf - --strip-components=1 Ubuntu2004-7.3/php_pdo_sqlsrv_73_nts.so Ubuntu2004-7.3/php_sqlsrv_73_nts.so) \
&& (curl -L https://github.com/microsoft/msphpsql/releases/download/v5.9.0/Ubuntu2004-7.4.tar | tar xf - --strip-components=1 Ubuntu2004-7.4/php_pdo_sqlsrv_74_nts.so Ubuntu2004-7.4/php_sqlsrv_74_nts.so) \
&& (curl -L https://github.com/microsoft/msphpsql/releases/download/v5.9.0/Ubuntu2004-8.0.tar | tar xf - --strip-components=1 Ubuntu2004-8.0/php_pdo_sqlsrv_80_nts.so Ubuntu2004-8.0/php_sqlsrv_80_nts.so) \
&& mv php_pdo_sqlsrv_73_nts.so $(php7.3 -i | grep -P '^extension_dir' | sed -E -e 's/^extension_dir\s+=>\s+\S+\s+=>\s+(.*)$/\1/')/pdo_sqlsrv.so \
&& mv php_sqlsrv_73_nts.so $(php7.3 -i | grep -P '^extension_dir' | sed -E -e 's/^extension_dir\s+=>\s+\S+\s+=>\s+(.*)$/\1/')/sqlsrv.so \
&& mv php_pdo_sqlsrv_74_nts.so $(php7.4 -i | grep -P '^extension_dir' | sed -E -e 's/^extension_dir\s+=>\s+\S+\s+=>\s+(.*)$/\1/')/pdo_sqlsrv.so \
&& mv php_sqlsrv_74_nts.so $(php7.4 -i | grep -P '^extension_dir' | sed -E -e 's/^extension_dir\s+=>\s+\S+\s+=>\s+(.*)$/\1/')/sqlsrv.so \
&& mv php_pdo_sqlsrv_80_nts.so $(php8.0 -i | grep -P '^extension_dir' | sed -E -e 's/^extension_dir\s+=>\s+\S+\s+=>\s+(.*)$/\1/')/pdo_sqlsrv.so \
&& mv php_sqlsrv_80_nts.so $(php8.0 -i | grep -P '^extension_dir' | sed -E -e 's/^extension_dir\s+=>\s+\S+\s+=>\s+(.*)$/\1/')/sqlsrv.so
COPY mods-available/sqlsrv.ini /etc/php/7.3/mods-available/sqlsrv.ini
COPY mods-available/sqlsrv.ini /etc/php/7.4/mods-available/sqlsrv.ini
COPY mods-available/sqlsrv.ini /etc/php/8.0/mods-available/sqlsrv.ini

# Install swoole modules for PHP 7.3 - 8.0
# (we don't need to support earlier than that in mezzio-swoole)
COPY mods-available/swoole.ini /etc/php/7.3/mods-available/swoole.ini
COPY mods-available/swoole.ini /etc/php/7.4/mods-available/swoole.ini
COPY mods-available/swoole.ini /etc/php/8.0/mods-available/swoole.ini
COPY scripts/install_swoole.sh /tmp/install_swoole.sh
RUN /tmp/install_swoole.sh && rm /tmp/install_swoole.sh
# Build/install static modules that do not have packages
COPY mods-available /mods-available
COPY mods-install /mods-install
RUN for INSTALLER in /mods-install/*.sh;do ${INSTALLER} ; done

RUN mkdir -p /etc/laminas-ci/problem-matcher \
&& cd /etc/laminas-ci/problem-matcher \
Expand All @@ -161,6 +144,7 @@ RUN mkdir -p /usr/local/share/composer \
&& composer global require staabm/annotate-pull-request-from-checkstyle \
&& ln -s /usr/local/share/composer/vendor/bin/cs2pr /usr/local/bin/cs2pr

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

RUN useradd -ms /bin/bash testuser
Expand Down
34 changes: 1 addition & 33 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,39 +149,7 @@ 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')

if [[ "${EXTENSIONS}" != "" ]];then
ENABLE_SQLSRV=false
if [[ "${EXTENSIONS}" =~ sqlsrv ]];then
if [[ ! ${PHP} =~ (7.3|7.4|8.0) ]];then
echo "Skipping enabling of sqlsrv extensions; not supported on PHP < 7.3"
else
ENABLE_SQLSRV=true
fi
EXTENSIONS=$(echo "${EXTENSIONS}" | sed -E -e 's/php[0-9.]+-(pdo[_-]){0,1}sqlsrv/ /g' | sed -E -e 's/\s{2,}/ /g')
fi

ENABLE_SWOOLE=false
if [[ "${EXTENSIONS}" =~ swoole ]];then
if [[ ! ${PHP} =~ (7.3|7.4|8.0) ]];then
echo "Skipping enabling of swoole extension; not supported on PHP < 7.3"
else
ENABLE_SWOOLE=true
fi
EXTENSIONS=$(echo "${EXTENSIONS}" | sed -E -e 's/php[0-9.]+-swoole/ /g' | sed -E -e 's/\s{2,}/ /g')
fi

echo "Installing extensions: ${EXTENSIONS}"
apt update
apt install -y "${EXTENSIONS}"

if [[ "${ENABLE_SQLSRV}" == "true" ]];then
echo "Enabling sqlsrv extensions"
phpenmod -v "${PHP}" -s ALL sqlsrv
fi

if [[ "${ENABLE_SWOOLE}" == "true" ]];then
echo "Enabling swoole extensions"
phpenmod -v "${PHP}" -s ALL swoole
fi
/scripts/extensions.sh "${PHP}" "${EXTENSIONS}"
fi

if [[ "${INI}" != "" ]];then
Expand Down
23 changes: 23 additions & 0 deletions mods-install/install_sqlsrv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

set -e

cd tmp

# Download extension versions from MS
curl -L https://github.com/microsoft/msphpsql/releases/download/v5.9.0/Ubuntu2004-7.3.tar | tar xf - --strip-components=1 Ubuntu2004-7.3/php_pdo_sqlsrv_73_nts.so Ubuntu2004-7.3/php_sqlsrv_73_nts.so
curl -L https://github.com/microsoft/msphpsql/releases/download/v5.9.0/Ubuntu2004-7.4.tar | tar xf - --strip-components=1 Ubuntu2004-7.4/php_pdo_sqlsrv_74_nts.so Ubuntu2004-7.4/php_sqlsrv_74_nts.so
curl -L https://github.com/microsoft/msphpsql/releases/download/v5.9.0/Ubuntu2004-8.0.tar | tar xf - --strip-components=1 Ubuntu2004-8.0/php_pdo_sqlsrv_80_nts.so Ubuntu2004-8.0/php_sqlsrv_80_nts.so

# Copy extensions to appropriate locations for each PHP version
mv php_pdo_sqlsrv_73_nts.so $(php7.3 -i | grep -P '^extension_dir' | sed -E -e 's/^extension_dir\s+=>\s+\S+\s+=>\s+(.*)$/\1/')/pdo_sqlsrv.so
mv php_sqlsrv_73_nts.so $(php7.3 -i | grep -P '^extension_dir' | sed -E -e 's/^extension_dir\s+=>\s+\S+\s+=>\s+(.*)$/\1/')/sqlsrv.so
mv php_pdo_sqlsrv_74_nts.so $(php7.4 -i | grep -P '^extension_dir' | sed -E -e 's/^extension_dir\s+=>\s+\S+\s+=>\s+(.*)$/\1/')/pdo_sqlsrv.so
mv php_sqlsrv_74_nts.so $(php7.4 -i | grep -P '^extension_dir' | sed -E -e 's/^extension_dir\s+=>\s+\S+\s+=>\s+(.*)$/\1/')/sqlsrv.so
mv php_pdo_sqlsrv_80_nts.so $(php8.0 -i | grep -P '^extension_dir' | sed -E -e 's/^extension_dir\s+=>\s+\S+\s+=>\s+(.*)$/\1/')/pdo_sqlsrv.so
mv php_sqlsrv_80_nts.so $(php8.0 -i | grep -P '^extension_dir' | sed -E -e 's/^extension_dir\s+=>\s+\S+\s+=>\s+(.*)$/\1/')/sqlsrv.so

# Copy conf file to appropriate locations
for PHP_VERSION in 7.3 7.4 8.0;do
cp /mods-available/sqlsrv.ini /etc/php/${PHP_VERSION}/mods-available/sqlsrv.ini
done
5 changes: 5 additions & 0 deletions scripts/install_swoole.sh → mods-install/install_swoole.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ 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
68 changes: 68 additions & 0 deletions scripts/extensions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash
# Install and/or enable extensions.
# Usage:
#
# extensions.sh PHP_VERSION LIST_OF_EXTENSIONS

set -e

STATIC_EXTENSIONS=(sqlsrv swoole)

function install_packaged_extensions {
local EXTENSIONS=${@:1}
echo "Installing packaged extensions: ${EXTENSIONS}"
apt update
apt install -y "${EXTENSIONS}"
}

function enable_static_extension {
local PHP=$1
local EXTENSION=$2
echo "Enabling ${EXTENSION} extension"
phpenmod -v "${PHP}" -s ALL "${EXTENSION}"
}

function enable_sqlsrv {
local __result=$1
local PHP=$2
local EXTENSIONS=${@:3}
if [[ ! ${PHP} =~ (7.3|7.4|8.0) ]];then
echo "Skipping enabling of swoole extension; not supported on PHP < 7.3"
eval $__result="${EXTENSIONS}"
else
enable_static_extension "${PHP}" sqlsrv
eval $__result=$(echo "${EXTENSIONS}" | sed -E -e 's/php[0-9.]+-(pdo[_-]){0,1}sqlsrv/ /g' | sed -E -e 's/\s{2,}/ /g')
fi
}

function enable_swoole {
local __result=$1
local PHP=$2
local EXTENSIONS=${@:3}
if [[ ! ${PHP} =~ (7.3|7.4|8.0) ]];then
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it would be possible to detect php versions automatically. adding 8.1 should not require us to change multiple files.

Copy link
Member Author

Choose a reason for hiding this comment

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

We need to do this manually. Extensions may or may not be updated to a particular ABI, so if we automatically enable for a new version, we may actually have errors when building the container due to extension compilation failure.

Consider this: MS only provides the sqlsrv binaries on Ubuntu 20.04 for 7.3, 7.4, and 8.0; we don't know if/when they'll have them available for 8.1. What if we build the day that 8.1 releases, and then this attempts to enable the extension for 8.1?

Similarly, many third-party extensions like Swoole take a few days to a few months to update. Automatically updating that list can lead to errors.

echo "Skipping enabling of swoole extension; not supported on PHP < 7.3"
eval $__result="${EXTENSIONS}"
else
enable_static_extension "${PHP}" swoole
eval $__result=$(echo "${EXTENSIONS}" | sed -E -e 's/php[0-9.]+-swoole/ /g' | sed -E -e 's/\s{2,}/ /g')
fi
}

PHP=$1
EXTENSIONS=${@:2}

# 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 [[ "${EXTENSIONS}" =~ ${EXTENSION} ]];then
ENABLE_FUNC="enable_${EXTENSION}"
$ENABLE_FUNC result "${PHP}" "${EXTENSIONS}"
EXTENSIONS="${result}"
fi
done

# If by now the extensions list is not empty, install packaged extensions.
if [[ "${EXTENSIONS}" != "" ]];then
install_packaged_extensions "${EXTENSIONS}"
fi