From 48ec136f1bd9beb80ab8dc85d9fdbcb02c183d01 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Fri, 5 Oct 2018 14:33:44 -0700 Subject: [PATCH 1/3] dockerfile: update default copy image Signed-off-by: Tonis Tiigi --- frontend/dockerfile/dockerfile2llb/convert.go | 2 +- frontend/dockerfile/dockerfile_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/dockerfile/dockerfile2llb/convert.go b/frontend/dockerfile/dockerfile2llb/convert.go index e6a52d8c5..fd0cd28ce 100644 --- a/frontend/dockerfile/dockerfile2llb/convert.go +++ b/frontend/dockerfile/dockerfile2llb/convert.go @@ -35,7 +35,7 @@ const ( localNameContext = "context" historyComment = "buildkit.dockerfile.v0" - DefaultCopyImage = "tonistiigi/copy:v0.1.5@sha256:eab89b76ffbb3c807663a67a41e8be31b8a0e362d7fb074a55bddace563a28bb" + DefaultCopyImage = "tonistiigi/copy:v0.1.7@sha256:9aab7d9ab369c6daf4831bf0653f7592110ab4b7e8a33fee2b9dca546e9d3089" ) type ConvertOpt struct { diff --git a/frontend/dockerfile/dockerfile_test.go b/frontend/dockerfile/dockerfile_test.go index 36a056a23..ae05db65b 100644 --- a/frontend/dockerfile/dockerfile_test.go +++ b/frontend/dockerfile/dockerfile_test.go @@ -51,7 +51,7 @@ func init() { opts = []integration.TestOpt{ integration.WithMirroredImages(integration.OfficialImages("busybox:latest")), integration.WithMirroredImages(map[string]string{ - "tonistiigi/copy:v0.1.5": "docker.io/" + dockerfile2llb.DefaultCopyImage, + "tonistiigi/copy:v0.1.7": "docker.io/" + dockerfile2llb.DefaultCopyImage, }), integration.WithMatrix("frontend", frontends), } From 8360d739468fc2abab655ed25f71909f22fe7022 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Fri, 5 Oct 2018 17:19:40 -0700 Subject: [PATCH 2/3] testutil: avoid overriding cleanup to nil on error Signed-off-by: Tonis Tiigi --- util/testutil/integration/run.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/testutil/integration/run.go b/util/testutil/integration/run.go index 14354ace9..29a807da4 100644 --- a/util/testutil/integration/run.go +++ b/util/testutil/integration/run.go @@ -217,7 +217,7 @@ mirrors=["%s"] return tmpdir, nil } -func runMirror(t *testing.T, mirroredImages map[string]string) (host string, cleanup func() error, err error) { +func runMirror(t *testing.T, mirroredImages map[string]string) (host string, _ func() error, err error) { mirrorDir := os.Getenv("BUILDKIT_REGISTRY_MIRROR_DIR") var f *os.File From 58a62038570a1029f2199aaa0089085057bd5523 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Fri, 5 Oct 2018 17:20:06 -0700 Subject: [PATCH 3/3] contentutil: add ref lock on push Signed-off-by: Tonis Tiigi --- util/contentutil/refs.go | 42 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/util/contentutil/refs.go b/util/contentutil/refs.go index b3a10d150..9df84063c 100644 --- a/util/contentutil/refs.go +++ b/util/contentutil/refs.go @@ -3,11 +3,16 @@ package contentutil import ( "context" "net/http" + "sync" "github.com/containerd/containerd/content" + "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/remotes" "github.com/containerd/containerd/remotes/docker" + "github.com/docker/docker/pkg/locker" + digest "github.com/opencontainers/go-digest" ocispec "github.com/opencontainers/image-spec/specs-go/v1" + "github.com/pkg/errors" ) func ProviderFromRef(ref string) (ocispec.Descriptor, content.Provider, error) { @@ -38,11 +43,13 @@ func IngesterFromRef(ref string) (content.Ingester, error) { } return &ingester{ + locker: locker.New(), pusher: pusher, }, nil } type ingester struct { + locker *locker.Locker pusher remotes.Pusher } @@ -53,5 +60,38 @@ func (w *ingester) Writer(ctx context.Context, opts ...content.WriterOpt) (conte return nil, err } } - return w.pusher.Push(ctx, wo.Desc) + if wo.Ref == "" { + return nil, errors.Wrap(errdefs.ErrInvalidArgument, "ref must not be empty") + } + w.locker.Lock(wo.Ref) + var once sync.Once + unlock := func() { + once.Do(func() { + w.locker.Unlock(wo.Ref) + }) + } + writer, err := w.pusher.Push(ctx, wo.Desc) + if err != nil { + return nil, err + } + return &lockedWriter{unlock: unlock, Writer: writer}, nil +} + +type lockedWriter struct { + unlock func() + content.Writer +} + +func (w *lockedWriter) Commit(ctx context.Context, size int64, expected digest.Digest, opts ...content.Opt) error { + err := w.Writer.Commit(ctx, size, expected, opts...) + if err == nil { + w.unlock() + } + return err +} + +func (w *lockedWriter) Close() error { + err := w.Writer.Close() + w.unlock() + return err }