PHP: Allow 'version:none' (#439)

* PHP: Allow 'version:none'

* fix tests
This commit is contained in:
Samruddhi Khandale 2023-02-07 09:52:33 -08:00 committed by GitHub
parent c997f9af69
commit 36d7664eba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 87 additions and 53 deletions

View file

@ -1,6 +1,6 @@
{
"id": "php",
"version": "1.1.1",
"version": "1.1.2",
"name": "PHP",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/php",
"options": {
@ -10,7 +10,8 @@
"latest",
"8",
"8.2",
"8.2.0"
"8.2.0",
"none"
],
"default": "latest",
"description": "Select or enter a PHP version"

View file

@ -123,38 +123,13 @@ find_version_from_git_tags() {
# Install PHP Composer
addcomposer() {
"${PHP_INSTALL_DIR}/bin/php" -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
"${PHP_SRC}" -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
HASH="$(wget -q -O - https://composer.github.io/installer.sig)"
"${PHP_INSTALL_DIR}/bin/php" -r "if (hash_file('sha384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
"${PHP_INSTALL_DIR}/bin/php" composer-setup.php
"${PHP_INSTALL_DIR}/bin/php" -r "unlink('composer-setup.php');"
mv composer.phar "${PHP_INSTALL_DIR}/bin/composer"
"${PHP_SRC}" -r "if (hash_file('sha384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
"${PHP_SRC}" composer-setup.php --install-dir="/usr/local/bin" --filename=composer
"${PHP_SRC}" -r "unlink('composer-setup.php');"
}
# Install PHP if it's missing
# Persistent / runtime dependencies
RUNTIME_DEPS="wget ca-certificates git build-essential xz-utils"
# PHP dependencies
PHP_DEPS="libssl-dev libcurl4-openssl-dev libedit-dev libsqlite3-dev libxml2-dev zlib1g-dev libsodium-dev libonig-dev"
. /etc/os-release
if [ "${VERSION_CODENAME}" = "bionic" ]; then
PHP_DEPS="${PHP_DEPS} libargon2-0-dev"
else
PHP_DEPS="${PHP_DEPS} libargon2-dev"
fi
# Dependencies required for running "phpize"
PHPIZE_DEPS="autoconf dpkg-dev file g++ gcc libc-dev make pkg-config re2c"
# Install dependencies
check_packages $RUNTIME_DEPS $PHP_DEPS $PHPIZE_DEPS
install_php() {
PHP_VERSION="$1"
PHP_INSTALL_DIR="${PHP_DIR}/${PHP_VERSION}"
@ -216,12 +191,62 @@ install_php() {
echo "xdebug.mode = debug" >> "${XDEBUG_INI}"
echo "xdebug.start_with_request = yes" >> "${XDEBUG_INI}"
echo "xdebug.client_port = 9003" >> "${XDEBUG_INI}"
}
# Install PHP Composer if needed
if [[ "${INSTALL_COMPOSER}" = "true" ]] || [[ $(composer --version) = "" ]]; then
addcomposer
if [ "${PHP_VERSION}" != "none" ]; then
# Persistent / runtime dependencies
RUNTIME_DEPS="wget ca-certificates git build-essential xz-utils"
# PHP dependencies
PHP_DEPS="libssl-dev libcurl4-openssl-dev libedit-dev libsqlite3-dev libxml2-dev zlib1g-dev libsodium-dev libonig-dev"
. /etc/os-release
if [ "${VERSION_CODENAME}" = "bionic" ]; then
PHP_DEPS="${PHP_DEPS} libargon2-0-dev"
else
PHP_DEPS="${PHP_DEPS} libargon2-dev"
fi
# Dependencies required for running "phpize"
PHPIZE_DEPS="autoconf dpkg-dev file g++ gcc libc-dev make pkg-config re2c"
# Install dependencies
check_packages $RUNTIME_DEPS $PHP_DEPS $PHPIZE_DEPS
find_version_from_git_tags PHP_VERSION https://github.com/php/php-src "tags/php-"
install_php "${PHP_VERSION}"
PHP_SRC="${PHP_INSTALL_DIR}/bin/php"
else
set +e
PHP_SRC=$(which php)
set -e
fi
# Install PHP Composer if needed
if [[ "${INSTALL_COMPOSER}" = "true" ]]; then
if [ -z "${PHP_SRC}" ]; then
echo "(!) Could not install Composer. PHP not found."
exit 1
fi
addcomposer
fi
# Additional php versions to be installed but not be set as default.
if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then
OLDIFS=$IFS
IFS=","
read -a additional_versions <<< "$ADDITIONAL_VERSIONS"
for version in "${additional_versions[@]}"; do
OVERRIDE_DEFAULT_VERSION="false"
install_php "${version}"
done
IFS=$OLDIFS
fi
if [ "${PHP_VERSION}" != "none" ]; then
CURRENT_DIR="${PHP_DIR}/current"
if [[ ! -d "${CURRENT_DIR}" ]]; then
ln -s -r "${PHP_INSTALL_DIR}" ${CURRENT_DIR}
@ -236,27 +261,12 @@ install_php() {
rm -rf "${PHP_SRC_DIR}"
updaterc "if [[ \"\${PATH}\" != *\"${CURRENT_DIR}\"* ]]; then export PATH=\"${CURRENT_DIR}/bin:\${PATH}\"; fi"
}
find_version_from_git_tags PHP_VERSION https://github.com/php/php-src "tags/php-"
install_php "${PHP_VERSION}"
# Additional php versions to be installed but not be set as default.
if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then
OLDIFS=$IFS
IFS=","
read -a additional_versions <<< "$ADDITIONAL_VERSIONS"
for version in "${additional_versions[@]}"; do
OVERRIDE_DEFAULT_VERSION="false"
install_php "${version}"
done
IFS=$OLDIFS
chown -R "${USERNAME}:php" "${PHP_DIR}"
chmod -R g+r+w "${PHP_DIR}"
find "${PHP_DIR}" -type d -print0 | xargs -n 1 -0 chmod g+s
fi
chown -R "${USERNAME}:php" "${PHP_DIR}"
chmod -R g+r+w "${PHP_DIR}"
find "${PHP_DIR}" -type d -print0 | xargs -n 1 -0 chmod g+s
# Clean up
rm -rf /var/lib/apt/lists/*

View file

@ -9,5 +9,7 @@ check "php version 8.1.4 installed as default" php --version | grep 8.1.4
check "php version 8.0.17 installed" ls -l /usr/local/php | grep 8.0.17
check "php version 8.0.3 installed" ls -l /usr/local/php | grep 8.0.3
check "composer-version" composer --version
# Report result
reportResults

View file

@ -0,0 +1,10 @@
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
check "composer-version" composer --version
# Report result
reportResults

View file

@ -6,6 +6,7 @@ set -e
source dev-container-features-test-lib
check "php-version-8-is-installed" bash -c "php --version | grep '8.'"
check "composer-version" composer --version
# Report result
reportResults

View file

@ -6,6 +6,7 @@ set -e
source dev-container-features-test-lib
check "php-version-8.2-is-installed" bash -c "php --version | grep '8.2'"
check "composer-version" composer --version
# Report result
reportResults

View file

@ -23,5 +23,14 @@
"version": "8.2"
}
}
},
"install_only_composer": {
"image": "mcr.microsoft.com/devcontainers/php:latest",
"features": {
"php": {
"version": "none",
"installComposer": true
}
}
}
}

View file

@ -7,7 +7,7 @@ source dev-container-features-test-lib
check "PHP version" php --version
check "Mbstring loaded" php -r "extension_loaded('mbstring') || throw new Error('Extension Mbstring is not loaded');"
check "Composer version" composer --version
check "composer-version" composer --version
# Report result
reportResults