From 55a3ce606f133220bebde5d19c618d0c56e652a4 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Thu, 2 Sep 2021 23:06:00 +0200 Subject: [PATCH] Built-in variable `BAKE_LOCAL_PLATFORM` Signed-off-by: CrazyMax --- commands/bake.go | 6 +++++- docs/reference/buildx_bake.md | 7 +++++++ docs/reference/docker_buildx_bake.yaml | 7 +++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/commands/bake.go b/commands/bake.go index 4a2e168b..48e9684b 100644 --- a/commands/bake.go +++ b/commands/bake.go @@ -6,6 +6,7 @@ import ( "fmt" "os" + "github.com/containerd/containerd/platforms" "github.com/docker/buildx/bake" "github.com/docker/buildx/build" "github.com/docker/buildx/util/progress" @@ -106,7 +107,10 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions) (err error } t, g, err := bake.ReadTargets(ctx, files, targets, overrides, map[string]string{ - "BAKE_CMD_CONTEXT": cmdContext, + // Don't forget to update documentation if you add a new + // built-in variable: docs/reference/buildx_bake.md#built-in-variables + "BAKE_CMD_CONTEXT": cmdContext, + "BAKE_LOCAL_PLATFORM": platforms.DefaultString(), }) if err != nil { return err diff --git a/docs/reference/buildx_bake.md b/docs/reference/buildx_bake.md index 72267790..23c9107e 100644 --- a/docs/reference/buildx_bake.md +++ b/docs/reference/buildx_bake.md @@ -861,3 +861,10 @@ Complete list of valid fields for `x-bake`: `tags`, `cache-from`, `cache-to`, `secret`, `ssh`, `platforms`, `output`, `pull`, `no-cache` + +### Built-in variables + +* `BAKE_CMD_CONTEXT` can be used to access the main `context` for bake command +from a bake file that has been [imported remotely](#file). +* `BAKE_LOCAL_PLATFORM` returns the current platform's default platform +specification (e.g. `linux/amd64`). diff --git a/docs/reference/docker_buildx_bake.yaml b/docs/reference/docker_buildx_bake.yaml index c638edd4..d0a624e9 100644 --- a/docs/reference/docker_buildx_bake.yaml +++ b/docs/reference/docker_buildx_bake.yaml @@ -931,6 +931,13 @@ examples: |- `tags`, `cache-from`, `cache-to`, `secret`, `ssh`, `platforms`, `output`, `pull`, `no-cache` + + ### Built-in variables + + * `BAKE_CMD_CONTEXT` can be used to access the main `context` for bake command + from a bake file that has been [imported remotely](#file). + * `BAKE_LOCAL_PLATFORM` returns the current platform's default platform + specification (e.g. `linux/amd64`). deprecated: false experimental: false experimentalcli: false