From d9bc5b25fce92786dc52dbb670b88795c2b8068c Mon Sep 17 00:00:00 2001 From: Shirley Xiaolin Xu Date: Wed, 28 Jul 2021 15:19:54 -0700 Subject: [PATCH 1/4] add platform flag to build --- builtin/docker/builder.go | 19 ++++++++++++++++++- .../partials/components/builder-docker.mdx | 9 +++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/builtin/docker/builder.go b/builtin/docker/builder.go index fe302747c9a..500373fdfb8 100644 --- a/builtin/docker/builder.go +++ b/builtin/docker/builder.go @@ -55,6 +55,9 @@ type BuilderConfig struct { // The name/path to the Dockerfile if it is not the root of the project Dockerfile string `hcl:"dockerfile,optional"` + // Controls the passing of platform flag variables + Platform string `hcl:"platform,optional"` + // Controls the passing of build time variables BuildArgs map[string]*string `hcl:"build_args,optional"` @@ -138,6 +141,14 @@ build { ), ) + doc.SetField( + "platform", + "set platform if server is multi-platform capable", + docs.Summary( + "Recommended usage with buildkit enabled.", + ), + ) + doc.SetField( "context", "Build context path", @@ -253,7 +264,7 @@ func (b *Builder) Build( step.Done() step = nil if err := b.buildWithDocker( - ctx, ui, sg, cli, contextDir, relDockerfile, result.Name(), b.config.BuildArgs, log, + ctx, ui, sg, cli, contextDir, relDockerfile, result.Name(), b.config.Platform, b.config.BuildArgs, log, ); err != nil { return nil, err } @@ -309,6 +320,7 @@ func (b *Builder) buildWithDocker( contextDir string, relDockerfile string, tag string, + platform string, buildArgs map[string]*string, log hclog.Logger, ) error { @@ -347,11 +359,16 @@ func (b *Builder) buildWithDocker( return err } + if platform != "" && ver != types.BuilderBuildKit { + return status.Errorf(codes.InvalidArgument, "buildkit is required to use platform option") + } + buildOpts := types.ImageBuildOptions{ Version: ver, Dockerfile: relDockerfile, Tags: []string{tag}, Remove: true, + Platform: platform, BuildArgs: buildArgs, } diff --git a/website/content/partials/components/builder-docker.mdx b/website/content/partials/components/builder-docker.mdx index feb4a5876c6..06b8b8eb596 100644 --- a/website/content/partials/components/builder-docker.mdx +++ b/website/content/partials/components/builder-docker.mdx @@ -86,6 +86,15 @@ Set this when the Dockerfile is not APP-PATH/Dockerfile. - Type: **string** - **Optional** +#### platform + +Set platform if server is multi-platform capable. + +Recommended usage with buildkit enabled. + +- Type: **string** +- **Optional** + ### Output Attributes Output attributes can be used in your `waypoint.hcl` as [variables](/docs/waypoint-hcl/variables) via [`artifact`](/docs/waypoint-hcl/variables/artifact) or [`deploy`](/docs/waypoint-hcl/variables/deploy). From 670901a17e78932c8dff7279981f7fd2fc3c0824 Mon Sep 17 00:00:00 2001 From: Shirley Xiaolin Xu Date: Wed, 28 Jul 2021 15:38:49 -0700 Subject: [PATCH 2/4] changelog --- .changelog/1949.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/1949.txt diff --git a/.changelog/1949.txt b/.changelog/1949.txt new file mode 100644 index 00000000000..fb20ce048e5 --- /dev/null +++ b/.changelog/1949.txt @@ -0,0 +1,3 @@ +```release-note:feature +plugin/docker: Enables image build for specified platform +``` From 70ac5a924fa0c0b04ec772b975e3f8814f18faeb Mon Sep 17 00:00:00 2001 From: Shirley Xiaolin Xu Date: Mon, 2 Aug 2021 16:19:14 -0700 Subject: [PATCH 3/4] wording changes --- .changelog/1949.txt | 2 +- builtin/docker/builder.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.changelog/1949.txt b/.changelog/1949.txt index fb20ce048e5..4db19a37950 100644 --- a/.changelog/1949.txt +++ b/.changelog/1949.txt @@ -1,3 +1,3 @@ -```release-note:feature +```release-note:improvement plugin/docker: Enables image build for specified platform ``` diff --git a/builtin/docker/builder.go b/builtin/docker/builder.go index 500373fdfb8..eebbc86d90d 100644 --- a/builtin/docker/builder.go +++ b/builtin/docker/builder.go @@ -143,9 +143,9 @@ build { doc.SetField( "platform", - "set platform if server is multi-platform capable", + "set target platform to build container if server is multi-platform capable", docs.Summary( - "Recommended usage with buildkit enabled.", + "Must enable Docker buildkit to use the 'platform' flag.", ), ) From 7ca6b52e9913021034a07e744eda5e09315b6131 Mon Sep 17 00:00:00 2001 From: Shirley Xiaolin Xu Date: Tue, 3 Aug 2021 10:31:54 -0700 Subject: [PATCH 4/4] update website docs --- website/content/partials/components/builder-docker.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/content/partials/components/builder-docker.mdx b/website/content/partials/components/builder-docker.mdx index 06b8b8eb596..06802da5d9d 100644 --- a/website/content/partials/components/builder-docker.mdx +++ b/website/content/partials/components/builder-docker.mdx @@ -88,9 +88,9 @@ Set this when the Dockerfile is not APP-PATH/Dockerfile. #### platform -Set platform if server is multi-platform capable. +Set target platform to build container if server is multi-platform capable. -Recommended usage with buildkit enabled. +Must enable Docker buildkit to use the 'platform' flag. - Type: **string** - **Optional**