title | description |
---|---|
Azure DevOps Build, Push Docker Image to ACR |
Create Azure Pipeline to Build and Push Docker Image to Azure Container Registry |
- Understand Azure DevOps Basics
- Understand Azure Pipelines
- Implement a pipeline to Build and Push Docker Image to Azure Container Registry
- Name: azure-devops-github-acr-aks-app1
- Description: Azure DevOps App1 Demo with AKS, Github and Azure Containter Registry
- Repo Type: Public / Private (Your choice)
- Click on Create Repository
- Create Local folders
# Create a folder for all Repos we are going to create
mkdir azure-devops-aks-demo-repos
cd azure-devops-aks-demo-repos
# Create a Directory for Repo
mkdir azure-devops-github-acr-aks-app1
cd azure-devops-github-acr-aks-app1
- Copy all files from
Giti-Repository-files
folder to our new repo folderazure-devops-github-acr-aks-app1
# Initialize Git Repo
cd azure-devops-github-acr-aks-app1
git init
# Do local Commit
echo "# Azure DevOps App1 Demo with AKS, Github and ACR" >> README.md
git add .
git commit -am "V1 Base Commit"
# Link Github Remote Repository
git remote add origin https://github.com/stacksimplify/azure-devops-github-acr-aks-app1.git
# Push to Remote Repository
git push --set-upstream origin master
# Go to Github Repo - Refresh and check files appeared in githbu repo
https://github.com/stacksimplify/azure-devops-github-acr-aks-app1
- kube-manifests
- Dockerfile
- index.html
- Go to Services -> Container Registries
- Click on Add
- Subscription: StackSimplify-Paid-Subsciption
- Resource Group: acr-rg1
- Registry Name: aksdevopsacr (NAME should be unique across Azure Cloud)
- Location: Central US
- SKU: Basic (Pricing Note: $0.167 per day)
- Click on Review + Create
- Click on Create
- Go to
- https://dev.azure.com/
- Sign in to Azure DevOps
- Our Organization will be automatically created and if you want to manually create organization you can create one.
- Organization Name: aksdemo1
- Project Name: azure-devops-github-acr-aks-app1
- Project Description: AKS CICD Pipelines with Github and Azure Container Registry ACR
- Visibility: Private
- Advanced: Leave to defaults
- Version Control: Git
- Work Item Process: Basic
- Create Folder -> App1-Pipelines
- Go to Pipelines -> Create New Pipeline
- Where is your Code?: Github
- Select Repository: azure-devops-github-acr-aks-app1
- Provide Github Password
- Click on Approve and Install for Repositories selected
- Configure Your Pipeline: Docker (Build and Push Image to Azure Container Registry )
- Select an Azure Subscription: stacksimplify-paid-subscription
- Continue (Login as admin user)
- Container Registry: aksdevopsacr
- Image Name: app1-nginx
- Dockerfile: $(Build.SourcesDirectory)/Dockerfile
- Click on Validate and Configure
- Change Pipeline Name: 01-docker-build-and-push-to-acr-pipeline.yml
- Click on Save and Run
- Commit Message: Pipeline-1: Docker Build and Push to ACR
- Commit directly to master branch: check
- Click on Save and Run
- Review Build logs
- Review Image in ACR
- Click on Pipeline -> Rename/Move
- Name: 01-Docker-Build-and-Push-to-ACR
# Pull changes related to pipeline to local repo
git pull
ls -lrt
# Make changes to index.html
index.html file - change version v2
# Push changes
git add .
git commit -am "V2 Commit for index.html"
git push
- Verify Build logs
- Verify ACR Image
- Go to Pipeline -> 01-Docker-Build-and-Push-to-ACR -> Edit
- Update the below and Save
# Before
imageRepository: 'app1nginx'
# After
imageRepository: 'app1/app1nginx'
- Verify Build logs
- Verify ACR Image
# Pull changes related to pipeline to local repo
git pull
ls -lrt
# Make changes to index.html
index.html file - change version v3
# Push changes
git add .
git commit -am "V3 Commit for index.html"
git push
- Verify Build logs
- Verify ACR Image
- Go to Pipeline -> 01-Docker-Build-and-Push-to-ACR -> Settings -> Disable
- Click on Pipeline -> Edit Pipeline
- Review pipeline code
- Review Service Connections
# Docker
# Build and push an image to Azure Container Registry
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- master
resources:
- repo: self
variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: '6a8843fd-7313-48e2-9381-3f9ef59ce82d' ## Review Service Connections
imageRepository: 'app1/app1nginx'
containerRegistry: 'aksdevopsacr.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
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)