From fa3412e499fd1659a61843c861dfe5f8d4510635 Mon Sep 17 00:00:00 2001 From: Aaron Powell Date: Fri, 7 Jul 2023 06:52:57 +1000 Subject: [PATCH] Add azd devcontainer feature (#1118) * Adding devcontainer definition - #1095 * Update ext/devcontainer/devcontainer-feature.json * adding workflow to publish devcontainer image * Update ext/devcontainer/devcontainer-feature.json * Update ext/devcontainer/README.md * adding tests and supporting the expected folder structure * ensuring curl is available and fixing tests * Update ext/devcontainer/src/azd/install.sh Co-authored-by: Daniel Jurek * combining devcontainer workflows into a single workflow - test jobs need to pass before deploy passes - deploy job linked to environment for approval * Updating based on some feedback Turns out that the script being run was uninstall not install, whoops * Apply suggestions from code review Co-authored-by: hemarina <104857065+hemarina@users.noreply.github.com> * Apply suggestions from code review * Update ext/devcontainer/src/azd/README.md Co-authored-by: Aaron Powell * Update ext/devcontainer/src/azd/install.sh Co-authored-by: Aaron Powell * Update ext/devcontainer/src/azd/install.sh Co-authored-by: hemarina <104857065+hemarina@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: hemarina <104857065+hemarina@users.noreply.github.com> * Update ext/devcontainer/src/azd/devcontainer-feature.json Co-authored-by: Matt Ellis * Update ext/devcontainer/src/azd/README.md * add xdg-utils/version due to local test/feedback * remove since vscode-node-azure-pack contains it * add auto pr for documentation update * separate release and test, add permission * add workflow test yml * add PAT for release tag --------- Co-authored-by: Daniel Jurek Co-authored-by: Victor Vazquez Co-authored-by: hemarina <104857065+hemarina@users.noreply.github.com> Co-authored-by: Matt Ellis Co-authored-by: hemarina --- .../devcontainer-feature-release.yml | 35 +++++++++++ .../workflows/devcontainer-feature-test.yml | 61 +++++++++++++++++++ ext/devcontainer/src/azd/README.md | 25 ++++++++ .../src/azd/devcontainer-feature.json | 25 ++++++++ ext/devcontainer/src/azd/install.sh | 26 ++++++++ ext/devcontainer/test/azd/test.sh | 12 ++++ 6 files changed, 184 insertions(+) create mode 100644 .github/workflows/devcontainer-feature-release.yml create mode 100644 .github/workflows/devcontainer-feature-test.yml create mode 100644 ext/devcontainer/src/azd/README.md create mode 100644 ext/devcontainer/src/azd/devcontainer-feature.json create mode 100644 ext/devcontainer/src/azd/install.sh create mode 100644 ext/devcontainer/test/azd/test.sh diff --git a/.github/workflows/devcontainer-feature-release.yml b/.github/workflows/devcontainer-feature-release.yml new file mode 100644 index 00000000000..ae1a95f113b --- /dev/null +++ b/.github/workflows/devcontainer-feature-release.yml @@ -0,0 +1,35 @@ +name: Release dev container feature image + +env: + IMAGE_NAME: ${{ github.repository }} + REGISTRY: ghcr.io + +on: + workflow_dispatch: + +jobs: + call-workflow-test: + uses: ".github/workflows/devcontainer-feature-test.yml" + + deploy: + if: ${{ github.ref == 'refs/heads/main' }} + runs-on: ubuntu-latest + needs: call-workflow-test + permissions: + contents: write + packages: write + pull-requests: write + environment: + name: deploy-devcontainer-feature + steps: + - uses: actions/checkout@v3 + + - name: "Publish Features" + uses: devcontainers/action@v1 + with: + publish-features: "true" + base-path-to-features: "./ext/devcontainer" + generate-docs: "false" + + env: + GITHUB_TOKEN: ${{ secrets.PAT }} \ No newline at end of file diff --git a/.github/workflows/devcontainer-feature-test.yml b/.github/workflows/devcontainer-feature-test.yml new file mode 100644 index 00000000000..4c1e87dab70 --- /dev/null +++ b/.github/workflows/devcontainer-feature-test.yml @@ -0,0 +1,61 @@ +name: Test dev container feature +on: + workflow_dispatch: + pull_request: + paths: + - "ext/devcontainer/**" + - ".github/workflows/devcontainer-feature-test.yml" + branches: [main] + workflow_call: + +jobs: + test: + runs-on: ubuntu-latest + continue-on-error: true + strategy: + matrix: + baseImage: + [ + "ubuntu:focal", + "ubuntu:jammy", + "ubuntu:bionic", + "debian:11", + "debian:10", + "mcr.microsoft.com/devcontainers/base:ubuntu", + "mcr.microsoft.com/devcontainers/base:debian", + ] + steps: + - uses: actions/checkout@v3 + + - name: "Install latest devcontainer CLI" + run: npm install -g @devcontainers/cli + + - name: "Generating tests for 'azd' against '${{ matrix.baseImage }}'" + run: devcontainer features test -f azd -i ${{ matrix.baseImage }} . + working-directory: ./ext/devcontainer + + test-scenarios: + runs-on: ubuntu-latest + continue-on-error: true + steps: + - uses: actions/checkout@v3 + + - name: "Install latest devcontainer CLI" + run: npm install -g @devcontainers/cli + + - name: "Testing 'azd' scenarios" + run: devcontainer features test -f azd --skip-autogenerated . + working-directory: ./ext/devcontainer + + test-global: + runs-on: ubuntu-latest + continue-on-error: true + steps: + - uses: actions/checkout@v3 + + - name: "Install latest devcontainer CLI" + run: npm install -g @devcontainers/cli + + - name: "Testing global scenarios" + run: devcontainer features test --global-scenarios-only . + working-directory: ./ext/devcontainer \ No newline at end of file diff --git a/ext/devcontainer/src/azd/README.md b/ext/devcontainer/src/azd/README.md new file mode 100644 index 00000000000..37327085f28 --- /dev/null +++ b/ext/devcontainer/src/azd/README.md @@ -0,0 +1,25 @@ +# Azure Developer CLI (azd) + +Installs the [Azure Developer CLI](https://github.com/Azure/azure-dev) along with needed dependencies. + +## Example Usage + +```json +"features": { + "ghcr.io/azure/azure-dev/azd:1": { + "version": "stable" + } +} +``` + +## Options + +| Options Id | Description | Type | Default Value | +|-----|-----|-----|-----| +| version | Select or enter an Azure Developer CLI version. (Available versions may vary by Linux distribution.) | string | stable | + +## Customizations + +### VS Code Extensions + +- `ms-azuretools.azure-dev` \ No newline at end of file diff --git a/ext/devcontainer/src/azd/devcontainer-feature.json b/ext/devcontainer/src/azd/devcontainer-feature.json new file mode 100644 index 00000000000..57a6d8ed812 --- /dev/null +++ b/ext/devcontainer/src/azd/devcontainer-feature.json @@ -0,0 +1,25 @@ +{ + "id": "azd", + "version": "0.1.0", + "name": "Azure Developer CLI", + "documentationURL": "https://github.com/azure/azure-dev/tree/main/ext/devcontainer/src/azd", + "description": "Installs the Azure Developer CLI along with needed dependencies.", + "options": { + "version": { + "type": "string", + "proposals": [ + "stable" + ], + "default": "stable", + "description": "Select or enter an Azure Developer CLI version. (Available versions may vary by Linux distribution.)" + } + }, + "customizations": { + "vscode": { + "extensions": [ + "ms-azuretools.vscode-bicep", + "ms-vscode.vscode-node-azure-pack" + ] + } + } + } \ No newline at end of file diff --git a/ext/devcontainer/src/azd/install.sh b/ext/devcontainer/src/azd/install.sh new file mode 100644 index 00000000000..0a35250052a --- /dev/null +++ b/ext/devcontainer/src/azd/install.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- + +AZD_VERSION=${VERSION:-"stable"} + +check_packages() { + if ! dpkg -s "$@" > /dev/null 2>&1; then + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update -y + fi + apt-get -y install --no-install-recommends "$@" + fi +} + +echo "(*) Ensuring dependencies are installed" + +check_packages apt-transport-https curl ca-certificates xdg-utils +check_packages $(apt-cache search '^libicu[0-9]+$' | cut -d' ' -f1) + +echo "(*) Installing Azure Developer CLI" + +curl -fsSL https://aka.ms/install-azd.sh | bash -s -- --version $AZD_VERSION -a $(dpkg --print-architecture) diff --git a/ext/devcontainer/test/azd/test.sh b/ext/devcontainer/test/azd/test.sh new file mode 100644 index 00000000000..94bae2649be --- /dev/null +++ b/ext/devcontainer/test/azd/test.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Definition specific tests +check "version" azd version + +# Report result +reportResults