Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Improvement: Plugin/Docker: Enables image build for specified platform #1949

Merged
merged 4 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/1949.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
plugin/docker: Enables image build for specified platform
```
19 changes: 18 additions & 1 deletion builtin/docker/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -309,6 +320,7 @@ func (b *Builder) buildWithDocker(
contextDir string,
relDockerfile string,
tag string,
platform string,
buildArgs map[string]*string,
log hclog.Logger,
) error {
Expand Down Expand Up @@ -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,
}

Expand Down
9 changes: 9 additions & 0 deletions website/content/partials/components/builder-docker.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down