From 45437f1dd3bba0b13c2ead6a4620a83dcd15b506 Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Mon, 11 Apr 2022 10:30:04 +0100 Subject: [PATCH] build: add --frontend flag Allow for specifying a custom frontend image as a command line argument using the gateway.v0 frontend. Signed-off-by: Justin Chadwell --- build/build.go | 6 ++++++ commands/build.go | 4 ++++ docs/reference/buildx_build.md | 1 + 3 files changed, 11 insertions(+) diff --git a/build/build.go b/build/build.go index ec0d20e9..75a40852 100644 --- a/build/build.go +++ b/build/build.go @@ -63,6 +63,7 @@ type Options struct { CgroupParent string Exports []client.ExportEntry ExtraHosts []string + Frontend string ImageIDFile string Labels map[string]string NetworkMode string @@ -415,6 +416,11 @@ func toSolveOpt(ctx context.Context, di DriverInfo, multiDriver bool, opt Option AllowedEntitlements: opt.Allow, } + if opt.Frontend != "" { + so.Frontend = "gateway.v0" + so.FrontendAttrs["source"] = opt.Frontend + } + if opt.CgroupParent != "" { so.FrontendAttrs["cgroup-parent"] = opt.CgroupParent } diff --git a/commands/build.go b/commands/build.go index 70a745b4..dc743617 100644 --- a/commands/build.go +++ b/commands/build.go @@ -50,6 +50,7 @@ type buildOptions struct { cgroupParent string contexts []string extraHosts []string + frontend string imageIDFile string labels []string networkMode string @@ -125,6 +126,7 @@ func runBuild(dockerCli command.Cli, in buildOptions) (err error) { BuildArgs: listToMap(in.buildArgs, true), ExtraHosts: in.extraHosts, ImageIDFile: in.imageIDFile, + Frontend: in.frontend, Labels: listToMap(in.labels, false), NetworkMode: in.networkMode, NoCache: noCache, @@ -359,6 +361,8 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command { flags.StringVar(&options.imageIDFile, "iidfile", "", "Write the image ID to the file") + flags.StringVar(&options.frontend, "frontend", "", "Set custom frontend to use for build") + flags.StringArrayVar(&options.labels, "label", []string{}, "Set metadata for an image") flags.BoolVar(&options.exportLoad, "load", false, `Shorthand for "--output=type=docker"`) diff --git a/docs/reference/buildx_build.md b/docs/reference/buildx_build.md index 94ecd614..bcd33d97 100644 --- a/docs/reference/buildx_build.md +++ b/docs/reference/buildx_build.md @@ -24,6 +24,7 @@ Start a build | [`--cache-to`](#cache-to) | `stringArray` | | Cache export destinations (e.g., `user/app:cache`, `type=local,dest=path/to/dir`) | | [`--cgroup-parent`](https://docs.docker.com/engine/reference/commandline/build/#use-a-custom-parent-cgroup---cgroup-parent) | `string` | | Optional parent cgroup for the container | | [`-f`](https://docs.docker.com/engine/reference/commandline/build/#specify-a-dockerfile--f), [`--file`](https://docs.docker.com/engine/reference/commandline/build/#specify-a-dockerfile--f) | `string` | | Name of the Dockerfile (default: `PATH/Dockerfile`) | +| `--frontend` | `string` | | Set custom frontend to use for build | | `--iidfile` | `string` | | Write the image ID to the file | | `--label` | `stringArray` | | Set metadata for an image | | [`--load`](#load) | | | Shorthand for `--output=type=docker` |