Merge pull request #286 from AkihiroSuda/oci-worker-overlay-false
worker/oci: allow using naive snapshotterdocker-18.09
commit
40212c5fcd
|
@ -27,6 +27,12 @@ func init() {
|
|||
Name: "oci-worker-labels",
|
||||
Usage: "user-specific annotation labels (com.example.foo=bar)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "oci-worker-snapshotter",
|
||||
Usage: "name of snapshotter (overlayfs or naive)",
|
||||
// TODO(AkihiroSuda): autodetect overlayfs availability when the value is set to "auto"?
|
||||
Value: "overlayfs",
|
||||
},
|
||||
)
|
||||
// TODO: allow multiple oci runtimes and snapshotters
|
||||
}
|
||||
|
@ -43,7 +49,7 @@ func ociWorkerInitializer(c *cli.Context, common workerInitializerOpt) ([]worker
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
opt, err := runc.NewWorkerOpt(common.root, labels)
|
||||
opt, err := runc.NewWorkerOpt(common.root, labels, c.GlobalString("oci-worker-snapshotter"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -11,19 +11,30 @@ import (
|
|||
"github.com/containerd/containerd/diff/walking"
|
||||
ctdmetadata "github.com/containerd/containerd/metadata"
|
||||
ctdsnapshot "github.com/containerd/containerd/snapshots"
|
||||
"github.com/containerd/containerd/snapshots/naive"
|
||||
"github.com/containerd/containerd/snapshots/overlay"
|
||||
"github.com/moby/buildkit/cache/metadata"
|
||||
"github.com/moby/buildkit/executor/runcexecutor"
|
||||
containerdsnapshot "github.com/moby/buildkit/snapshot/containerd"
|
||||
"github.com/moby/buildkit/worker/base"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// NewWorkerOpt creates a WorkerOpt.
|
||||
// But it does not set the following fields:
|
||||
// - SessionManager
|
||||
func NewWorkerOpt(root string, labels map[string]string) (base.WorkerOpt, error) {
|
||||
func NewWorkerOpt(root string, labels map[string]string, snapshotterName string) (base.WorkerOpt, error) {
|
||||
var opt base.WorkerOpt
|
||||
name := "runc-overlayfs"
|
||||
var snapshotterNew func(root string) (ctdsnapshot.Snapshotter, error)
|
||||
switch snapshotterName {
|
||||
case "naive":
|
||||
snapshotterNew = naive.NewSnapshotter
|
||||
case "overlayfs": // not "overlay", for consistency with containerd snapshotter plugin ID.
|
||||
snapshotterNew = overlay.NewSnapshotter
|
||||
default:
|
||||
return opt, errors.Errorf("unknown snapshotter name: %q", snapshotterName)
|
||||
}
|
||||
name := "runc-" + snapshotterName
|
||||
root = filepath.Join(root, name)
|
||||
if err := os.MkdirAll(root, 0700); err != nil {
|
||||
return opt, err
|
||||
|
@ -36,7 +47,7 @@ func NewWorkerOpt(root string, labels map[string]string) (base.WorkerOpt, error)
|
|||
if err != nil {
|
||||
return opt, err
|
||||
}
|
||||
s, err := overlay.NewSnapshotter(filepath.Join(root, "snapshots"))
|
||||
s, err := snapshotterNew(filepath.Join(root, "snapshots"))
|
||||
if err != nil {
|
||||
return opt, err
|
||||
}
|
||||
|
@ -52,7 +63,7 @@ func NewWorkerOpt(root string, labels map[string]string) (base.WorkerOpt, error)
|
|||
}
|
||||
|
||||
mdb := ctdmetadata.NewDB(db, c, map[string]ctdsnapshot.Snapshotter{
|
||||
"overlayfs": s,
|
||||
snapshotterName: s,
|
||||
})
|
||||
if err := mdb.Init(context.TODO()); err != nil {
|
||||
return opt, err
|
||||
|
@ -69,7 +80,7 @@ func NewWorkerOpt(root string, labels map[string]string) (base.WorkerOpt, error)
|
|||
if err != nil {
|
||||
return opt, err
|
||||
}
|
||||
xlabels := base.Labels("oci", "overlayfs")
|
||||
xlabels := base.Labels("oci", snapshotterName)
|
||||
for k, v := range labels {
|
||||
xlabels[k] = v
|
||||
}
|
||||
|
@ -78,7 +89,7 @@ func NewWorkerOpt(root string, labels map[string]string) (base.WorkerOpt, error)
|
|||
Labels: xlabels,
|
||||
MetadataStore: md,
|
||||
Executor: exe,
|
||||
Snapshotter: containerdsnapshot.NewSnapshotter(mdb.Snapshotter("overlayfs"), c, md, "buildkit", gc),
|
||||
Snapshotter: containerdsnapshot.NewSnapshotter(mdb.Snapshotter(snapshotterName), c, md, "buildkit", gc),
|
||||
ContentStore: c,
|
||||
Applier: apply.NewFileSystemApplier(c),
|
||||
Differ: walking.NewWalkingDiff(c),
|
||||
|
|
|
@ -38,7 +38,7 @@ func TestRuncWorker(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
workerOpt, err := NewWorkerOpt(tmpdir, nil)
|
||||
workerOpt, err := NewWorkerOpt(tmpdir, nil, "overlayfs")
|
||||
require.NoError(t, err)
|
||||
|
||||
workerOpt.SessionManager, err = session.NewManager()
|
||||
|
|
Loading…
Reference in New Issue