From 52b5602713cfc05d9cb0910dc144e810475967d5 Mon Sep 17 00:00:00 2001 From: Paul Yu Date: Tue, 22 Nov 2022 20:12:41 -0800 Subject: [PATCH 1/2] Adding azure-cli bicep installer to correctly install on arm64 containers --- src/azure-cli/devcontainer-feature.json | 7 ++++++- src/azure-cli/install.sh | 23 +++++++++++++++++++++++ test/azure-cli/install_bicep.sh | 16 ++++++++++++++++ test/azure-cli/scenarios.json | 12 +++++++++++- 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 test/azure-cli/install_bicep.sh diff --git a/src/azure-cli/devcontainer-feature.json b/src/azure-cli/devcontainer-feature.json index 012e28784..a2ba45221 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.6", + "version": "1.0.7", "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.", @@ -17,6 +17,11 @@ "type": "string", "default": "", "description": "Optional comma separated list of Azure CLI extensions to install in profile." + }, + "installBicep": { + "type": "boolean", + "description": "Optionally install Azure Bicep", + "default": false } }, "customizations": { diff --git a/src/azure-cli/install.sh b/src/azure-cli/install.sh index 99b4af57e..3ad180613 100755 --- a/src/azure-cli/install.sh +++ b/src/azure-cli/install.sh @@ -14,6 +14,7 @@ rm -rf /var/lib/apt/lists/* AZ_VERSION=${VERSION:-"latest"} AZ_EXTENSIONS=${EXTENSIONS} +AZ_INSTALLBICEP=${INSTALLBICEP:-false} MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc" AZCLI_ARCHIVE_ARCHITECTURES="amd64" @@ -197,6 +198,28 @@ if [ ${#AZ_EXTENSIONS[@]} -gt 0 ]; then done fi +if [ "${AZ_INSTALLBICEP}" = "true" ]; then + # Properly install Azure Bicep based on current architecture + # The `az bicep install` command installs the linux-x64 binary even on arm64 devcontainers + # The `az bicep install --target-platform` could be a solution; however, linux-arm64 is not an allowed value for this argument yet + # Manually installing Bicep and moving to the appropriate directory where az expects it to be + apt-get install curl -y + + if [ "${architecture}" = "arm64" ]; then + curl -Lo bicep https://github.com/Azure/bicep/releases/latest/download/bicep-linux-arm64 + else + curl -Lo bicep https://github.com/Azure/bicep/releases/latest/download/bicep-linux-x64 + fi + + chmod +x ./bicep + mv ./bicep /usr/local/bin/bicep + + # Add a synlink 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 +fi + # Clean up rm -rf /var/lib/apt/lists/* diff --git a/test/azure-cli/install_bicep.sh b/test/azure-cli/install_bicep.sh new file mode 100644 index 000000000..955507fda --- /dev/null +++ b/test/azure-cli/install_bicep.sh @@ -0,0 +1,16 @@ +#!/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 + +# Bicep-specific tests +check "bicep" bicep --version +check "az bicep" az bicep version + +# Report result +reportResults \ No newline at end of file diff --git a/test/azure-cli/scenarios.json b/test/azure-cli/scenarios.json index aa21f7262..cc1fd7512 100644 --- a/test/azure-cli/scenarios.json +++ b/test/azure-cli/scenarios.json @@ -1,6 +1,6 @@ { "install_extensions": { - "image": "ubuntu:focal", + "image": "mcr.microsoft.com/devcontainers/base:jammy", "user": "vscode", "features": { "azure-cli": { @@ -8,5 +8,15 @@ "extensions": "aks-preview,amg,containerapp" } } + }, + "install_bicep": { + "image": "mcr.microsoft.com/devcontainers/base:jammy", + "user": "vscode", + "features": { + "azure-cli": { + "version": "latest", + "installBicep": true + } + } } } \ No newline at end of file From dbf33ae78d1a8bdae644ed727138749bf70d5a13 Mon Sep 17 00:00:00 2001 From: Paul Yu Date: Wed, 23 Nov 2022 11:51:54 -0800 Subject: [PATCH 2/2] Adding a few updates following @joshspicer's review. --- src/azure-cli/install.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/azure-cli/install.sh b/src/azure-cli/install.sh index 3ad180613..31bc6d864 100755 --- a/src/azure-cli/install.sh +++ b/src/azure-cli/install.sh @@ -199,11 +199,13 @@ if [ ${#AZ_EXTENSIONS[@]} -gt 0 ]; then fi if [ "${AZ_INSTALLBICEP}" = "true" ]; then + # Install dependencies + check_packages apt-transport-https curl + # Properly install Azure Bicep based on current architecture # The `az bicep install` command installs the linux-x64 binary even on arm64 devcontainers # The `az bicep install --target-platform` could be a solution; however, linux-arm64 is not an allowed value for this argument yet # Manually installing Bicep and moving to the appropriate directory where az expects it to be - apt-get install curl -y if [ "${architecture}" = "arm64" ]; then curl -Lo bicep https://github.com/Azure/bicep/releases/latest/download/bicep-linux-arm64 @@ -214,7 +216,7 @@ if [ "${AZ_INSTALLBICEP}" = "true" ]; then chmod +x ./bicep mv ./bicep /usr/local/bin/bicep - # Add a synlink so bicep can be accessed as a standalone executable or as part of az + # 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