Debian Codegraph @

cmd/soci/commands/rebuild_db.go

raw symbols SCIP
1 /*
2 Copyright The Soci Snapshotter Authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 package commands
18
19 import (
20 "path/filepath"
21
22 "github.com/awslabs/soci-snapshotter/soci"
23 "github.com/awslabs/soci-snapshotter/soci/store"
24 "github.com/containerd/containerd/cmd/ctr/commands"
25 "github.com/urfave/cli"
26 )
27
28 var RebuildDBCommand = cli.Command{
29 Name: "rebuild-db",
30 Usage: `rebuild the artifacts database. You should use this command after "rpull" so that indices/ztocs can be discovered by commands like "soci index list", and after "index rm" when using the containerd content store so that deleted orphaned zTOCs will be forgotten`,
31 Action: func(cliContext *cli.Context) error {
32 client, ctx, cancel, err := commands.NewClient(cliContext)
33 if err != nil {
34 return err
35 }
36 defer cancel()
37 containerdContentStore := client.ContentStore()
38 artifactsDb, err := soci.NewDB(soci.ArtifactsDbPath())
39 if err != nil {
40 return err
41 }
42 ctx, blobStore, err := store.NewContentStore(ctx, store.WithType(store.ContentStoreType(cliContext.GlobalString("content-store"))), store.WithNamespace(cliContext.GlobalString("namespace")))
43 if err != nil {
44 return err
45 }
46
47 contentStorePath, err := store.GetContentStorePath(store.ContentStoreType(cliContext.GlobalString("content-store")))
48 if err != nil {
49 return err
50 }
51
52 blobStorePath := filepath.Join(contentStorePath, "blobs")
53 return artifactsDb.SyncWithLocalStore(ctx, blobStore, blobStorePath, containerdContentStore)
54 },
55 }