aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamruddhi Khandale <skhandale@microsoft.com>2023-02-07 20:52:33 +0300
committerGitHub <noreply@github.com>2023-02-07 20:52:33 +0300
commit36d7664ebab393f0033bbc25394c67e3aed3efb1 (patch)
treefd18851a0c825de108f70e7d8cf377451b51769a
parentc997f9af697c6f09143d4b0f5305332e7adb71f5 (diff)
PHP: Allow 'version:none' (#439)feature_php_1.1.2
* PHP: Allow 'version:none' * fix tests
-rw-r--r--src/php/devcontainer-feature.json5
-rwxr-xr-xsrc/php/install.sh110
-rw-r--r--test/php/install_additional_php.sh2
-rw-r--r--test/php/install_only_composer.sh10
-rw-r--r--test/php/install_php_8.sh1
-rw-r--r--test/php/install_php_8_2.sh1
-rw-r--r--test/php/scenarios.json9
-rwxr-xr-xtest/php/test.sh2
8 files changed, 87 insertions, 53 deletions
diff --git a/src/php/devcontainer-feature.json b/src/php/devcontainer-feature.json
index ae270d0..77fcf98 100644
--- a/src/php/devcontainer-feature.json
+++ b/src/php/devcontainer-feature.json
@@ -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"
diff --git a/src/php/install.sh b/src/php/install.sh
index 0c577b1..48140e1 100755
--- a/src/php/install.sh
+++ b/src/php/install.sh
@@ -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,30 +191,48 @@ 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
- fi
+if [ "${PHP_VERSION}" != "none" ]; then
+ # Persistent / runtime dependencies
+ RUNTIME_DEPS="wget ca-certificates git build-essential xz-utils"
- CURRENT_DIR="${PHP_DIR}/current"
- if [[ ! -d "${CURRENT_DIR}" ]]; then
- ln -s -r "${PHP_INSTALL_DIR}" ${CURRENT_DIR}
- fi
+ # PHP dependencies
+ PHP_DEPS="libssl-dev libcurl4-openssl-dev libedit-dev libsqlite3-dev libxml2-dev zlib1g-dev libsodium-dev libonig-dev"
- if [ "${OVERRIDE_DEFAULT_VERSION}" = "true" ]; then
- if [[ $(ls -l ${CURRENT_DIR}) != *"-> ${PHP_INSTALL_DIR}"* ]] ; then
- rm "${CURRENT_DIR}"
- ln -s -r "${PHP_INSTALL_DIR}" "${CURRENT_DIR}"
- fi
+ . /etc/os-release
+
+ if [ "${VERSION_CODENAME}" = "bionic" ]; then
+ PHP_DEPS="${PHP_DEPS} libargon2-0-dev"
+ else
+ PHP_DEPS="${PHP_DEPS} libargon2-dev"
fi
- rm -rf "${PHP_SRC_DIR}"
- updaterc "if [[ \"\${PATH}\" != *\"${CURRENT_DIR}\"* ]]; then export PATH=\"${CURRENT_DIR}/bin:\${PATH}\"; fi"
-}
+ # Dependencies required for running "phpize"
+ PHPIZE_DEPS="autoconf dpkg-dev file g++ gcc libc-dev make pkg-config re2c"
-find_version_from_git_tags PHP_VERSION https://github.com/php/php-src "tags/php-"
-install_php "${PHP_VERSION}"
+ # 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
@@ -253,9 +246,26 @@ if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then
IFS=$OLDIFS
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
+if [ "${PHP_VERSION}" != "none" ]; then
+ CURRENT_DIR="${PHP_DIR}/current"
+ if [[ ! -d "${CURRENT_DIR}" ]]; then
+ ln -s -r "${PHP_INSTALL_DIR}" ${CURRENT_DIR}
+ fi
+
+ if [ "${OVERRIDE_DEFAULT_VERSION}" = "true" ]; then
+ if [[ $(ls -l ${CURRENT_DIR}) != *"-> ${PHP_INSTALL_DIR}"* ]] ; then
+ rm "${CURRENT_DIR}"
+ ln -s -r "${PHP_INSTALL_DIR}" "${CURRENT_DIR}"
+ fi
+ fi
+
+ rm -rf "${PHP_SRC_DIR}"
+ updaterc "if [[ \"\${PATH}\" != *\"${CURRENT_DIR}\"* ]]; then export PATH=\"${CURRENT_DIR}/bin:\${PATH}\"; 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
+fi
# Clean up
rm -rf /var/lib/apt/lists/*
diff --git a/test/php/install_additional_php.sh b/test/php/install_additional_php.sh
index 590187a..f22315a 100644
--- a/test/php/install_additional_php.sh
+++ b/test/php/install_additional_php.sh
@@ -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
diff --git a/test/php/install_only_composer.sh b/test/php/install_only_composer.sh
new file mode 100644
index 0000000..c940ece
--- /dev/null
+++ b/test/php/install_only_composer.sh
@@ -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
diff --git a/test/php/install_php_8.sh b/test/php/install_php_8.sh
index a510525..0b79533 100644
--- a/test/php/install_php_8.sh
+++ b/test/php/install_php_8.sh
@@ -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
diff --git a/test/php/install_php_8_2.sh b/test/php/install_php_8_2.sh
index 9320268..7427229 100644
--- a/test/php/install_php_8_2.sh
+++ b/test/php/install_php_8_2.sh
@@ -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
diff --git a/test/php/scenarios.json b/test/php/scenarios.json
index dac7998..1e4df06 100644
--- a/test/php/scenarios.json
+++ b/test/php/scenarios.json
@@ -23,5 +23,14 @@
"version": "8.2"
}
}
+ },
+ "install_only_composer": {
+ "image": "mcr.microsoft.com/devcontainers/php:latest",
+ "features": {
+ "php": {
+ "version": "none",
+ "installComposer": true
+ }
+ }
}
}
diff --git a/test/php/test.sh b/test/php/test.sh
index 0f49c1a..c75f7ea 100755
--- a/test/php/test.sh
+++ b/test/php/test.sh
@@ -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 \ No newline at end of file