From 2caffb12c7b78aca96028f43d6cef8c060cc3e77 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Fri, 15 Mar 2019 19:09:39 -0700 Subject: [PATCH] build: enable platform flag for build if buildkit Signed-off-by: Tonis Tiigi --- cli/command/image/build.go | 11 ++++++++++- docs/reference/commandline/cli.md | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cli/command/image/build.go b/cli/command/image/build.go index a28e2b3c19..8f925cc0b0 100644 --- a/cli/command/image/build.go +++ b/cli/command/image/build.go @@ -146,7 +146,16 @@ func NewBuildCommand(dockerCli command.Cli) *cobra.Command { flags.StringVar(&options.imageIDFile, "iidfile", "", "Write the image ID to the file") command.AddTrustVerificationFlags(flags, &options.untrusted, dockerCli.ContentTrustEnabled()) - command.AddPlatformFlag(flags, &options.platform) + + flags.StringVar(&options.platform, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable") + // Platform is not experimental when BuildKit is used + buildkitEnabled, err := command.BuildKitEnabled(dockerCli.ServerInfo()) + if err == nil && buildkitEnabled { + flags.SetAnnotation("platform", "version", []string{"1.38"}) + } else { + flags.SetAnnotation("platform", "version", []string{"1.32"}) + flags.SetAnnotation("platform", "experimental", nil) + } flags.BoolVar(&options.squash, "squash", false, "Squash newly built layers into a single new layer") flags.SetAnnotation("squash", "experimental", nil) diff --git a/docs/reference/commandline/cli.md b/docs/reference/commandline/cli.md index 9c1049b493..32fed43118 100644 --- a/docs/reference/commandline/cli.md +++ b/docs/reference/commandline/cli.md @@ -80,6 +80,7 @@ by the `docker` command line: printed. This may become the default in a future release, at which point this environment-variable is removed. * `DOCKER_TMPDIR` Location for temporary Docker files. * `DOCKER_CONTEXT` Specify the context to use (overrides DOCKER_HOST env var and default context set with "docker context use") +* `DOCKER_DEFAULT_PLATFORM` Specify the default platform for the commands that take the `--platform` flag. Because Docker is developed using Go, you can also use any environment variables used by the Go runtime. In particular, you may find these useful: