| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
} |