2017-06-08 00:54:29 +00:00
|
|
|
// +build standalone containerd
|
|
|
|
|
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"github.com/containerd/containerd/content"
|
2017-07-10 20:03:38 +00:00
|
|
|
"github.com/containerd/containerd/images"
|
2017-06-08 00:54:29 +00:00
|
|
|
"github.com/containerd/containerd/rootfs"
|
|
|
|
ctdsnapshot "github.com/containerd/containerd/snapshot"
|
2017-06-22 20:15:46 +00:00
|
|
|
"github.com/moby/buildkit/cache"
|
2017-07-06 20:15:54 +00:00
|
|
|
"github.com/moby/buildkit/cache/instructioncache"
|
2017-07-05 02:00:27 +00:00
|
|
|
"github.com/moby/buildkit/cache/metadata"
|
2017-07-10 20:03:38 +00:00
|
|
|
"github.com/moby/buildkit/exporter"
|
|
|
|
imageexporter "github.com/moby/buildkit/exporter/containerimage"
|
2017-07-11 17:12:12 +00:00
|
|
|
"github.com/moby/buildkit/session"
|
2017-06-22 20:15:46 +00:00
|
|
|
"github.com/moby/buildkit/snapshot/blobmapping"
|
|
|
|
"github.com/moby/buildkit/source"
|
|
|
|
"github.com/moby/buildkit/source/containerimage"
|
2017-07-07 21:35:10 +00:00
|
|
|
"github.com/moby/buildkit/source/git"
|
2017-07-11 17:12:12 +00:00
|
|
|
"github.com/moby/buildkit/source/local"
|
2017-06-08 00:54:29 +00:00
|
|
|
)
|
|
|
|
|
2017-07-10 20:03:38 +00:00
|
|
|
const keyImageExporter = "image"
|
|
|
|
|
2017-06-08 00:54:29 +00:00
|
|
|
type pullDeps struct {
|
|
|
|
Snapshotter ctdsnapshot.Snapshotter
|
|
|
|
ContentStore content.Store
|
|
|
|
Applier rootfs.Applier
|
2017-07-10 20:03:38 +00:00
|
|
|
Differ rootfs.MountDiffer
|
|
|
|
Images images.Store
|
2017-06-08 00:54:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func defaultControllerOpts(root string, pd pullDeps) (*Opt, error) {
|
2017-07-05 02:00:27 +00:00
|
|
|
md, err := metadata.NewStore(filepath.Join(root, "metadata.db"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-06-08 00:54:29 +00:00
|
|
|
snapshotter, err := blobmapping.NewSnapshotter(blobmapping.Opt{
|
2017-07-05 02:00:27 +00:00
|
|
|
Content: pd.ContentStore,
|
|
|
|
Snapshotter: pd.Snapshotter,
|
|
|
|
MetadataStore: md,
|
2017-06-08 00:54:29 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
cm, err := cache.NewManager(cache.ManagerOpt{
|
2017-07-05 02:00:27 +00:00
|
|
|
Snapshotter: snapshotter,
|
|
|
|
MetadataStore: md,
|
2017-06-08 00:54:29 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-07-06 20:15:54 +00:00
|
|
|
ic := &instructioncache.LocalStore{
|
|
|
|
MetadataStore: md,
|
|
|
|
Cache: cm,
|
|
|
|
}
|
|
|
|
|
2017-06-08 00:54:29 +00:00
|
|
|
sm, err := source.NewManager()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
is, err := containerimage.NewSource(containerimage.SourceOpt{
|
|
|
|
Snapshotter: snapshotter,
|
|
|
|
ContentStore: pd.ContentStore,
|
|
|
|
Applier: pd.Applier,
|
|
|
|
CacheAccessor: cm,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
sm.Register(is)
|
|
|
|
|
2017-07-07 21:35:10 +00:00
|
|
|
gs, err := git.NewSource(git.Opt{
|
|
|
|
CacheAccessor: cm,
|
|
|
|
MetadataStore: md,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
sm.Register(gs)
|
|
|
|
|
2017-07-11 17:12:12 +00:00
|
|
|
sessm, err := session.NewManager()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ss, err := local.NewSource(local.Opt{
|
|
|
|
SessionManager: sessm,
|
|
|
|
CacheAccessor: cm,
|
2017-07-14 18:59:31 +00:00
|
|
|
MetadataStore: md,
|
2017-07-11 17:12:12 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
sm.Register(ss)
|
|
|
|
|
2017-07-10 20:03:38 +00:00
|
|
|
exporters := map[string]exporter.Exporter{}
|
|
|
|
|
|
|
|
imageExporter, err := imageexporter.New(imageexporter.Opt{
|
|
|
|
Snapshotter: snapshotter,
|
|
|
|
ContentStore: pd.ContentStore,
|
|
|
|
Differ: pd.Differ,
|
|
|
|
CacheAccessor: cm,
|
|
|
|
Images: pd.Images,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
exporters[keyImageExporter] = imageExporter
|
|
|
|
|
2017-06-08 00:54:29 +00:00
|
|
|
return &Opt{
|
2017-07-06 20:15:54 +00:00
|
|
|
Snapshotter: snapshotter,
|
|
|
|
CacheManager: cm,
|
|
|
|
SourceManager: sm,
|
|
|
|
InstructionCache: ic,
|
2017-07-10 20:03:38 +00:00
|
|
|
Exporters: exporters,
|
2017-07-11 17:12:12 +00:00
|
|
|
SessionManager: sessm,
|
2017-06-08 00:54:29 +00:00
|
|
|
}, nil
|
|
|
|
}
|