c062a85782
After implementing pull, a few changes are required to the content store interface to make sure that the implementation works smoothly. Specifically, we work to make sure the predeclaration path for digests works the same between remote and local writers. Before, we were hesitent to require the the size and digest up front, but it became clear that having this provided significant benefit. There are also several cleanups related to naming. We now call the expected digest `Expected` consistently across the board and `Total` is used to mark the expected size. This whole effort comes together to provide a very smooth status reporting workflow for image pull and push. This will be more obvious when the bulk of pull code lands. There are a few other changes to make `content.WriteBlob` more broadly useful. In accordance with addition for predeclaring expected size when getting a `Writer`, `WriteBlob` now supports this fully. It will also resume downloads if provided an `io.Seeker` or `io.ReaderAt`. Coupled with the `httpReadSeeker` from `docker/distribution`, we should only be a lines of code away from resumable downloads. Signed-off-by: Stephen J Day <stephen.day@docker.com>
61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
contextpkg "context"
|
|
"fmt"
|
|
"os"
|
|
|
|
contentapi "github.com/docker/containerd/api/services/content"
|
|
"github.com/docker/containerd/content"
|
|
"github.com/opencontainers/go-digest"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
var ingestCommand = cli.Command{
|
|
Name: "ingest",
|
|
Usage: "accept content into the store",
|
|
ArgsUsage: "[flags] <key>",
|
|
Description: `Ingest objects into the local content store.`,
|
|
Flags: []cli.Flag{
|
|
cli.Int64Flag{
|
|
Name: "expected-size",
|
|
Usage: "validate against provided size",
|
|
},
|
|
cli.StringFlag{
|
|
Name: "expected-digest",
|
|
Usage: "verify content against expected digest",
|
|
},
|
|
},
|
|
Action: func(context *cli.Context) error {
|
|
var (
|
|
ctx = background
|
|
cancel func()
|
|
ref = context.Args().First()
|
|
expectedSize = context.Int64("expected-size")
|
|
expectedDigest = digest.Digest(context.String("expected-digest"))
|
|
)
|
|
|
|
ctx, cancel = contextpkg.WithCancel(ctx)
|
|
defer cancel()
|
|
|
|
if err := expectedDigest.Validate(); expectedDigest != "" && err != nil {
|
|
return err
|
|
}
|
|
|
|
conn, err := connectGRPC(context)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if ref == "" {
|
|
return fmt.Errorf("must specify a transaction reference")
|
|
}
|
|
|
|
ingester := content.NewIngesterFromClient(contentapi.NewContentClient(conn))
|
|
|
|
// TODO(stevvooe): Allow ingest to be reentrant. Currently, we expect
|
|
// all data to be written in a single invocation. Allow multiple writes
|
|
// to the same transaction key followed by a commit.
|
|
return content.WriteBlob(ctx, ingester, ref, os.Stdin, expectedSize, expectedDigest)
|
|
},
|
|
}
|