Skip to content

Commit

Permalink
automatically compile bicep to arm
Browse files Browse the repository at this point in the history
  • Loading branch information
colbylwilliams committed Mar 15, 2023
1 parent d92e693 commit 112c839
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/build_arm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Bicep -> ARM

on:
push:
branches: [main]
paths:
# only run if bicep files changed
- 'Environments/**/*.bicep'

jobs:
build:
runs-on: ubuntu-latest

permissions:
contents: write

steps:
- uses: actions/checkout@v3

- name: Install Bicep
run: az bicep install && az bicep upgrade

- name: Build Bicep -> ARM
run: python ./tools/build-arm.py

- name: Commit changes
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git commit -am "Rebuild ARM templates"
git push
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,14 @@ dmypy.json

# Pyre type checker
.pyre/

.DS_Store

[lL]ocal
.[lL]ocal

.venv
.env

local.settings.json
local.parameters.json
4 changes: 2 additions & 2 deletions Environments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ 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.
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.

**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 templates.**
**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.**

### What is Bicep?

Expand Down
12 changes: 12 additions & 0 deletions tools/build-arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import shutil
import subprocess

from pathlib import Path

repository_root = Path(__file__).resolve().parent.parent
Expand All @@ -21,6 +22,17 @@
environments.append(Path(dirpath))
# image_names.append(Path(dirpath).name)

# get the full path to the git executable
git = shutil.which('git')

for environment in environments:
print(f' Ensuring: {environment}/azuredeploy.json')
if not (environment / 'azuredeploy.json').exists():
# if the azuredeploy.json file doesn't exist, create it
(environment / 'azuredeploy.json').touch()
# run the git command to add the azuredeploy.json file
subprocess.run([git, 'add', environment / 'azuredeploy.json'])

# get the full path to the azure cli executable
az = shutil.which('az')

Expand Down

0 comments on commit 112c839

Please sign in to comment.