From 4fa4284ac0d4b5f1f9c5a59d405a4f728a439de7 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Thu, 28 Oct 2021 10:39:25 +0200 Subject: [PATCH] build: add cgroup-parent support Signed-off-by: CrazyMax --- build/build.go | 41 ++++++++++++++++++--------------- commands/build.go | 42 +++++++++++++++++----------------- docs/reference/buildx_build.md | 1 + 3 files changed, 44 insertions(+), 40 deletions(-) diff --git a/build/build.go b/build/build.go index 14fa421d7152..965cd0b8fb61 100644 --- a/build/build.go +++ b/build/build.go @@ -51,23 +51,24 @@ var ( type Options struct { Inputs Inputs - Allow []entitlements.Entitlement - BuildArgs map[string]string - CacheFrom []client.CacheOptionsEntry - CacheTo []client.CacheOptionsEntry - Exports []client.ExportEntry - ExtraHosts []string - ImageIDFile string - Labels map[string]string - NetworkMode string - NoCache bool - Platforms []specs.Platform - Pull bool - Session []session.Attachable - ShmSize opts.MemBytes - Tags []string - Target string - Ulimits *opts.UlimitOpt + Allow []entitlements.Entitlement + BuildArgs map[string]string + CacheFrom []client.CacheOptionsEntry + CacheTo []client.CacheOptionsEntry + CgroupParent string + Exports []client.ExportEntry + ExtraHosts []string + ImageIDFile string + Labels map[string]string + NetworkMode string + NoCache bool + Platforms []specs.Platform + Pull bool + Session []session.Attachable + ShmSize opts.MemBytes + Tags []string + Target string + Ulimits *opts.UlimitOpt } type Inputs struct { @@ -391,8 +392,10 @@ func toSolveOpt(ctx context.Context, d driver.Driver, multiDriver bool, opt Opti } so := client.SolveOpt{ - Frontend: "dockerfile.v0", - FrontendAttrs: map[string]string{}, + Frontend: "dockerfile.v0", + FrontendAttrs: map[string]string{ + "cgroup-parent": opt.CgroupParent, + }, LocalDirs: map[string]string{}, CacheExports: cacheTo, CacheImports: cacheFrom, diff --git a/commands/build.go b/commands/build.go index 041ab643c32c..8b0be4e4ffae 100644 --- a/commands/build.go +++ b/commands/build.go @@ -33,23 +33,24 @@ type buildOptions struct { contextPath string dockerfileName string - allow []string - buildArgs []string - cacheFrom []string - cacheTo []string - extraHosts []string - imageIDFile string - labels []string - networkMode string - outputs []string - platforms []string - quiet bool - secrets []string - shmSize dockeropts.MemBytes - ssh []string - tags []string - target string - ulimits *dockeropts.UlimitOpt + allow []string + buildArgs []string + cacheFrom []string + cacheTo []string + cgroupParent string + extraHosts []string + imageIDFile string + labels []string + networkMode string + outputs []string + platforms []string + quiet bool + secrets []string + shmSize dockeropts.MemBytes + ssh []string + tags []string + target string + ulimits *dockeropts.UlimitOpt commonOptions } @@ -287,6 +288,9 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command { flags.StringArrayVar(&options.cacheTo, "cache-to", []string{}, "Cache export destinations (e.g., `user/app:cache`, `type=local,dest=path/to/dir`)") + flags.StringVar(&options.cgroupParent, "cgroup-parent", "", "Optional parent cgroup for the container") + flags.SetAnnotation("cgroup-parent", "docs.external.url", []string{"https://docs.docker.com/engine/reference/commandline/build/#use-a-custom-parent-cgroup---cgroup-parent"}) + flags.StringVarP(&options.dockerfileName, "file", "f", "", "Name of the Dockerfile (default: `PATH/Dockerfile`)") flags.SetAnnotation("file", "docs.external.url", []string{"https://docs.docker.com/engine/reference/commandline/build/#specify-a-dockerfile--f"}) @@ -326,10 +330,6 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command { var ignoreBool bool var ignoreInt int64 - flags.StringVar(&ignore, "cgroup-parent", "", "Optional parent cgroup for the container") - flags.MarkHidden("cgroup-parent") - //flags.SetAnnotation("cgroup-parent", "flag-warn", []string{"cgroup-parent is not implemented."}) - flags.BoolVar(&ignoreBool, "compress", false, "Compress the build context using gzip") flags.MarkHidden("compress") diff --git a/docs/reference/buildx_build.md b/docs/reference/buildx_build.md index 6290e52a272d..7d139cd68741 100644 --- a/docs/reference/buildx_build.md +++ b/docs/reference/buildx_build.md @@ -21,6 +21,7 @@ Start a build | `--builder string` | Override the configured builder instance | | [`--cache-from stringArray`](#cache-from) | External cache sources (e.g., `user/app:cache`, `type=local,src=path/to/dir`) | | [`--cache-to stringArray`](#cache-to) | Cache export destinations (e.g., `user/app:cache`, `type=local,dest=path/to/dir`) | +| [`--cgroup-parent string`](https://docs.docker.com/engine/reference/commandline/build/#use-a-custom-parent-cgroup---cgroup-parent) | Optional parent cgroup for the container | | [`-f`](https://docs.docker.com/engine/reference/commandline/build/#specify-a-dockerfile--f), [`--file string`](https://docs.docker.com/engine/reference/commandline/build/#specify-a-dockerfile--f) | Name of the Dockerfile (default: `PATH/Dockerfile`) | | `--iidfile string` | Write the image ID to the file | | `--label stringArray` | Set metadata for an image |