Add labels and fileters to content

Update list content command to support filters
Add label subcommand to content in dist tool to update labels
Add uncompressed label on unpack

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan
2017-07-05 17:00:11 -07:00
parent 1a49f5ea79
commit fba7463ed3
14 changed files with 973 additions and 160 deletions

63
cmd/dist/labels.go vendored Normal file
View File

@@ -0,0 +1,63 @@
package main
import (
"fmt"
"strings"
digest "github.com/opencontainers/go-digest"
"github.com/urfave/cli"
)
var labelCommand = cli.Command{
Name: "label",
Usage: "adds labels to content",
ArgsUsage: "[flags] <digest> [<label>=<value> ...]",
Description: `Labels blobs in the content store`,
Flags: []cli.Flag{},
Action: func(context *cli.Context) error {
var (
object = context.Args().First()
labelArgs = context.Args().Tail()
)
ctx, cancel := appContext(context)
defer cancel()
cs, err := resolveContentStore(context)
if err != nil {
return err
}
dgst, err := digest.Parse(object)
if err != nil {
return err
}
info, err := cs.Info(ctx, dgst)
if err != nil {
return err
}
if info.Labels == nil {
info.Labels = map[string]string{}
}
var paths []string
for _, arg := range labelArgs {
var k, v string
if idx := strings.IndexByte(arg, '='); idx > 0 {
k = arg[:idx]
v = arg[idx+1:]
} else {
k = arg
}
paths = append(paths, fmt.Sprintf("labels.%s", k))
if v == "" {
delete(info.Labels, k)
} else {
info.Labels[k] = v
}
}
return cs.Update(ctx, info, paths...)
},
}

28
cmd/dist/list.go vendored
View File

@@ -3,11 +3,11 @@ package main
import (
"fmt"
"os"
"strings"
"text/tabwriter"
"time"
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/log"
units "github.com/docker/go-units"
"github.com/urfave/cli"
)
@@ -16,7 +16,7 @@ var listCommand = cli.Command{
Name: "list",
Aliases: []string{"ls"},
Usage: "list all blobs in the store.",
ArgsUsage: "[flags] [<prefix>, ...]",
ArgsUsage: "[flags] [<filter>, ...]",
Description: `List blobs in the content store.`,
Flags: []cli.Flag{
cli.BoolFlag{
@@ -37,12 +37,6 @@ var listCommand = cli.Command{
return err
}
if len(args) > 0 {
// TODO(stevvooe): Implement selection of a few blobs. Not sure
// what kind of efficiency gains we can actually get here.
log.G(ctx).Warnf("args ignored; need to implement matchers")
}
var walkFn content.WalkFunc
if quiet {
walkFn = func(info content.Info) error {
@@ -53,17 +47,27 @@ var listCommand = cli.Command{
tw := tabwriter.NewWriter(os.Stdout, 1, 8, 1, '\t', 0)
defer tw.Flush()
fmt.Fprintln(tw, "DIGEST\tSIZE\tAGE")
fmt.Fprintln(tw, "DIGEST\tSIZE\tAGE\tLABELS")
walkFn = func(info content.Info) error {
fmt.Fprintf(tw, "%s\t%s\t%s\n",
var labelStrings []string
for k, v := range info.Labels {
labelStrings = append(labelStrings, strings.Join([]string{k, v}, "="))
}
labels := strings.Join(labelStrings, ",")
if labels == "" {
labels = "-"
}
fmt.Fprintf(tw, "%s\t%s\t%s\t%s\n",
info.Digest,
units.HumanSize(float64(info.Size)),
units.HumanDuration(time.Since(info.CommittedAt)))
units.HumanDuration(time.Since(info.CommittedAt)),
labels)
return nil
}
}
return cs.Walk(ctx, walkFn)
return cs.Walk(ctx, walkFn, args...)
},
}

1
cmd/dist/main.go vendored
View File

@@ -101,5 +101,6 @@ var contentCommand = cli.Command{
getCommand,
editCommand,
deleteCommand,
labelCommand,
},
}