Open Pesa opened 5 months ago
You can use the matrix feature for this purpose, like:
target "default" {
name = "build-${tgt}"
matrix = {
tgt = ["foo", "bar"]
}
dockerfile = "Dockerfile.${tgt}"
tags = ["my/${tgt}:latest"]
}
@crazy-max sorry, I'm not sure I understand. How would I combine the matrix with the tags generated by docker/metadata-action
? If I set:
inherits = ["docker-metadata-action"]
isn't that going to overwrite the whole tag my/${tgt}:latest
?
Basically, I would need something like this:
// docker-bake.hcl
target "default" {
name = "${tgt}-${version}"
matrix = {
tgt = ["foo", "bar"]
version = [...list of version tags generated by metadata-action...] // ???
}
dockerfile = "Dockerfile.${tgt}"
tags = ["my/${tgt}:${version}"]
}
And then I'd call metadata-action
with an empty images
input so that it generates raw version tags without base name.
Description
Let's say I have the following
docker-bake.hcl
:The tags listed above function a bit like defaults, i.e., they're used when I run bake locally for testing. On GitHub Actions, however, I'd like to use
docker/metadata-action
to generate a list of tags based on various criteria (semver, date, etc...). These generated tags should replace the:latest
tag fromdocker-bake.hcl
, but I still want to keep the base name of the two images (my/foo
andmy/bar
).This would be trivial to accomplish with a single target (using the
images
input), but I didn't find a way to do it for multiple targets, where each target has a distinct image name.Apologies if I missed something obvious (seems odd that this use case isn't already supported, since the whole point of bake is orchestrating the build of multiple targets).