2020-10-30 15:47:06 -04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"github.com/containerd/containerd/content"
|
|
|
|
"github.com/containerd/containerd/content/local"
|
|
|
|
"github.com/containerd/containerd/leases"
|
|
|
|
"github.com/containerd/containerd/metadata"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"go.etcd.io/bbolt"
|
|
|
|
)
|
|
|
|
|
2021-08-21 18:46:07 -04:00
|
|
|
func (daemon *Daemon) configureLocalContentStore() (content.Store, leases.Manager, error) {
|
|
|
|
if err := os.MkdirAll(filepath.Join(daemon.root, "content"), 0700); err != nil {
|
2020-10-30 15:47:06 -04:00
|
|
|
return nil, nil, errors.Wrap(err, "error creating dir for content store")
|
|
|
|
}
|
2021-08-21 18:46:07 -04:00
|
|
|
db, err := bbolt.Open(filepath.Join(daemon.root, "content", "metadata.db"), 0600, nil)
|
2020-10-30 15:47:06 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, errors.Wrap(err, "error opening bolt db for content metadata store")
|
|
|
|
}
|
2021-08-21 18:46:07 -04:00
|
|
|
cs, err := local.NewStore(filepath.Join(daemon.root, "content", "data"))
|
2020-10-30 15:47:06 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, errors.Wrap(err, "error setting up content store")
|
|
|
|
}
|
|
|
|
md := metadata.NewDB(db, cs, nil)
|
2021-08-21 18:46:07 -04:00
|
|
|
daemon.mdDB = db
|
2020-10-30 15:47:06 -04:00
|
|
|
return md.ContentStore(), metadata.NewLeaseManager(md), nil
|
|
|
|
}
|