Browse code

vendor: github.com/moby/buildkit v0.12.4

full diff: https://github.com/moby/buildkit/compare/v0.12.3...v0.12.4

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>

Paweł Gronowski authored on 2023/12/04 18:56:20
Showing 7 changed files
... ...
@@ -61,7 +61,7 @@ require (
61 61
 	github.com/miekg/dns v1.1.43
62 62
 	github.com/mistifyio/go-zfs/v3 v3.0.1
63 63
 	github.com/mitchellh/copystructure v1.2.0
64
-	github.com/moby/buildkit v0.12.3
64
+	github.com/moby/buildkit v0.12.4
65 65
 	github.com/moby/ipvs v1.1.0
66 66
 	github.com/moby/locker v1.0.1
67 67
 	github.com/moby/patternmatcher v0.6.0
... ...
@@ -912,8 +912,8 @@ github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zx
912 912
 github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
913 913
 github.com/mndrix/tap-go v0.0.0-20171203230836-629fa407e90b/go.mod h1:pzzDgJWZ34fGzaAZGFW22KVZDfyrYW+QABMrWnJBnSs=
914 914
 github.com/moby/buildkit v0.8.1/go.mod h1:/kyU1hKy/aYCuP39GZA9MaKioovHku57N6cqlKZIaiQ=
915
-github.com/moby/buildkit v0.12.3 h1:cFaPVnyC0PwAP5xHHfzdU5v9rgQrCi6HnGSg3WuFKp4=
916
-github.com/moby/buildkit v0.12.3/go.mod h1:adB4y0SxxX8trnrY+oEulb48ODLqPO6pKMF0ppGcCoI=
915
+github.com/moby/buildkit v0.12.4 h1:yKZDsObXLKarXqUx7YMnaB+TKv810bBhq0XLFWbkjT0=
916
+github.com/moby/buildkit v0.12.4/go.mod h1:XG74uz06nPWQpnxYwgCryrVidvor0+ElUxGosbZPQG4=
917 917
 github.com/moby/ipvs v1.1.0 h1:ONN4pGaZQgAx+1Scz5RvWV4Q7Gb+mvfRh3NsPS+1XQQ=
918 918
 github.com/moby/ipvs v1.1.0/go.mod h1:4VJMWuf098bsUMmZEiD4Tjk/O7mOn3l1PTD3s4OoYAs=
919 919
 github.com/moby/locker v1.0.1 h1:fOXqR41zeveg4fFODix+1Ch4mj/gT0NE1XJbp/epuBg=
... ...
@@ -55,15 +55,17 @@ func (ck *CacheKey) Output() Index {
55 55
 }
56 56
 
57 57
 func (ck *CacheKey) clone() *CacheKey {
58
+	ck.mu.RLock()
58 59
 	nk := &CacheKey{
59 60
 		ID:     ck.ID,
60 61
 		digest: ck.digest,
61 62
 		vtx:    ck.vtx,
62 63
 		output: ck.output,
63
-		ids:    map[*cacheManager]string{},
64
+		ids:    make(map[*cacheManager]string, len(ck.ids)),
64 65
 	}
65 66
 	for cm, id := range ck.ids {
66 67
 		nk.ids[cm] = id
67 68
 	}
69
+	ck.mu.RUnlock()
68 70
 	return nk
69 71
 }
... ...
@@ -101,34 +101,41 @@ func (cm *combinedCacheManager) Save(key *CacheKey, s Result, createdAt time.Tim
101 101
 }
102 102
 
103 103
 func (cm *combinedCacheManager) Records(ctx context.Context, ck *CacheKey) ([]*CacheRecord, error) {
104
+	ck.mu.RLock()
104 105
 	if len(ck.ids) == 0 {
106
+		ck.mu.RUnlock()
105 107
 		return nil, errors.Errorf("no results")
106 108
 	}
107 109
 
110
+	cms := make([]*cacheManager, 0, len(ck.ids))
111
+	for cm := range ck.ids {
112
+		cms = append(cms, cm)
113
+	}
114
+	ck.mu.RUnlock()
115
+
108 116
 	records := map[string]*CacheRecord{}
109 117
 	var mu sync.Mutex
110 118
 
111 119
 	eg, _ := errgroup.WithContext(context.TODO())
112
-	for c := range ck.ids {
113
-		func(c *cacheManager) {
114
-			eg.Go(func() error {
115
-				recs, err := c.Records(ctx, ck)
116
-				if err != nil {
117
-					return err
118
-				}
119
-				mu.Lock()
120
-				for _, rec := range recs {
121
-					if _, ok := records[rec.ID]; !ok || c == cm.main {
122
-						if c == cm.main {
123
-							rec.Priority = 1
124
-						}
125
-						records[rec.ID] = rec
120
+	for _, c := range cms {
121
+		c := c
122
+		eg.Go(func() error {
123
+			recs, err := c.Records(ctx, ck)
124
+			if err != nil {
125
+				return err
126
+			}
127
+			mu.Lock()
128
+			for _, rec := range recs {
129
+				if _, ok := records[rec.ID]; !ok || c == cm.main {
130
+					if c == cm.main {
131
+						rec.Priority = 1
126 132
 					}
133
+					records[rec.ID] = rec
127 134
 				}
128
-				mu.Unlock()
129
-				return nil
130
-			})
131
-		}(c)
135
+			}
136
+			mu.Unlock()
137
+			return nil
138
+		})
132 139
 	}
133 140
 
134 141
 	if err := eg.Wait(); err != nil {
... ...
@@ -85,8 +85,9 @@ func (e *exporter) ExportTo(ctx context.Context, t CacheExporterTarget, opt Cach
85 85
 		r        CacheExporterRecord
86 86
 		selector digest.Digest
87 87
 	}
88
+	k := e.k.clone() // protect against *CacheKey internal ids mutation from other exports
88 89
 
89
-	recKey := rootKey(e.k.Digest(), e.k.Output())
90
+	recKey := rootKey(k.Digest(), k.Output())
90 91
 	rec := t.Add(recKey)
91 92
 	allRec := []CacheExporterRecord{rec}
92 93
 
... ...
@@ -97,7 +98,7 @@ func (e *exporter) ExportTo(ctx context.Context, t CacheExporterTarget, opt Cach
97 97
 	}
98 98
 
99 99
 	exportRecord := opt.ExportRoots
100
-	if len(e.k.Deps()) > 0 {
100
+	if len(deps) > 0 {
101 101
 		exportRecord = true
102 102
 	}
103 103
 
... ...
@@ -126,7 +127,7 @@ func (e *exporter) ExportTo(ctx context.Context, t CacheExporterTarget, opt Cach
126 126
 		if opt.CompressionOpt != nil {
127 127
 			for _, r := range remotes { // record all remaining remotes as well
128 128
 				rec := t.Add(recKey)
129
-				rec.AddResult(e.k.vtx, int(e.k.output), v.CreatedAt, r)
129
+				rec.AddResult(k.vtx, int(k.output), v.CreatedAt, r)
130 130
 				variants = append(variants, rec)
131 131
 			}
132 132
 		}
... ...
@@ -147,7 +148,7 @@ func (e *exporter) ExportTo(ctx context.Context, t CacheExporterTarget, opt Cach
147 147
 			if opt.CompressionOpt != nil {
148 148
 				for _, r := range remotes { // record all remaining remotes as well
149 149
 					rec := t.Add(recKey)
150
-					rec.AddResult(e.k.vtx, int(e.k.output), v.CreatedAt, r)
150
+					rec.AddResult(k.vtx, int(k.output), v.CreatedAt, r)
151 151
 					variants = append(variants, rec)
152 152
 				}
153 153
 			}
... ...
@@ -155,7 +156,7 @@ func (e *exporter) ExportTo(ctx context.Context, t CacheExporterTarget, opt Cach
155 155
 
156 156
 		if remote != nil {
157 157
 			for _, rec := range allRec {
158
-				rec.AddResult(e.k.vtx, int(e.k.output), v.CreatedAt, remote)
158
+				rec.AddResult(k.vtx, int(k.output), v.CreatedAt, remote)
159 159
 			}
160 160
 		}
161 161
 		allRec = append(allRec, variants...)
... ...
@@ -198,7 +199,7 @@ func (e *exporter) ExportTo(ctx context.Context, t CacheExporterTarget, opt Cach
198 198
 			}
199 199
 		}
200 200
 
201
-		for cm, id := range e.k.ids {
201
+		for cm, id := range k.ids {
202 202
 			if _, err := addBacklinks(t, rec, cm, id, bkm); err != nil {
203 203
 				return nil, err
204 204
 			}
... ...
@@ -762,6 +762,9 @@ func (h *HistoryQueue) Listen(ctx context.Context, req *controlapi.BuildHistoryR
762 762
 		}()
763 763
 	}
764 764
 
765
+	// make a copy of events for active builds so we don't keep a lock during grpc send
766
+	actives := make([]*controlapi.BuildHistoryEvent, 0, len(h.active))
767
+
765 768
 	for _, e := range h.active {
766 769
 		if req.Ref != "" && e.Ref != req.Ref {
767 770
 			continue
... ...
@@ -769,7 +772,7 @@ func (h *HistoryQueue) Listen(ctx context.Context, req *controlapi.BuildHistoryR
769 769
 		if _, ok := h.deleted[e.Ref]; ok {
770 770
 			continue
771 771
 		}
772
-		sub.send(&controlapi.BuildHistoryEvent{
772
+		actives = append(actives, &controlapi.BuildHistoryEvent{
773 773
 			Type:   controlapi.BuildHistoryEventType_STARTED,
774 774
 			Record: e,
775 775
 		})
... ...
@@ -777,6 +780,12 @@ func (h *HistoryQueue) Listen(ctx context.Context, req *controlapi.BuildHistoryR
777 777
 
778 778
 	h.mu.Unlock()
779 779
 
780
+	for _, e := range actives {
781
+		if err := f(e); err != nil {
782
+			return err
783
+		}
784
+	}
785
+
780 786
 	if !req.ActiveOnly {
781 787
 		events := []*controlapi.BuildHistoryEvent{}
782 788
 		if err := h.opt.DB.View(func(tx *bolt.Tx) error {
... ...
@@ -810,7 +819,7 @@ func (h *HistoryQueue) Listen(ctx context.Context, req *controlapi.BuildHistoryR
810 810
 		}
811 811
 		h.mu.Unlock()
812 812
 		for _, e := range events {
813
-			if e.Record == nil {
813
+			if e == nil || e.Record == nil {
814 814
 				continue
815 815
 			}
816 816
 			if err := f(e); err != nil {
... ...
@@ -680,7 +680,7 @@ github.com/mitchellh/hashstructure/v2
680 680
 # github.com/mitchellh/reflectwalk v1.0.2
681 681
 ## explicit
682 682
 github.com/mitchellh/reflectwalk
683
-# github.com/moby/buildkit v0.12.3
683
+# github.com/moby/buildkit v0.12.4
684 684
 ## explicit; go 1.20
685 685
 github.com/moby/buildkit/api/services/control
686 686
 github.com/moby/buildkit/api/types