mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-11-01 00:23:56 +08:00 
			
		
		
		
	Add example of interpolation to the README
Signed-off-by: Patrick Van Stee <patrick@vanstee.me>
This commit is contained in:
		
							
								
								
									
										53
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										53
									
								
								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. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Patrick Van Stee
					Patrick Van Stee