Wednesday, July 7, 2021

Azure DevOps: Deploying an ASP.NET Core Worker Service to Azure Container Instances

I had a requirement where I wanted to run a timely job. Thought of using an Azure Function, but due to the complexity of the job, moved ahead with an ASP.NET Core Worker Service

Once the dev work is done, wanted to run this on Azure and set up the DevOps side of it. Azure Container Instances (ACI) is the ideal service to run an ASP.NET Core Worker Service in Azure and setting up CI/CD was pretty simple. CI part is just creating a docker image and getting it pushed to an ACR (Azure Container Registry) or where ever you want to. In my scenario, I had the Docker image pushed to an ACR. A very nice thing with ACR to note: there is this option under Repositories -> Images, where you can run any Docker image as an instance on ACI from the portal itself.
Run instance on ACI
But I wanted to CD through DevOps, and that turned out to be just a single Azure CLI Command: az container. I just had to create a container in a container group using an image from Azure Container Registry. The command is something like this (almost all of the arguments are self-descriptive).
az container create -g <ResourceGroup> `
    --name nzmiq-monitor-worker-instance `
    --image myacr.azurecr.io/nzmiqmonitor/worker:$(Build.BuildId) `
    --cpu 1 `
    --memory 1.5 `
    --registry-login-server myacr.azurecr.io `
    --registry-username <RegistryUsername> `
    --registry-password <RegistryPassword> 
Here the $(Build.BuildId) is taken from the Build pipeline.

Isn't it nice?

Happy Coding.

Regards,
Jaliya

No comments:

Post a Comment