Skip to content

Commit eafa282

Browse files
authored
Add new option to install azure-cli extensions (#165)
* Add new option for azure-cli extensions * Update to install az extensions as $_REMOTE_USER * Skip unknown extensions * Change azure cli extension option type to string * Adding test for azure-cli extensions
1 parent e00724a commit eafa282

File tree

4 files changed

+53
-7
lines changed

4 files changed

+53
-7
lines changed
+12-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "azure-cli",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"name": "Azure CLI",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/azure-cli",
66
"description": "Installs the Azure CLI along with needed dependencies. Useful for base Dockerfiles that often are missing required install dependencies like gpg.",
@@ -12,16 +12,21 @@
1212
],
1313
"default": "latest",
1414
"description": "Select or enter an Azure CLI version. (Available versions may vary by Linux distribution.)"
15+
},
16+
"extensions": {
17+
"type": "string",
18+
"default": "",
19+
"description": "Optional comma separated list of Azure CLI extensions to install in profile."
1520
}
1621
},
1722
"customizations": {
18-
"vscode": {
19-
"extensions": [
20-
"ms-vscode.azurecli"
21-
]
22-
}
23+
"vscode": {
24+
"extensions": [
25+
"ms-vscode.azurecli"
26+
]
27+
}
2328
},
2429
"installsAfter": [
2530
"ghcr.io/devcontainers/features/common-utils"
2631
]
27-
}
32+
}

src/azure-cli/install.sh

+12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ set -e
1313
rm -rf /var/lib/apt/lists/*
1414

1515
AZ_VERSION=${VERSION:-"latest"}
16+
AZ_EXTENSIONS=${EXTENSIONS}
1617

1718
MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc"
1819
AZCLI_ARCHIVE_ARCHITECTURES="amd64"
@@ -185,6 +186,17 @@ if [ "${use_pip}" = "true" ]; then
185186
fi
186187
fi
187188

189+
# If Azure CLI extensions are requested, loop through and install
190+
if [ ${#AZ_EXTENSIONS[@]} -gt 0 ]; then
191+
echo "Installing Azure CLI extensions: ${AZ_EXTENSIONS}"
192+
extensions=(`echo ${AZ_EXTENSIONS} | tr ',' ' '`)
193+
for i in "${extensions[@]}"
194+
do
195+
echo "Installing ${i}"
196+
su ${_REMOTE_USER} -c "az extension add --name ${i} -y" || continue
197+
done
198+
fi
199+
188200
# Clean up
189201
rm -rf /var/lib/apt/lists/*
190202

test/azure-cli/install_extensions.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Import test library for `check` command
6+
source dev-container-features-test-lib
7+
8+
# Check to make sure the user is vscode
9+
check "user is vscode" whoami | grep vscode
10+
11+
# Extension-specific tests
12+
check "aks-preview" az extension show --name aks-preview
13+
check "amg" az extension show --name amg
14+
check "containerapp" az extension show --name containerapp
15+
16+
# Report result
17+
reportResults

test/azure-cli/scenarios.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"install_extensions": {
3+
"image": "ubuntu:focal",
4+
"user": "vscode",
5+
"features": {
6+
"azure-cli": {
7+
"version": "latest",
8+
"extensions": "aks-preview,amg,containerapp"
9+
}
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)