dockerfile: use fileop for http context

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
docker-19.03
Tonis Tiigi 2019-04-15 23:38:31 -07:00
parent e4cb7b17f1
commit 4b97a7fed0
2 changed files with 29 additions and 10 deletions

View File

@ -20,6 +20,7 @@ import (
"github.com/moby/buildkit/frontend/dockerfile/dockerfile2llb"
"github.com/moby/buildkit/frontend/gateway/client"
"github.com/moby/buildkit/solver/pb"
"github.com/moby/buildkit/util/apicaps"
specs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
@ -151,6 +152,13 @@ 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 {
src = llb.Scratch().File(llb.Copy(httpContext, "/context", "/", &llb.CopyInfo{
AttemptUnpack: true,
}))
buildContext = &src
} else {
copyImage := opts[keyOverrideCopyImage]
if copyImage == "" {
copyImage = dockerfile2llb.DefaultCopyImage
@ -160,6 +168,7 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {
unpack.AddMount("/src", httpContext, llb.Readonly)
src = unpack.AddMount("/out", llb.Scratch())
buildContext = &src
}
} else {
filename = "context"
src = httpContext
@ -529,3 +538,13 @@ func parseNetMode(v string) (pb.NetMode, error) {
return 0, errors.Errorf("invalid netmode %s", v)
}
}
func useFileOp(args map[string]string, caps *apicaps.CapSet) bool {
enabled := true
if v, ok := args["build-arg:BUILDKIT_DISABLE_FILEOP"]; ok {
if b, err := strconv.ParseBool(v); err == nil {
enabled = !b
}
}
return enabled && caps != nil && caps.Supports(pb.CapFileBase) == nil
}

View File

@ -16,8 +16,8 @@ const (
func New(ctx context.Context, c session.Caller, url *url.URL) (*Upload, error) {
opts := map[string][]string{
keyPath: []string{url.Path},
keyHost: []string{url.Host},
keyPath: {url.Path},
keyHost: {url.Host},
}
client := NewUploadClient(c.Conn())