This repo contains an experiment to run Azure Pipeline Agents in Azure Container Apps. For production use, consider Scale set agents (sample repo).
Features (see limitations below):
- KEDA Azure Pipelines scaler
- Diagnostics logs saved on Azure Files
- Ubuntu based image with core set of tools e.g. Azure CLI, Bash, Helm, Kubectl, Packer, PowerShell, Terraform (
Dockerfile)
There are a number of scripts and pipelines you can use to get going. Below, I'll describe a local and pipeline approach, but you can blend these.
- AKS: Register the AKS-KedaPreview feature flag
- You'll need Azure CLI, Docker, PowerShell and Terraform
- You can use an existing Azure Container Registry (if you already have a shared registry) or let Terraform create one. In case Terraform creates the ACR, there is no opportunity to build and push the container image to the ACR before the Container App will use it.
Either let Terraform fail -> build & push the image -> retry Terraform apply, or pre-create the ACR. In case you pre-create the ACR, you also need to pre-create a User-assigned Managed Identity withAcrPullrole on the ACR. - Build and push the agent container image using
build_image.ps1script (alternatively, use thebuild-image.ymlpipeline in case you don't have Docker locally) - Create a Personal Access Token with Agent Pools read & manage scope
- Create a
config.auto.tfvarsfile (example) in the terraform directory, and use it to override the following variables:
agent_identity_resource_id
container_registry_id
devops_pat
devops_url(Organization urlhttps://dev.azure.com/<org>) - Provision infrastructure by running
terraform apply
This approach uses the deploy-container-agents.yml pipeline to build the container image, provision Container App infrastructure and run a test job on a newly created agent.
- You'll need an existing Azure Container Registry (the assumption is that the Service Connection identity does not have the Azure
Ownerrole required to configure RBAC and the ACR is a shared component anyway) - Create an User-assigned Managed Identity with
AcrPushrole on the Azure Container Registry - Create an Terraform azurerm backend
- Create a Docker Registry Service Connection to the ACR
- Create a Personal Access Token with Agent Pools read & manage scope
- Create a variable group
build-container-agent-imagewith the following variable:
containerRegistry(ACR Service Connection) - Create a variable group
pipeline-container-agentswith the following variables:
subscriptionConnection(Azure Service Connection)
TF_STATE_CONTAINER_NAME(Terraform azurerm backend storage container)
TF_STATE_RESOURCE_GROUP_NAME(Terraform azurerm backend storage account resource group)
TF_STATE_STORAGE_ACCOUNT_NAME(Terraform azurerm backend storage account)
TF_VAR_agent_identity_resource_id
TF_VAR_container_registry_id
TF_VAR_devops_pat - Make sure you have the Terraform extension installed
- Use the
deploy-container-agents.ymlto build the agent container image, provision infrastructure and run a test job on a newly created agent. Override the destroy parameter to prevent the Container App infrastructure from being destroyed at the end of the pipeline run
By default, the agents will be created in the Default agent pool with system capability CONTAINER_APP_NAME. Use the image-info.yml pipeline to test the agents. You can override the numberOfJobs parameter to test elasticity
This repo is an experiment, you may have various stability issues. Here are some known issues:
- The container image is not a general purpose image that works with all of the standard Azure Pipeline Tasks.
- Using Container Registry Private Endpoints has an issue.
