Skip to content

Latest commit

 

History

History
210 lines (154 loc) · 8.32 KB

File metadata and controls

210 lines (154 loc) · 8.32 KB

Azure CLI Deployment

This folder contains Bash scripts for deploying an Azure Functions application with supporting Azure services using the lstk CLI. The deployment creates a complete gaming scoreboard system using Azure Functions and Azure Storage Account with direct Azure CLI commands through the LocalStack Azure emulator. For more information, see Azure Functions Sample with LocalStack for Azure.

Prerequisites

Before deploying this solution, ensure you have the following tools installed:

  • LocalStack for Azure: Local Azure cloud emulator for development and testing
  • Visual Studio Code: Code editor installed on one of the supported platforms
  • .NET SDK: Required for building and publishing the C# Azure Functions application
  • Docker: Container runtime required for LocalStack
  • Azure CLI: Azure command-line interface
  • lstk CLI: LocalStack command-line interface (proxies the Azure CLI via lstk az)
  • jq: JSON processor for scripting and parsing command outputs

Installing lstk CLI

Deploying to LocalStack requires the lstk CLI, which routes Azure CLI commands to the emulator (run lstk az start-interception before deploying). Install it using Homebrew:

brew install localstack/tap/lstk

or npm:

npm install -g @localstack/lstk

Alternatively, download a pre-built binary from the lstk releases page. For more information, see the lstk CLI documentation and the lstk GitHub repository.

Architecture Overview

This deploy.sh script creates the following Azure resources using Azure CLI commands:

  1. Azure Resource Group: Logical container for all gaming system resources.
  2. Azure Storage Account: Provides blob containers, queues, and tables for the gaming system.
  3. Azure Linux Function App Serverless compute platform hosting the gaming logic with consumption plan.

The system implements a complete gaming scoreboard with multiple Azure Functions that handle HTTP requests, process blob uploads, manage queue messages, and maintain game statistics. For more information, see Azure Functions Sample with LocalStack for Azure.

Provisioning Scripts

See deploy.sh for the complete deployment script. The script performs:

  • Creates resource group if it doesn't exist
  • Creates Storage Account and retrieves access key
  • Creates Function App with consumption plan
  • Constructs storage connection string
  • Configures Function App settings (storage, queue, table, timer configurations)
  • Builds and publishes the .NET application in Release configuration
  • Creates deployment zip package from published output
  • Deploys the zip to Azure Function App using az functionapp deploy

Deployment

  1. You can set up the Azure emulator by utilizing LocalStack for Azure Docker image. Before starting, ensure you have a valid LOCALSTACK_AUTH_TOKEN to access the Azure emulator. Refer to the Auth Token guide to obtain your Auth Token and specify it in the LOCALSTACK_AUTH_TOKEN environment variable. The Azure Docker image is available on the LocalStack Docker Hub. To pull the Azure Docker image, execute the following command:

    docker pull localstack/localstack-azure
  2. Start the LocalStack Azure emulator using the localstack CLI, execute the following command:

    export LOCALSTACK_AUTH_TOKEN=<your_auth_token>
    IMAGE_NAME=localstack/localstack-azure localstack start
  3. Navigate to the scripts directory

    cd samples/function-app-storage-http/dotnet/scripts
  4. Make the script executable:

    chmod +x deploy.sh
  5. Run the deployment script:

    ./deploy.sh

Configuration Options

Environment Variables

You can customize the deployment by modifying the variables at the top of deploy.sh:

# Customizable variables
PREFIX='myapp'              # Change resource name prefix
SUFFIX='prod'               # Change resource name suffix  
LOCATION='eastus'           # Change deployment region
RUNTIME="DOTNET-ISOLATED"   # Runtime type
RUNTIME_VERSION="10"        # Runtime version

Application Settings

The script configures the following application settings for the gaming system:

Setting Purpose Default Value
AzureWebJobsStorage Functions runtime storage Auto-generated connection string
STORAGE_ACCOUNT_CONNECTION_STRING Application storage access Auto-generated connection string
INPUT_STORAGE_CONTAINER_NAME Blob input container input
OUTPUT_STORAGE_CONTAINER_NAME Blob output container output
INPUT_QUEUE_NAME Message input queue input
OUTPUT_QUEUE_NAME Message output queue output
TRIGGER_QUEUE_NAME Queue trigger name trigger
INPUT_TABLE_NAME Scoreboards table scoreboards
OUTPUT_TABLE_NAME Winners table winners
PLAYER_NAMES Game player list Comma-separated names
TIMER_SCHEDULE Scheduled function trigger 0 */1 * * * * (every minute)
FUNCTIONS_WORKER_RUNTIME Runtime specification dotnet-isolated

LocalStack-Specific Commands

  1. lstk az start-interception:

    • Redirects Azure CLI calls to LocalStack endpoints
    • Enables local development without Azure subscription
    • Maintains compatibility with standard Azure CLI syntax
  2. az functionapp deploy:

    • Deploys the zipped publish output to the function app
    • Works identically against LocalStack and Azure
    • Uses the standard Azure CLI zip deployment mechanism
  3. lstk az stop-interception:

    • Restores normal Azure CLI behavior
    • Cleans up LocalStack session state
    • Returns CLI to standard Azure cloud operations

Validation

After deployment, you can use the validate.sh script to verify that all resources were created and configured correctly:

#!/bin/bash

# Variables
# Check resource group
az group show \
  --name local-rg \
  --output table

# List resources
az resource list \
  --resource-group local-rg \
  --output table

# Check function app status
az functionapp show  \
  --name local-func-test \
  --resource-group local-rg \
  --output table

# Check storage account properties
az storage account show \
  --name localstoragetest \
  --resource-group local-rg \
  --output table

# List storage containers
az storage container list \
  --account-name localstoragetest \
  --output table \
  --only-show-errors

# List storage queues
az storage queue list \
  --account-name localstoragetest \
  --output table \
  --only-show-errors

# List storage tables
az storage table list \
  --account-name localstoragetest \
  --output table \
  --only-show-errors

Cleanup

To destroy all created resources:

# Delete resource group and all contained resources
az group delete --name local-rg --yes --no-wait

# Verify deletion
az group list --output table

This will remove all Azure resources created by the CLI deployment script.

Related Documentation