diff --git a/.changelog/1949.txt b/.changelog/1949.txt new file mode 100644 index 00000000000..4db19a37950 --- /dev/null +++ b/.changelog/1949.txt @@ -0,0 +1,3 @@ +```release-note:improvement +plugin/docker: Enables image build for specified platform +``` diff --git a/builtin/docker/builder.go b/builtin/docker/builder.go index fe302747c9a..eebbc86d90d 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 target platform to build container if server is multi-platform capable", + docs.Summary( + "Must enable Docker buildkit to use the 'platform' flag.", + ), + ) + 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..06802da5d9d 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 target platform to build container if server is multi-platform capable. + +Must enable Docker buildkit to use the 'platform' flag. + +- 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).