Skip to content
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

Adding tooling for bash #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Environments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.**

Expand Down
46 changes: 46 additions & 0 deletions tools/build-arm.sh
Original file line number Diff line number Diff line change
@@ -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"