Publish a Docker image to ACR (Azure Container Registry) from an HCL file

Hi,

Documentation about post-processors (docker-import, docker-push) lacks some real life samples, and I can’t find my answers anywhere on the web.

I just have one question: given the following basic sample (HCL), is it possible to use the docker-push post processor to publish the produced image to an Azure Container Registry?

# Settings variables
variable "acr_url" {
  type = string
  default = "<account>.azurecr.io"
}
variable "acr_login" {
  type = string
  default = "<account>"
}
variable "acr_password" {
  type = string
  default = "mySuperDuperPassword"
  sensitive = true
}

# Set docker source
source "docker" "ubuntu" {
  image = "ubuntu:20.04"
  pull = true
  commit = true
}

# Build steps
build {
  name = "agent"
  source "sources.docker.ubuntu" {
    changes = [
      "ENV AGENT_OS linux"
    ]
  }

  post-processor "docker-tag" {
    repository = "alm/agent/ubuntu"
    tags = [ "latest" ]
  }
}

I tried to add this post-processor without success.

  post-processor "docker-push" {
    login = true
    login_server = "${var.acr_url}"
    login_username = "${var.acr_login}"
    login_password = "${var.acr_password}"
    tags = [ "latest" ]
  }

I also tried to push from the HCL file to Docker Hub (changing the repo name which does not allow ‘/’), without success: I can only make it work from the command line.

Thanks for any advice.

Hi,

I see duplicate login_password properties.

login_password = "${var.acr_login}"
login_password = "${var.acr_password}"

Is that a typo when c/c on the forum or a typo in your code ?

Thanks for noticing.
That’s a typo when c/c. I’ve edited my post.

I lost 2 days of work but I finally found why it didn’t work, thanks to this issue.

Post-processors (tag, push…) must be enclosed in a post-processors (plural) for the docker-push to actually push the tagged image and not the artifact of the build):

post-processors {
  post-processor "docker-tag" {...}
  post-processor "docker-push" {...}
}

Hi Boblechat,
Thanks for this post, it helped me in moving forward with my post-processors code, I tried to use the code you mentioned above.
post-processor “docker-push” {
login = true
login_server = “{var.acr_url}" login_username = "{var.acr_login}”
login_password = “${var.acr_password}”
tags = [ “latest” ]
}

However, I am getting below error:
Error: Failed preparing post-processor-block “docker-push” “”

on .\docker.pkr.hcl line 56:
(source code not available)

.\docker.pkr.hcl:61,7-11: Unsupported argument; An argument named “tags” is not expected here.

any advice on this?

Thanks!