Post

Create a Multi Step Task with Azure Container Registry

Azure Container Registry supports Multi-Step Tasks which allow you to build, push and execute commands against one or more container images sequentially or in parralel.

In this tutorial we will create an Azure Container Registry and then we will create a multi-step task using a YAML file. After that we will run the multi-step task against our Azure Container Registry using the Azure command line interface.

This content is available in video form on the Cloud Engineer Skills YouTube channel.

Prerequisites

Before we get started for this tutorial you will need the following:

Creating an Multi-Step Task using Azure Container Registry

We will need to create an Azure Container Registry before we can run a multi-step task against it. Let’s start by creating our Azure Container Registry using the Azure CLI.

Creating the Azure Container Registry

We will start by creating an Azure Container Registry inside a resource group.

1
2
3
az login
az group create --name cloudengineerskills-acr-cli-rg --location eastus
az acr create --resource-group cloudengineerskills-acr-cli-rg --name cloudengineerskillscliacr --sku Premium

Creating the Multi-Step Task YAML File

Multi-step tasks are defined using a YAML file. A YAML file contains one or more Task Steps for which there are three types of Task Steps.

  • The build step: used for building the container image
  • The push step: used for pushing the container image into the Azure Container Registry or another container registry
  • The cmd step: used for running an image as a container

Steps can reference different container images, and can be run sequentially or in parralel using the when property on the build, push, or cmd step.

See the sample task.yaml file and Dockerfile below that we will be using in our tutorial.

1
2
3
4
5
6
version: v1.1.0
steps:
  - build: -t cloudengineerskillscliacr.azurecr.io/hello-world:$ID -f Dockerfile .
  - push:
      - cloudengineerskillscliacr.azurecr.io/hello-world:$ID
  - cmd: cloudengineerskillscliacr.azurecr.io/hello-world:$ID
1
FROM hello-world

Refer to the Multi-Step Task reference page for detailled documentation on the different attributes you can use in the YAML file.

Running the Multi-Step Task

We will run the Multi-Step Task manually, however Multi-Step Tasks can also run automatically on source code updates, and on base image updates. You can refer to the Azure Container Registry automatically triggered task tutorial on how to do this.

You can run the following command in the same directory that has your task.yaml file.

1
az acr run --registry cloudengineerskillscliacr -f task.yaml .

Cleaning up the Resources

1
az group delete --resource-group cloudengineerskills-acr-cli-rg

Further Reading

This post is licensed under CC BY 4.0 by the author.