exporter: keep lease when exporting images

As manifests may be temporary if the same image is built in parallel one build can delete the manifest+config before the export for another finishes.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
docker-19.03
Tonis Tiigi 2019-07-12 11:50:50 -07:00
parent 6e7d3a1062
commit 0d22b5056f
4 changed files with 23 additions and 1 deletions

View File

@ -10,11 +10,13 @@ import (
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/leases"
"github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/rootfs"
"github.com/moby/buildkit/exporter"
"github.com/moby/buildkit/session"
"github.com/moby/buildkit/snapshot"
"github.com/moby/buildkit/util/leaseutil"
"github.com/moby/buildkit/util/push"
"github.com/moby/buildkit/util/resolver"
digest "github.com/opencontainers/go-digest"
@ -37,6 +39,7 @@ type Opt struct {
ImageWriter *ImageWriter
Images images.Store
ResolverOpt resolver.ResolveOptionsFunc
LeaseManager leases.Manager
}
type imageExporter struct {
@ -140,6 +143,13 @@ func (e *imageExporterInstance) Export(ctx context.Context, src exporter.Source)
for k, v := range e.meta {
src.Metadata[k] = v
}
ctx, done, err := leaseutil.WithLease(ctx, e.opt.LeaseManager)
if err != nil {
return nil, err
}
defer done(context.TODO())
desc, err := e.opt.ImageWriter.Commit(ctx, src, e.ociTypes)
if err != nil {
return nil, err

View File

@ -8,12 +8,14 @@ import (
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/images/oci"
"github.com/containerd/containerd/leases"
"github.com/docker/distribution/reference"
"github.com/moby/buildkit/exporter"
"github.com/moby/buildkit/exporter/containerimage"
"github.com/moby/buildkit/session"
"github.com/moby/buildkit/session/filesync"
"github.com/moby/buildkit/util/dockerexporter"
"github.com/moby/buildkit/util/leaseutil"
"github.com/moby/buildkit/util/progress"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
@ -32,6 +34,7 @@ type Opt struct {
SessionManager *session.Manager
ImageWriter *containerimage.ImageWriter
Variant ExporterVariant
LeaseManager leases.Manager
}
type imageExporter struct {
@ -113,6 +116,12 @@ func (e *imageExporterInstance) Export(ctx context.Context, src exporter.Source)
src.Metadata[k] = v
}
ctx, done, err := leaseutil.WithLease(ctx, e.opt.LeaseManager)
if err != nil {
return nil, err
}
defer done(context.TODO())
desc, err := e.opt.ImageWriter.Commit(ctx, src, e.ociTypes)
if err != nil {
return nil, err

2
vendor/modules.txt vendored
View File

@ -46,13 +46,13 @@ github.com/containerd/containerd/containers
github.com/containerd/containerd/contrib/seccomp
github.com/containerd/containerd/namespaces
github.com/containerd/containerd/errdefs
github.com/containerd/containerd/leases
github.com/containerd/containerd/rootfs
github.com/containerd/containerd/images/oci
github.com/containerd/containerd/api/services/content/v1
github.com/containerd/containerd/content/proxy
github.com/containerd/containerd/services/content/contentserver
github.com/containerd/containerd/reference
github.com/containerd/containerd/leases
github.com/containerd/containerd/metadata
github.com/containerd/containerd/remotes/docker/schema1
github.com/containerd/containerd/images/archive

View File

@ -255,6 +255,7 @@ func (w *Worker) Exporter(name string, sm *session.Manager) (exporter.Exporter,
SessionManager: sm,
ImageWriter: w.imageWriter,
ResolverOpt: w.ResolveOptionsFunc,
LeaseManager: w.LeaseManager,
})
case client.ExporterLocal:
return localexporter.New(localexporter.Opt{
@ -269,12 +270,14 @@ func (w *Worker) Exporter(name string, sm *session.Manager) (exporter.Exporter,
SessionManager: sm,
ImageWriter: w.imageWriter,
Variant: ociexporter.VariantOCI,
LeaseManager: w.LeaseManager,
})
case client.ExporterDocker:
return ociexporter.New(ociexporter.Opt{
SessionManager: sm,
ImageWriter: w.imageWriter,
Variant: ociexporter.VariantDocker,
LeaseManager: w.LeaseManager,
})
default:
return nil, errors.Errorf("exporter %q could not be found", name)