ScottishTapWater
ScottishTapWater

Reputation: 4846

Uploading Docker Image to ACR through Devops Pipeline

There are a lot of questions that seem tangentially related to this, but unfortunately, I've not been able to tie these disparate bits of information together to get to a solution.


I'm trying to use a custom docker image with an Azure function and have been following along with this guide.

I've been building up these steps inside a devops pipeline so I can accurately reproduce them, and I've got that working fine as far as provisioning is concerned.

However, I'm struggling when it comes to actually uploading the built image to the ACR.

I've found this yaml snippet in the documentation:

      - task: Docker@2
        displayName: Build and push an image to container registry
        inputs:
          command: buildAndPush
          repository: "xxx"
          dockerfile: "xxx"
          containerRegistry: "xxx"
          imageRepository: "xxx"
          tags: "xxx"

However, when I fill this out with the url for our ACR as the container registry, I get an error about needing to use a service reference.

Now, I've looked through the docs pretty extensively and I can't quite work out how this is all meant to tie together in a devops pipeline...

I've tried to come up with something like this:

    resources:
      containers:
        - container: "xxx" # name of the container (Alias) 
          type: ACR # type of registry
          azureSubscription: arm-connection # name of the ARM service connection
          resourceGroup: "$(resourceGroupName)" # Azure resource group with the container
          registry: "$(dockerRegistryName)" # Azure container registry name
          repository: "xxx" # name of the of container image collection
          trigger:
            tags:
              - "$(dockerTag):$(dockerVersion)" # tag for the container image to use

But that looks like it's creating a pointer to a specific container rather than to the registry...

So yeah, I'm a bit stuck... Could someone please help by pointing out what I'm misunderstanding here and ideally providing an example of how I can build and push an image to the ACR?

Upvotes: 2

Views: 1385

Answers (1)

Andriy Bilous
Andriy Bilous

Reputation: 2522

Command called buildAndPush allows for build and push of images to a container registry in a single command, you can find an example in Azure DevOps documentation

You will need to create Service Connection for Azure Container Registry in your Azure DevOps to configure an access, please see doc

The following YAML snippet is an example of building and pushing an image to ACR

steps:
- task: Docker@2
  displayName: Build and Push
  inputs:
    command: buildAndPush
    containerRegistry: azureContainerRegistryServiceConnectionName
    repository: repositoryName
    Dockerfile: '**/Dockerfile'
    buildContext: .
    addPipelineData: true
    tags: |
      tag1

Upvotes: 2

Related Questions