diff --git a/builder/builder-next/adapters/snapshot/snapshot.go b/builder/builder-next/adapters/snapshot/snapshot.go index 8c5f803885..a559e15b4b 100644 --- a/builder/builder-next/adapters/snapshot/snapshot.go +++ b/builder/builder-next/adapters/snapshot/snapshot.go @@ -16,6 +16,7 @@ import ( "github.com/docker/docker/pkg/idtools" "github.com/moby/buildkit/identity" "github.com/moby/buildkit/snapshot" + "github.com/moby/buildkit/util/leaseutil" "github.com/opencontainers/go-digest" "github.com/pkg/errors" bolt "go.etcd.io/bbolt" @@ -57,7 +58,7 @@ type snapshotter struct { } // NewSnapshotter creates a new snapshotter -func NewSnapshotter(opt Opt, prevLM leases.Manager) (snapshot.Snapshotter, leases.Manager, error) { +func NewSnapshotter(opt Opt, prevLM leases.Manager, ns string) (snapshot.Snapshotter, *leaseutil.Manager, error) { dbPath := filepath.Join(opt.Root, "snapshots.db") db, err := bolt.Open(dbPath, 0o600, nil) if err != nil { @@ -76,7 +77,8 @@ func NewSnapshotter(opt Opt, prevLM leases.Manager) (snapshot.Snapshotter, lease reg: reg, } - lm := newLeaseManager(s, prevLM) + slm := newLeaseManager(s, prevLM) + lm := leaseutil.WithNamespace(slm, ns) ll, err := lm.List(context.TODO()) if err != nil { @@ -89,7 +91,7 @@ func NewSnapshotter(opt Opt, prevLM leases.Manager) (snapshot.Snapshotter, lease } for _, r := range rr { if r.Type == "snapshots/default" { - lm.addRef(l.ID, r.ID) + slm.addRef(l.ID, r.ID) } } } diff --git a/builder/builder-next/controller.go b/builder/builder-next/controller.go index b9805f7ebd..59981ef239 100644 --- a/builder/builder-next/controller.go +++ b/builder/builder-next/controller.go @@ -39,10 +39,10 @@ import ( "github.com/moby/buildkit/frontend/gateway" "github.com/moby/buildkit/frontend/gateway/forwarder" containerdsnapshot "github.com/moby/buildkit/snapshot/containerd" + "github.com/moby/buildkit/solver" "github.com/moby/buildkit/solver/bboltcachestorage" "github.com/moby/buildkit/util/archutil" "github.com/moby/buildkit/util/entitlements" - "github.com/moby/buildkit/util/leaseutil" "github.com/moby/buildkit/util/network/netproviders" "github.com/moby/buildkit/util/tracing/detect" "github.com/moby/buildkit/worker" @@ -135,7 +135,7 @@ func newSnapshotterController(ctx context.Context, rt http.RoundTripper, opt Opt SessionManager: opt.SessionManager, WorkerController: wc, Frontends: frontends, - CacheKeyStorage: cacheStorage, + CacheManager: solver.NewCacheManager(ctx, "local", cacheStorage, worker.NewCacheResultStorage(wc)), ResolveCacheImporterFuncs: map[string]remotecache.ResolveCacheImporterFunc{ "gha": gha.ResolveCacheImporterFunc(), "local": localremotecache.ResolveCacheImporterFunc(opt.SessionManager), @@ -202,7 +202,7 @@ func newGraphDriverController(ctx context.Context, rt http.RoundTripper, opt Opt return nil, errors.Errorf("could not access graphdriver") } - store, err := local.NewStore(filepath.Join(root, "content")) + innerStore, err := local.NewStore(filepath.Join(root, "content")) if err != nil { return nil, err } @@ -212,18 +212,16 @@ func newGraphDriverController(ctx context.Context, rt http.RoundTripper, opt Opt return nil, errors.WithStack(err) } - mdb := ctdmetadata.NewDB(db, store, map[string]snapshots.Snapshotter{}) + mdb := ctdmetadata.NewDB(db, innerStore, map[string]snapshots.Snapshotter{}) - store = containerdsnapshot.NewContentStore(mdb.ContentStore(), "buildkit") - - lm := leaseutil.WithNamespace(ctdmetadata.NewLeaseManager(mdb), "buildkit") + store := containerdsnapshot.NewContentStore(mdb.ContentStore(), "buildkit") snapshotter, lm, err := snapshot.NewSnapshotter(snapshot.Opt{ GraphDriver: driver, LayerStore: dist.LayerStore, Root: root, IdentityMapping: opt.IdentityMapping, - }, lm) + }, ctdmetadata.NewLeaseManager(mdb), "buildkit") if err != nil { return nil, err } @@ -358,7 +356,7 @@ func newGraphDriverController(ctx context.Context, rt http.RoundTripper, opt Opt SessionManager: opt.SessionManager, WorkerController: wc, Frontends: frontends, - CacheKeyStorage: cacheStorage, + CacheManager: solver.NewCacheManager(ctx, "local", cacheStorage, worker.NewCacheResultStorage(wc)), ResolveCacheImporterFuncs: map[string]remotecache.ResolveCacheImporterFunc{ "registry": localinlinecache.ResolveCacheImporterFunc(opt.SessionManager, opt.RegistryHosts, store, dist.ReferenceStore, dist.ImageStore), "local": localremotecache.ResolveCacheImporterFunc(opt.SessionManager), diff --git a/builder/builder-next/worker/worker.go b/builder/builder-next/worker/worker.go index 277c7a371a..a3e17b1ae0 100644 --- a/builder/builder-next/worker/worker.go +++ b/builder/builder-next/worker/worker.go @@ -9,7 +9,6 @@ import ( "github.com/containerd/containerd/content" "github.com/containerd/containerd/images" - "github.com/containerd/containerd/leases" "github.com/containerd/containerd/log" "github.com/containerd/containerd/platforms" "github.com/containerd/containerd/rootfs" @@ -32,6 +31,7 @@ import ( "github.com/moby/buildkit/frontend" "github.com/moby/buildkit/session" "github.com/moby/buildkit/snapshot" + containerdsnapshot "github.com/moby/buildkit/snapshot/containerd" "github.com/moby/buildkit/solver" "github.com/moby/buildkit/solver/llbsolver/mounts" "github.com/moby/buildkit/solver/llbsolver/ops" @@ -42,6 +42,7 @@ import ( "github.com/moby/buildkit/source/local" "github.com/moby/buildkit/util/archutil" "github.com/moby/buildkit/util/contentutil" + "github.com/moby/buildkit/util/leaseutil" "github.com/moby/buildkit/util/progress" "github.com/moby/buildkit/version" "github.com/opencontainers/go-digest" @@ -71,9 +72,9 @@ type Opt struct { GCPolicy []client.PruneInfo Executor executor.Executor Snapshotter snapshot.Snapshotter - ContentStore content.Store + ContentStore *containerdsnapshot.Store CacheManager cache.Manager - LeaseManager leases.Manager + LeaseManager *leaseutil.Manager ImageSource *containerimage.Source DownloadManager *xfer.LayerDownloadManager V2MetadataService distmetadata.V2MetadataService @@ -186,13 +187,13 @@ func (w *Worker) Close() error { return nil } -// ContentStore returns content store -func (w *Worker) ContentStore() content.Store { +// ContentStore returns the wrapped content store +func (w *Worker) ContentStore() *containerdsnapshot.Store { return w.Opt.ContentStore } -// LeaseManager returns leases.Manager for the worker -func (w *Worker) LeaseManager() leases.Manager { +// LeaseManager returns the wrapped lease manager +func (w *Worker) LeaseManager() *leaseutil.Manager { return w.Opt.LeaseManager } diff --git a/daemon/config/builder.go b/daemon/config/builder.go index 52be1b314c..8801ba20cb 100644 --- a/daemon/config/builder.go +++ b/daemon/config/builder.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/docker/docker/api/types/filters" + bkconfig "github.com/moby/buildkit/cmd/buildkitd/config" ) // BuilderGCRule represents a GC rule for buildkit cache @@ -62,8 +63,8 @@ type BuilderGCConfig struct { // BuilderHistoryConfig contains history config for a buildkit builder type BuilderHistoryConfig struct { - MaxAge int64 `json:",omitempty"` - MaxEntries int64 `json:",omitempty"` + MaxAge bkconfig.Duration `json:",omitempty"` + MaxEntries int64 `json:",omitempty"` } // BuilderEntitlements contains settings to enable/disable entitlements