From 825e2c474b236285e4608c6ae25a9187cbfae18b Mon Sep 17 00:00:00 2001 From: Paul Yu Date: Fri, 16 Sep 2022 14:27:43 -0700 Subject: [PATCH 1/5] Add new option for azure-cli extensions --- src/azure-cli/devcontainer-feature.json | 17 +++++++++++------ src/azure-cli/install.sh | 12 ++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/azure-cli/devcontainer-feature.json b/src/azure-cli/devcontainer-feature.json index 12a40921f..430cfe4f1 100644 --- a/src/azure-cli/devcontainer-feature.json +++ b/src/azure-cli/devcontainer-feature.json @@ -12,16 +12,21 @@ ], "default": "latest", "description": "Select or enter an Azure CLI version. (Available versions may vary by Linux distribution.)" + }, + "extensions": { + "type": "array", + "default": [], + "description": "Enter Azure CLI extension names you wish to include." } }, "customizations": { - "vscode": { - "extensions": [ - "ms-vscode.azurecli" - ] - } + "vscode": { + "extensions": [ + "ms-vscode.azurecli" + ] + } }, "installsAfter": [ "ghcr.io/devcontainers/features/common-utils" ] -} +} \ No newline at end of file diff --git a/src/azure-cli/install.sh b/src/azure-cli/install.sh index de5d65dfa..9d532ea3f 100755 --- a/src/azure-cli/install.sh +++ b/src/azure-cli/install.sh @@ -13,6 +13,7 @@ set -e rm -rf /var/lib/apt/lists/* AZ_VERSION=${VERSION:-"latest"} +AZ_EXTENSIONS=${EXTENSIONS} MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc" AZCLI_ARCHIVE_ARCHITECTURES="amd64" @@ -185,6 +186,17 @@ if [ "${use_pip}" = "true" ]; then fi fi +# If Azure CLI extensions are requested, loop through and install +if [ ${#AZ_EXTENSIONS[@]} -gt 0 ]; then + echo "Installing Azure CLI extensions: ${AZ_EXTENSIONS}" + extensions=(`echo ${AZ_EXTENSIONS} | tr ',' ' '`) + for i in "${extensions[@]}" + do + echo "Installing ${i}" + su $(getent passwd "1000" | cut -d: -f1) -c "az extension add --name ${i} -y" + done +fi + # Clean up rm -rf /var/lib/apt/lists/* From 924de1627254058ffc6727b14708dba977bb74ce Mon Sep 17 00:00:00 2001 From: Paul Yu Date: Thu, 27 Oct 2022 18:01:17 -0700 Subject: [PATCH 2/5] Update to install az extensions as $_REMOTE_USER --- src/azure-cli/devcontainer-feature.json | 2 +- src/azure-cli/install.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/azure-cli/devcontainer-feature.json b/src/azure-cli/devcontainer-feature.json index 430cfe4f1..49b223170 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.5", + "version": "1.0.6", "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.", diff --git a/src/azure-cli/install.sh b/src/azure-cli/install.sh index 9d532ea3f..7c681b287 100755 --- a/src/azure-cli/install.sh +++ b/src/azure-cli/install.sh @@ -193,7 +193,7 @@ if [ ${#AZ_EXTENSIONS[@]} -gt 0 ]; then for i in "${extensions[@]}" do echo "Installing ${i}" - su $(getent passwd "1000" | cut -d: -f1) -c "az extension add --name ${i} -y" + su ${_REMOTE_USER} -c "az extension add --name ${i} -y" done fi From 958ab681af8bbde5687816f6eda9c8d15de81c8e Mon Sep 17 00:00:00 2001 From: Paul Yu Date: Thu, 27 Oct 2022 18:14:55 -0700 Subject: [PATCH 3/5] Skip unknown extensions --- src/azure-cli/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/install.sh b/src/azure-cli/install.sh index 7c681b287..99b4af57e 100755 --- a/src/azure-cli/install.sh +++ b/src/azure-cli/install.sh @@ -193,7 +193,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" + su ${_REMOTE_USER} -c "az extension add --name ${i} -y" || continue done fi From 3b49608d04767822916c8f00acd25feeac668437 Mon Sep 17 00:00:00 2001 From: Paul Yu Date: Tue, 8 Nov 2022 09:37:52 -0800 Subject: [PATCH 4/5] Change azure cli extension option type to string --- src/azure-cli/devcontainer-feature.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/azure-cli/devcontainer-feature.json b/src/azure-cli/devcontainer-feature.json index 49b223170..012e28784 100644 --- a/src/azure-cli/devcontainer-feature.json +++ b/src/azure-cli/devcontainer-feature.json @@ -14,9 +14,9 @@ "description": "Select or enter an Azure CLI version. (Available versions may vary by Linux distribution.)" }, "extensions": { - "type": "array", - "default": [], - "description": "Enter Azure CLI extension names you wish to include." + "type": "string", + "default": "", + "description": "Optional comma separated list of Azure CLI extensions to install in profile." } }, "customizations": { From 967dfc7874c52e6f42fb76e902e862cd11fb709f Mon Sep 17 00:00:00 2001 From: Paul Yu Date: Tue, 8 Nov 2022 14:49:06 -0800 Subject: [PATCH 5/5] Adding test for azure-cli extensions --- test/azure-cli/install_extensions.sh | 17 +++++++++++++++++ test/azure-cli/scenarios.json | 12 ++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/azure-cli/install_extensions.sh create mode 100644 test/azure-cli/scenarios.json diff --git a/test/azure-cli/install_extensions.sh b/test/azure-cli/install_extensions.sh new file mode 100644 index 000000000..1e66e2633 --- /dev/null +++ b/test/azure-cli/install_extensions.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -e + +# Import test library for `check` command +source dev-container-features-test-lib + +# Check to make sure the user is vscode +check "user is vscode" whoami | grep vscode + +# Extension-specific tests +check "aks-preview" az extension show --name aks-preview +check "amg" az extension show --name amg +check "containerapp" az extension show --name containerapp + +# Report result +reportResults \ No newline at end of file diff --git a/test/azure-cli/scenarios.json b/test/azure-cli/scenarios.json new file mode 100644 index 000000000..aa21f7262 --- /dev/null +++ b/test/azure-cli/scenarios.json @@ -0,0 +1,12 @@ +{ + "install_extensions": { + "image": "ubuntu:focal", + "user": "vscode", + "features": { + "azure-cli": { + "version": "latest", + "extensions": "aks-preview,amg,containerapp" + } + } + } +} \ No newline at end of file