Browse code

Happy birthday Docker! cgroup-parent option for docker build. Thanks to Michael, Nathan and Jessie for their support! #42

Signed-off-by: Julien Barbier <write0@gmail.com>

Julien Barbier authored on 2015/03/27 08:14:31
Showing 5 changed files
... ...
@@ -58,6 +58,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
58 58
 	flCpuQuota := cmd.Int64([]string{"-cpu-quota"}, 0, "Limit the CPU CFS (Completely Fair Scheduler) quota")
59 59
 	flCPUSetCpus := cmd.String([]string{"-cpuset-cpus"}, "", "CPUs in which to allow execution (0-3, 0,1)")
60 60
 	flCPUSetMems := cmd.String([]string{"-cpuset-mems"}, "", "MEMs in which to allow execution (0-3, 0,1)")
61
+	flCgroupParent := cmd.String([]string{"-cgroup-parent"}, "", "Optional parent cgroup for the container")
61 62
 
62 63
 	cmd.Require(flag.Exact, 1)
63 64
 	cmd.ParseFlags(args, true)
... ...
@@ -276,6 +277,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
276 276
 	v.Set("cpuquota", strconv.FormatInt(*flCpuQuota, 10))
277 277
 	v.Set("memory", strconv.FormatInt(memory, 10))
278 278
 	v.Set("memswap", strconv.FormatInt(memorySwap, 10))
279
+	v.Set("cgroupparent", *flCgroupParent)
279 280
 
280 281
 	v.Set("dockerfile", *dockerfileName)
281 282
 
... ...
@@ -1346,6 +1346,7 @@ func (s *Server) postBuild(eng *engine.Engine, version version.Version, w http.R
1346 1346
 	buildConfig.CpuQuota = int64Value(r, "cpuquota")
1347 1347
 	buildConfig.CpuSetCpus = r.FormValue("cpusetcpus")
1348 1348
 	buildConfig.CpuSetMems = r.FormValue("cpusetmems")
1349
+	buildConfig.CgroupParent = r.FormValue("cgroupparent")
1349 1350
 
1350 1351
 	// Job cancellation. Note: not all job types support this.
1351 1352
 	if closeNotifier, ok := w.(http.CloseNotifier); ok {
... ...
@@ -121,12 +121,13 @@ type Builder struct {
121 121
 	noBaseImage    bool          // indicates that this build does not start from any base image, but is being built from an empty file system.
122 122
 
123 123
 	// Set resource restrictions for build containers
124
-	cpuSetCpus string
125
-	cpuSetMems string
126
-	cpuShares  int64
127
-	cpuQuota   int64
128
-	memory     int64
129
-	memorySwap int64
124
+	cpuSetCpus   string
125
+	cpuSetMems   string
126
+	cpuShares    int64
127
+	cpuQuota     int64
128
+	cgroupParent string
129
+	memory       int64
130
+	memorySwap   int64
130 131
 
131 132
 	cancelled <-chan struct{} // When closed, job was cancelled.
132 133
 }
... ...
@@ -546,12 +546,13 @@ func (b *Builder) create() (*daemon.Container, error) {
546 546
 	b.Config.Image = b.image
547 547
 
548 548
 	hostConfig := &runconfig.HostConfig{
549
-		CpuShares:  b.cpuShares,
550
-		CpuQuota:   b.cpuQuota,
551
-		CpusetCpus: b.cpuSetCpus,
552
-		CpusetMems: b.cpuSetMems,
553
-		Memory:     b.memory,
554
-		MemorySwap: b.memorySwap,
549
+		CpuShares:    b.cpuShares,
550
+		CpuQuota:     b.cpuQuota,
551
+		CpusetCpus:   b.cpuSetCpus,
552
+		CpusetMems:   b.cpuSetMems,
553
+		CgroupParent: b.cgroupParent,
554
+		Memory:       b.memory,
555
+		MemorySwap:   b.memorySwap,
555 556
 	}
556 557
 
557 558
 	config := *b.Config
... ...
@@ -52,6 +52,7 @@ type Config struct {
52 52
 	CpuQuota       int64
53 53
 	CpuSetCpus     string
54 54
 	CpuSetMems     string
55
+	CgroupParent   string
55 56
 	AuthConfig     *cliconfig.AuthConfig
56 57
 	ConfigFile     *cliconfig.ConfigFile
57 58
 
... ...
@@ -166,6 +167,7 @@ func Build(d *daemon.Daemon, buildConfig *Config) error {
166 166
 		cpuQuota:        buildConfig.CpuQuota,
167 167
 		cpuSetCpus:      buildConfig.CpuSetCpus,
168 168
 		cpuSetMems:      buildConfig.CpuSetMems,
169
+		cgroupParent:    buildConfig.CgroupParent,
169 170
 		memory:          buildConfig.Memory,
170 171
 		memorySwap:      buildConfig.MemorySwap,
171 172
 		cancelled:       buildConfig.WaitCancelled(),