Browse code

bump buildkit v0.5.0

full diff: https://github.com/moby/buildkit/compare/8818c67cff663befa7b70f21454e340f71616581...v0.5.0

- moby/buildkit#909 exporter: support unpack opt for image exporter
- moby/buildkit#961 dockerfile: allow subdirs for remote contexts

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 3e4723cf3395dcdaa4c98acba549ac0170899504)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2019/04/28 06:24:35
Showing 4 changed files
... ...
@@ -74,6 +74,10 @@ func NewSnapshotter(opt Opt) (snapshot.SnapshotterBase, error) {
74 74
 	return s, nil
75 75
 }
76 76
 
77
+func (s *snapshotter) Name() string {
78
+	return "default"
79
+}
80
+
77 81
 func (s *snapshotter) IdentityMapping() *idtools.IdentityMapping {
78 82
 	return nil
79 83
 }
... ...
@@ -27,7 +27,7 @@ github.com/imdario/mergo                            7c29201646fa3de8506f70121347
27 27
 golang.org/x/sync                                   e225da77a7e68af35c70ccbf71af2b83e6acac3c
28 28
 
29 29
 # buildkit
30
-github.com/moby/buildkit                            8818c67cff663befa7b70f21454e340f71616581
30
+github.com/moby/buildkit                            8c0fa8fdec187d8f259a349d2da16dc2dc5f144a # v0.5.0
31 31
 github.com/tonistiigi/fsutil                        3bbb99cdbd76619ab717299830c60f6f2a533a6b
32 32
 github.com/grpc-ecosystem/grpc-opentracing          8e809c8a86450a29b90dcc9efbf062d0fe6d9746
33 33
 github.com/opentracing/opentracing-go               1361b9cd60be79c4c3a7fa9841b3c132e40066a7
... ...
@@ -8,6 +8,7 @@ import (
8 8
 	"encoding/json"
9 9
 	"fmt"
10 10
 	"net"
11
+	"path"
11 12
 	"regexp"
12 13
 	"strconv"
13 14
 	"strings"
... ...
@@ -46,6 +47,7 @@ const (
46 46
 	keyOverrideCopyImage       = "override-copy-image" // remove after CopyOp implemented
47 47
 	keyNameContext             = "contextkey"
48 48
 	keyNameDockerfile          = "dockerfilekey"
49
+	keyContextSubDir           = "contextsubdir"
49 50
 )
50 51
 
51 52
 var httpPrefix = regexp.MustCompile("^https?://")
... ...
@@ -122,6 +124,8 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {
122 122
 		dockerfile2llb.WithInternalName(name),
123 123
 	)
124 124
 
125
+	fileop := useFileOp(opts, &caps)
126
+
125 127
 	var buildContext *llb.State
126 128
 	isScratchContext := false
127 129
 	if st, ok := detectGitContext(opts[localNameContext]); ok {
... ...
@@ -157,7 +161,6 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {
157 157
 			return nil, errors.Errorf("failed to read downloaded context")
158 158
 		}
159 159
 		if isArchive(dt) {
160
-			fileop := useFileOp(opts, &caps)
161 160
 			if fileop {
162 161
 				bc := llb.Scratch().File(llb.Copy(httpContext, "/context", "/", &llb.CopyInfo{
163 162
 					AttemptUnpack: true,
... ...
@@ -190,6 +193,12 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {
190 190
 		}
191 191
 	}
192 192
 
193
+	if buildContext != nil {
194
+		if sub, ok := opts[keyContextSubDir]; ok {
195
+			buildContext = scopeToSubDir(buildContext, fileop, sub)
196
+		}
197
+	}
198
+
193 199
 	def, err := src.Marshal(marshalOpts...)
194 200
 	if err != nil {
195 201
 		return nil, errors.Wrapf(err, "failed to marshal local source")
... ...
@@ -561,3 +570,17 @@ func useFileOp(args map[string]string, caps *apicaps.CapSet) bool {
561 561
 	}
562 562
 	return enabled && caps != nil && caps.Supports(pb.CapFileBase) == nil
563 563
 }
564
+
565
+func scopeToSubDir(c *llb.State, fileop bool, dir string) *llb.State {
566
+	if fileop {
567
+		bc := llb.Scratch().File(llb.Copy(*c, dir, "/", &llb.CopyInfo{
568
+			CopyDirContentsOnly: true,
569
+		}))
570
+		return &bc
571
+	}
572
+	unpack := llb.Image(dockerfile2llb.DefaultCopyImage, dockerfile2llb.WithInternalName("helper image for file operations")).
573
+		Run(llb.Shlexf("copy %s/. /out/", path.Join("/src", dir)), llb.ReadonlyRootFS(), dockerfile2llb.WithInternalName("filtering build context"))
574
+	unpack.AddMount("/src", *c, llb.Readonly)
575
+	bc := unpack.AddMount("/out", llb.Scratch())
576
+	return &bc
577
+}
... ...
@@ -18,6 +18,7 @@ type Mountable interface {
18 18
 }
19 19
 
20 20
 type SnapshotterBase interface {
21
+	Name() string
21 22
 	Mounts(ctx context.Context, key string) (Mountable, error)
22 23
 	Prepare(ctx context.Context, key, parent string, opts ...snapshots.Opt) error
23 24
 	View(ctx context.Context, key, parent string, opts ...snapshots.Opt) (Mountable, error)
... ...
@@ -43,15 +44,20 @@ type Blobmapper interface {
43 43
 	SetBlob(ctx context.Context, key string, diffID, blob digest.Digest) error
44 44
 }
45 45
 
46
-func FromContainerdSnapshotter(s snapshots.Snapshotter, idmap *idtools.IdentityMapping) SnapshotterBase {
47
-	return &fromContainerd{Snapshotter: s, idmap: idmap}
46
+func FromContainerdSnapshotter(name string, s snapshots.Snapshotter, idmap *idtools.IdentityMapping) SnapshotterBase {
47
+	return &fromContainerd{name: name, Snapshotter: s, idmap: idmap}
48 48
 }
49 49
 
50 50
 type fromContainerd struct {
51
+	name string
51 52
 	snapshots.Snapshotter
52 53
 	idmap *idtools.IdentityMapping
53 54
 }
54 55
 
56
+func (s *fromContainerd) Name() string {
57
+	return s.name
58
+}
59
+
55 60
 func (s *fromContainerd) Mounts(ctx context.Context, key string) (Mountable, error) {
56 61
 	mounts, err := s.Snapshotter.Mounts(ctx, key)
57 62
 	if err != nil {