Skip to content

Commit 5e25191

Browse files
authored
Merge pull request #814 from crazy-max/cgroup-parent
build: add cgroup-parent support
2 parents 81cf206 + dd15969 commit 5e25191

File tree

3 files changed

+46
-43
lines changed

3 files changed

+46
-43
lines changed

build/build.go

+24-22
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,26 @@ var (
4949
)
5050

5151
type Options struct {
52-
Inputs Inputs
53-
Tags []string
54-
Labels map[string]string
55-
BuildArgs map[string]string
56-
Pull bool
57-
ImageIDFile string
58-
ExtraHosts []string
59-
NetworkMode string
60-
ShmSize opts.MemBytes
61-
Ulimits *opts.UlimitOpt
62-
63-
NoCache bool
64-
Target string
65-
Platforms []specs.Platform
66-
Exports []client.ExportEntry
67-
Session []session.Attachable
68-
69-
CacheFrom []client.CacheOptionsEntry
70-
CacheTo []client.CacheOptionsEntry
71-
72-
Allow []entitlements.Entitlement
73-
// DockerTarget
52+
Inputs Inputs
53+
54+
Allow []entitlements.Entitlement
55+
BuildArgs map[string]string
56+
CacheFrom []client.CacheOptionsEntry
57+
CacheTo []client.CacheOptionsEntry
58+
CgroupParent string
59+
Exports []client.ExportEntry
60+
ExtraHosts []string
61+
ImageIDFile string
62+
Labels map[string]string
63+
NetworkMode string
64+
NoCache bool
65+
Platforms []specs.Platform
66+
Pull bool
67+
Session []session.Attachable
68+
ShmSize opts.MemBytes
69+
Tags []string
70+
Target string
71+
Ulimits *opts.UlimitOpt
7472
}
7573

7674
type Inputs struct {
@@ -402,6 +400,10 @@ func toSolveOpt(ctx context.Context, d driver.Driver, multiDriver bool, opt Opti
402400
AllowedEntitlements: opt.Allow,
403401
}
404402

403+
if opt.CgroupParent != "" {
404+
so.FrontendAttrs["cgroup-parent"] = opt.CgroupParent
405+
}
406+
405407
if v, ok := opt.BuildArgs["BUILDKIT_MULTI_PLATFORM"]; ok {
406408
if v, _ := strconv.ParseBool(v); v {
407409
so.FrontendAttrs["multi-platform"] = "true"

commands/build.go

+21-21
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,24 @@ type buildOptions struct {
3333
contextPath string
3434
dockerfileName string
3535

36-
allow []string
37-
buildArgs []string
38-
cacheFrom []string
39-
cacheTo []string
40-
extraHosts []string
41-
imageIDFile string
42-
labels []string
43-
networkMode string
44-
outputs []string
45-
platforms []string
46-
quiet bool
47-
secrets []string
48-
shmSize dockeropts.MemBytes
49-
ssh []string
50-
tags []string
51-
target string
52-
ulimits *dockeropts.UlimitOpt
36+
allow []string
37+
buildArgs []string
38+
cacheFrom []string
39+
cacheTo []string
40+
cgroupParent string
41+
extraHosts []string
42+
imageIDFile string
43+
labels []string
44+
networkMode string
45+
outputs []string
46+
platforms []string
47+
quiet bool
48+
secrets []string
49+
shmSize dockeropts.MemBytes
50+
ssh []string
51+
tags []string
52+
target string
53+
ulimits *dockeropts.UlimitOpt
5354
commonOptions
5455
}
5556

@@ -287,6 +288,9 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
287288

288289
flags.StringArrayVar(&options.cacheTo, "cache-to", []string{}, "Cache export destinations (e.g., `user/app:cache`, `type=local,dest=path/to/dir`)")
289290

291+
flags.StringVar(&options.cgroupParent, "cgroup-parent", "", "Optional parent cgroup for the container")
292+
flags.SetAnnotation("cgroup-parent", "docs.external.url", []string{"https://docs.docker.com/engine/reference/commandline/build/#use-a-custom-parent-cgroup---cgroup-parent"})
293+
290294
flags.StringVarP(&options.dockerfileName, "file", "f", "", "Name of the Dockerfile (default: `PATH/Dockerfile`)")
291295
flags.SetAnnotation("file", "docs.external.url", []string{"https://docs.docker.com/engine/reference/commandline/build/#specify-a-dockerfile--f"})
292296

@@ -326,10 +330,6 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
326330
var ignoreBool bool
327331
var ignoreInt int64
328332

329-
flags.StringVar(&ignore, "cgroup-parent", "", "Optional parent cgroup for the container")
330-
flags.MarkHidden("cgroup-parent")
331-
//flags.SetAnnotation("cgroup-parent", "flag-warn", []string{"cgroup-parent is not implemented."})
332-
333333
flags.BoolVar(&ignoreBool, "compress", false, "Compress the build context using gzip")
334334
flags.MarkHidden("compress")
335335

docs/reference/buildx_build.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Start a build
2121
| `--builder string` | Override the configured builder instance |
2222
| [`--cache-from stringArray`](#cache-from) | External cache sources (e.g., `user/app:cache`, `type=local,src=path/to/dir`) |
2323
| [`--cache-to stringArray`](#cache-to) | Cache export destinations (e.g., `user/app:cache`, `type=local,dest=path/to/dir`) |
24+
| [`--cgroup-parent string`](https://docs.docker.com/engine/reference/commandline/build/#use-a-custom-parent-cgroup---cgroup-parent) | Optional parent cgroup for the container |
2425
| [`-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`) |
2526
| `--iidfile string` | Write the image ID to the file |
2627
| `--label stringArray` | Set metadata for an image |

0 commit comments

Comments
 (0)