Skip to content

Commit 6560bb9

Browse files
authored
Merge pull request moby#4304 from jedevc/v0.12.3-cherry-picks
[v0.12] Cherry-picks for v0.12.3
2 parents f94ed7c + 58a5cb9 commit 6560bb9

File tree

17 files changed

+465
-22
lines changed

17 files changed

+465
-22
lines changed

client/client.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/url"
99
"os"
1010
"strings"
11+
"time"
1112

1213
contentapi "github.com/containerd/containerd/api/services/content/v1"
1314
"github.com/containerd/containerd/defaults"
@@ -186,16 +187,29 @@ func (c *Client) Dialer() session.Dialer {
186187
}
187188

188189
func (c *Client) Wait(ctx context.Context) error {
189-
opts := []grpc.CallOption{grpc.WaitForReady(true)}
190-
_, err := c.ControlClient().Info(ctx, &controlapi.InfoRequest{}, opts...)
191-
if err != nil {
192-
if code := grpcerrors.Code(err); code == codes.Unimplemented {
190+
for {
191+
_, err := c.ControlClient().Info(ctx, &controlapi.InfoRequest{})
192+
if err == nil {
193+
return nil
194+
}
195+
196+
switch code := grpcerrors.Code(err); code {
197+
case codes.Unavailable:
198+
case codes.Unimplemented:
193199
// only buildkit v0.11+ supports the info api, but an unimplemented
194200
// response error is still a response so we can ignore it
195201
return nil
202+
default:
203+
return err
204+
}
205+
206+
select {
207+
case <-ctx.Done():
208+
return ctx.Err()
209+
case <-time.After(time.Second):
196210
}
211+
c.conn.ResetConnectBackoff()
197212
}
198-
return err
199213
}
200214

201215
func (c *Client) Close() error {

client/llb/sourcemap.go

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package llb
22

33
import (
4+
"bytes"
45
"context"
56

67
"github.com/moby/buildkit/solver/pb"
@@ -47,6 +48,33 @@ func (s *SourceMap) Location(r []*pb.Range) ConstraintsOpt {
4748
})
4849
}
4950

51+
func equalSourceMap(sm1, sm2 *SourceMap) (out bool) {
52+
if sm1 == nil || sm2 == nil {
53+
return false
54+
}
55+
if sm1.Filename != sm2.Filename {
56+
return false
57+
}
58+
if sm1.Language != sm2.Language {
59+
return false
60+
}
61+
if len(sm1.Data) != len(sm2.Data) {
62+
return false
63+
}
64+
if !bytes.Equal(sm1.Data, sm2.Data) {
65+
return false
66+
}
67+
if sm1.Definition != nil && sm2.Definition != nil {
68+
if len(sm1.Definition.Def) != len(sm2.Definition.Def) && len(sm1.Definition.Def) != 0 {
69+
return false
70+
}
71+
if !bytes.Equal(sm1.Definition.Def[len(sm1.Definition.Def)-1], sm2.Definition.Def[len(sm2.Definition.Def)-1]) {
72+
return false
73+
}
74+
}
75+
return true
76+
}
77+
5078
type SourceLocation struct {
5179
SourceMap *SourceMap
5280
Ranges []*pb.Range
@@ -69,8 +97,18 @@ func (smc *sourceMapCollector) Add(dgst digest.Digest, ls []*SourceLocation) {
6997
for _, l := range ls {
7098
idx, ok := smc.index[l.SourceMap]
7199
if !ok {
72-
idx = len(smc.maps)
73-
smc.maps = append(smc.maps, l.SourceMap)
100+
idx = -1
101+
// slow equality check
102+
for i, m := range smc.maps {
103+
if equalSourceMap(m, l.SourceMap) {
104+
idx = i
105+
break
106+
}
107+
}
108+
if idx == -1 {
109+
idx = len(smc.maps)
110+
smc.maps = append(smc.maps, l.SourceMap)
111+
}
74112
}
75113
smc.index[l.SourceMap] = idx
76114
}

cmd/buildctl/common/common.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import (
1616
"github.com/pkg/errors"
1717
"github.com/urfave/cli"
1818
"go.opentelemetry.io/otel/trace"
19-
"google.golang.org/grpc"
20-
"google.golang.org/grpc/backoff"
2119
)
2220

2321
// ResolveClient resolves a client from CLI args
@@ -69,12 +67,6 @@ func ResolveClient(c *cli.Context) (*client.Client, error) {
6967

7068
opts := []client.ClientOpt{client.WithFailFast()}
7169

72-
backoffConfig := backoff.DefaultConfig
73-
backoffConfig.MaxDelay = 1 * time.Second
74-
opts = append(opts, client.WithGRPCDialOption(
75-
grpc.WithConnectParams(grpc.ConnectParams{Backoff: backoffConfig}),
76-
))
77-
7870
ctx := CommandContext(c)
7971

8072
if span := trace.SpanFromContext(ctx); span.SpanContext().IsValid() {

cmd/buildkitd/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ func newController(c *cli.Context, cfg *config.Config) (*control.Controller, err
722722
Entitlements: cfg.Entitlements,
723723
TraceCollector: tc,
724724
HistoryDB: historyDB,
725+
CacheStore: cacheStorage,
725726
LeaseManager: w.LeaseManager(),
726727
ContentStore: w.ContentStore(),
727728
HistoryConfig: cfg.History,

control/control.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/containerd/containerd/content"
1313
"github.com/containerd/containerd/services/content/contentserver"
1414
"github.com/docker/distribution/reference"
15+
"github.com/hashicorp/go-multierror"
1516
"github.com/mitchellh/hashstructure/v2"
1617
controlapi "github.com/moby/buildkit/api/services/control"
1718
apitypes "github.com/moby/buildkit/api/types"
@@ -29,6 +30,7 @@ import (
2930
"github.com/moby/buildkit/session/grpchijack"
3031
containerdsnapshot "github.com/moby/buildkit/snapshot/containerd"
3132
"github.com/moby/buildkit/solver"
33+
"github.com/moby/buildkit/solver/bboltcachestorage"
3234
"github.com/moby/buildkit/solver/llbsolver"
3335
"github.com/moby/buildkit/solver/llbsolver/proc"
3436
"github.com/moby/buildkit/solver/pb"
@@ -61,6 +63,7 @@ type Opt struct {
6163
Entitlements []string
6264
TraceCollector sdktrace.SpanExporter
6365
HistoryDB *bbolt.DB
66+
CacheStore *bboltcachestorage.Store
6467
LeaseManager *leaseutil.Manager
6568
ContentStore *containerdsnapshot.Store
6669
HistoryConfig *config.HistoryConfig
@@ -123,7 +126,16 @@ func NewController(opt Opt) (*Controller, error) {
123126
}
124127

125128
func (c *Controller) Close() error {
126-
return c.opt.WorkerController.Close()
129+
rerr := c.opt.HistoryDB.Close()
130+
if err := c.opt.WorkerController.Close(); err != nil {
131+
rerr = multierror.Append(rerr, err)
132+
}
133+
134+
if err := c.opt.CacheStore.Close(); err != nil {
135+
rerr = multierror.Append(rerr, err)
136+
}
137+
138+
return rerr
127139
}
128140

129141
func (c *Controller) Register(server *grpc.Server) {

executor/oci/spec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func GenerateSpec(ctx context.Context, meta executor.Meta, mounts []executor.Mou
137137
return nil, nil, err
138138
}
139139

140-
if cgroupNamespaceSupported() {
140+
if cgroupV2NamespaceSupported() {
141141
s.Linux.Namespaces = append(s.Linux.Namespaces, specs.LinuxNamespace{
142142
Type: specs.CgroupNamespace,
143143
})

executor/oci/spec_unix.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,19 @@ func getTracingSocket() string {
147147
return fmt.Sprintf("unix://%s", tracingSocketPath)
148148
}
149149

150-
func cgroupNamespaceSupported() bool {
150+
func cgroupV2NamespaceSupported() bool {
151+
// Check if cgroups v2 namespaces are supported. Trying to do cgroup
152+
// namespaces with cgroups v1 results in EINVAL when we encounter a
153+
// non-standard hierarchy.
154+
// See https://github.com/moby/buildkit/issues/4108
151155
cgroupNSOnce.Do(func() {
152-
if _, err := os.Stat("/proc/self/ns/cgroup"); !os.IsNotExist(err) {
153-
supportsCgroupNS = true
156+
if _, err := os.Stat("/proc/self/ns/cgroup"); os.IsNotExist(err) {
157+
return
154158
}
159+
if _, err := os.Stat("/sys/fs/cgroup/cgroup.subtree_control"); os.IsNotExist(err) {
160+
return
161+
}
162+
supportsCgroupNS = true
155163
})
156164
return supportsCgroupNS
157165
}

executor/oci/spec_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ func getTracingSocket() string {
6464
return fmt.Sprintf("npipe://%s", filepath.ToSlash(tracingSocketPath))
6565
}
6666

67-
func cgroupNamespaceSupported() bool {
67+
func cgroupV2NamespaceSupported() bool {
6868
return false
6969
}

0 commit comments

Comments
 (0)