diff --git a/README.md b/README.md index 2d1e25ea..a619c70e 100644 --- a/README.md +++ b/README.md @@ -614,6 +614,59 @@ target "db" { Complete list of valid target fields: args, cache-from, cache-to, context, dockerfile, inherits, labels, no-cache, output, platform, pull, secrets, ssh, tags, target +#### HCL variable interpolation + +Similar to how Terraform provides a way to +[define variables](https://www.terraform.io/docs/configuration/variables.html#declaring-an-input-variable), +the HCL file format also supports variable block definitions. These can be used +to define variables with values provided by the current environment or a +default value when unset. + + +Example of using interpolation to tag an image with the git sha: + +``` +$ cat <<'EOF' > docker-bake.hcl +variable "TAG" { + default = "latest" +} + +group "default" { + targets = ["webapp"] +} + +target "webapp" { + tags = ["docker.io/username/webapp:${TAG}"] +} +EOF + +$ docker buildx bake --print webapp +{ + "target": { + "webapp": { + "context": ".", + "dockerfile": "Dockerfile", + "tags": [ + "docker.io/username/webapp:latest" + ] + } + } +} + +$ TAG=$(git rev-parse --short HEAD) docker buildx bake --print webapp +{ + "target": { + "webapp": { + "context": ".", + "dockerfile": "Dockerfile", + "tags": [ + "docker.io/username/webapp:985e9e9" + ] + } + } +} +``` + ### `buildx imagetools create [OPTIONS] [SOURCE] [SOURCE...]` Imagetools contains commands for working with manifest lists in the registry. These commands are useful for inspecting multi-platform build results.