This guide will help you set up Azure Container Apps deployment for the SKB Visualization application using OIDC authentication and your existing Azure Container Registry.
- Azure CLI installed and logged in
- GitHub CLI installed and authenticated
- Existing Azure Container Registry (ACR) in subscription one
- Repository owner or admin permissions
# Set your Azure subscription and resource details
$SUBSCRIPTION_ID = "your-subscription-id" # Replace with your subscription one ID
$RESOURCE_GROUP = "your-resource-group" # Your existing resource group with ACR
$ACR_NAME = "your-acr-name" # Your existing ACR name
$LOCATION = "East US" # Preferred Azure region
$APP_NAME = "skb-visualization" # Container App name
$GITHUB_REPO = "your-username/Wireframe" # Your GitHub repository
# App Registration details
$APP_REGISTRATION_NAME = "skb-visualization-github-oidc"
$CONTAINER_ENV_NAME = "skb-container-env"# Create Container Apps environment if it doesn't exist
az containerapp env create `
--name $CONTAINER_ENV_NAME `
--resource-group $RESOURCE_GROUP `
--location $LOCATION `
--subscription $SUBSCRIPTION_ID# Create the App Registration for OIDC
$APP_ID = $(az ad app create `
--display-name $APP_REGISTRATION_NAME `
--query appId `
--output tsv)
echo "App Registration ID: $APP_ID"
# Create a service principal
az ad sp create --id $APP_ID# Create federated credential for main branch
az ad app federated-credential create `
--id $APP_ID `
--parameters '{
"name": "main-branch",
"issuer": "https://token.actions.githubusercontent.com",
"subject": "repo:' + $GITHUB_REPO + ':ref:refs/heads/main",
"description": "GitHub Actions Main Branch",
"audiences": ["api://AzureADTokenExchange"]
}'
# Create federated credential for pull requests (optional)
az ad app federated-credential create `
--id $APP_ID `
--parameters '{
"name": "pull-requests",
"issuer": "https://token.actions.githubusercontent.com",
"subject": "repo:' + $GITHUB_REPO + ':pull_request",
"description": "GitHub Actions Pull Requests",
"audiences": ["api://AzureADTokenExchange"]
}'# Get the subscription ID and resource group information
$SUBSCRIPTION_SCOPE = "/subscriptions/$SUBSCRIPTION_ID"
$RG_SCOPE = "/subscriptions/$SUBSCRIPTION_ID/resourceGroups/$RESOURCE_GROUP"
# Assign AcrPush role for container registry access
az role assignment create `
--assignee $APP_ID `
--role "AcrPush" `
--scope "$RG_SCOPE/providers/Microsoft.ContainerRegistry/registries/$ACR_NAME"
# Assign Container Apps Contributor role
az role assignment create `
--assignee $APP_ID `
--role "ContainerApp Contributor" `
--scope $RG_SCOPE
# Assign Container Apps Environment Contributor role
az role assignment create `
--assignee $APP_ID `
--role "ContainerApp Environment Contributor" `
--scope $RG_SCOPE# Create the container app with a placeholder image
az containerapp create `
--name $APP_NAME `
--resource-group $RESOURCE_GROUP `
--environment $CONTAINER_ENV_NAME `
--image "mcr.microsoft.com/azuredocs/containerapps-helloworld:latest" `
--target-port 5000 `
--ingress external `
--cpu 1.0 `
--memory 2.0Gi `
--min-replicas 1 `
--max-replicas 10 `
--env-vars `
SKB_ENVIRONMENT=production `
SKB_DEBUG=false `
SKB_ENABLE_CACHING=true `
SKB_CACHE_BACKEND=memory `
SKB_LOG_LEVEL=INFO `
SKB_HOST=0.0.0.0 `
SKB_PORT=5000# Get the tenant ID
$TENANT_ID = $(az account show --query tenantId --output tsv)
# Set GitHub repository secrets using GitHub CLI
gh secret set AZURE_CLIENT_ID --body $APP_ID --repo $GITHUB_REPO
gh secret set AZURE_TENANT_ID --body $TENANT_ID --repo $GITHUB_REPO
gh secret set AZURE_SUBSCRIPTION_ID --body $SUBSCRIPTION_ID --repo $GITHUB_REPO
gh secret set AZURE_RESOURCE_GROUP --body $RESOURCE_GROUP --repo $GITHUB_REPO
gh secret set ACR_NAME --body $ACR_NAME --repo $GITHUB_REPO
gh secret set CONTAINER_APP_NAME --body $APP_NAME --repo $GITHUB_REPO
gh secret set CONTAINER_APP_ENVIRONMENT --body $CONTAINER_ENV_NAME --repo $GITHUB_REPO# List all secrets to verify they were set correctly
gh secret list --repo $GITHUB_REPO# Trigger the deployment workflow manually
gh workflow run "Deploy to Azure Container Apps" --repo $GITHUB_REPO# Watch the workflow status
gh run list --repo $GITHUB_REPO --limit 1
# Get the Container App URL
$APP_URL = $(az containerapp show `
--name $APP_NAME `
--resource-group $RESOURCE_GROUP `
--query properties.configuration.ingress.fqdn `
--output tsv)
echo "Application URL: https://$APP_URL"# Create Log Analytics workspace for monitoring
$LOG_WORKSPACE = "skb-logs-workspace"
az monitor log-analytics workspace create `
--resource-group $RESOURCE_GROUP `
--workspace-name $LOG_WORKSPACE `
--location $LOCATION
# Get workspace details for Container Apps environment
$WORKSPACE_ID = $(az monitor log-analytics workspace show `
--resource-group $RESOURCE_GROUP `
--workspace-name $LOG_WORKSPACE `
--query customerId `
--output tsv)
$WORKSPACE_KEY = $(az monitor log-analytics workspace get-shared-keys `
--resource-group $RESOURCE_GROUP `
--workspace-name $LOG_WORKSPACE `
--query primarySharedKey `
--output tsv)
# Update Container Apps environment with logging
az containerapp env update `
--name $CONTAINER_ENV_NAME `
--resource-group $RESOURCE_GROUP `
--logs-workspace-id $WORKSPACE_ID `
--logs-workspace-key $WORKSPACE_KEY# Add custom domain to container app
az containerapp hostname add `
--hostname "your-custom-domain.com" `
--name $APP_NAME `
--resource-group $RESOURCE_GROUP- Permission Errors: Ensure the service principal has all required role assignments
- OIDC Authentication Failures: Verify federated credentials are correctly configured
- Container Start Failures: Check application logs in Azure Portal
- Network Issues: Ensure Container Apps environment is properly configured
# Check container app status
az containerapp show --name $APP_NAME --resource-group $RESOURCE_GROUP
# View container app logs
az containerapp logs show --name $APP_NAME --resource-group $RESOURCE_GROUP --follow
# List all container apps in resource group
az containerapp list --resource-group $RESOURCE_GROUP --output table
# Check GitHub Actions workflow status
gh run list --repo $GITHUB_REPO
# View specific workflow run details
gh run view [RUN_ID] --repo $GITHUB_REPO- Least Privilege: Only assign necessary permissions to the service principal
- Secrets Management: Never commit secrets to the repository
- Environment Separation: Use separate app registrations for different environments
- Regular Rotation: Periodically review and rotate credentials
- Monitoring: Enable logging and monitoring for security events
After successful deployment:
- Test the application thoroughly in the Azure environment
- Set up monitoring and alerting
- Configure backup and disaster recovery
- Implement CI/CD for different environments (staging, production)
- Consider implementing Azure Front Door for global distribution