diff --git a/Environments/README.md b/Environments/README.md index ae20f97d..a8486be7 100644 --- a/Environments/README.md +++ b/Environments/README.md @@ -10,7 +10,7 @@ The sample Catalog consists of a few catalog items (ARM Template + associated ma ## ARM and Bicep -Each catalog item has _main.bicep_ file in addition to the ARM template (_azuredeploy.json_). This is because the ARM templates in this repository are written in [bicep](https://github.com/Azure/bicep) and transpiled to ARM using the [build-arm.py](/tools/build-arm.py) script in the [tools](/tools/) folder. The script simply walks the Environments folder and runs the [`az bicep build`](https://learn.microsoft.com/en-us/cli/azure/bicep?view=azure-cli-latest#az-bicep-build) command on each folder's main.bicep file, and is automatically run via the [build_arm.yml](/.github/workflows/build_arm.yml) workflow any time a bicep file changes. +Each catalog item has _main.bicep_ file in addition to the ARM template (_azuredeploy.json_). This is because the ARM templates in this repository are written in [bicep](https://github.com/Azure/bicep) and transpiled to ARM using the [build-arm.py](/tools/build-arm.py) or [build-arm.sh][/tools/build-arm.sh] script in the [tools](/tools/) folder. The script simply walks the Environments folder and runs the [`az bicep build`](https://learn.microsoft.com/en-us/cli/azure/bicep?view=azure-cli-latest#az-bicep-build) command on each folder's main.bicep file, and is automatically run via the [build_arm.yml](/.github/workflows/build_arm.yml) workflow any time a bicep file changes. **Please note: This is not a requirement for creating catalog item templates. It is done in this repo to make it easier to understand what is being deployed in each template.** diff --git a/tools/build-arm.sh b/tools/build-arm.sh new file mode 100644 index 00000000..d115fa4d --- /dev/null +++ b/tools/build-arm.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ + +repository_root="$(dirname "$(readlink -f "$0")")/.." +echo "Repo root: {$repository_root}" +environments_path="$repository_root/Environments" +echo "Environments path: {$environments_path}" + +environments=() +echo "Building ARM templates from bicep files..." + +for environment in "$environments_path"/*/; do + if [ "$environment" != "$environments_path/" ]; then + environments+=("$environment") + fi +done + +echo "${#environments[@]} environments detected" + +# get the full path to the git executable +git="$(command -v git)" + +for environment in "${environments[@]}"; do + echo " Ensuring: $environment/azuredeploy.json" + if [ ! -f "$environment/azuredeploy.json" ]; then + # if the azuredeploy.json file doesn't exist, create it + touch "$environment/azuredeploy.json" + # run the git command to add the azuredeploy.json file + "$git" add "$environment/azuredeploy.json" + fi +done + +# get the full path to the azure cli executable +az="$(command -v az)" + +for environment in "${environments[@]}"; do + echo " Compiling template: $environment" + # run the azure cli command to compile the template + "$az" bicep build --file "$environment/main.bicep" --outfile "$environment/azuredeploy.json" +done + +echo "Done" \ No newline at end of file