Skip to content

Latest commit

Β 

History

History
386 lines (273 loc) Β· 12.1 KB

File metadata and controls

386 lines (273 loc) Β· 12.1 KB

πŸ“œ Scripts Guide

Azure Essentials | How to run scripts, preflight checks, and deployments


πŸ’» Where Do I Run These Commands?

All scripts in this project are run from a terminal (also called a command line or shell). Here's how to open one:

Platform How to Open a Terminal
VS Code (any OS) Press Ctrl+` (backtick) or go to Terminal β†’ New Terminal from the menu bar. This is the easiest option!
macOS Open Terminal (search for it in Spotlight with Cmd+Space)
Windows Open PowerShell (search for it in the Start menu)
Linux Open your distro's terminal emulator (usually Ctrl+Alt+T)
No install needed Use Azure Cloud Shell β€” runs in your browser with all tools pre-installed

⚠️ Important: Make sure your terminal is in the project root folder (azure_essentials/) before running any command. After cloning, run cd azure_essentials to get there. If you're using VS Code's built-in terminal, it opens in the project root automatically.

What does ./ mean? When you see ./scripts/bash/deploy.sh, the ./ means "run this file from the current folder." On Windows, you'll use .\ instead (e.g., .\scripts\powershell\deploy.ps1).


πŸš€ Quick Start for Learners

Follow these steps before starting any lesson:

Step 1: Run Preflight Checks

Before deploying anything, validate your environment is properly configured:

Platform Command Description
macOS ./scripts/bash/validate-env.sh Validates all tools, auth, and Azure access
Linux ./scripts/bash/validate-env.sh Same as macOS
Windows .\scripts\powershell\validate-env.ps1 PowerShell validation script
Cloud Shell az login && az account show Minimal check for Cloud Shell
# macOS / Linux
chmod +x scripts/bash/validate-env.sh
./scripts/bash/validate-env.sh
# Windows (PowerShell)
.\scripts\powershell\validate-env.ps1

βœ… Expected Output: All green checkmarks (βœ“) for required tools


πŸ“ Script Locations

scripts/
β”œβ”€β”€ bash/                      # macOS & Linux scripts
β”‚   β”œβ”€β”€ deploy.sh              # πŸš€ Interactive lesson deployment
β”‚   β”œβ”€β”€ validate-env.sh        # βœ… Preflight environment check
β”‚   β”œβ”€β”€ setup-local-tools.sh   # πŸ”§ Install all required tools
β”‚   β”œβ”€β”€ test-all-lessons.sh    # πŸ§ͺ Test all lesson deployments
β”‚   β”œβ”€β”€ test-lessons-e2e.sh    # πŸ§ͺ End-to-end lesson validation
β”‚   └── test-deployment.sh     # πŸ§ͺ Test a specific deployment
β”‚
β”œβ”€β”€ powershell/                # Windows scripts
β”‚   β”œβ”€β”€ deploy.ps1             # πŸš€ Interactive lesson deployment
β”‚   β”œβ”€β”€ validate-env.ps1       # βœ… Preflight environment check
β”‚   β”œβ”€β”€ setup-local-tools.ps1  # πŸ”§ Install all required tools
β”‚   β”œβ”€β”€ test-deploy.ps1        # πŸ§ͺ Quick deployment test
β”‚   └── test-deployment.ps1    # πŸ§ͺ Full deployment test with cleanup
β”‚
└── azure-cli/                 # Pure Azure CLI scripts (any OS)
    β”œβ”€β”€ deploy.sh              # πŸš€ Interactive menu for CLI scripts
    β”œβ”€β”€ lesson-*.sh            # Individual lesson scripts
    β”œβ”€β”€ README.md              # CLI scripts documentation
    └── commands/              # πŸ“‹ Copy-paste command reference
        β”œβ”€β”€ README.md
        └── lesson-*.md        # Per-lesson CLI commands

πŸ”§ Setup & Installation

Install All Required Tools (One Command)

Don't have the tools installed? Run our automated setup:

Platform Command
macOS ./scripts/bash/setup-local-tools.sh
Linux (Ubuntu/Debian) ./scripts/bash/setup-local-tools.sh
Windows .\scripts\powershell\setup-local-tools.ps1

This installs:

  • βœ… Azure CLI (az)
  • βœ… Azure Developer CLI (azd)
  • βœ… Git
  • βœ… Python 3.13+
  • βœ… kubectl
  • βœ… Docker (guided)
  • βœ… VS Code extensions

πŸ§ͺ Testing & Validation (For Trainers)

End-to-End Lesson Tests

Before teaching, validate that lessons work correctly with live Azure resources:

# Test all lessons (06 + 07)
./scripts/bash/test-lessons-e2e.sh

# Test only Lesson 06 (Linux/MicroK8s)
./scripts/bash/test-lessons-e2e.sh 06

# Test only Lesson 07 (Containers/ACR/Container Apps)
./scripts/bash/test-lessons-e2e.sh 07
What It Tests Duration Cost Estimate
Lesson 06: VM β†’ SSH β†’ MicroK8s β†’ Deploy nginx β†’ NodePort β†’ Browser access ~10 min ~$2
Lesson 07: ACR β†’ Build image β†’ Container Apps β†’ Public HTTPS URL ~8 min ~$3

⚠️ Cost Warning: This creates real Azure resources. Cleanup is offered at the end of the test.


πŸš€ Deployment Options

You have three ways to deploy lesson resources:

Option 1: Interactive Deployment Script (Recommended)

The easiest way for beginners:

# macOS / Linux
./scripts/bash/deploy.sh

# Windows (PowerShell)
.\scripts\powershell\deploy.ps1

This guided script will:

  1. βœ… Check all prerequisites
  2. βœ… Let you choose a region (Top 5 North America regions)
  3. βœ… Select specific lessons to deploy
  4. βœ… Create separate resource groups per lesson

Option 2: Azure Developer CLI (azd)

For more control, use azd directly:

# Authenticate
azd auth login

# Initialize environment
azd init

# Set region and lesson
azd env set AZURE_LOCATION eastus
azd env set LESSON_NUMBER 03    # Deploy Lesson 03 only

# Deploy
azd up

# Clean up when done
azd down --force --purge

Option 3: Pure Azure CLI Scripts

Learn the actual Azure CLI commands (great for understanding what's happening):

# Interactive menu
./scripts/azure-cli/deploy.sh

# Or run individual lesson scripts
./scripts/azure-cli/lesson-03-storage.sh

# See the CLI commands without running
./scripts/azure-cli/lesson-03-storage.sh --commands

# Clean up resources
./scripts/azure-cli/lesson-03-storage.sh --cleanup

Option 4: Copy-Paste Commands (Cloud Shell)

For Azure Cloud Shell or step-by-step learning, use the copy-paste reference:

  1. Open Azure Cloud Shell β†’ Select Bash
  2. Browse to scripts/azure-cli/commands/
  3. Open the lesson file (e.g., lesson-03-storage.md)
  4. Copy and paste commands one at a time

βœ… Preflight Checks Explained

What the Validation Script Checks

Check Required? What It Verifies
Azure CLI βœ… Yes az command available and version
Azure Developer CLI βœ… Yes azd command available
Git βœ… Yes git available for version control
Azure CLI Login βœ… Yes Authenticated to Azure subscription
azd Login βœ… Yes Authenticated for azd deployments
Python 3 πŸ“Œ Recommended For Azure Functions & AI lessons
kubectl πŸ“Œ Recommended For Kubernetes lessons
Docker πŸ“Œ Recommended For container lessons
VS Code Extensions πŸ“Œ Optional Bicep, Azure Tools installed

Interpreting Results

βœ“ = Passed (green)    β†’ All good, no action needed
βœ— = Failed (red)      β†’ Required - action needed before continuing
β—‹ = Optional (yellow) β†’ Recommended but not blocking

Fixing Common Issues

# Azure CLI not authenticated
az login

# Azure Developer CLI not authenticated
azd auth login

# Scripts not executable (macOS/Linux)
chmod +x scripts/bash/*.sh
chmod +x scripts/azure-cli/*.sh

# Docker not running
# macOS/Windows: Start Docker Desktop
# Linux: sudo systemctl start docker

πŸ”„ Script Comparison

Feature bash/ scripts powershell/ scripts azure-cli/ scripts
Platform macOS, Linux, WSL Windows Any (with bash)
Method Azure Developer CLI Azure Developer CLI Native az commands
Templates Bicep (declarative) Bicep (declarative) None (imperative)
Best For Production-style Windows users Learning CLI commands
Cloud Shell ⚠️ Needs azd ❌ No βœ… Yes
Dependencies azd, Bicep azd, Bicep, PowerShell Azure CLI only

🧹 Cleanup

Always clean up resources when done to avoid charges:

Option 1: Interactive Cleanup (Recommended)

The deploy scripts have a built-in cleanup option:

# macOS / Linux - Interactive menu (choose 'c' for cleanup)
./scripts/bash/deploy.sh

# macOS / Linux - Direct cleanup command
./scripts/bash/deploy.sh --cleanup

# Non-interactive (for scripting)
./scripts/bash/deploy.sh --cleanup --env azlearn-yourname --yes
# Windows - Interactive menu (choose 'c' for cleanup)
.\scripts\powershell\deploy.ps1

# Windows - Direct cleanup command
.\scripts\powershell\deploy.ps1 -Cleanup

# Non-interactive (for scripting)
.\scripts\powershell\deploy.ps1 -Cleanup -Environment azlearn-yourname -Yes

Option 2: Using azd

# Removes all resources deployed via azd
azd down --force --purge

Option 3: Using Azure CLI scripts

./scripts/azure-cli/lesson-03-storage.sh --cleanup

Option 4: Manual cleanup

# Delete a specific resource group
az group delete --name rg-yourname-lesson03-storage --yes --no-wait

# List all your resource groups
az group list --query "[?contains(name, 'yourname')].name" -o tsv

What Gets Cleaned Up

The cleanup process removes:

  • βœ… All lesson resource groups (rg--lesson)
  • βœ… Management groups (if Lesson 02 was deployed)
  • βœ… Soft-deleted Key Vaults (purges them)
  • βœ… Soft-deleted Cognitive Services (AI Foundry resources)

πŸ†˜ Troubleshooting

"Permission denied" when running scripts

# macOS / Linux
chmod +x scripts/bash/*.sh
chmod +x scripts/azure-cli/*.sh

"Command not found" after installation

# macOS / Linux - restart shell or source profile
source ~/.bashrc   # or ~/.zshrc

# Windows - restart PowerShell terminal

Azure CLI login issues

# Clear cached credentials
az logout
az account clear

# Login again
az login

azd deployment failures

# Check current status
azd show

# Debug mode for more info
azd up --debug

# If stuck, force cleanup and retry
azd down --force --purge
azd up

πŸ“– More Resources


Happy Learning! πŸŽ‰