- Published on
Azure DevOps CI/CD
- Authors
- Name
- Me
Introduction
I was tasked with helping test a company azure tenant environment, and needed to test a few different use cases. One of these included setting up a Azure Devops CI/CD pipeline, making sure that the procedure was painless.
Pipeline
For the basis of my implementation, I used the kanslobarometern project to be used in the deployment. For more information about kanslobarometern, click here. The process flow was simple: Build and push the new code to ACR, and enable continous deployment with the ACA instance. You can find the azure-pipelines.yml at the bottom of the page.
Challenges
Storing the .env file
The project uses NextJS, and NextJs looks for an .env file at build time. Using environmental variables for secrets instead of a file seems to cause issues. As such, I used the Secure File functionality of Azure DevOps. The .env file gets fetched and saved for the duration of the pipeline process.
Continous Deployment
If I remember correctly, there was issues with the continous deployment setting in Azure. I think there might have been an incompatibility with the free tier. Thus, the new image for the container app gets set manually through the pipeline via CLI (see "Update Container App").
# Docker
# Build a Docker image
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- master
resources:
- repo: self
variables:
tag: "$(Build.BuildId)"
stages:
- stage: Build
displayName: Build image
jobs: - job: Build
displayName: Build
pool:
vmImage: ubuntu-latest
steps:
- task: DownloadSecureFile@1
name: downloadSecureFile
inputs:
secureFile: ".env.local"
- script: |
cp $(downloadSecureFile.secureFilePath) $(Build.SourcesDirectory)/.env.local # Copy the secure file to the project folder
displayName: "Copy Secure File to Project Folder"
- task: Docker@2
displayName: Build an image
inputs:
containerRegistry: "ACR"
repository: "$(acr-repo)"
command: "buildAndPush"
Dockerfile: "**/Dockerfile"
tags: "$(tag)"
- task: AzureCLI@2
displayName: Update Container App
inputs:
azureSubscription: "Azure subscription 1(xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx)"
scriptType: "pscore"
scriptLocation: "inlineScript"
inlineScript: "az containerapp update -n $(aca-name) -g $(aca-rg) --image $(aca-acr)/$(acr-repo):$(tag)"