Hello and welcome to another entry on my blog! In this episode we will focus on automating the deployment process of our application to Azure Container Apps.
I have not chosen the best time to work on this project, because it looks like that even Microsoft is closed down during Christmas period. That is the message I’ve found on the request page for free concurrency grants:

It appears so that new Azure accounts do have access to many services for free, although there is one „but”. When it comes to access to Azure agents in pool needed to execute the pipelines one needs to send a request to Microsoft for access which usually takes 2 do 3 business days to finish. Fortunately, there is a workaround in form of hosting the agent locally on your machine using self hosted Azure agent. I won’t deep dive into it there; however if you want to know more details you can find it on this page.
In the previous episode we deployed the Azure Container App using external Image repository in form of Docker Hub. But this time let’s try something different and create an Azure Container Registry. This will allow us to build images on the fly directly from Dockerfile present in our Azure Project Repository.
To create Container registry find this resource type in Azure Services search and hit „Create”. You will be presented with screen such as the one below:

There are only few fields to fill in: the resource group to use, name of the registry, location and pricing plan (Basic is enough for our needs). For the remaining tabs we can stick to default. After all the fields are filled in hit „Create” button.
To access the container registry from the pipeline we are going to utilise username and password. In order to store them securely let’s also create an Azure Key Vault with secrets. Find Key Vault in resource list and go to creation wizard.
As usual we are required to specify resource group, name of the resource, region and pricing tier (standard is fine). Rest of the pages can stay as they are. Hit „Review and create” to create the resource.

Now that the key vault is created let’s fetch the admin password for Container Registry. Find the resource and go to „Access keys” tab in resource page:

Make sure that „Admin user” checkbox is marked as checked. Note the username and click on „Show” to retrieve the password. We can now create the Secret in Key Vault. Navigate to the Key Vault resource and go to „Secrets” tab.

Once there hit „Generate/Import” button and create two secrets – one named ACR-USERNAME and ACR-PASSWORD. In „Secret value” field fill in username and password respectively.
Now that we have setup both Container Registry and Key vault with Secrets let’s take a look at full pipeline.yml file:
trigger:
branches:
include:
- master
pool: Default
variables:
azureSubscription: '91b277db-132d-41ed-beda-d2effc05ba4a'
port: 5000
location: 'polandcentral'
resourceGroup: 'project2025'
keyVaultName: 'project2025-keyvault'
containerAppName: 'rpg-app'
containerAppEnvironment: 'rpg-app-env'
acrName: 'rpgproject'
ingress: 'external'
steps:
- task: AzureKeyVault@2
inputs:
azureSubscription: $(azureSubscription)
KeyVaultName: $(keyVaultName)
SecretsFilter: '*'
RunAsPreJob: true
- task: AzureContainerApps@1
inputs:
azureSubscription: $(azureSubscription)
appSourcePath: '$(Build.SourcesDirectory)'
containerAppName: $(containerAppName)
resourceGroup: $(resourceGroup)
acrName: $(acrName)
acrUsername: $(ACR-USERNAME)
acrPassword: $(ACR-PASSWORD)
ingress: $(ingress)
location: $(location)
targetPort: $(port)
containerAppEnvironment: $(containerAppEnvironment)
The pipeline triggers automatically after a commit is pushed to the master branch of our Azure project repository. The agent pool I am using is called „Default”. Note this is the self hosted agent pool. Pool called „default” (with lowercase „d”) would use 'ubuntu-latest’ VM.
I decided to use variables to separate the content of values from logic of the pipeline and to not hardcode the names of resources used. This allows for reusability if me or someone else decides to use it in different project.
The pipeline itself consists of two steps. In the first one we reach to Azure Key Vault to retrieve secrets stored in it. The second one is responsible for creating the Azure Container Apps. In this task we are passing a lot of arguments to specify the name of Azure Container registry, source of application code, the location where we want the application deployed etc.
After committing the changes to repository the pipeline runs, builds a docker image from the Dockerfile in repository and deploys the application as Azure Container App.

Let’s retrieve the content of /character endpoint and see if we receive the output we are expecting:

And here are our characters! Thank you for reading through the end. In my next blog post we will create a local instance of PostgreSQL database in order to use it in our application.
Dodaj komentarz