This tutorial guides you through setting up a robust Continuous Integration and Continuous Delivery (CI/CD) pipeline for containerized applications using Azure DevOps and Azure Container Registry.
Azure Container Registry is a managed, private Docker registry service that stores and manages private Docker container images. It's essential for securely storing your container images.
We'll use Azure Repos for source control and Azure Pipelines for the CI/CD automation.
This pipeline will build your Docker image, tag it, and push it to Azure Container Registry.
azure-pipelines.yml
trigger:
- main
variables:
# Replace with your ACR name
azureContainerRegistry: 'youracrname.azurecr.io'
dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
tag: '$(Build.BuildId)'
# Agent VM image name
vmImageName: 'ubuntu-latest'
stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build and push job
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(azureContainerRegistry)
tags: |
$(tag)
latest
- task: AzureContainerRegistry@0
inputs:
action: 'Login'
azureSubscriptionEndpoint: 'YourAzureServiceConnection' # Replace with your Service Connection name
#acrName: '$(azureContainerRegistry)' # Optional if using Service Connection
Explanation:
trigger: - main
: This pipeline will run whenever changes are pushed to the main
branch.variables
: Defines variables for your ACR name, Dockerfile path, and image tag.azureContainerRegistry
: The login server name of your Azure Container Registry.tag
: Uses the unique Build ID as the tag for the Docker image.Docker@2
task: Builds the Docker image using the specified dockerfilePath
and pushes it to your azureContainerRegistry
with both the build ID and latest
tags.AzureContainerRegistry@0
task: Logs into your ACR using a pre-configured Azure Service Connection. Ensure you have created a Service Connection in your Azure DevOps project that has permissions to push to your ACR.This pipeline will deploy your container image to an Azure service, such as Azure Kubernetes Service (AKS) or Azure App Service.
For this example, we'll outline deployment to Azure App Service (Web App for Containers).
youracrname.azurecr.io/your-image-name:latest
).Your release pipeline will automatically trigger after a successful CI build, pulling the latest container image and deploying it to your Azure App Service.
latest
to ensure reproducibility.By following these steps, you can establish an automated CI/CD workflow that builds, tests, and deploys your containerized applications to Azure efficiently and reliably.