Skip to content

Instantly share code, notes, and snippets.

@kimsk
Last active June 24, 2021 20:25
Show Gist options
  • Save kimsk/30e5307df2db8a0f892844603c67ffef to your computer and use it in GitHub Desktop.
Save kimsk/30e5307df2db8a0f892844603c67ffef to your computer and use it in GitHub Desktop.
Manage Azure AppService & Container Registry (ACR) using Azure CLI

Instructions (using PowerShell)

Initial

Setup Varialbes

$appServiceName = "myApp"
$appServicePlan = "myAppPlan"
$resourceGroup = "myResource"

$containerName = "myContainer"
$containerImageName = "myImage:myTag"

$acr = "myACR.azurecr.io"
$acrUrl = "https://$acr"
$dockerContainerImageName = "$acr/$containerImageName"

Acquire ACR credentials

$acrName = "myACRName"
$creds = az acr credential show 
    --resource-group $resourceGroup `
    --name $acrName `
    --query "{username:username,password:passwords[0].value}" | ConvertFrom-Json

Setup WebApp

Create WebApp

# Create AppService
az webapp create --name $appServiceName `
    --resource-group $resourceGroup `
    --plan $appServicePlan `
    --deployment-container-image-name $dockerContainerImageName

Setup Docker

# Set up Docker Repository Information
az webapp config container set --name $appServiceName `
    --resource-group $resourceGroup `
    --docker-custom-image-name $dockerContainerImageName `
    --docker-registry-server-url $acrUrl `
    --docker-registry-server-user $creds.Username `
    --docker-registry-server-password  $creds.Password

# Update Container configuration
az webapp deployment container config --name $appServiceName `
    --resource-group $resourceGroup `
    --enable-cd true

Storage Mounting

# Get Access Key
$accessKey = az storage account keys list `
    --resource-group $resourceGroup `
    --account-name $storageName `
    --query "[0].value"

$shareName = "myShareName"
$mountPath = "/path/to/mount"

# Mount
az webapp config storage-account add `
    --resource-group $resourceGroup `
    --name $appServiceName `
    --access-key $accessKey `
    --account-name $storageName `
    --storage-type AzureFiles `
    --share-name $shareName `
    --mount-path $mountPath `
    --custom-id $shareName

# Verify
az webapp config storage-account list -g $resourceGroup -n $appServiceName

Restart

az webapp restart --name $appServiceName `
    --resource-group $resourceGroup

List

# List

az webapp list --query "[?resourceGroup=='$resourceGroup'].{name:name,resourceGroup:resourceGroup}" `
    --output table

az webapp list --query "[?name=='$appServiceName']"

Delete

az webapp delete --name $appServiceName `
    --resource-group $resourceGroup

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment