Skip to content

Commit

Permalink
Azure CLI: Compatibility with Debian bookworm (#578)
Browse files Browse the repository at this point in the history
* add flag

* try to install via apt version of pipx (will only work on bookworm)

* _REMOTE_USER aware

* dont change more than you need to,josh

* increment azure-cli minor version (v1.1.0)

* install globally

* make sure env variables are in scope
  • Loading branch information
joshspicer authored Jun 27, 2023
1 parent de40074 commit ccce957
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/azure-cli/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down
56 changes: 44 additions & 12 deletions src/azure-cli/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ 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

echo "Effective REMOTE_USER: ${_REMOTE_USER}"

# Get central common setting
get_common_setting() {
if [ "${common_settings_file_loaded}" != "true" ]; then
Expand Down Expand Up @@ -57,8 +64,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() {
Expand Down Expand Up @@ -127,7 +132,39 @@ 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() {
echo "(*) Attempting to install globally with pipx..."
local ver="$1"
export
local

if ! type pipx > /dev/null 2>&1; then
echo "(*) Installing pipx..."
check_packages 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() {
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
Expand All @@ -144,25 +181,20 @@ install_using_pip() {
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}

# 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
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
Expand All @@ -176,7 +208,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})."
Expand Down
2 changes: 2 additions & 0 deletions test/azure-cli/install_bicep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/azure-cli/install_extensions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/azure-cli/install_extensions_bookworm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -e

# Import test library for `check` command
source dev-container-features-test-lib

./install_extensions.sh
10 changes: 10 additions & 0 deletions test/azure-cli/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ccce957

Please sign in to comment.