Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cache/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"context"
"encoding/json"
"os"
"path/filepath"
"strings"
"sync"

Expand All @@ -27,6 +29,18 @@ type Store struct {
}

func NewStore(dbPath string) (*Store, error) {
// Check for legacy (v1) cache state.
//
// Automatic migration was removed in https://github.com/moby/buildkit/pull/6509
if _, err := os.Stat(dbPath); errors.Is(err, os.ErrNotExist) {
legacyMetadata := filepath.Join(filepath.Dir(dbPath), "metadata.db")
if _, err := os.Stat(legacyMetadata); err == nil {
return nil, errors.Errorf(
"legacy (v1) cache metadata found at %q and needs to be removed or migrated; downgrade BuildKit to v0.27.1 to perform automatic migration or remove the existing cache",
legacyMetadata,
)
}
}
Comment on lines 32 to 43
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated; https://github.com/moby/buildkit/compare/97bf000f37af60ea3628889cff6c7f37c81adb71..13bc686bd6adfdcaec59d03bfe26b36ad14a29f8

Decided to roll the check into the constructor here, so that BuildKit can remove it when we're comfortable; could use some input on the error-message though (not sure if it's just the metadata.db to look for, or if the user has to remove (or migrate) state elsewhere.

db, err := boltutil.Open(dbPath, 0600, nil)
if err != nil {
return nil, errors.Wrapf(err, "failed to open database file %s", dbPath)
Expand Down
267 changes: 0 additions & 267 deletions cache/migrate_v2.go

This file was deleted.

16 changes: 1 addition & 15 deletions worker/containerd/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/containerd/containerd/v2/core/leases"
"github.com/containerd/containerd/v2/pkg/gc"
"github.com/containerd/platforms"
"github.com/moby/buildkit/cache"
"github.com/moby/buildkit/cache/metadata"
"github.com/moby/buildkit/executor/containerdexecutor"
"github.com/moby/buildkit/executor/oci"
Expand Down Expand Up @@ -135,19 +134,6 @@ func newContainerd(client *ctd.Client, workerOpts WorkerOptions) (base.WorkerOpt
}
}

snap := containerdsnapshot.NewSnapshotter(workerOpts.SnapshotterName, client.SnapshotService(workerOpts.SnapshotterName), workerOpts.Namespace, nil)

if err := cache.MigrateV2(
context.TODO(),
filepath.Join(root, "metadata.db"),
filepath.Join(root, "metadata_v2.db"),
cs,
snap,
lm,
); err != nil {
return base.WorkerOpt{}, err
}

md, err := metadata.NewStore(filepath.Join(root, "metadata_v2.db"))
if err != nil {
return base.WorkerOpt{}, err
Expand All @@ -174,7 +160,7 @@ func newContainerd(client *ctd.Client, workerOpts WorkerOptions) (base.WorkerOpt
MetadataStore: md,
NetworkProviders: np,
Executor: containerdexecutor.New(executorOpts),
Snapshotter: snap,
Snapshotter: containerdsnapshot.NewSnapshotter(workerOpts.SnapshotterName, client.SnapshotService(workerOpts.SnapshotterName), workerOpts.Namespace, nil),
ContentStore: cs,
Applier: winlayers.NewFileSystemApplierWithWindows(cs, df),
Differ: winlayers.NewWalkingDiffWithWindows(cs, df),
Expand Down
17 changes: 2 additions & 15 deletions worker/runc/runc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/containerd/containerd/v2/plugins/content/local"
"github.com/containerd/containerd/v2/plugins/diff/walking"
"github.com/containerd/platforms"
"github.com/moby/buildkit/cache"
"github.com/moby/buildkit/cache/metadata"
"github.com/moby/buildkit/executor/oci"
"github.com/moby/buildkit/executor/resources"
Expand Down Expand Up @@ -130,18 +129,6 @@ func NewWorkerOpt(root string, snFactory SnapshotterFactory, rootless bool, proc
}

maps.Copy(xlabels, labels)
lm := leaseutil.WithNamespace(ctdmetadata.NewLeaseManager(mdb), "buildkit")
snap := containerdsnapshot.NewSnapshotter(snFactory.Name, mdb.Snapshotter(snFactory.Name), "buildkit", idmap)
if err := cache.MigrateV2(
context.TODO(),
filepath.Join(root, "metadata.db"),
filepath.Join(root, "metadata_v2.db"),
c,
snap,
lm,
); err != nil {
return opt, err
}

md, err := metadata.NewStore(filepath.Join(root, "metadata_v2.db"))
if err != nil {
Expand All @@ -155,14 +142,14 @@ func NewWorkerOpt(root string, snFactory SnapshotterFactory, rootless bool, proc
MetadataStore: md,
NetworkProviders: np,
Executor: exe,
Snapshotter: snap,
Snapshotter: containerdsnapshot.NewSnapshotter(snFactory.Name, mdb.Snapshotter(snFactory.Name), "buildkit", idmap),
ContentStore: c,
Applier: winlayers.NewFileSystemApplierWithWindows(c, apply.NewFileSystemApplier(c)),
Differ: winlayers.NewWalkingDiffWithWindows(c, walking.NewWalkingDiff(c)),
ImageStore: nil, // explicitly
Platforms: []ocispecs.Platform{platforms.Normalize(platforms.DefaultSpec())},
IdentityMapping: idmap,
LeaseManager: lm,
LeaseManager: leaseutil.WithNamespace(ctdmetadata.NewLeaseManager(mdb), "buildkit"),
GarbageCollect: mdb.GarbageCollect,
ParallelismSem: parallelismSem,
MountPoolRoot: filepath.Join(root, "cachemounts"),
Expand Down
Loading