From 43551585b550005666a245ab940fef993ec66d1a Mon Sep 17 00:00:00 2001 From: Josh Spicer Date: Fri, 16 Jun 2023 22:13:52 +0000 Subject: [PATCH 1/7] add flag --- src/azure-cli/install.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/azure-cli/install.sh b/src/azure-cli/install.sh index 31bc6d864..bb5481a50 100755 --- a/src/azure-cli/install.sh +++ b/src/azure-cli/install.sh @@ -140,7 +140,8 @@ install_using_pip() { export PIP_CACHE_DIR=/tmp/pip-tmp/cache pipx_bin=pipx if ! type pipx > /dev/null 2>&1; then - pip3 install --disable-pip-version-check --no-cache-dir --user pipx + # TODO: Revisit if --break-system-packages is the best choice here. Added to support debian bookworm. + pip3 install --disable-pip-version-check --no-cache-dir --user pipx --break-system-packages pipx_bin=/tmp/pip-tmp/bin/pipx fi From 361d96b24a28cbd17ce4b1d3bff5cad9c1348960 Mon Sep 17 00:00:00 2001 From: Josh Spicer Date: Thu, 22 Jun 2023 23:08:26 +0000 Subject: [PATCH 2/7] try to install via apt version of pipx (will only work on bookworm) --- src/azure-cli/install.sh | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/azure-cli/install.sh b/src/azure-cli/install.sh index bb5481a50..32b2a54c8 100755 --- a/src/azure-cli/install.sh +++ b/src/azure-cli/install.sh @@ -127,7 +127,31 @@ install_using_apt() { fi } -install_using_pip() { +install_using_pip_strategy() { + local ver="" + if [ "${AZ_VERSION}" = "latest" ] || [ "${AZ_VERSION}" = "lts" ] || [ "${AZ_VERSION}" = "stable" ]; then + # Empty, meaning grab the "latest" in the apt repo + ver="" + else + ver="==${AZ_VERSION}" + fi + + install_with_pipx "${ver}" || install_with_complete_python_installation "${ver}" || return 1 +} + +install_with_pipx() { + local ver="$1" + if ! type pipx > /dev/null 2>&1; then + echo "(*) Installing pipx..." + check_packages pipx + pipx ensurepath + fi + + pipx install azure-cli${ver} +} + +install_with_complete_python_installation() { + local ver="$1" echo "(*) No pre-built binaries available in apt-cache. Installing via pip3." if ! dpkg -s python3-minimal python3-pip libffi-dev python3-venv > /dev/null 2>&1; then apt_get_update @@ -140,18 +164,10 @@ install_using_pip() { export PIP_CACHE_DIR=/tmp/pip-tmp/cache pipx_bin=pipx if ! type pipx > /dev/null 2>&1; then - # TODO: Revisit if --break-system-packages is the best choice here. Added to support debian bookworm. - pip3 install --disable-pip-version-check --no-cache-dir --user pipx --break-system-packages + pip3 install --disable-pip-version-check --no-cache-dir --user pipx pipx_bin=/tmp/pip-tmp/bin/pipx fi - if [ "${AZ_VERSION}" = "latest" ] || [ "${AZ_VERSION}" = "lts" ] || [ "${AZ_VERSION}" = "stable" ]; then - # Empty, meaning grab the "latest" in the apt repo - ver="" - else - ver="==${AZ_VERSION}" - fi - set +e ${pipx_bin} install --pip-args '--no-cache-dir --force-reinstall' -f azure-cli${ver} @@ -177,7 +193,7 @@ fi if [ "${use_pip}" = "true" ]; then AZ_VERSION=${CACHED_AZURE_VERSION} - install_using_pip + install_using_pip_strategy if [ "$?" != 0 ]; then echo "Please provide a valid version for your distribution ${ID} ${VERSION_CODENAME} (${architecture})." From 7f8ebff42d84cf52e0496d296717b71c86220c1b Mon Sep 17 00:00:00 2001 From: Josh Spicer Date: Fri, 23 Jun 2023 23:47:21 +0000 Subject: [PATCH 3/7] _REMOTE_USER aware --- src/azure-cli/install.sh | 19 +++++++++++++------ test/azure-cli/install_bicep.sh | 2 ++ test/azure-cli/install_extensions.sh | 2 ++ test/azure-cli/install_extensions_bookworm.sh | 8 ++++++++ test/azure-cli/scenarios.json | 10 ++++++++++ 5 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 test/azure-cli/install_extensions_bookworm.sh diff --git a/src/azure-cli/install.sh b/src/azure-cli/install.sh index 32b2a54c8..d37a86a60 100755 --- a/src/azure-cli/install.sh +++ b/src/azure-cli/install.sh @@ -16,6 +16,7 @@ AZ_VERSION=${VERSION:-"latest"} AZ_EXTENSIONS=${EXTENSIONS} AZ_INSTALLBICEP=${INSTALLBICEP:-false} +USERNAME="${USERNAME:-"${_REMOTE_USER:-"root"}"}" MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc" AZCLI_ARCHIVE_ARCHITECTURES="amd64" AZCLI_ARCHIVE_VERSION_CODENAMES="stretch buster bullseye bionic focal jammy" @@ -57,8 +58,6 @@ check_packages() { fi } -export DEBIAN_FRONTEND=noninteractive - # Soft version matching that resolves a version for a given package in the *current apt-cache* # Return value is stored in first argument (the unprocessed version) apt_cache_version_soft_match() { @@ -141,13 +140,19 @@ install_using_pip_strategy() { install_with_pipx() { local ver="$1" + + local REMOTE_USER_LOCAL_FOLDER="${_REMOTE_USER_HOME}/.local" + local PIPX_HOME="${REMOTE_USER_LOCAL_FOLDER}/pipx" + local PIPX_BIN_DIR="${REMOTE_USER_LOCAL_FOLDER}/bin" + if ! type pipx > /dev/null 2>&1; then echo "(*) Installing pipx..." check_packages pipx - pipx ensurepath + pipx ensurepath # Adds PIPX_BIN_DIR to the PATH fi pipx install azure-cli${ver} + chown -hR ${USERNAME}:${USERNAME} "${REMOTE_USER_LOCAL_FOLDER}" } install_with_complete_python_installation() { @@ -180,6 +185,8 @@ install_with_complete_python_installation() { set -e } +export DEBIAN_FRONTEND=noninteractive + # See if we're on x86_64 and if so, install via apt-get, otherwise use pip3 echo "(*) Installing Azure CLI..." . /etc/os-release @@ -211,7 +218,7 @@ if [ ${#AZ_EXTENSIONS[@]} -gt 0 ]; then for i in "${extensions[@]}" do echo "Installing ${i}" - su ${_REMOTE_USER} -c "az extension add --name ${i} -y" || continue + su ${USERNAME} -c "az extension add --name ${i} -y" || continue done fi @@ -235,8 +242,8 @@ if [ "${AZ_INSTALLBICEP}" = "true" ]; then # Add a symlink so bicep can be accessed as a standalone executable or as part of az mkdir -p ${_REMOTE_USER_HOME}/.azure/bin - chown -hR ${_REMOTE_USER}:${_REMOTE_USER} ${_REMOTE_USER_HOME}/.azure - ln -s /usr/local/bin/bicep ${_REMOTE_USER_HOME}/.azure/bin/bicep + chown -hR ${USERNAME}:${USERNAME} ${USERNAME}/.azure + ln -s /usr/local/bin/bicep ${USERNAME}/.azure/bin/bicep fi # Clean up diff --git a/test/azure-cli/install_bicep.sh b/test/azure-cli/install_bicep.sh index 955507fda..0430c64da 100644 --- a/test/azure-cli/install_bicep.sh +++ b/test/azure-cli/install_bicep.sh @@ -8,6 +8,8 @@ source dev-container-features-test-lib # Check to make sure the user is vscode check "user is vscode" whoami | grep vscode +check "version" az --version + # Bicep-specific tests check "bicep" bicep --version check "az bicep" az bicep version diff --git a/test/azure-cli/install_extensions.sh b/test/azure-cli/install_extensions.sh index 1e66e2633..58d1cfff2 100644 --- a/test/azure-cli/install_extensions.sh +++ b/test/azure-cli/install_extensions.sh @@ -8,6 +8,8 @@ source dev-container-features-test-lib # Check to make sure the user is vscode check "user is vscode" whoami | grep vscode +check "version" az --version + # Extension-specific tests check "aks-preview" az extension show --name aks-preview check "amg" az extension show --name amg diff --git a/test/azure-cli/install_extensions_bookworm.sh b/test/azure-cli/install_extensions_bookworm.sh new file mode 100644 index 000000000..3c281e685 --- /dev/null +++ b/test/azure-cli/install_extensions_bookworm.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -e + +# Import test library for `check` command +source dev-container-features-test-lib + +./install_extensions.sh \ No newline at end of file diff --git a/test/azure-cli/scenarios.json b/test/azure-cli/scenarios.json index cc1fd7512..231345225 100644 --- a/test/azure-cli/scenarios.json +++ b/test/azure-cli/scenarios.json @@ -9,6 +9,16 @@ } } }, + "install_extensions_bookworm": { + "image": "mcr.microsoft.com/devcontainers/base:bookworm", + "user": "vscode", + "features": { + "azure-cli": { + "version": "latest", + "extensions": "aks-preview,amg,containerapp" + } + } + }, "install_bicep": { "image": "mcr.microsoft.com/devcontainers/base:jammy", "user": "vscode", From 68c1e24ec5cfca1b2e2813b2ec5e89df743e0161 Mon Sep 17 00:00:00 2001 From: Josh Spicer Date: Fri, 23 Jun 2023 23:59:19 +0000 Subject: [PATCH 4/7] dont change more than you need to,josh --- src/azure-cli/install.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/azure-cli/install.sh b/src/azure-cli/install.sh index d37a86a60..2efc65ff8 100755 --- a/src/azure-cli/install.sh +++ b/src/azure-cli/install.sh @@ -16,7 +16,6 @@ AZ_VERSION=${VERSION:-"latest"} AZ_EXTENSIONS=${EXTENSIONS} AZ_INSTALLBICEP=${INSTALLBICEP:-false} -USERNAME="${USERNAME:-"${_REMOTE_USER:-"root"}"}" MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc" AZCLI_ARCHIVE_ARCHITECTURES="amd64" AZCLI_ARCHIVE_VERSION_CODENAMES="stretch buster bullseye bionic focal jammy" @@ -26,6 +25,11 @@ if [ "$(id -u)" -ne 0 ]; then exit 1 fi +if [ -z "${_REMOTE_USER}" ]; then + echo -e 'Feature script must be executed by a tool that implements the dev container specification. See https://containers.dev/ for more information.' + exit 1 +fi + # Get central common setting get_common_setting() { if [ "${common_settings_file_loaded}" != "true" ]; then @@ -152,7 +156,7 @@ install_with_pipx() { fi pipx install azure-cli${ver} - chown -hR ${USERNAME}:${USERNAME} "${REMOTE_USER_LOCAL_FOLDER}" + chown -hR ${_REMOTE_USER}:${_REMOTE_USER} "${REMOTE_USER_LOCAL_FOLDER}" } install_with_complete_python_installation() { @@ -218,7 +222,7 @@ if [ ${#AZ_EXTENSIONS[@]} -gt 0 ]; then for i in "${extensions[@]}" do echo "Installing ${i}" - su ${USERNAME} -c "az extension add --name ${i} -y" || continue + su ${_REMOTE_USER} -c "az extension add --name ${i} -y" || continue done fi @@ -242,8 +246,8 @@ if [ "${AZ_INSTALLBICEP}" = "true" ]; then # Add a symlink so bicep can be accessed as a standalone executable or as part of az mkdir -p ${_REMOTE_USER_HOME}/.azure/bin - chown -hR ${USERNAME}:${USERNAME} ${USERNAME}/.azure - ln -s /usr/local/bin/bicep ${USERNAME}/.azure/bin/bicep + chown -hR ${_REMOTE_USER}:${_REMOTE_USER} ${_REMOTE_USER_HOME}/.azure + ln -s /usr/local/bin/bicep ${_REMOTE_USER_HOME}/.azure/bin/bicep fi # Clean up From ac96d8bcf1b6568542e4ec6e6760735faf27617b Mon Sep 17 00:00:00 2001 From: Josh Spicer Date: Sat, 24 Jun 2023 00:41:01 +0000 Subject: [PATCH 5/7] increment azure-cli minor version (v1.1.0) --- src/azure-cli/devcontainer-feature.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/devcontainer-feature.json b/src/azure-cli/devcontainer-feature.json index 9ab2cc39b..901ba4fc1 100644 --- a/src/azure-cli/devcontainer-feature.json +++ b/src/azure-cli/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "azure-cli", - "version": "1.0.8", + "version": "1.1.0", "name": "Azure CLI", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/azure-cli", "description": "Installs the Azure CLI along with needed dependencies. Useful for base Dockerfiles that often are missing required install dependencies like gpg.", From d99d018fcb128339329f187f4f372feeb078ee49 Mon Sep 17 00:00:00 2001 From: Josh Spicer Date: Mon, 26 Jun 2023 22:38:54 +0000 Subject: [PATCH 6/7] install globally --- src/azure-cli/install.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/azure-cli/install.sh b/src/azure-cli/install.sh index 2efc65ff8..ff3433f16 100755 --- a/src/azure-cli/install.sh +++ b/src/azure-cli/install.sh @@ -143,20 +143,18 @@ install_using_pip_strategy() { } install_with_pipx() { + echo "(*) Attempting to install globally with pipx..." local ver="$1" - - local REMOTE_USER_LOCAL_FOLDER="${_REMOTE_USER_HOME}/.local" - local PIPX_HOME="${REMOTE_USER_LOCAL_FOLDER}/pipx" - local PIPX_BIN_DIR="${REMOTE_USER_LOCAL_FOLDER}/bin" + local PIPX_HOME="/usr/local/pipx" + local PIPX_BIN_DIR=/usr/local/bin if ! type pipx > /dev/null 2>&1; then echo "(*) Installing pipx..." check_packages pipx - pipx ensurepath # Adds PIPX_BIN_DIR to the PATH + pipx ensurepath # Ensures PIPX_BIN_DIR is on the PATH fi pipx install azure-cli${ver} - chown -hR ${_REMOTE_USER}:${_REMOTE_USER} "${REMOTE_USER_LOCAL_FOLDER}" } install_with_complete_python_installation() { From 23b24cf9ae1213cba0bcb217558fba299449fcbc Mon Sep 17 00:00:00 2001 From: Josh Spicer Date: Tue, 27 Jun 2023 19:58:08 +0000 Subject: [PATCH 7/7] make sure env variables are in scope --- src/azure-cli/install.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/azure-cli/install.sh b/src/azure-cli/install.sh index ff3433f16..181d62f05 100755 --- a/src/azure-cli/install.sh +++ b/src/azure-cli/install.sh @@ -30,6 +30,8 @@ if [ -z "${_REMOTE_USER}" ]; then exit 1 fi +echo "Effective REMOTE_USER: ${_REMOTE_USER}" + # Get central common setting get_common_setting() { if [ "${common_settings_file_loaded}" != "true" ]; then @@ -145,8 +147,8 @@ install_using_pip_strategy() { install_with_pipx() { echo "(*) Attempting to install globally with pipx..." local ver="$1" - local PIPX_HOME="/usr/local/pipx" - local PIPX_BIN_DIR=/usr/local/bin + export + local if ! type pipx > /dev/null 2>&1; then echo "(*) Installing pipx..." @@ -154,7 +156,11 @@ install_with_pipx() { pipx ensurepath # Ensures PIPX_BIN_DIR is on the PATH fi + PIPX_HOME="/usr/local/pipx" \ + PIPX_BIN_DIR=/usr/local/bin \ pipx install azure-cli${ver} + + echo "(*) Finished installing globally with pipx." } install_with_complete_python_installation() { @@ -180,7 +186,7 @@ install_with_complete_python_installation() { # Fail gracefully if [ "$?" != 0 ]; then - echo "Could not install azure-cli${ver} via pip" + echo "Could not install azure-cli${ver} via pip3" rm -rf /tmp/pip-tmp return 1 fi