Skip to content

Latest commit

 

History

History
202 lines (148 loc) · 8.03 KB

File metadata and controls

202 lines (148 loc) · 8.03 KB

Azure CLI Deployment

This folder contains Bash scripts for deploying an Azure Functions application with supporting Azure services using the azlocal 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:

Installing azlocal CLI

The deploy.sh Bash script uses the azlocal CLI to work with LocalStack. Install it using:

pip install azlocal

For more information, see Get started with the az tool on LocalStack.

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:

  • Detects environment (LocalStack vs Azure Cloud) and selects appropriate CLI
  • 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)
  • Publishes the .NET application using funclocal or func azure functionapp publish

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-alpha
  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-alpha localstack start
  3. Navigate to the scripts directory

    cd samples/function-app-and-storage/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="9"         # 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. azlocal start-interception:

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

    • Deploys function app to LocalStack Azure emulator
    • Wraps the Azure Functions Core Tools
    • Provides local testing environment for Azure Functions
  3. azlocal 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