Skip to content

Optionally install Azure Bicep as part of azure-cli feature #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 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.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.",
Expand All @@ -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": {
Expand Down
25 changes: 25 additions & 0 deletions src/azure-cli/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -197,6 +198,30 @@ if [ ${#AZ_EXTENSIONS[@]} -gt 0 ]; then
done
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

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 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
fi

# Clean up
rm -rf /var/lib/apt/lists/*

Expand Down
16 changes: 16 additions & 0 deletions test/azure-cli/install_bicep.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 11 additions & 1 deletion test/azure-cli/scenarios.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
{
"install_extensions": {
"image": "ubuntu:focal",
"image": "mcr.microsoft.com/devcontainers/base:jammy",
"user": "vscode",
"features": {
"azure-cli": {
"version": "latest",
"extensions": "aks-preview,amg,containerapp"
}
}
},
"install_bicep": {
"image": "mcr.microsoft.com/devcontainers/base:jammy",
"user": "vscode",
"features": {
"azure-cli": {
"version": "latest",
"installBicep": true
}
}
}
}