-
Notifications
You must be signed in to change notification settings - Fork 39
feat(composer): install PECL extension #286
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
Changes from all commits
e518e14
eb2a08f
2b4f51a
a2b288a
7a0c232
afd1a1a
c5aea70
078bddc
17ab35f
db3894b
1ee469d
7a5a59c
2e8f674
336de5f
b6b2566
190e897
d253f4d
83b3b1d
7903a16
e49d20a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
function apt_install() { | ||
local apt_deps="${1}" | ||
local build_dir="${2}" | ||
local cache_dir="${3}" | ||
local env_dir="${4}" | ||
|
||
apt_manifest="$(mktemp "${build_dir}/Aptfile.php-XXX")" | ||
echo "${apt_deps}" | tr ' ' '\n' > "${apt_manifest}" | ||
|
||
apt_deps_buildpack_dir=$(mktemp /tmp/apt_buildpack_XXXX) | ||
rm "${apt_deps_buildpack_dir}" | ||
|
||
readonly apt_buildpack_url="https://github.com/Scalingo/apt-buildpack.git" | ||
git clone --quiet --depth=1 "${apt_buildpack_url}" "${apt_deps_buildpack_dir}" >/dev/null 2>&1 | ||
|
||
readonly apt_log_file=$(mktemp /tmp/apt_log_XXXX.log) | ||
APT_FILE_MANIFEST="$(basename ${apt_manifest})" "${apt_deps_buildpack_dir}/bin/compile" "${build_dir}" "${cache_dir}" "${env_dir}" >"${apt_log_file}" 2>&1 | ||
Soulou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if [ $? -ne 0 ] ; then | ||
tail -n 30 "${apt_log_file}" | indent | ||
echo | ||
warn "Fail to install apt packages $apt_deps" | ||
echo | ||
exit 1 | ||
Soulou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fi | ||
|
||
# Source new libs for future buildpack (update of LD_LIBRARY_PATH) | ||
echo "${apt_deps_buildpack_dir}/export" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
function fetch_engine_package() { | ||
local engine="$1" | ||
local version="$2" | ||
local location="$3" | ||
|
||
local base_url="$PHP_BASE_URL" | ||
if [ "$engine" = "nginx" ] ; then | ||
base_url="$NGINX_BASE_URL" | ||
fi | ||
|
||
fetch_package "$base_url" "${engine}-${version}" "$location" | ||
} | ||
|
||
function has_package() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. best practice: I'm not sure about what this function does. Maybe add a comment or rename it so that it's clearer? If I understand correctly it makes a HEAD request to our object storage to check if the given package exists, which means that we pre-compiled the extension, isn't it?
Soulou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
local base_url="${1}" | ||
local package="${2}" | ||
|
||
local package_url="${base_url}/package/${package}.tgz" | ||
|
||
curl --output /dev/null --silent --head --location --fail "${package_url}" | ||
if [ $? -eq 0 ] ; then | ||
echo "true" | ||
else | ||
echo "false" | ||
fi | ||
} | ||
|
||
function fetch_package() { | ||
local base_url="$1" | ||
local package="$2" | ||
local location="$3" | ||
|
||
mkdir -p "$location" | ||
|
||
local checksum_url="${base_url}/package/${package}.md5" | ||
local package_url="${base_url}/package/${package}.tgz" | ||
local checksum=$(curl --fail --retry 3 --retry-delay 2 --connect-timeout 3 --max-time 30 "$checksum_url" 2> /dev/null) | ||
local cache_checksum="" | ||
|
||
if [ -f "$CACHE_DIR/package/${package}.md5" ]; then | ||
local cache_checksum=$(cat "$CACHE_DIR/package/${package}.md5") | ||
fi | ||
|
||
mkdir -p "$CACHE_DIR/package/$(dirname "$package")" | ||
|
||
if [ "$cache_checksum" != "$checksum" ]; then | ||
curl --fail --retry 3 --retry-delay 2 --connect-timeout 3 --max-time 30 "$package_url" --location --silent > "$CACHE_DIR/package/${package}.tgz" | ||
echo "$checksum" > "$CACHE_DIR/package/${package}.md5" | ||
else | ||
echo "Checksums match. Fetching from cache." | indent | ||
fi | ||
|
||
mkdir -p "$location" | ||
tar xzf "$CACHE_DIR/package/${package}.tgz" --directory "$location" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
function install_pecl_extension() { | ||
local extension_name="${1}" | ||
local version="${2}" | ||
local cache_dir="${3}" | ||
|
||
if [[ $version = '*' ]]; then | ||
local version=$(curl --silent "https://pecl.php.net/rest/r/$extension_name/latest.txt") | ||
fi | ||
local ext_dir=/app/vendor/php/lib/php/extensions/no-debug-non-zts-$(php_api_version) | ||
|
||
local cache_extension_file="${cache_dir}/${extension_name}-${version}.so" | ||
if [ -f "${cache_extension_file}" ]; then | ||
echo "Installing PECL extension ${extension_name} version ${version} from the cache" | indent | ||
cp "${cache_extension_file}" "${ext_dir}/${extension_name}.so" | ||
enable_pecl_extension ${extension_name} | ||
return | ||
fi | ||
|
||
local build_dir=$(pwd) | ||
local temp_dir=$(mktmpdir "pecl-extension") | ||
|
||
echo "Installing PECL extension ${extension_name} version ${version}" | indent | ||
|
||
pushd "${temp_dir}" > /dev/null | ||
|
||
curl --silent --location "https://pecl.php.net/get/${extension_name}-${version}.tgz" | tar xz | ||
|
||
pushd ${extension_name}-${version} > /dev/null | ||
( | ||
set +e | ||
readonly phpize_log_file=$(mktemp "/tmp/pecl-phpize-${extension_name}-XXXX.log") | ||
/app/vendor/php/bin/phpize > "${phpize_log_file}" 2>&1 | ||
[ $? -eq 0 ] || install_pecl_error "${extension_name}" "package" "${phpize_log_file}" | ||
|
||
local configure_extension_args_var_name="PHP_PECL_EXTENSION_CONFIGURE_ARGS_$extension_name" | ||
local configure_extension_args=$(printenv $configure_extension_args_var_name) | ||
local flags=$(echo $configure_extension_args | sed "s|\$BUILD_DIR|$build_dir|") | ||
|
||
if [[ $extension_name = 'oci8' ]]; then | ||
flags="--with-oci8=instantclient,${ORACLE_HOME}" | ||
fi | ||
|
||
readonly configure_log_file=$(mktemp "/tmp/pecl-configure-${extension_name}-XXXX.log") | ||
./configure --with-php-config=/app/vendor/php/bin/php-config $flags > "${configure_log_file}" 2>&1 | ||
[ $? -eq 0 ] || install_pecl_error "${extension_name}" "configure build" "${configure_log_file}" | ||
|
||
readonly make_log_file=$(mktemp "/tmp/pecl-make-${extension_name}-XXXX.log") | ||
make -j 2 > "${make_log_file}" 2>&1 | ||
[ $? -eq 0 ] || install_pecl_error "${extension_name}" "compile" "${make_log_file}" | ||
) | ||
|
||
cp modules/${extension_name}.so "${ext_dir}/${extension_name}.so" | ||
cp modules/${extension_name}.so "${cache_extension_file}" | ||
enable_pecl_extension ${extension_name} | ||
|
||
popd > /dev/null | ||
popd > /dev/null | ||
} | ||
|
||
function enable_pecl_extension() { | ||
local extension_name="${1}" | ||
local is_zend_extension_var_name="PHP_PECL_EXTENSION_IS_ZEND_$extension_name" | ||
local is_zend_extension=$(printenv $is_zend_extension_var_name) | ||
|
||
if [[ $is_zend_extension = "true" ]] ; then | ||
Soulou marked this conversation as resolved.
Show resolved
Hide resolved
Soulou marked this conversation as resolved.
Show resolved
Hide resolved
Soulou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
echo "zend_extension=${extension_name}.so" > "/app/vendor/php/etc/conf.d/${extension_name}.ini" | ||
else | ||
echo "extension=${extension_name}.so" > "/app/vendor/php/etc/conf.d/${extension_name}.ini" | ||
fi | ||
} | ||
|
||
function install_pecl_error() { | ||
local extension_name="${1}" | ||
local action="${2}" | ||
local log_file="${3}" | ||
|
||
echo | ||
tail -n 30 "${log_file}" | indent | ||
echo | ||
# This sleep prevents from having the following lines mixed up with the output | ||
# of the above tail. Mystery of shellscripting. | ||
sleep 0.1 | ||
warn "Fail to ${action} of PHP PECL extension: ${extension_name}" | ||
echo "Read above logs to understand the source of the issue" | indent | ||
echo | ||
exit 1 | ||
} |
Uh oh!
There was an error while loading. Please reload this page.