Closed johnypony3 closed 2 years ago
Hello @johnypony3 sorry for the delay in response,
This issue is occurring because your variable is not being interpolated correctly I think, and you're uploading the tag literally as "centos:{{.ImageSha256}}"
, you can read more about what Docker tag allows here. The relevant section from that is Name components may contain lowercase letters, digits and separators. A separator is defined as a period, one or two underscores, or one or more dashes. A name component may not start or end with a separator.
Here is a working example in HCL to use a variable in a docker tag (just name the file filename.pkr.hcl and run packer build like always)
packer {
required_plugins {
docker = {
version = ">= 0.0.7"
source = "github.com/hashicorp/docker"
}
}
}
source "docker" "ubuntu" {
image = "ubuntu:xenial"
commit = true
}
variable "ImageSha256" {
type = string
default = "nil"
}
build {
name = "learn-packer"
sources = [
"source.docker.ubuntu"
]
post-processor "docker-tag" {
repository = "learn-packer"
tags = ["build-${var.ImageSha256}"]
}
}
I am on Packer version 1.7.9 and tested the above HCL and using the -var flag in packer build
$ packer build -var "ImageSha256=12" docker_ubuntu_build_tag.pkr.hcl
learn-packer.docker.ubuntu: output will be in this color.
==> learn-packer.docker.ubuntu: Creating a temporary directory for sharing data...
==> learn-packer.docker.ubuntu: Pulling Docker image: ubuntu:xenial
learn-packer.docker.ubuntu: xenial: Pulling from library/ubuntu
learn-packer.docker.ubuntu: Digest: sha256:0f71fa8d4d2d4292c3c617fda2b36f6dabe5c8b6e34c3dc5b0d17d4e704bd39c
learn-packer.docker.ubuntu: Status: Image is up to date for ubuntu:xenial
learn-packer.docker.ubuntu: docker.io/library/ubuntu:xenial
==> learn-packer.docker.ubuntu: Starting docker container...
learn-packer.docker.ubuntu: Run command: docker run -v /Users/jgoldstrich/.packer.d/tmp028413911:/packer-files -d -i -t --entrypoint=/bin/sh -- ubuntu:xenial
learn-packer.docker.ubuntu: Container ID: 3d917c6fd945f94ce60fa9cee154faaeae2cdd2162f16606106e04282d747af0
==> learn-packer.docker.ubuntu: Using docker communicator to connect: 172.17.0.2
==> learn-packer.docker.ubuntu: Committing the container
learn-packer.docker.ubuntu: Image ID: sha256:b613a7407b5e1fa59a71fc631acae17a9d04f0913b1b95e3c7b82712a580189d
==> learn-packer.docker.ubuntu: Killing the container: 3d917c6fd945f94ce60fa9cee154faaeae2cdd2162f16606106e04282d747af0
==> learn-packer.docker.ubuntu: Running post-processor: (type docker-tag)
learn-packer.docker.ubuntu (docker-tag): Tagging image: sha256:b613a7407b5e1fa59a71fc631acae17a9d04f0913b1b95e3c7b82712a580189d
learn-packer.docker.ubuntu (docker-tag): Repository: learn-packer:build12
Build 'learn-packer.docker.ubuntu' finished after 3 seconds 910 milliseconds.
I am closing this is issue, please feel free to re-open if you are still experiencing this issue, or have further questions, or feel free to open a new issue.
Thanks! Jenna
Overview of the Issue
I would like to tag the image with the build variable ImageSha256, however this fails.
Reproduction Steps
packer build the buildfile below
Plugin and Packer version
Packer: 1.7.2
Simplified Packer Buildfile
Operating system and Environment details
MacOS Big Sur 11.4 Docker version 20.10.6, build 370c289 Docker Desktop 3.3.3
Log Fragments and crash.log files