-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
weierophinney
merged 5 commits into
laminas:1.9.x
from
weierophinney:feature/extension-modularity
May 26, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
88285b0
feat: modularize building/installing static modules
weierophinney a12e734
feat: make extension enablement more modular
weierophinney b8d20be
qa: fix errors flagged by shellcheck
weierophinney 2622a25
fix: count array length of extensions
weierophinney 707749c
fix: better detection of extensinos and empty values
weierophinney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#!/bin/bash | ||
# Install and/or enable extensions. | ||
# Usage: | ||
# | ||
# extensions.sh PHP_VERSION LIST_OF_EXTENSIONS | ||
|
||
set -e | ||
|
||
STATIC_EXTENSIONS=(sqlsrv swoole) | ||
|
||
function match_in_array { | ||
local NEEDLE="$1" | ||
local -a ARRAY_SET=("${@:2}") | ||
local item | ||
|
||
for item in "${ARRAY_SET[@]}";do | ||
[[ "${item}" =~ ${NEEDLE} ]] && return 0 | ||
done | ||
|
||
return 1 | ||
} | ||
|
||
function install_packaged_extensions { | ||
local -a EXTENSIONS=("${@:1}") | ||
local TO_INSTALL="${EXTENSIONS[*]}" | ||
|
||
echo "Installing packaged extensions: ${TO_INSTALL}" | ||
apt update | ||
# shellcheck disable=SC2086,SC2046 | ||
apt install -y ${TO_INSTALL} | ||
} | ||
|
||
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 -a EXTENSIONS=("${@:3}") | ||
local TO_RETURN | ||
|
||
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 | ||
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 | ||
|
||
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 | ||
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 | ||
done | ||
|
||
# If by now the extensions list is not empty, install packaged extensions. | ||
if [[ ${#EXTENSIONS[@]} != 0 ]];then | ||
install_packaged_extensions "${EXTENSIONS[@]}" | ||
fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.