cmd/dist, images: allow image delete

This adds very simple deletion of images by name. We still need to
consider the approach to handling image name, so this may change. For
the time being, it allows one to delete an image entry in the metadata
database.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2017-03-30 17:20:16 -07:00
parent b488d4d7e2
commit cc983be17a
No known key found for this signature in database
GPG key ID: 67B3DED84EDC823F
4 changed files with 46 additions and 0 deletions

38
cmd/dist/images.go vendored
View file

@ -61,3 +61,41 @@ var imagesCommand = cli.Command{
return nil
},
}
var rmiCommand = cli.Command{
Name: "rmi",
Usage: "Delete one or more images by reference.",
ArgsUsage: "[flags] <ref> [<ref>, ...]",
Description: `Delete one or more images by reference.`,
Flags: []cli.Flag{},
Action: func(clicontext *cli.Context) error {
var (
ctx = background
exitErr error
)
db, err := getDB(clicontext, false)
if err != nil {
return errors.Wrap(err, "failed to open database")
}
tx, err := db.Begin(true)
if err != nil {
return errors.Wrap(err, "could not start transaction")
}
defer tx.Rollback()
for _, target := range clicontext.Args() {
if err := images.Delete(tx, target); err != nil {
if exitErr == nil {
exitErr = errors.Wrapf(err, "unable to delete %v", target)
}
log.G(ctx).WithError(err).Errorf("unable to delete %v", target)
}
fmt.Println(target)
}
return exitErr
},
}

1
cmd/dist/main.go vendored
View file

@ -62,6 +62,7 @@ distribution tool
}
app.Commands = []cli.Command{
imagesCommand,
rmiCommand,
pullCommand,
fetchCommand,
fetchObjectCommand,

1
cmd/dist/pull.go vendored
View file

@ -67,6 +67,7 @@ command. As part of this process, we do the following:
ingester := contentservice.NewIngesterFromClient(contentapi.NewContentClient(conn))
provider := contentservice.NewProviderFromClient(contentapi.NewContentClient(conn))
cs, err := resolveContentStore(clicontext)
if err != nil {
return err

View file

@ -103,6 +103,12 @@ func List(tx *bolt.Tx) ([]Image, error) {
return images, nil
}
func Delete(tx *bolt.Tx, name string) error {
return withImagesBucket(tx, func(bkt *bolt.Bucket) error {
return bkt.DeleteBucket([]byte(name))
})
}
func readImage(image *Image, bkt *bolt.Bucket) error {
return bkt.ForEach(func(k, v []byte) error {
if v == nil {