Browse code

vendor: update buildkit for 19.03

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>

Tonis Tiigi authored on 2019/09/21 09:27:23
Showing 17 changed files
... ...
@@ -27,8 +27,8 @@ github.com/imdario/mergo                            7c29201646fa3de8506f70121347
27 27
 golang.org/x/sync                                   e225da77a7e68af35c70ccbf71af2b83e6acac3c
28 28
 
29 29
 # buildkit
30
-github.com/moby/buildkit                            588c73e1e4f0f3d7d3738abaaa7cf8026064b33e
31
-github.com/tonistiigi/fsutil                        3bbb99cdbd76619ab717299830c60f6f2a533a6b
30
+github.com/moby/buildkit                            ae10b292fefb00e0fbf9fecd1419c5f252e58895
31
+github.com/tonistiigi/fsutil                        3d2716dd0a4d06ff854241c7e8b6f3f904e1719f
32 32
 github.com/grpc-ecosystem/grpc-opentracing          8e809c8a86450a29b90dcc9efbf062d0fe6d9746
33 33
 github.com/opentracing/opentracing-go               1361b9cd60be79c4c3a7fa9841b3c132e40066a7
34 34
 github.com/google/shlex                             6f45313302b9c56850fc17f99e40caebce98c716
... ...
@@ -125,7 +125,7 @@ github.com/containerd/fifo                          a9fb20d87448d386e6d50b1f2e1f
125 125
 github.com/containerd/continuity                    aaeac12a7ffcd198ae25440a9dff125c2e2703a7
126 126
 github.com/containerd/cgroups                       4994991857f9b0ae8dc439551e8bebdbb4bf66c1
127 127
 github.com/containerd/console                       0650fd9eeb50bab4fc99dceb9f2e14cf58f36e7f
128
-github.com/containerd/go-runc                       7d11b49dc0769f6dbb0d1b19f3d48524d1bad9ad
128
+github.com/containerd/go-runc                       e029b79d8cda8374981c64eba71f28ec38e5526f
129 129
 github.com/containerd/typeurl                       2a93cfde8c20b23de8eb84a5adbc234ddf7a9e8d
130 130
 github.com/containerd/ttrpc                         699c4e40d1e7416e08bf7019c7ce2e9beced4636
131 131
 github.com/gogo/googleapis                          d31c731455cb061f42baff3bda55bad0118b126b # v1.2.0
... ...
@@ -20,6 +20,7 @@ import (
20 20
 	"context"
21 21
 	"os"
22 22
 	"os/exec"
23
+	"strings"
23 24
 	"syscall"
24 25
 )
25 26
 
... ...
@@ -32,10 +33,24 @@ func (r *Runc) command(context context.Context, args ...string) *exec.Cmd {
32 32
 	cmd.SysProcAttr = &syscall.SysProcAttr{
33 33
 		Setpgid: r.Setpgid,
34 34
 	}
35
-	cmd.Env = os.Environ()
35
+	cmd.Env = filterEnv(os.Environ(), "NOTIFY_SOCKET") // NOTIFY_SOCKET introduces a special behavior in runc but should only be set if invoked from systemd
36 36
 	if r.PdeathSignal != 0 {
37 37
 		cmd.SysProcAttr.Pdeathsig = r.PdeathSignal
38 38
 	}
39 39
 
40 40
 	return cmd
41 41
 }
42
+
43
+func filterEnv(in []string, names ...string) []string {
44
+	out := make([]string, 0, len(in))
45
+loop0:
46
+	for _, v := range in {
47
+		for _, k := range names {
48
+			if strings.HasPrefix(v, k+"=") {
49
+				continue loop0
50
+			}
51
+		}
52
+		out = append(out, v)
53
+	}
54
+	return out
55
+}
... ...
@@ -275,7 +275,11 @@ func (r *Runc) Run(context context.Context, id, bundle string, opts *CreateOpts)
275 275
 	if err != nil {
276 276
 		return -1, err
277 277
 	}
278
-	return Monitor.Wait(cmd, ec)
278
+	status, err := Monitor.Wait(cmd, ec)
279
+	if err == nil && status != 0 {
280
+		err = fmt.Errorf("%s did not terminate sucessfully", cmd.Args[0])
281
+	}
282
+	return status, err
279 283
 }
280 284
 
281 285
 type DeleteOpts struct {
... ...
@@ -570,7 +574,11 @@ func (r *Runc) Restore(context context.Context, id, bundle string, opts *Restore
570 570
 			}
571 571
 		}
572 572
 	}
573
-	return Monitor.Wait(cmd, ec)
573
+	status, err := Monitor.Wait(cmd, ec)
574
+	if err == nil && status != 0 {
575
+		err = fmt.Errorf("%s did not terminate sucessfully", cmd.Args[0])
576
+	}
577
+	return status, err
574 578
 }
575 579
 
576 580
 // Update updates the current container with the provided resource spec
... ...
@@ -293,12 +293,11 @@ func (w *runcExecutor) Exec(ctx context.Context, meta executor.Meta, root cache.
293 293
 		NoPivot: w.noPivot,
294 294
 	})
295 295
 	close(done)
296
-	if err != nil {
297
-		return err
298
-	}
299 296
 
300
-	if status != 0 {
301
-		err := errors.Errorf("exit code: %d", status)
297
+	if status != 0 || err != nil {
298
+		if err == nil {
299
+			err = errors.Errorf("exit code: %d", status)
300
+		}
302 301
 		select {
303 302
 		case <-ctx.Done():
304 303
 			return errors.Wrapf(ctx.Err(), err.Error())
... ...
@@ -10,10 +10,10 @@ require (
10 10
 	github.com/containerd/cgroups v0.0.0-20190226200435-dbea6f2bd416 // indirect
11 11
 	github.com/containerd/console v0.0.0-20181022165439-0650fd9eeb50
12 12
 	github.com/containerd/containerd v1.3.0-0.20190507210959-7c1e88399ec0
13
-	github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc
13
+	github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6
14 14
 	github.com/containerd/fifo v0.0.0-20180307165137-3d5202aec260 // indirect
15 15
 	github.com/containerd/go-cni v0.0.0-20190610170741-5a4663dad645
16
-	github.com/containerd/go-runc v0.0.0-20180907222934-5a6d9f37cfa3
16
+	github.com/containerd/go-runc v0.0.0-20190911050354-e029b79d8cda
17 17
 	github.com/containerd/ttrpc v0.0.0-20190411181408-699c4e40d1e7 // indirect
18 18
 	github.com/containerd/typeurl v0.0.0-20180627222232-a93fcdb778cd // indirect
19 19
 	github.com/containernetworking/cni v0.6.1-0.20180218032124-142cde0c766c // indirect
... ...
@@ -53,7 +53,7 @@ require (
53 53
 	github.com/sirupsen/logrus v1.3.0
54 54
 	github.com/stretchr/testify v1.3.0
55 55
 	github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2 // indirect
56
-	github.com/tonistiigi/fsutil v0.0.0-20190327153851-3bbb99cdbd76
56
+	github.com/tonistiigi/fsutil v0.0.0-20190819224149-3d2716dd0a4d
57 57
 	github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea
58 58
 	github.com/uber/jaeger-client-go v0.0.0-20180103221425-e02c85f9069e
59 59
 	github.com/uber/jaeger-lib v1.2.1 // indirect
... ...
@@ -9,17 +9,17 @@ import (
9 9
 	"google.golang.org/grpc"
10 10
 )
11 11
 
12
-func Copy(ctx context.Context, conn io.ReadWriteCloser, stream grpc.Stream) error {
12
+func Copy(ctx context.Context, conn io.ReadWriteCloser, stream grpc.Stream, closeStream func() error) error {
13 13
 	g, ctx := errgroup.WithContext(ctx)
14 14
 
15 15
 	g.Go(func() (retErr error) {
16 16
 		p := &BytesMessage{}
17 17
 		for {
18 18
 			if err := stream.RecvMsg(p); err != nil {
19
+				conn.Close()
19 20
 				if err == io.EOF {
20 21
 					return nil
21 22
 				}
22
-				conn.Close()
23 23
 				return errors.WithStack(err)
24 24
 			}
25 25
 			select {
... ...
@@ -42,6 +42,9 @@ func Copy(ctx context.Context, conn io.ReadWriteCloser, stream grpc.Stream) erro
42 42
 			n, err := conn.Read(buf)
43 43
 			switch {
44 44
 			case err == io.EOF:
45
+				if closeStream != nil {
46
+					closeStream()
47
+				}
45 48
 				return nil
46 49
 			case err != nil:
47 50
 				return errors.WithStack(err)
... ...
@@ -49,7 +49,7 @@ func (s *server) run(ctx context.Context, l net.Listener, id string) error {
49 49
 				return err
50 50
 			}
51 51
 
52
-			go Copy(ctx, conn, stream)
52
+			go Copy(ctx, conn, stream, stream.CloseSend)
53 53
 		}
54 54
 	})
55 55
 
... ...
@@ -177,6 +177,9 @@ func (e *edge) finishIncoming(req pipe.Sender) {
177 177
 
178 178
 // updateIncoming updates the current value of incoming pipe request
179 179
 func (e *edge) updateIncoming(req pipe.Sender) {
180
+	if debugScheduler {
181
+		logrus.Debugf("updateIncoming %s %#v desired=%s", e.edge.Vertex.Name(), e.edgeState, req.Request().Payload.(*edgeRequest).desiredState)
182
+	}
180 183
 	req.Update(&e.edgeState)
181 184
 }
182 185
 
... ...
@@ -11,11 +11,15 @@ import (
11 11
 type channel struct {
12 12
 	OnSendCompletion func()
13 13
 	value            atomic.Value
14
-	lastValue        interface{}
14
+	lastValue        *wrappedValue
15
+}
16
+
17
+type wrappedValue struct {
18
+	value interface{}
15 19
 }
16 20
 
17 21
 func (c *channel) Send(v interface{}) {
18
-	c.value.Store(v)
22
+	c.value.Store(&wrappedValue{value: v})
19 23
 	if c.OnSendCompletion != nil {
20 24
 		c.OnSendCompletion()
21 25
 	}
... ...
@@ -23,11 +27,11 @@ func (c *channel) Send(v interface{}) {
23 23
 
24 24
 func (c *channel) Receive() (interface{}, bool) {
25 25
 	v := c.value.Load()
26
-	if c.lastValue == v {
26
+	if v == nil || v.(*wrappedValue) == c.lastValue {
27 27
 		return nil, false
28 28
 	}
29
-	c.lastValue = v
30
-	return v, true
29
+	c.lastValue = v.(*wrappedValue)
30
+	return v.(*wrappedValue).value, true
31 31
 }
32 32
 
33 33
 type Pipe struct {
... ...
@@ -54,7 +54,7 @@ func (b *llbBridge) Solve(ctx context.Context, req frontend.SolveRequest) (res *
54 54
 			}
55 55
 		}
56 56
 		if prevCm, ok := b.cms[cmId]; !ok {
57
-			func(cmId string) {
57
+			func(cmId string, im gw.CacheOptionsEntry) {
58 58
 				cm = newLazyCacheManager(cmId, func() (solver.CacheManager, error) {
59 59
 					var cmNew solver.CacheManager
60 60
 					if err := inVertexContext(b.builder.Context(ctx), "importing cache manifest from "+cmId, "", func(ctx context.Context) error {
... ...
@@ -74,7 +74,7 @@ func (b *llbBridge) Solve(ctx context.Context, req frontend.SolveRequest) (res *
74 74
 					}
75 75
 					return cmNew, nil
76 76
 				})
77
-			}(cmId)
77
+			}(cmId, im)
78 78
 			b.cms[cmId] = cm
79 79
 		} else {
80 80
 			cm = prevCm
... ...
@@ -144,6 +144,11 @@ func (hs *httpSourceHandler) CacheKey(ctx context.Context, index int) (string, b
144 144
 	req = req.WithContext(ctx)
145 145
 	m := map[string]*metadata.StorageItem{}
146 146
 
147
+	// If we request a single ETag in 'If-None-Match', some servers omit the
148
+	// unambiguous ETag in their response.
149
+	// See: https://github.com/moby/buildkit/issues/905
150
+	var onlyETag string
151
+
147 152
 	if len(sis) > 0 {
148 153
 		for _, si := range sis {
149 154
 			// if metaDigest := getMetaDigest(si); metaDigest == hs.formatCacheKey("") {
... ...
@@ -160,6 +165,10 @@ func (hs *httpSourceHandler) CacheKey(ctx context.Context, index int) (string, b
160 160
 				etags = append(etags, t)
161 161
 			}
162 162
 			req.Header.Add("If-None-Match", strings.Join(etags, ", "))
163
+
164
+			if len(etags) == 1 {
165
+				onlyETag = etags[0]
166
+			}
163 167
 		}
164 168
 	}
165 169
 
... ...
@@ -172,6 +181,12 @@ func (hs *httpSourceHandler) CacheKey(ctx context.Context, index int) (string, b
172 172
 		if err == nil {
173 173
 			if resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusNotModified {
174 174
 				respETag := resp.Header.Get("ETag")
175
+
176
+				// If a 304 is returned without an ETag and we had only sent one ETag,
177
+				// the response refers to the ETag we asked about.
178
+				if respETag == "" && onlyETag != "" && resp.StatusCode == http.StatusNotModified {
179
+					respETag = onlyETag
180
+				}
175 181
 				si, ok := m[respETag]
176 182
 				if ok {
177 183
 					hs.refID = si.ID()
... ...
@@ -197,6 +212,13 @@ func (hs *httpSourceHandler) CacheKey(ctx context.Context, index int) (string, b
197 197
 	}
198 198
 	if resp.StatusCode == http.StatusNotModified {
199 199
 		respETag := resp.Header.Get("ETag")
200
+		if respETag == "" && onlyETag != "" {
201
+			respETag = onlyETag
202
+
203
+			// Set the missing ETag header on the response so that it's available
204
+			// to .save()
205
+			resp.Header.Set("ETag", onlyETag)
206
+		}
200 207
 		si, ok := m[respETag]
201 208
 		if !ok {
202 209
 			return "", false, errors.Errorf("invalid not-modified ETag: %v", respETag)
... ...
@@ -329,21 +329,6 @@ func ensureEmptyFileTarget(dst string) error {
329 329
 	return os.Remove(dst)
330 330
 }
331 331
 
332
-func copyFile(source, target string) error {
333
-	src, err := os.Open(source)
334
-	if err != nil {
335
-		return errors.Wrapf(err, "failed to open source %s", source)
336
-	}
337
-	defer src.Close()
338
-	tgt, err := os.Create(target)
339
-	if err != nil {
340
-		return errors.Wrapf(err, "failed to open target %s", target)
341
-	}
342
-	defer tgt.Close()
343
-
344
-	return copyFileContent(tgt, src)
345
-}
346
-
347 332
 func containsWildcards(name string) bool {
348 333
 	isWindows := runtime.GOOS == "windows"
349 334
 	for i := 0; i < len(name); i++ {
350 335
new file mode 100644
... ...
@@ -0,0 +1,84 @@
0
+// +build darwin
1
+
2
+package fs
3
+
4
+import (
5
+	"io"
6
+	"os"
7
+	"syscall"
8
+	"unsafe"
9
+
10
+	"github.com/pkg/errors"
11
+	"golang.org/x/sys/unix"
12
+)
13
+
14
+// <sys/clonefile.h
15
+// int clonefileat(int, const char *, int, const char *, uint32_t) __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0);
16
+
17
+const CLONE_NOFOLLOW = 0x0001    /* Don't follow symbolic links */
18
+const CLONE_NOOWNERCOPY = 0x0002 /* Don't copy ownership information from */
19
+
20
+func copyFile(source, target string) error {
21
+	if err := clonefile(source, target); err != nil {
22
+		if err != unix.EINVAL {
23
+			return err
24
+		}
25
+	} else {
26
+		return nil
27
+	}
28
+
29
+	src, err := os.Open(source)
30
+	if err != nil {
31
+		return errors.Wrapf(err, "failed to open source %s", source)
32
+	}
33
+	defer src.Close()
34
+	tgt, err := os.Create(target)
35
+	if err != nil {
36
+		return errors.Wrapf(err, "failed to open target %s", target)
37
+	}
38
+	defer tgt.Close()
39
+
40
+	return copyFileContent(tgt, src)
41
+}
42
+
43
+func copyFileContent(dst, src *os.File) error {
44
+	buf := bufferPool.Get().(*[]byte)
45
+	_, err := io.CopyBuffer(dst, src, *buf)
46
+	bufferPool.Put(buf)
47
+
48
+	return err
49
+}
50
+
51
+// errnoErr returns common boxed Errno values, to prevent
52
+// allocations at runtime.
53
+func errnoErr(e syscall.Errno) error {
54
+	switch e {
55
+	case 0:
56
+		return nil
57
+	case unix.EAGAIN:
58
+		return syscall.EAGAIN
59
+	case unix.EINVAL:
60
+		return syscall.EINVAL
61
+	case unix.ENOENT:
62
+		return syscall.ENOENT
63
+	}
64
+	return e
65
+}
66
+
67
+func clonefile(src, dst string) (err error) {
68
+	var _p0, _p1 *byte
69
+	_p0, err = unix.BytePtrFromString(src)
70
+	if err != nil {
71
+		return
72
+	}
73
+	_p1, err = unix.BytePtrFromString(dst)
74
+	if err != nil {
75
+		return
76
+	}
77
+	fdcwd := unix.AT_FDCWD
78
+	_, _, e1 := unix.Syscall6(unix.SYS_CLONEFILEAT, uintptr(fdcwd), uintptr(unsafe.Pointer(_p0)), uintptr(fdcwd), uintptr(unsafe.Pointer(_p1)), uintptr(CLONE_NOFOLLOW), 0)
79
+	if e1 != 0 {
80
+		err = errnoErr(e1)
81
+	}
82
+	return
83
+}
... ...
@@ -52,6 +52,21 @@ func (c *copier) copyFileInfo(fi os.FileInfo, name string) error {
52 52
 	return nil
53 53
 }
54 54
 
55
+func copyFile(source, target string) error {
56
+	src, err := os.Open(source)
57
+	if err != nil {
58
+		return errors.Wrapf(err, "failed to open source %s", source)
59
+	}
60
+	defer src.Close()
61
+	tgt, err := os.Create(target)
62
+	if err != nil {
63
+		return errors.Wrapf(err, "failed to open target %s", target)
64
+	}
65
+	defer tgt.Close()
66
+
67
+	return copyFileContent(tgt, src)
68
+}
69
+
55 70
 func copyFileContent(dst, src *os.File) error {
56 71
 	st, err := src.Stat()
57 72
 	if err != nil {
... ...
@@ -3,7 +3,6 @@
3 3
 package fs
4 4
 
5 5
 import (
6
-	"io"
7 6
 	"os"
8 7
 	"syscall"
9 8
 
... ...
@@ -51,14 +50,6 @@ func (c *copier) copyFileInfo(fi os.FileInfo, name string) error {
51 51
 	return nil
52 52
 }
53 53
 
54
-func copyFileContent(dst, src *os.File) error {
55
-	buf := bufferPool.Get().(*[]byte)
56
-	_, err := io.CopyBuffer(dst, src, *buf)
57
-	bufferPool.Put(buf)
58
-
59
-	return err
60
-}
61
-
62 54
 func copyDevice(dst string, fi os.FileInfo) error {
63 55
 	st, ok := fi.Sys().(*syscall.Stat_t)
64 56
 	if !ok {
... ...
@@ -17,6 +17,21 @@ func (c *copier) copyFileInfo(fi os.FileInfo, name string) error {
17 17
 	return nil
18 18
 }
19 19
 
20
+func copyFile(source, target string) error {
21
+	src, err := os.Open(source)
22
+	if err != nil {
23
+		return errors.Wrapf(err, "failed to open source %s", source)
24
+	}
25
+	defer src.Close()
26
+	tgt, err := os.Create(target)
27
+	if err != nil {
28
+		return errors.Wrapf(err, "failed to open target %s", target)
29
+	}
30
+	defer tgt.Close()
31
+
32
+	return copyFileContent(tgt, src)
33
+}
34
+
20 35
 func copyFileContent(dst, src *os.File) error {
21 36
 	buf := bufferPool.Get().(*[]byte)
22 37
 	_, err := io.CopyBuffer(dst, src, *buf)
... ...
@@ -49,6 +49,9 @@ func mkstat(path, relpath string, fi os.FileInfo, inodemap map[uint64]string) (*
49 49
 		stat.Mode = noPermPart | permPart
50 50
 	}
51 51
 
52
+	// Clear the socket bit since archive/tar.FileInfoHeader does not handle it
53
+	stat.Mode &^= uint32(os.ModeSocket)
54
+
52 55
 	return stat, nil
53 56
 }
54 57