Browse code

update vendor

Signed-off-by: Anda Xu <anda.xu@docker.com>

Anda Xu authored on 2018/09/07 03:50:41
Showing 15 changed files
... ...
@@ -10,7 +10,7 @@ import (
10 10
 	"github.com/moby/buildkit/executor"
11 11
 )
12 12
 
13
-func newExecutor(_ string, _ libnetwork.NetworkController) (executor.Executor, error) {
13
+func newExecutor(_, _ string, _ libnetwork.NetworkController) (executor.Executor, error) {
14 14
 	return &winExecutor{}, nil
15 15
 }
16 16
 
... ...
@@ -46,6 +46,7 @@ import (
46 46
 type Opt struct {
47 47
 	ID                string
48 48
 	Labels            map[string]string
49
+	GCPolicy          []client.PruneInfo
49 50
 	SessionManager    *session.Manager
50 51
 	MetadataStore     *metadata.Store
51 52
 	Executor          executor.Executor
... ...
@@ -130,6 +131,11 @@ func (w *Worker) Platforms() []ocispec.Platform {
130 130
 	return []ocispec.Platform{platforms.DefaultSpec()}
131 131
 }
132 132
 
133
+// GCPolicy returns automatic GC Policy
134
+func (w *Worker) GCPolicy() []client.PruneInfo {
135
+	return w.Opt.GCPolicy
136
+}
137
+
133 138
 // LoadRef loads a reference by ID
134 139
 func (w *Worker) LoadRef(id string) (cache.ImmutableRef, error) {
135 140
 	return w.CacheManager.Get(context.TODO(), id)
... ...
@@ -176,8 +182,8 @@ func (w *Worker) DiskUsage(ctx context.Context, opt client.DiskUsageInfo) ([]*cl
176 176
 }
177 177
 
178 178
 // Prune deletes reclaimable build cache
179
-func (w *Worker) Prune(ctx context.Context, ch chan client.UsageInfo, info client.PruneInfo) error {
180
-	return w.CacheManager.Prune(ctx, ch, info)
179
+func (w *Worker) Prune(ctx context.Context, ch chan client.UsageInfo, info ...client.PruneInfo) error {
180
+	return w.CacheManager.Prune(ctx, ch, info...)
181 181
 }
182 182
 
183 183
 // Exporter returns exporter by name
... ...
@@ -259,7 +259,7 @@ type routerOptions struct {
259 259
 	cluster        *cluster.Cluster
260 260
 }
261 261
 
262
-func newRouterOptions(config *config.Config, daemon *daemon.Daemon) (routerOptions, error) {
262
+func newRouterOptions(config *config.Config, d *daemon.Daemon) (routerOptions, error) {
263 263
 	opts := routerOptions{}
264 264
 	sm, err := session.NewManager()
265 265
 	if err != nil {
... ...
@@ -280,7 +280,7 @@ func newRouterOptions(config *config.Config, daemon *daemon.Daemon) (routerOptio
280 280
 		return opts, errors.Wrap(err, "failed to create fscache")
281 281
 	}
282 282
 
283
-	manager, err := dockerfile.NewBuildManager(daemon.BuilderBackend(), sm, buildCache, daemon.IdentityMapping())
283
+	manager, err := dockerfile.NewBuildManager(d.BuilderBackend(), sm, buildCache, d.IdentityMapping())
284 284
 	if err != nil {
285 285
 		return opts, err
286 286
 	}
... ...
@@ -298,15 +298,15 @@ func newRouterOptions(config *config.Config, daemon *daemon.Daemon) (routerOptio
298 298
 	bk, err := buildkit.New(buildkit.Opt{
299 299
 		SessionManager:      sm,
300 300
 		Root:                filepath.Join(config.Root, "buildkit"),
301
-		Dist:                daemon.DistributionServices(),
302
-		NetworkController:   daemon.NetworkController(),
301
+		Dist:                d.DistributionServices(),
302
+		NetworkController:   d.NetworkController(),
303 303
 		DefaultCgroupParent: cgroupParent,
304 304
 	})
305 305
 	if err != nil {
306 306
 		return opts, err
307 307
 	}
308 308
 
309
-	bb, err := buildbackend.NewBackend(daemon.ImageService(), manager, buildCache, bk)
309
+	bb, err := buildbackend.NewBackend(d.ImageService(), manager, buildCache, bk)
310 310
 	if err != nil {
311 311
 		return opts, errors.Wrap(err, "failed to create buildmanager")
312 312
 	}
... ...
@@ -315,8 +315,8 @@ func newRouterOptions(config *config.Config, daemon *daemon.Daemon) (routerOptio
315 315
 		buildBackend:   bb,
316 316
 		buildCache:     buildCache,
317 317
 		buildkit:       bk,
318
-		features:       daemon.Features(),
319
-		daemon:         daemon,
318
+		features:       d.Features(),
319
+		daemon:         d,
320 320
 	}, nil
321 321
 }
322 322
 
... ...
@@ -26,7 +26,7 @@ github.com/imdario/mergo v0.3.6
26 26
 golang.org/x/sync 1d60e4601c6fd243af51cc01ddf169918a5407ca
27 27
 
28 28
 # buildkit
29
-github.com/moby/buildkit 6812dac65e0440bb75affce1fb2175e640edc15d
29
+github.com/moby/buildkit a9fe50acf16dd05d1f9877b27068884543ad7a1f
30 30
 github.com/tonistiigi/fsutil b19464cd1b6a00773b4f2eb7acf9c30426f9df42
31 31
 github.com/grpc-ecosystem/grpc-opentracing 8e809c8a86450a29b90dcc9efbf062d0fe6d9746
32 32
 github.com/opentracing/opentracing-go 1361b9cd60be79c4c3a7fa9841b3c132e40066a7
... ...
@@ -9,6 +9,7 @@
9 9
 
10 10
 	It has these top-level messages:
11 11
 		WorkerRecord
12
+		GCPolicy
12 13
 */
13 14
 package moby_buildkit_v1_types
14 15
 
... ...
@@ -35,6 +36,7 @@ type WorkerRecord struct {
35 35
 	ID        string            `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"`
36 36
 	Labels    map[string]string `protobuf:"bytes,2,rep,name=Labels" json:"Labels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
37 37
 	Platforms []pb.Platform     `protobuf:"bytes,3,rep,name=platforms" json:"platforms"`
38
+	GCPolicy  []*GCPolicy       `protobuf:"bytes,4,rep,name=GCPolicy" json:"GCPolicy,omitempty"`
38 39
 }
39 40
 
40 41
 func (m *WorkerRecord) Reset()                    { *m = WorkerRecord{} }
... ...
@@ -63,8 +65,56 @@ func (m *WorkerRecord) GetPlatforms() []pb.Platform {
63 63
 	return nil
64 64
 }
65 65
 
66
+func (m *WorkerRecord) GetGCPolicy() []*GCPolicy {
67
+	if m != nil {
68
+		return m.GCPolicy
69
+	}
70
+	return nil
71
+}
72
+
73
+type GCPolicy struct {
74
+	All          bool     `protobuf:"varint,1,opt,name=all,proto3" json:"all,omitempty"`
75
+	KeepDuration int64    `protobuf:"varint,2,opt,name=keepDuration,proto3" json:"keepDuration,omitempty"`
76
+	KeepBytes    int64    `protobuf:"varint,3,opt,name=keepBytes,proto3" json:"keepBytes,omitempty"`
77
+	Filters      []string `protobuf:"bytes,4,rep,name=filters" json:"filters,omitempty"`
78
+}
79
+
80
+func (m *GCPolicy) Reset()                    { *m = GCPolicy{} }
81
+func (m *GCPolicy) String() string            { return proto.CompactTextString(m) }
82
+func (*GCPolicy) ProtoMessage()               {}
83
+func (*GCPolicy) Descriptor() ([]byte, []int) { return fileDescriptorWorker, []int{1} }
84
+
85
+func (m *GCPolicy) GetAll() bool {
86
+	if m != nil {
87
+		return m.All
88
+	}
89
+	return false
90
+}
91
+
92
+func (m *GCPolicy) GetKeepDuration() int64 {
93
+	if m != nil {
94
+		return m.KeepDuration
95
+	}
96
+	return 0
97
+}
98
+
99
+func (m *GCPolicy) GetKeepBytes() int64 {
100
+	if m != nil {
101
+		return m.KeepBytes
102
+	}
103
+	return 0
104
+}
105
+
106
+func (m *GCPolicy) GetFilters() []string {
107
+	if m != nil {
108
+		return m.Filters
109
+	}
110
+	return nil
111
+}
112
+
66 113
 func init() {
67 114
 	proto.RegisterType((*WorkerRecord)(nil), "moby.buildkit.v1.types.WorkerRecord")
115
+	proto.RegisterType((*GCPolicy)(nil), "moby.buildkit.v1.types.GCPolicy")
68 116
 }
69 117
 func (m *WorkerRecord) Marshal() (dAtA []byte, err error) {
70 118
 	size := m.Size()
... ...
@@ -116,6 +166,71 @@ func (m *WorkerRecord) MarshalTo(dAtA []byte) (int, error) {
116 116
 			i += n
117 117
 		}
118 118
 	}
119
+	if len(m.GCPolicy) > 0 {
120
+		for _, msg := range m.GCPolicy {
121
+			dAtA[i] = 0x22
122
+			i++
123
+			i = encodeVarintWorker(dAtA, i, uint64(msg.Size()))
124
+			n, err := msg.MarshalTo(dAtA[i:])
125
+			if err != nil {
126
+				return 0, err
127
+			}
128
+			i += n
129
+		}
130
+	}
131
+	return i, nil
132
+}
133
+
134
+func (m *GCPolicy) Marshal() (dAtA []byte, err error) {
135
+	size := m.Size()
136
+	dAtA = make([]byte, size)
137
+	n, err := m.MarshalTo(dAtA)
138
+	if err != nil {
139
+		return nil, err
140
+	}
141
+	return dAtA[:n], nil
142
+}
143
+
144
+func (m *GCPolicy) MarshalTo(dAtA []byte) (int, error) {
145
+	var i int
146
+	_ = i
147
+	var l int
148
+	_ = l
149
+	if m.All {
150
+		dAtA[i] = 0x8
151
+		i++
152
+		if m.All {
153
+			dAtA[i] = 1
154
+		} else {
155
+			dAtA[i] = 0
156
+		}
157
+		i++
158
+	}
159
+	if m.KeepDuration != 0 {
160
+		dAtA[i] = 0x10
161
+		i++
162
+		i = encodeVarintWorker(dAtA, i, uint64(m.KeepDuration))
163
+	}
164
+	if m.KeepBytes != 0 {
165
+		dAtA[i] = 0x18
166
+		i++
167
+		i = encodeVarintWorker(dAtA, i, uint64(m.KeepBytes))
168
+	}
169
+	if len(m.Filters) > 0 {
170
+		for _, s := range m.Filters {
171
+			dAtA[i] = 0x22
172
+			i++
173
+			l = len(s)
174
+			for l >= 1<<7 {
175
+				dAtA[i] = uint8(uint64(l)&0x7f | 0x80)
176
+				l >>= 7
177
+				i++
178
+			}
179
+			dAtA[i] = uint8(l)
180
+			i++
181
+			i += copy(dAtA[i:], s)
182
+		}
183
+	}
119 184
 	return i, nil
120 185
 }
121 186
 
... ...
@@ -149,6 +264,33 @@ func (m *WorkerRecord) Size() (n int) {
149 149
 			n += 1 + l + sovWorker(uint64(l))
150 150
 		}
151 151
 	}
152
+	if len(m.GCPolicy) > 0 {
153
+		for _, e := range m.GCPolicy {
154
+			l = e.Size()
155
+			n += 1 + l + sovWorker(uint64(l))
156
+		}
157
+	}
158
+	return n
159
+}
160
+
161
+func (m *GCPolicy) Size() (n int) {
162
+	var l int
163
+	_ = l
164
+	if m.All {
165
+		n += 2
166
+	}
167
+	if m.KeepDuration != 0 {
168
+		n += 1 + sovWorker(uint64(m.KeepDuration))
169
+	}
170
+	if m.KeepBytes != 0 {
171
+		n += 1 + sovWorker(uint64(m.KeepBytes))
172
+	}
173
+	if len(m.Filters) > 0 {
174
+		for _, s := range m.Filters {
175
+			l = len(s)
176
+			n += 1 + l + sovWorker(uint64(l))
177
+		}
178
+	}
152 179
 	return n
153 180
 }
154 181
 
... ...
@@ -372,6 +514,174 @@ func (m *WorkerRecord) Unmarshal(dAtA []byte) error {
372 372
 				return err
373 373
 			}
374 374
 			iNdEx = postIndex
375
+		case 4:
376
+			if wireType != 2 {
377
+				return fmt.Errorf("proto: wrong wireType = %d for field GCPolicy", wireType)
378
+			}
379
+			var msglen int
380
+			for shift := uint(0); ; shift += 7 {
381
+				if shift >= 64 {
382
+					return ErrIntOverflowWorker
383
+				}
384
+				if iNdEx >= l {
385
+					return io.ErrUnexpectedEOF
386
+				}
387
+				b := dAtA[iNdEx]
388
+				iNdEx++
389
+				msglen |= (int(b) & 0x7F) << shift
390
+				if b < 0x80 {
391
+					break
392
+				}
393
+			}
394
+			if msglen < 0 {
395
+				return ErrInvalidLengthWorker
396
+			}
397
+			postIndex := iNdEx + msglen
398
+			if postIndex > l {
399
+				return io.ErrUnexpectedEOF
400
+			}
401
+			m.GCPolicy = append(m.GCPolicy, &GCPolicy{})
402
+			if err := m.GCPolicy[len(m.GCPolicy)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
403
+				return err
404
+			}
405
+			iNdEx = postIndex
406
+		default:
407
+			iNdEx = preIndex
408
+			skippy, err := skipWorker(dAtA[iNdEx:])
409
+			if err != nil {
410
+				return err
411
+			}
412
+			if skippy < 0 {
413
+				return ErrInvalidLengthWorker
414
+			}
415
+			if (iNdEx + skippy) > l {
416
+				return io.ErrUnexpectedEOF
417
+			}
418
+			iNdEx += skippy
419
+		}
420
+	}
421
+
422
+	if iNdEx > l {
423
+		return io.ErrUnexpectedEOF
424
+	}
425
+	return nil
426
+}
427
+func (m *GCPolicy) Unmarshal(dAtA []byte) error {
428
+	l := len(dAtA)
429
+	iNdEx := 0
430
+	for iNdEx < l {
431
+		preIndex := iNdEx
432
+		var wire uint64
433
+		for shift := uint(0); ; shift += 7 {
434
+			if shift >= 64 {
435
+				return ErrIntOverflowWorker
436
+			}
437
+			if iNdEx >= l {
438
+				return io.ErrUnexpectedEOF
439
+			}
440
+			b := dAtA[iNdEx]
441
+			iNdEx++
442
+			wire |= (uint64(b) & 0x7F) << shift
443
+			if b < 0x80 {
444
+				break
445
+			}
446
+		}
447
+		fieldNum := int32(wire >> 3)
448
+		wireType := int(wire & 0x7)
449
+		if wireType == 4 {
450
+			return fmt.Errorf("proto: GCPolicy: wiretype end group for non-group")
451
+		}
452
+		if fieldNum <= 0 {
453
+			return fmt.Errorf("proto: GCPolicy: illegal tag %d (wire type %d)", fieldNum, wire)
454
+		}
455
+		switch fieldNum {
456
+		case 1:
457
+			if wireType != 0 {
458
+				return fmt.Errorf("proto: wrong wireType = %d for field All", wireType)
459
+			}
460
+			var v int
461
+			for shift := uint(0); ; shift += 7 {
462
+				if shift >= 64 {
463
+					return ErrIntOverflowWorker
464
+				}
465
+				if iNdEx >= l {
466
+					return io.ErrUnexpectedEOF
467
+				}
468
+				b := dAtA[iNdEx]
469
+				iNdEx++
470
+				v |= (int(b) & 0x7F) << shift
471
+				if b < 0x80 {
472
+					break
473
+				}
474
+			}
475
+			m.All = bool(v != 0)
476
+		case 2:
477
+			if wireType != 0 {
478
+				return fmt.Errorf("proto: wrong wireType = %d for field KeepDuration", wireType)
479
+			}
480
+			m.KeepDuration = 0
481
+			for shift := uint(0); ; shift += 7 {
482
+				if shift >= 64 {
483
+					return ErrIntOverflowWorker
484
+				}
485
+				if iNdEx >= l {
486
+					return io.ErrUnexpectedEOF
487
+				}
488
+				b := dAtA[iNdEx]
489
+				iNdEx++
490
+				m.KeepDuration |= (int64(b) & 0x7F) << shift
491
+				if b < 0x80 {
492
+					break
493
+				}
494
+			}
495
+		case 3:
496
+			if wireType != 0 {
497
+				return fmt.Errorf("proto: wrong wireType = %d for field KeepBytes", wireType)
498
+			}
499
+			m.KeepBytes = 0
500
+			for shift := uint(0); ; shift += 7 {
501
+				if shift >= 64 {
502
+					return ErrIntOverflowWorker
503
+				}
504
+				if iNdEx >= l {
505
+					return io.ErrUnexpectedEOF
506
+				}
507
+				b := dAtA[iNdEx]
508
+				iNdEx++
509
+				m.KeepBytes |= (int64(b) & 0x7F) << shift
510
+				if b < 0x80 {
511
+					break
512
+				}
513
+			}
514
+		case 4:
515
+			if wireType != 2 {
516
+				return fmt.Errorf("proto: wrong wireType = %d for field Filters", wireType)
517
+			}
518
+			var stringLen uint64
519
+			for shift := uint(0); ; shift += 7 {
520
+				if shift >= 64 {
521
+					return ErrIntOverflowWorker
522
+				}
523
+				if iNdEx >= l {
524
+					return io.ErrUnexpectedEOF
525
+				}
526
+				b := dAtA[iNdEx]
527
+				iNdEx++
528
+				stringLen |= (uint64(b) & 0x7F) << shift
529
+				if b < 0x80 {
530
+					break
531
+				}
532
+			}
533
+			intStringLen := int(stringLen)
534
+			if intStringLen < 0 {
535
+				return ErrInvalidLengthWorker
536
+			}
537
+			postIndex := iNdEx + intStringLen
538
+			if postIndex > l {
539
+				return io.ErrUnexpectedEOF
540
+			}
541
+			m.Filters = append(m.Filters, string(dAtA[iNdEx:postIndex]))
542
+			iNdEx = postIndex
375 543
 		default:
376 544
 			iNdEx = preIndex
377 545
 			skippy, err := skipWorker(dAtA[iNdEx:])
... ...
@@ -501,23 +811,28 @@ var (
501 501
 func init() { proto.RegisterFile("worker.proto", fileDescriptorWorker) }
502 502
 
503 503
 var fileDescriptorWorker = []byte{
504
-	// 273 bytes of a gzipped FileDescriptorProto
505
-	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x8f, 0x41, 0x4b, 0xf3, 0x40,
506
-	0x10, 0x86, 0xbf, 0x4d, 0x3e, 0x0b, 0xdd, 0x06, 0x91, 0x45, 0x24, 0xe4, 0x10, 0x8b, 0xa7, 0x1e,
507
-	0x74, 0xb6, 0xea, 0x45, 0x3d, 0x96, 0x0a, 0x16, 0x3c, 0x48, 0x2e, 0x9e, 0xb3, 0xed, 0x36, 0x86,
508
-	0x24, 0xce, 0xb2, 0xd9, 0x44, 0xf2, 0x0f, 0x7b, 0xf4, 0xe2, 0x55, 0x24, 0xbf, 0x44, 0xba, 0x89,
509
-	0x98, 0x83, 0xb7, 0x79, 0x87, 0x67, 0x1e, 0xde, 0xa1, 0xde, 0x1b, 0xea, 0x4c, 0x6a, 0x50, 0x1a,
510
-	0x0d, 0xb2, 0x93, 0x02, 0x45, 0x03, 0xa2, 0x4a, 0xf3, 0x4d, 0x96, 0x1a, 0xa8, 0x2f, 0xc1, 0x34,
511
-	0x4a, 0x96, 0xc1, 0x45, 0x92, 0x9a, 0x97, 0x4a, 0xc0, 0x1a, 0x0b, 0x9e, 0x60, 0x82, 0xdc, 0xe2,
512
-	0xa2, 0xda, 0xda, 0x64, 0x83, 0x9d, 0x3a, 0x4d, 0x70, 0x3e, 0xc0, 0xf7, 0x46, 0xfe, 0x63, 0xe4,
513
-	0x25, 0xe6, 0xb5, 0xd4, 0x5c, 0x09, 0x8e, 0xaa, 0xec, 0xe8, 0xb3, 0x0f, 0x42, 0xbd, 0x67, 0xdb,
514
-	0x22, 0x92, 0x6b, 0xd4, 0x1b, 0x76, 0x48, 0x9d, 0xd5, 0xd2, 0x27, 0x53, 0x32, 0x1b, 0x47, 0xce,
515
-	0x6a, 0xc9, 0x1e, 0xe8, 0xe8, 0x31, 0x16, 0x32, 0x2f, 0x7d, 0x67, 0xea, 0xce, 0x26, 0x57, 0x73,
516
-	0xf8, 0xbb, 0x26, 0x0c, 0x2d, 0xd0, 0x9d, 0xdc, 0xbf, 0x1a, 0xdd, 0x44, 0xfd, 0x3d, 0x9b, 0xd3,
517
-	0xb1, 0xca, 0x63, 0xb3, 0x45, 0x5d, 0x94, 0xbe, 0x6b, 0x65, 0x1e, 0x28, 0x01, 0x4f, 0xfd, 0x72,
518
-	0xf1, 0x7f, 0xf7, 0x79, 0xfa, 0x2f, 0xfa, 0x85, 0x82, 0x5b, 0x3a, 0x19, 0x88, 0xd8, 0x11, 0x75,
519
-	0x33, 0xd9, 0xf4, 0xdd, 0xf6, 0x23, 0x3b, 0xa6, 0x07, 0x75, 0x9c, 0x57, 0xd2, 0x77, 0xec, 0xae,
520
-	0x0b, 0x77, 0xce, 0x0d, 0x59, 0x78, 0xbb, 0x36, 0x24, 0xef, 0x6d, 0x48, 0xbe, 0xda, 0x90, 0x88,
521
-	0x91, 0x7d, 0xf6, 0xfa, 0x3b, 0x00, 0x00, 0xff, 0xff, 0xa9, 0x5c, 0x8f, 0x26, 0x71, 0x01, 0x00,
522
-	0x00,
504
+	// 355 bytes of a gzipped FileDescriptorProto
505
+	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0xc1, 0x4e, 0xea, 0x40,
506
+	0x14, 0x86, 0x6f, 0x5b, 0x2e, 0x97, 0x0e, 0xcd, 0x8d, 0x99, 0x18, 0xd3, 0x10, 0x83, 0x84, 0x15,
507
+	0x0b, 0x9d, 0xa2, 0x6e, 0xd4, 0xb8, 0x42, 0x8c, 0x92, 0xb8, 0x20, 0xb3, 0x71, 0xdd, 0x81, 0x01,
508
+	0x9b, 0x0e, 0x9c, 0xc9, 0x74, 0x8a, 0xf6, 0x39, 0x7c, 0x29, 0x96, 0x3e, 0x81, 0x31, 0x3c, 0x89,
509
+	0x99, 0x29, 0x08, 0x26, 0xba, 0x3b, 0xff, 0x9f, 0xff, 0xfb, 0xe7, 0x9c, 0x0c, 0x0a, 0x9e, 0x41,
510
+	0xa5, 0x5c, 0x11, 0xa9, 0x40, 0x03, 0x3e, 0x98, 0x01, 0x2b, 0x08, 0xcb, 0x13, 0x31, 0x4e, 0x13,
511
+	0x4d, 0x16, 0xa7, 0x44, 0x17, 0x92, 0x67, 0x8d, 0x93, 0x69, 0xa2, 0x9f, 0x72, 0x46, 0x46, 0x30,
512
+	0x8b, 0xa6, 0x30, 0x85, 0xc8, 0xc6, 0x59, 0x3e, 0xb1, 0xca, 0x0a, 0x3b, 0x95, 0x35, 0x8d, 0xe3,
513
+	0x9d, 0xb8, 0x69, 0x8c, 0x36, 0x8d, 0x51, 0x06, 0x62, 0xc1, 0x55, 0x24, 0x59, 0x04, 0x32, 0x2b,
514
+	0xd3, 0xed, 0x57, 0x17, 0x05, 0x8f, 0x76, 0x0b, 0xca, 0x47, 0xa0, 0xc6, 0xf8, 0x3f, 0x72, 0x07,
515
+	0xfd, 0xd0, 0x69, 0x39, 0x1d, 0x9f, 0xba, 0x83, 0x3e, 0xbe, 0x47, 0xd5, 0x87, 0x98, 0x71, 0x91,
516
+	0x85, 0x6e, 0xcb, 0xeb, 0xd4, 0xcf, 0xba, 0xe4, 0xe7, 0x35, 0xc9, 0x6e, 0x0b, 0x29, 0x91, 0xdb,
517
+	0xb9, 0x56, 0x05, 0x5d, 0xf3, 0xb8, 0x8b, 0x7c, 0x29, 0x62, 0x3d, 0x01, 0x35, 0xcb, 0x42, 0xcf,
518
+	0x96, 0x05, 0x44, 0x32, 0x32, 0x5c, 0x9b, 0xbd, 0xca, 0xf2, 0xfd, 0xe8, 0x0f, 0xdd, 0x86, 0xf0,
519
+	0x35, 0xaa, 0xdd, 0xdd, 0x0c, 0x41, 0x24, 0xa3, 0x22, 0xac, 0x58, 0xa0, 0xf5, 0xdb, 0xeb, 0x9b,
520
+	0x1c, 0xfd, 0x22, 0x1a, 0x97, 0xa8, 0xbe, 0xb3, 0x06, 0xde, 0x43, 0x5e, 0xca, 0x8b, 0xf5, 0x65,
521
+	0x66, 0xc4, 0xfb, 0xe8, 0xef, 0x22, 0x16, 0x39, 0x0f, 0x5d, 0xeb, 0x95, 0xe2, 0xca, 0xbd, 0x70,
522
+	0xda, 0x2f, 0xdb, 0x87, 0x0d, 0x17, 0x0b, 0x61, 0xb9, 0x1a, 0x35, 0x23, 0x6e, 0xa3, 0x20, 0xe5,
523
+	0x5c, 0xf6, 0x73, 0x15, 0xeb, 0x04, 0xe6, 0x16, 0xf7, 0xe8, 0x37, 0x0f, 0x1f, 0x22, 0xdf, 0xe8,
524
+	0x5e, 0xa1, 0xb9, 0x39, 0xd6, 0x04, 0xb6, 0x06, 0x0e, 0xd1, 0xbf, 0x49, 0x22, 0x34, 0x57, 0x99,
525
+	0xbd, 0xcb, 0xa7, 0x1b, 0xd9, 0x0b, 0x96, 0xab, 0xa6, 0xf3, 0xb6, 0x6a, 0x3a, 0x1f, 0xab, 0xa6,
526
+	0xc3, 0xaa, 0xf6, 0x93, 0xce, 0x3f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xfc, 0x79, 0x52, 0x6a, 0x29,
527
+	0x02, 0x00, 0x00,
523 528
 }
... ...
@@ -13,4 +13,12 @@ message WorkerRecord {
13 13
 	string ID = 1;
14 14
 	map<string, string> Labels = 2;
15 15
 	repeated pb.Platform platforms = 3 [(gogoproto.nullable) = false];
16
+	repeated GCPolicy GCPolicy = 4;
17
+}
18
+
19
+message GCPolicy {
20
+	bool all = 1;
21
+	int64 keepDuration = 2;
22
+	int64 keepBytes = 3;
23
+	repeated string filters = 4;
16 24
 }
... ...
@@ -39,7 +39,7 @@ type Accessor interface {
39 39
 
40 40
 type Controller interface {
41 41
 	DiskUsage(ctx context.Context, info client.DiskUsageInfo) ([]*client.UsageInfo, error)
42
-	Prune(ctx context.Context, ch chan client.UsageInfo, info client.PruneInfo) error
42
+	Prune(ctx context.Context, ch chan client.UsageInfo, info ...client.PruneInfo) error
43 43
 	GC(ctx context.Context) error
44 44
 }
45 45
 
... ...
@@ -304,10 +304,19 @@ func (cm *cacheManager) GetMutable(ctx context.Context, id string) (MutableRef,
304 304
 	return rec.mref(), nil
305 305
 }
306 306
 
307
-func (cm *cacheManager) Prune(ctx context.Context, ch chan client.UsageInfo, opt client.PruneInfo) error {
307
+func (cm *cacheManager) Prune(ctx context.Context, ch chan client.UsageInfo, opts ...client.PruneInfo) error {
308 308
 	cm.muPrune.Lock()
309 309
 	defer cm.muPrune.Unlock()
310 310
 
311
+	for _, opt := range opts {
312
+		if err := cm.pruneOnce(ctx, ch, opt); err != nil {
313
+			return err
314
+		}
315
+	}
316
+	return nil
317
+}
318
+
319
+func (cm *cacheManager) pruneOnce(ctx context.Context, ch chan client.UsageInfo, opt client.PruneInfo) error {
311 320
 	filter, err := filters.ParseAll(opt.Filter...)
312 321
 	if err != nil {
313 322
 		return err
... ...
@@ -67,7 +67,7 @@ func (s State) Value(k interface{}) interface{} {
67 67
 	return s.ctx.Value(k)
68 68
 }
69 69
 
70
-func (s State) SetMarhalDefaults(co ...ConstraintsOpt) State {
70
+func (s State) SetMarshalDefaults(co ...ConstraintsOpt) State {
71 71
 	s.opts = co
72 72
 	return s
73 73
 }
... ...
@@ -2,8 +2,10 @@ package client
2 2
 
3 3
 import (
4 4
 	"context"
5
+	"time"
5 6
 
6 7
 	controlapi "github.com/moby/buildkit/api/services/control"
8
+	apitypes "github.com/moby/buildkit/api/types"
7 9
 	"github.com/moby/buildkit/solver/pb"
8 10
 	specs "github.com/opencontainers/image-spec/specs-go/v1"
9 11
 	"github.com/pkg/errors"
... ...
@@ -13,6 +15,7 @@ type WorkerInfo struct {
13 13
 	ID        string
14 14
 	Labels    map[string]string
15 15
 	Platforms []specs.Platform
16
+	GCPolicy  []PruneInfo
16 17
 }
17 18
 
18 19
 func (c *Client) ListWorkers(ctx context.Context, opts ...ListWorkersOption) ([]*WorkerInfo, error) {
... ...
@@ -34,6 +37,7 @@ func (c *Client) ListWorkers(ctx context.Context, opts ...ListWorkersOption) ([]
34 34
 			ID:        w.ID,
35 35
 			Labels:    w.Labels,
36 36
 			Platforms: pb.ToSpecPlatforms(w.Platforms),
37
+			GCPolicy:  fromAPIGCPolicy(w.GCPolicy),
37 38
 		})
38 39
 	}
39 40
 
... ...
@@ -47,3 +51,16 @@ type ListWorkersOption interface {
47 47
 type ListWorkersInfo struct {
48 48
 	Filter []string
49 49
 }
50
+
51
+func fromAPIGCPolicy(in []*apitypes.GCPolicy) []PruneInfo {
52
+	out := make([]PruneInfo, 0, len(in))
53
+	for _, p := range in {
54
+		out = append(out, PruneInfo{
55
+			All:          p.All,
56
+			Filter:       p.Filters,
57
+			KeepDuration: time.Duration(p.KeepDuration),
58
+			KeepBytes:    p.KeepBytes,
59
+		})
60
+	}
61
+	return out
62
+}
... ...
@@ -2,6 +2,7 @@ package control
2 2
 
3 3
 import (
4 4
 	"context"
5
+	"sync"
5 6
 	"time"
6 7
 
7 8
 	"github.com/docker/distribution/reference"
... ...
@@ -17,6 +18,7 @@ import (
17 17
 	"github.com/moby/buildkit/solver"
18 18
 	"github.com/moby/buildkit/solver/llbsolver"
19 19
 	"github.com/moby/buildkit/solver/pb"
20
+	"github.com/moby/buildkit/util/throttle"
20 21
 	"github.com/moby/buildkit/worker"
21 22
 	"github.com/pkg/errors"
22 23
 	"github.com/sirupsen/logrus"
... ...
@@ -40,6 +42,8 @@ type Controller struct { // TODO: ControlService
40 40
 	solver           *llbsolver.Solver
41 41
 	cache            solver.CacheManager
42 42
 	gatewayForwarder *controlgateway.GatewayForwarder
43
+	throttledGC      func()
44
+	gcmu             sync.Mutex
43 45
 }
44 46
 
45 47
 func NewController(opt Opt) (*Controller, error) {
... ...
@@ -58,6 +62,12 @@ func NewController(opt Opt) (*Controller, error) {
58 58
 		cache:            cache,
59 59
 		gatewayForwarder: gatewayForwarder,
60 60
 	}
61
+	c.throttledGC = throttle.ThrottleAfter(time.Minute, c.gc)
62
+
63
+	defer func() {
64
+		time.AfterFunc(time.Second, c.throttledGC)
65
+	}()
66
+
61 67
 	return c, nil
62 68
 }
63 69
 
... ...
@@ -172,6 +182,10 @@ func (c *Controller) Prune(req *controlapi.PruneRequest, stream controlapi.Contr
172 172
 func (c *Controller) Solve(ctx context.Context, req *controlapi.SolveRequest) (*controlapi.SolveResponse, error) {
173 173
 	ctx = session.NewContext(ctx, req.Session)
174 174
 
175
+	defer func() {
176
+		time.AfterFunc(time.Second, c.throttledGC)
177
+	}()
178
+
175 179
 	var expi exporter.ExporterInstance
176 180
 	// TODO: multiworker
177 181
 	// This is actually tricky, as the exporter should come from the worker that has the returned reference. We may need to delay this so that the solver loads this.
... ...
@@ -313,11 +327,55 @@ func (c *Controller) ListWorkers(ctx context.Context, r *controlapi.ListWorkersR
313 313
 			ID:        w.ID(),
314 314
 			Labels:    w.Labels(),
315 315
 			Platforms: pb.PlatformsFromSpec(w.Platforms()),
316
+			GCPolicy:  toPBGCPolicy(w.GCPolicy()),
316 317
 		})
317 318
 	}
318 319
 	return resp, nil
319 320
 }
320 321
 
322
+func (c *Controller) gc() {
323
+	c.gcmu.Lock()
324
+	defer c.gcmu.Unlock()
325
+
326
+	workers, err := c.opt.WorkerController.List()
327
+	if err != nil {
328
+		return
329
+	}
330
+
331
+	eg, ctx := errgroup.WithContext(context.TODO())
332
+
333
+	var size int64
334
+	ch := make(chan client.UsageInfo)
335
+	done := make(chan struct{})
336
+	go func() {
337
+		for ui := range ch {
338
+			size += ui.Size
339
+		}
340
+		close(done)
341
+	}()
342
+
343
+	for _, w := range workers {
344
+		func(w worker.Worker) {
345
+			eg.Go(func() error {
346
+				if policy := w.GCPolicy(); len(policy) > 0 {
347
+					return w.Prune(ctx, ch, policy...)
348
+				}
349
+				return nil
350
+			})
351
+		}(w)
352
+	}
353
+
354
+	err = eg.Wait()
355
+	close(ch)
356
+	if err != nil {
357
+		logrus.Errorf("gc error: %+v", err)
358
+	}
359
+	<-done
360
+	if size > 0 {
361
+		logrus.Debugf("gc cleaned up %d bytes", size)
362
+	}
363
+}
364
+
321 365
 func parseCacheExporterOpt(opt map[string]string) solver.CacheExportMode {
322 366
 	for k, v := range opt {
323 367
 		switch k {
... ...
@@ -336,3 +394,16 @@ func parseCacheExporterOpt(opt map[string]string) solver.CacheExportMode {
336 336
 	}
337 337
 	return solver.CacheExportModeMin
338 338
 }
339
+
340
+func toPBGCPolicy(in []client.PruneInfo) []*apitypes.GCPolicy {
341
+	policy := make([]*apitypes.GCPolicy, 0, len(in))
342
+	for _, p := range in {
343
+		policy = append(policy, &apitypes.GCPolicy{
344
+			All:          p.All,
345
+			KeepBytes:    p.KeepBytes,
346
+			KeepDuration: int64(p.KeepDuration),
347
+			Filters:      p.Filter,
348
+		})
349
+	}
350
+	return policy
351
+}
... ...
@@ -36,6 +36,8 @@ type Opt struct {
36 36
 	CommandCandidates []string
37 37
 	// without root privileges (has nothing to do with Opt.Root directory)
38 38
 	Rootless bool
39
+	// DefaultCgroupParent is the cgroup-parent name for executor
40
+	DefaultCgroupParent string
39 41
 }
40 42
 
41 43
 var defaultCommandCandidates = []string{"buildkit-runc", "runc"}
... ...
@@ -44,6 +46,7 @@ type runcExecutor struct {
44 44
 	runc             *runc.Runc
45 45
 	root             string
46 46
 	cmd              string
47
+	cgroupParent     string
47 48
 	rootless         bool
48 49
 	networkProviders map[pb.NetMode]network.Provider
49 50
 }
... ...
@@ -94,6 +97,7 @@ func New(opt Opt, networkProviders map[pb.NetMode]network.Provider) (executor.Ex
94 94
 	w := &runcExecutor{
95 95
 		runc:             runtime,
96 96
 		root:             root,
97
+		cgroupParent:     opt.DefaultCgroupParent,
97 98
 		rootless:         opt.Rootless,
98 99
 		networkProviders: networkProviders,
99 100
 	}
... ...
@@ -173,6 +177,17 @@ func (w *runcExecutor) Exec(ctx context.Context, meta executor.Meta, root cache.
173 173
 	if meta.ReadonlyRootFS {
174 174
 		opts = append(opts, containerdoci.WithRootFSReadonly())
175 175
 	}
176
+
177
+	if w.cgroupParent != "" {
178
+		var cgroupsPath string
179
+		lastSeparator := w.cgroupParent[len(w.cgroupParent)-1:]
180
+		if strings.Contains(w.cgroupParent, ".slice") && lastSeparator == ":" {
181
+			cgroupsPath = w.cgroupParent + id
182
+		} else {
183
+			cgroupsPath = filepath.Join("/", w.cgroupParent, "buildkit", id)
184
+		}
185
+		opts = append(opts, containerdoci.WithCgroup(cgroupsPath))
186
+	}
176 187
 	spec, cleanup, err := oci.GenerateSpec(ctx, meta, mounts, id, resolvConf, hostsFile, namespace, opts...)
177 188
 	if err != nil {
178 189
 		return err
... ...
@@ -347,7 +347,7 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State,
347 347
 	}
348 348
 	buildContext.Output = bc.Output()
349 349
 
350
-	st := target.state.SetMarhalDefaults(llb.Platform(platformOpt.targetPlatform))
350
+	st := target.state.SetMarshalDefaults(llb.Platform(platformOpt.targetPlatform))
351 351
 
352 352
 	if !platformOpt.implicitTarget {
353 353
 		target.image.OS = platformOpt.targetPlatform.OS
... ...
@@ -67,7 +67,11 @@ func (c *bridgeClient) Solve(ctx context.Context, req client.SolveRequest) (*cli
67 67
 func (c *bridgeClient) BuildOpts() client.BuildOpts {
68 68
 	workers := make([]client.WorkerInfo, 0, len(c.workerInfos))
69 69
 	for _, w := range c.workerInfos {
70
-		workers = append(workers, client.WorkerInfo(w))
70
+		workers = append(workers, client.WorkerInfo{
71
+			ID:        w.ID,
72
+			Labels:    w.Labels,
73
+			Platforms: w.Platforms,
74
+		})
71 75
 	}
72 76
 
73 77
 	return client.BuildOpts{
74 78
new file mode 100644
... ...
@@ -0,0 +1,58 @@
0
+package throttle
1
+
2
+import (
3
+	"sync"
4
+	"time"
5
+)
6
+
7
+// Throttle wraps a function so that internal function does not get called
8
+// more frequently than the specified duration.
9
+func Throttle(d time.Duration, f func()) func() {
10
+	return throttle(d, f, true)
11
+}
12
+
13
+// ThrottleAfter wraps a function so that internal function does not get called
14
+// more frequently than the specified duration. The delay is added after function
15
+// has been called.
16
+func ThrottleAfter(d time.Duration, f func()) func() {
17
+	return throttle(d, f, false)
18
+}
19
+
20
+func throttle(d time.Duration, f func(), wait bool) func() {
21
+	var next, running bool
22
+	var mu sync.Mutex
23
+	return func() {
24
+		mu.Lock()
25
+		defer mu.Unlock()
26
+
27
+		next = true
28
+		if !running {
29
+			running = true
30
+			go func() {
31
+				for {
32
+					mu.Lock()
33
+					if next == false {
34
+						running = false
35
+						mu.Unlock()
36
+						return
37
+					}
38
+					if !wait {
39
+						next = false
40
+					}
41
+					mu.Unlock()
42
+
43
+					if wait {
44
+						time.Sleep(d)
45
+						mu.Lock()
46
+						next = false
47
+						mu.Unlock()
48
+						f()
49
+					} else {
50
+						f()
51
+						time.Sleep(d)
52
+					}
53
+				}
54
+			}()
55
+		}
56
+	}
57
+}
... ...
@@ -20,6 +20,7 @@ type Worker interface {
20 20
 	ID() string
21 21
 	Labels() map[string]string
22 22
 	Platforms() []specs.Platform
23
+	GCPolicy() []client.PruneInfo
23 24
 	LoadRef(id string) (cache.ImmutableRef, error)
24 25
 	// ResolveOp resolves Vertex.Sys() to Op implementation.
25 26
 	ResolveOp(v solver.Vertex, s frontend.FrontendLLBBridge) (solver.Op, error)
... ...
@@ -28,7 +29,7 @@ type Worker interface {
28 28
 	Exec(ctx context.Context, meta executor.Meta, rootFS cache.ImmutableRef, stdin io.ReadCloser, stdout, stderr io.WriteCloser) error
29 29
 	DiskUsage(ctx context.Context, opt client.DiskUsageInfo) ([]*client.UsageInfo, error)
30 30
 	Exporter(name string) (exporter.Exporter, error)
31
-	Prune(ctx context.Context, ch chan client.UsageInfo, opt client.PruneInfo) error
31
+	Prune(ctx context.Context, ch chan client.UsageInfo, opt ...client.PruneInfo) error
32 32
 	GetRemote(ctx context.Context, ref cache.ImmutableRef, createIfNeeded bool) (*solver.Remote, error)
33 33
 	FromRemote(ctx context.Context, remote *solver.Remote) (cache.ImmutableRef, error)
34 34
 }