Skip to content

Commit

Permalink
Merge pull request #1077 from tonistiigi/exporter-lease
Browse files Browse the repository at this point in the history
exporter: keep lease when exporting images
  • Loading branch information
AkihiroSuda authored Jul 15, 2019
2 parents e368049 + 0d22b50 commit aee28f4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
10 changes: 10 additions & 0 deletions exporter/containerimage/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -37,6 +39,7 @@ type Opt struct {
ImageWriter *ImageWriter
Images images.Store
ResolverOpt resolver.ResolveOptionsFunc
LeaseManager leases.Manager
}

type imageExporter struct {
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions exporter/oci/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -32,6 +34,7 @@ type Opt struct {
SessionManager *session.Manager
ImageWriter *containerimage.ImageWriter
Variant ExporterVariant
LeaseManager leases.Manager
}

type imageExporter struct {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions worker/base/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
Expand Down

0 comments on commit aee28f4

Please sign in to comment.