buildx icon indicating copy to clipboard operation
buildx copied to clipboard

Documentation: setting array values with `bake --set`

Open zachary-povey opened this issue 4 years ago • 1 comments

Original Issue (please see edit below)

Steps to reproduce

  • Create an empty dir
  • Add a Dockerfile:
FROM centos:8
  • Add a docker-bake.hcl:
group "default" {
  targets = ["image"]
}
target "image" {
  context = "."
}
  • Run docker buildx bake --set "*.tags=image_name_1" --load image - this passes as expected and loads image_1:latest into the local docker instance
  • Run docker buildx bake --set "*.tags=image_name_1,image_name_2" --load image - this fails with:
[+] Building 0.0s (0/0)                                                                                                                                              
error: invalid tag "image_name_1,image_name_2": invalid reference format

Expected behaviour

Based on the plural name, and looking at the code, I believe the intent is for target.tags to be an array - am I using the wrong separator or is this a bug?

Edit

Ok so I realised to set multiple tags you need to specify multiple values in the command the same as you would for tag in a build invocation (https://github.com/docker/buildx/issues/396). I.e. you can get this working with:

docker buildx bake --set "*.tags=image_name_1" --set "*.tags=image_name_2" image 

For context the reason I felt so sure I needed to use a csv was because I had been successfully using a csv when setting platform via set, for example this works fine:

docker buildx bake --set "*.tags=image_name_1" --set "*.platform=linux/amd64,linux/arm64" image 

and I assumed all array type overrides would be formatted the same way.

I'm going to leave this open for now as a question and/or documentation issue. At the moment the bake docs don't give any examples of setting array values and as they only give a single type for --set (stringArray) don't really explain the type/format for the individual overrides - this seems important especially as there does seem to be differences (e.g. platform vs tag).

zachary-povey avatar Dec 02 '21 14:12 zachary-povey

I particularly had a hard time to get around it as well... It would be great if this is well documented with examples...

marcellodesales avatar Jan 17 '22 21:01 marcellodesales

Similar comment regarding docker buildx bake -f, where -f takes a stringArray. I want to pass in multiple docker-bake.json files.

pongnguy avatar Jan 07 '23 05:01 pongnguy

In the a docker-bake.hcl file, we would set the tags like this:

# docker-bake.hcl
target "webapp-dev" {
  dockerfile = "Dockerfile.webapp"
  tags = ["docker.io/username/webapp:latest"]
}

Where tags takes an array. So, I expected the arg to --set to accept an array, e.g. docker buildx bake --set 'webapp-dev.tags=[foo/bar:latest,foo/bar:v1.2.3]', that didn't work and searching I found this issue.

I would have expected repeating args, that the last arg would override the previous args. I think it makes more sense that the arg is an array, like the HCL syntax.

berney avatar May 10 '23 11:05 berney

It turns out shell brace expansion is a pretty good fit here, so maybe we can document that? e.g. docker buildx bake all --set=\*.tags=foo/bar:{baz,qux}.

neersighted avatar May 17 '23 14:05 neersighted