Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Prepare applications for Azure deployment by generating infrastructure code, Dockerfiles, and config files.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/recipes/azcli/scripts.md
1# Deployment Scripts23Script templates for AZCLI deployments.45## Bash Script67```bash8#!/bin/bash9set -euo pipefail1011# Configuration12RESOURCE_GROUP="${RESOURCE_GROUP:-rg-myapp}"13LOCATION="${LOCATION:-eastus2}"14ENVIRONMENT="${ENVIRONMENT:-dev}"1516echo "Deploying to $ENVIRONMENT environment..."1718# Create resource group19az group create \20--name "$RESOURCE_GROUP" \21--location "$LOCATION" \22--tags environment="$ENVIRONMENT"2324# Deploy infrastructure25az deployment group create \26--resource-group "$RESOURCE_GROUP" \27--template-file ./infra/main.bicep \28--parameters ./infra/main.parameters.json \29--parameters environmentName="$ENVIRONMENT"3031# Get outputs32ACR_NAME=$(az deployment group show \33--resource-group "$RESOURCE_GROUP" \34--name main \35--query properties.outputs.acrName.value -o tsv)3637# Build and push containers38az acr login --name "$ACR_NAME"39az acr build --registry "$ACR_NAME" --image api:latest ./src/api4041echo "Deployment complete!"42```4344## PowerShell Script4546```powershell47#Requires -Version 7.048$ErrorActionPreference = "Stop"4950# Configuration51$ResourceGroup = $env:RESOURCE_GROUP ?? "rg-myapp"52$Location = $env:LOCATION ?? "eastus2"53$Environment = $env:ENVIRONMENT ?? "dev"5455Write-Host "Deploying to $Environment environment..."5657# Create resource group58az group create `59--name $ResourceGroup `60--location $Location `61--tags environment=$Environment6263# Deploy infrastructure64az deployment group create `65--resource-group $ResourceGroup `66--template-file ./infra/main.bicep `67--parameters ./infra/main.parameters.json `68--parameters environmentName=$Environment6970# Get outputs71$AcrName = az deployment group show `72--resource-group $ResourceGroup `73--name main `74--query properties.outputs.acrName.value -o tsv7576# Build and push containers77az acr login --name $AcrName78az acr build --registry $AcrName --image api:latest ./src/api7980Write-Host "Deployment complete!"81```8283## Script Best Practices8485| Practice | Description |86|----------|-------------|87| Fail fast | `set -euo pipefail` (bash) or `$ErrorActionPreference = "Stop"` (pwsh) |88| Use variables | Environment-based configuration |89| Idempotent | Safe to run multiple times |90| Output logging | Clear progress messages |91| Error handling | Capture and report failures |92