Deploy a Container to Azure ACI with GitHub Actions

This post will take our GitHub Actions another step forward, and today we will push a stored Docker image from ACR to Azure Container Instances (ACI) using a workflow.

In the previous posts, we learned how to build a Docker image and push it to ACR using GitHub Actions. Also learned how to scan a Docker image with a security vulnerability scan.

Azure Container Instances (ACI)

Azure ACI is a great service that works very well with Azure Container Registry (ACR), and it makes a lot of sense to use the two services in a single workflow, as you will see on the following code.

Workflow

In the following workflow, I am using the existing code from the previous two posts but adding another step that will take a built Docker image from ACR and push it to ACI.

Go ahead and change the last code block. You will need to provide a resource group name, DNS label and a name. The upside of using that with ACR is that you can use the code block above for the Docker image.

In the code below, we are building, pushing, scanning and deploying a Docker image.

name: Build a Docker image, Push it to ACR and deply to ACI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      
      - uses: azure/docker-login@v1
        with:
          login-server: yourACRname.azurecr.io
          username: ${{ secrets.ACR_USERNAME }}
          password: ${{ secrets.ACR_PASSWORD }}

      - run: |
          docker build . -t yourACRname.azurecr.io/appdb:${{ github.sha }}
          docker push yourACRname.azurecr.io/appdb:${{ github.sha }}

      - name: Container image scan
        uses: Azure/container-scan@v0.1
        with:
          image-name: yourACRname.azurecr.io/appdb:${{ github.sha }}
          username: ${{ secrets.ACR_USERNAME }}
          password: ${{ secrets.ACR_PASSWORD }}
 
      - name: 'Deploy to Azure Container Instances'
        uses: 'azure/aci-deploy@v1'
        with:
          resource-group: RG-NAME
          dns-name-label: appdb
          image: yourACRname.azurecr.io/appdb:${{ github.sha }}
          registry-username: ${{ secrets.ACR_USERNAME }}
          registry-password: ${{ secrets.ACR_PASSWORD }}
          name: appdb-container
          location: 'West US'     

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.