Преглед на файлове

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>
Sebastiaan van Stijn преди 6 години
родител
ревизия
3e4723cf33

+ 4 - 0
builder/builder-next/adapters/snapshot/snapshot.go

@@ -74,6 +74,10 @@ func NewSnapshotter(opt Opt) (snapshot.SnapshotterBase, error) {
 	return s, nil
 }
 
+func (s *snapshotter) Name() string {
+	return "default"
+}
+
 func (s *snapshotter) IdentityMapping() *idtools.IdentityMapping {
 	return nil
 }

+ 1 - 1
vendor.conf

@@ -27,7 +27,7 @@ github.com/imdario/mergo                            7c29201646fa3de8506f70121347
 golang.org/x/sync                                   e225da77a7e68af35c70ccbf71af2b83e6acac3c
 
 # buildkit
-github.com/moby/buildkit                            8818c67cff663befa7b70f21454e340f71616581
+github.com/moby/buildkit                            8c0fa8fdec187d8f259a349d2da16dc2dc5f144a # v0.5.0
 github.com/tonistiigi/fsutil                        3bbb99cdbd76619ab717299830c60f6f2a533a6b
 github.com/grpc-ecosystem/grpc-opentracing          8e809c8a86450a29b90dcc9efbf062d0fe6d9746
 github.com/opentracing/opentracing-go               1361b9cd60be79c4c3a7fa9841b3c132e40066a7

+ 24 - 1
vendor/github.com/moby/buildkit/frontend/dockerfile/builder/build.go

@@ -8,6 +8,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"net"
+	"path"
 	"regexp"
 	"strconv"
 	"strings"
@@ -46,6 +47,7 @@ const (
 	keyOverrideCopyImage       = "override-copy-image" // remove after CopyOp implemented
 	keyNameContext             = "contextkey"
 	keyNameDockerfile          = "dockerfilekey"
+	keyContextSubDir           = "contextsubdir"
 )
 
 var httpPrefix = regexp.MustCompile("^https?://")
@@ -122,6 +124,8 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {
 		dockerfile2llb.WithInternalName(name),
 	)
 
+	fileop := useFileOp(opts, &caps)
+
 	var buildContext *llb.State
 	isScratchContext := false
 	if st, ok := detectGitContext(opts[localNameContext]); ok {
@@ -157,7 +161,6 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {
 			return nil, errors.Errorf("failed to read downloaded context")
 		}
 		if isArchive(dt) {
-			fileop := useFileOp(opts, &caps)
 			if fileop {
 				bc := llb.Scratch().File(llb.Copy(httpContext, "/context", "/", &llb.CopyInfo{
 					AttemptUnpack: true,
@@ -190,6 +193,12 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {
 		}
 	}
 
+	if buildContext != nil {
+		if sub, ok := opts[keyContextSubDir]; ok {
+			buildContext = scopeToSubDir(buildContext, fileop, sub)
+		}
+	}
+
 	def, err := src.Marshal(marshalOpts...)
 	if err != nil {
 		return nil, errors.Wrapf(err, "failed to marshal local source")
@@ -561,3 +570,17 @@ func useFileOp(args map[string]string, caps *apicaps.CapSet) bool {
 	}
 	return enabled && caps != nil && caps.Supports(pb.CapFileBase) == nil
 }
+
+func scopeToSubDir(c *llb.State, fileop bool, dir string) *llb.State {
+	if fileop {
+		bc := llb.Scratch().File(llb.Copy(*c, dir, "/", &llb.CopyInfo{
+			CopyDirContentsOnly: true,
+		}))
+		return &bc
+	}
+	unpack := llb.Image(dockerfile2llb.DefaultCopyImage, dockerfile2llb.WithInternalName("helper image for file operations")).
+		Run(llb.Shlexf("copy %s/. /out/", path.Join("/src", dir)), llb.ReadonlyRootFS(), dockerfile2llb.WithInternalName("filtering build context"))
+	unpack.AddMount("/src", *c, llb.Readonly)
+	bc := unpack.AddMount("/out", llb.Scratch())
+	return &bc
+}

+ 8 - 2
vendor/github.com/moby/buildkit/snapshot/snapshotter.go

@@ -18,6 +18,7 @@ type Mountable interface {
 }
 
 type SnapshotterBase interface {
+	Name() string
 	Mounts(ctx context.Context, key string) (Mountable, error)
 	Prepare(ctx context.Context, key, parent string, opts ...snapshots.Opt) error
 	View(ctx context.Context, key, parent string, opts ...snapshots.Opt) (Mountable, error)
@@ -43,15 +44,20 @@ type Blobmapper interface {
 	SetBlob(ctx context.Context, key string, diffID, blob digest.Digest) error
 }
 
-func FromContainerdSnapshotter(s snapshots.Snapshotter, idmap *idtools.IdentityMapping) SnapshotterBase {
-	return &fromContainerd{Snapshotter: s, idmap: idmap}
+func FromContainerdSnapshotter(name string, s snapshots.Snapshotter, idmap *idtools.IdentityMapping) SnapshotterBase {
+	return &fromContainerd{name: name, Snapshotter: s, idmap: idmap}
 }
 
 type fromContainerd struct {
+	name string
 	snapshots.Snapshotter
 	idmap *idtools.IdentityMapping
 }
 
+func (s *fromContainerd) Name() string {
+	return s.name
+}
+
 func (s *fromContainerd) Mounts(ctx context.Context, key string) (Mountable, error) {
 	mounts, err := s.Snapshotter.Mounts(ctx, key)
 	if err != nil {