cmd: don't alias context package, and use cliContext for cli.Context
Unfortunately, this is a rather large diff, but perhaps worth a one-time "rip off the bandaid" for v2. This patch removes the use of "gocontext" as alias for stdLib's "context", and uses "cliContext" for uses of cli.context. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -59,16 +59,16 @@ When '--all-platforms' is given all images in a manifest list must be available.
|
||||
Usage: "Exports content from all platforms",
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
var convertOpts []converter.Opt
|
||||
srcRef := context.Args().Get(0)
|
||||
targetRef := context.Args().Get(1)
|
||||
srcRef := cliContext.Args().Get(0)
|
||||
targetRef := cliContext.Args().Get(1)
|
||||
if srcRef == "" || targetRef == "" {
|
||||
return errors.New("src and target image need to be specified")
|
||||
}
|
||||
|
||||
if !context.Bool("all-platforms") {
|
||||
if pss := context.StringSlice("platform"); len(pss) > 0 {
|
||||
if !cliContext.Bool("all-platforms") {
|
||||
if pss := cliContext.StringSlice("platform"); len(pss) > 0 {
|
||||
all, err := platforms.ParseAll(pss)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -79,15 +79,15 @@ When '--all-platforms' is given all images in a manifest list must be available.
|
||||
}
|
||||
}
|
||||
|
||||
if context.Bool("uncompress") {
|
||||
if cliContext.Bool("uncompress") {
|
||||
convertOpts = append(convertOpts, converter.WithLayerConvertFunc(uncompress.LayerConvertFunc))
|
||||
}
|
||||
|
||||
if context.Bool("oci") {
|
||||
if cliContext.Bool("oci") {
|
||||
convertOpts = append(convertOpts, converter.WithDockerToOCI(true))
|
||||
}
|
||||
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -97,7 +97,7 @@ When '--all-platforms' is given all images in a manifest list must be available.
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintln(context.App.Writer, newImg.Target.Digest.String())
|
||||
fmt.Fprintln(cliContext.App.Writer, newImg.Target.Digest.String())
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
@@ -66,17 +66,17 @@ When '--all-platforms' is given all images in a manifest list must be available.
|
||||
Usage: "Run export locally rather than through transfer API",
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
var (
|
||||
out = context.Args().First()
|
||||
images = context.Args().Tail()
|
||||
out = cliContext.Args().First()
|
||||
images = cliContext.Args().Tail()
|
||||
exportOpts = []archive.ExportOpt{}
|
||||
)
|
||||
if out == "" || len(images) == 0 {
|
||||
return errors.New("please provide both an output filename and an image reference to export")
|
||||
}
|
||||
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -93,12 +93,12 @@ When '--all-platforms' is given all images in a manifest list must be available.
|
||||
}
|
||||
defer w.Close()
|
||||
|
||||
if !context.Bool("local") {
|
||||
if !cliContext.Bool("local") {
|
||||
pf, done := ProgressHandler(ctx, os.Stdout)
|
||||
defer done()
|
||||
|
||||
exportOpts := []tarchive.ExportOpt{}
|
||||
if pss := context.StringSlice("platform"); len(pss) > 0 {
|
||||
if pss := cliContext.StringSlice("platform"); len(pss) > 0 {
|
||||
for _, ps := range pss {
|
||||
p, err := platforms.Parse(ps)
|
||||
if err != nil {
|
||||
@@ -107,15 +107,15 @@ When '--all-platforms' is given all images in a manifest list must be available.
|
||||
exportOpts = append(exportOpts, tarchive.WithPlatform(p))
|
||||
}
|
||||
}
|
||||
if context.Bool("all-platforms") {
|
||||
if cliContext.Bool("all-platforms") {
|
||||
exportOpts = append(exportOpts, tarchive.WithAllPlatforms)
|
||||
}
|
||||
|
||||
if context.Bool("skip-manifest-json") {
|
||||
if cliContext.Bool("skip-manifest-json") {
|
||||
exportOpts = append(exportOpts, tarchive.WithSkipCompatibilityManifest)
|
||||
}
|
||||
|
||||
if context.Bool("skip-non-distributable") {
|
||||
if cliContext.Bool("skip-non-distributable") {
|
||||
exportOpts = append(exportOpts, tarchive.WithSkipNonDistributableBlobs)
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ When '--all-platforms' is given all images in a manifest list must be available.
|
||||
)
|
||||
}
|
||||
|
||||
if pss := context.StringSlice("platform"); len(pss) > 0 {
|
||||
if pss := cliContext.StringSlice("platform"); len(pss) > 0 {
|
||||
all, err := platforms.ParseAll(pss)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -141,15 +141,15 @@ When '--all-platforms' is given all images in a manifest list must be available.
|
||||
exportOpts = append(exportOpts, archive.WithPlatform(platforms.DefaultStrict()))
|
||||
}
|
||||
|
||||
if context.Bool("all-platforms") {
|
||||
if cliContext.Bool("all-platforms") {
|
||||
exportOpts = append(exportOpts, archive.WithAllPlatforms())
|
||||
}
|
||||
|
||||
if context.Bool("skip-manifest-json") {
|
||||
if cliContext.Bool("skip-manifest-json") {
|
||||
exportOpts = append(exportOpts, archive.WithSkipDockerManifest())
|
||||
}
|
||||
|
||||
if context.Bool("skip-non-distributable") {
|
||||
if cliContext.Bool("skip-non-distributable") {
|
||||
exportOpts = append(exportOpts, archive.WithSkipNonDistributableBlobs())
|
||||
}
|
||||
|
||||
|
||||
@@ -70,12 +70,12 @@ var listCommand = &cli.Command{
|
||||
Usage: "Print only the image refs",
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
var (
|
||||
filters = context.Args().Slice()
|
||||
quiet = context.Bool("quiet")
|
||||
filters = cliContext.Args().Slice()
|
||||
quiet = cliContext.Bool("quiet")
|
||||
)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -154,12 +154,12 @@ var setLabelsCommand = &cli.Command{
|
||||
Usage: "Replace all labels",
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
var (
|
||||
replaceAll = context.Bool("replace-all")
|
||||
name, labels = commands.ObjectWithLabelArgs(context)
|
||||
replaceAll = cliContext.Bool("replace-all")
|
||||
name, labels = commands.ObjectWithLabelArgs(cliContext)
|
||||
)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -214,12 +214,12 @@ var checkCommand = &cli.Command{
|
||||
Usage: "Print only the ready image refs (fully downloaded and unpacked)",
|
||||
},
|
||||
}, commands.SnapshotterFlags...),
|
||||
Action: func(context *cli.Context) error {
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
var (
|
||||
exitErr error
|
||||
quiet = context.Bool("quiet")
|
||||
quiet = cliContext.Bool("quiet")
|
||||
)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -227,7 +227,7 @@ var checkCommand = &cli.Command{
|
||||
|
||||
var contentStore = client.ContentStore()
|
||||
|
||||
args := context.Args().Slice()
|
||||
args := cliContext.Args().Slice()
|
||||
imageList, err := client.ListImages(ctx, args...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed listing images: %w", err)
|
||||
@@ -287,7 +287,7 @@ var checkCommand = &cli.Command{
|
||||
size = "-"
|
||||
}
|
||||
|
||||
unpacked, err := image.IsUnpacked(ctx, context.String("snapshotter"))
|
||||
unpacked, err := image.IsUnpacked(ctx, cliContext.String("snapshotter"))
|
||||
if err != nil {
|
||||
if exitErr == nil {
|
||||
exitErr = fmt.Errorf("unable to check unpack for %v: %w", image.Name(), err)
|
||||
@@ -328,8 +328,8 @@ var removeCommand = &cli.Command{
|
||||
Usage: "Synchronously remove image and all associated resources",
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -338,9 +338,9 @@ var removeCommand = &cli.Command{
|
||||
exitErr error
|
||||
imageStore = client.ImageService()
|
||||
)
|
||||
for i, target := range context.Args().Slice() {
|
||||
for i, target := range cliContext.Args().Slice() {
|
||||
var opts []images.DeleteOpt
|
||||
if context.Bool("sync") && i == context.NArg()-1 {
|
||||
if cliContext.Bool("sync") && i == cliContext.NArg()-1 {
|
||||
opts = append(opts, images.SynchronousDelete())
|
||||
}
|
||||
if err := imageStore.Delete(ctx, target, opts...); err != nil {
|
||||
@@ -373,14 +373,14 @@ var pruneCommand = &cli.Command{
|
||||
},
|
||||
// adapted from `nerdctl`:
|
||||
// https://github.com/containerd/nerdctl/blob/272dc9c29fc1434839d3ec63194d7efa24d7c0ef/cmd/nerdctl/image_prune.go#L86
|
||||
Action: func(context *cli.Context) error {
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
all := context.Bool("all")
|
||||
all := cliContext.Bool("all")
|
||||
if !all {
|
||||
log.G(ctx).Warn("No images pruned. `image prune` requires --all to be specified.")
|
||||
// NOP
|
||||
|
||||
@@ -101,28 +101,28 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
|
||||
},
|
||||
}, append(commands.SnapshotterFlags, commands.LabelFlag)...),
|
||||
|
||||
Action: func(context *cli.Context) error {
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
var (
|
||||
in = context.Args().First()
|
||||
in = cliContext.Args().First()
|
||||
opts []containerd.ImportOpt
|
||||
platformMatcher platforms.MatchComparer
|
||||
)
|
||||
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
if !context.Bool("local") {
|
||||
if !cliContext.Bool("local") {
|
||||
unsupportedFlags := []string{"discard-unpacked-layers"}
|
||||
for _, s := range unsupportedFlags {
|
||||
if context.IsSet(s) {
|
||||
if cliContext.IsSet(s) {
|
||||
return fmt.Errorf("\"--%s\" requires \"--local\" flag", s)
|
||||
}
|
||||
}
|
||||
var opts []image.StoreOpt
|
||||
prefix := context.String("base-name")
|
||||
prefix := cliContext.String("base-name")
|
||||
var overwrite bool
|
||||
if prefix == "" {
|
||||
prefix = fmt.Sprintf("import-%s", time.Now().Format("2006-01-02"))
|
||||
@@ -130,13 +130,13 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
|
||||
overwrite = true
|
||||
}
|
||||
|
||||
labels := context.StringSlice("label")
|
||||
labels := cliContext.StringSlice("label")
|
||||
if len(labels) > 0 {
|
||||
opts = append(opts, image.WithImageLabels(commands.LabelArgs(labels)))
|
||||
}
|
||||
|
||||
if context.Bool("digests") {
|
||||
opts = append(opts, image.WithDigestRef(prefix, overwrite, !context.Bool("skip-digest-for-named")))
|
||||
if cliContext.Bool("digests") {
|
||||
opts = append(opts, image.WithDigestRef(prefix, overwrite, !cliContext.Bool("skip-digest-for-named")))
|
||||
} else {
|
||||
opts = append(opts, image.WithNamedPrefix(prefix, overwrite))
|
||||
}
|
||||
@@ -144,9 +144,9 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
|
||||
var platSpec ocispec.Platform
|
||||
// Only when all-platforms not specified, we will check platform value
|
||||
// Implicitly if the platforms is empty, it means all-platforms
|
||||
if !context.Bool("all-platforms") {
|
||||
if !cliContext.Bool("all-platforms") {
|
||||
// If platform specified, use that one, if not use default
|
||||
if platform := context.String("platform"); platform != "" {
|
||||
if platform := cliContext.String("platform"); platform != "" {
|
||||
platSpec, err = platforms.Parse(platform)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -157,8 +157,8 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
|
||||
opts = append(opts, image.WithPlatforms(platSpec))
|
||||
}
|
||||
|
||||
if !context.Bool("no-unpack") {
|
||||
snapshotter := context.String("snapshotter")
|
||||
if !cliContext.Bool("no-unpack") {
|
||||
snapshotter := cliContext.String("snapshotter")
|
||||
// If OS field is not empty, it means platSpec was updated in the above block
|
||||
// i.e all-platforms was not specified
|
||||
if platSpec.OS != "" {
|
||||
@@ -170,11 +170,11 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
|
||||
}
|
||||
}
|
||||
|
||||
is := image.NewStore(context.String("index-name"), opts...)
|
||||
is := image.NewStore(cliContext.String("index-name"), opts...)
|
||||
|
||||
var iopts []tarchive.ImportOpt
|
||||
|
||||
if context.Bool("compress-blobs") {
|
||||
if cliContext.Bool("compress-blobs") {
|
||||
iopts = append(iopts, tarchive.WithForceCompression)
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
|
||||
|
||||
// Local logic
|
||||
|
||||
prefix := context.String("base-name")
|
||||
prefix := cliContext.String("base-name")
|
||||
if prefix == "" {
|
||||
prefix = fmt.Sprintf("import-%s", time.Now().Format("2006-01-02"))
|
||||
opts = append(opts, containerd.WithImageRefTranslator(archive.AddRefPrefix(prefix)))
|
||||
@@ -213,25 +213,25 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
|
||||
opts = append(opts, containerd.WithImageRefTranslator(archive.FilterRefPrefix(prefix)))
|
||||
}
|
||||
|
||||
if context.Bool("digests") {
|
||||
if cliContext.Bool("digests") {
|
||||
opts = append(opts, containerd.WithDigestRef(archive.DigestTranslator(prefix)))
|
||||
}
|
||||
if context.Bool("skip-digest-for-named") {
|
||||
if !context.Bool("digests") {
|
||||
if cliContext.Bool("skip-digest-for-named") {
|
||||
if !cliContext.Bool("digests") {
|
||||
return errors.New("--skip-digest-for-named must be specified with --digests option")
|
||||
}
|
||||
opts = append(opts, containerd.WithSkipDigestRef(func(name string) bool { return name != "" }))
|
||||
}
|
||||
|
||||
if idxName := context.String("index-name"); idxName != "" {
|
||||
if idxName := cliContext.String("index-name"); idxName != "" {
|
||||
opts = append(opts, containerd.WithIndexName(idxName))
|
||||
}
|
||||
|
||||
if context.Bool("compress-blobs") {
|
||||
if cliContext.Bool("compress-blobs") {
|
||||
opts = append(opts, containerd.WithImportCompression())
|
||||
}
|
||||
|
||||
if platform := context.String("platform"); platform != "" {
|
||||
if platform := cliContext.String("platform"); platform != "" {
|
||||
platSpec, err := platforms.Parse(platform)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -240,16 +240,16 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
|
||||
opts = append(opts, containerd.WithImportPlatform(platformMatcher))
|
||||
}
|
||||
|
||||
opts = append(opts, containerd.WithAllPlatforms(context.Bool("all-platforms")))
|
||||
opts = append(opts, containerd.WithAllPlatforms(cliContext.Bool("all-platforms")))
|
||||
|
||||
if context.Bool("discard-unpacked-layers") {
|
||||
if context.Bool("no-unpack") {
|
||||
if cliContext.Bool("discard-unpacked-layers") {
|
||||
if cliContext.Bool("no-unpack") {
|
||||
return errors.New("--discard-unpacked-layers and --no-unpack are incompatible options")
|
||||
}
|
||||
opts = append(opts, containerd.WithDiscardUnpackedLayers())
|
||||
}
|
||||
|
||||
labels := context.StringSlice("label")
|
||||
labels := cliContext.StringSlice("label")
|
||||
if len(labels) > 0 {
|
||||
opts = append(opts, containerd.WithImageLabels(commands.LabelArgs(labels)))
|
||||
}
|
||||
@@ -279,7 +279,7 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
|
||||
return closeErr
|
||||
}
|
||||
|
||||
if !context.Bool("no-unpack") {
|
||||
if !cliContext.Bool("no-unpack") {
|
||||
log.G(ctx).Debugf("unpacking %d images", len(imgs))
|
||||
|
||||
for _, img := range imgs {
|
||||
@@ -290,7 +290,7 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
|
||||
|
||||
// TODO: Show unpack status
|
||||
fmt.Printf("unpacking %s (%s)...", img.Name, img.Target.Digest)
|
||||
err = image.Unpack(ctx, context.String("snapshotter"))
|
||||
err = image.Unpack(ctx, cliContext.String("snapshotter"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -36,14 +36,14 @@ var inspectCommand = &cli.Command{
|
||||
Usage: "Show JSON content",
|
||||
},
|
||||
},
|
||||
Action: func(clicontext *cli.Context) error {
|
||||
client, ctx, cancel, err := commands.NewClient(clicontext)
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
var (
|
||||
ref = clicontext.Args().First()
|
||||
ref = cliContext.Args().First()
|
||||
imageStore = client.ImageService()
|
||||
cs = client.ContentStore()
|
||||
)
|
||||
@@ -56,7 +56,7 @@ var inspectCommand = &cli.Command{
|
||||
opts := []display.PrintOpt{
|
||||
display.WithWriter(os.Stdout),
|
||||
}
|
||||
if clicontext.Bool("content") {
|
||||
if cliContext.Bool("content") {
|
||||
opts = append(opts, display.Verbose)
|
||||
}
|
||||
|
||||
|
||||
@@ -51,10 +51,10 @@ When you are done, use the unmount command.
|
||||
Value: platforms.DefaultString(),
|
||||
},
|
||||
),
|
||||
Action: func(context *cli.Context) (retErr error) {
|
||||
Action: func(cliContext *cli.Context) (retErr error) {
|
||||
var (
|
||||
ref = context.Args().First()
|
||||
target = context.Args().Get(1)
|
||||
ref = cliContext.Args().First()
|
||||
target = cliContext.Args().Get(1)
|
||||
)
|
||||
if ref == "" {
|
||||
return errors.New("please provide an image reference to mount")
|
||||
@@ -63,13 +63,13 @@ When you are done, use the unmount command.
|
||||
return errors.New("please provide a target path to mount to")
|
||||
}
|
||||
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
snapshotter := context.String("snapshotter")
|
||||
snapshotter := cliContext.String("snapshotter")
|
||||
if snapshotter == "" {
|
||||
snapshotter = defaults.DefaultSnapshotter
|
||||
}
|
||||
@@ -89,7 +89,7 @@ When you are done, use the unmount command.
|
||||
}
|
||||
}()
|
||||
|
||||
ps := context.String("platform")
|
||||
ps := cliContext.String("platform")
|
||||
p, err := platforms.Parse(ps)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to parse platform %s: %w", ps, err)
|
||||
@@ -115,7 +115,7 @@ When you are done, use the unmount command.
|
||||
s := client.SnapshotService(snapshotter)
|
||||
|
||||
var mounts []mount.Mount
|
||||
if context.Bool("rw") {
|
||||
if cliContext.Bool("rw") {
|
||||
mounts, err = s.Prepare(ctx, target, chainID)
|
||||
} else {
|
||||
mounts, err = s.View(ctx, target, chainID)
|
||||
@@ -131,12 +131,12 @@ When you are done, use the unmount command.
|
||||
|
||||
if err := mount.All(mounts, target); err != nil {
|
||||
if err := s.Remove(ctx, target); err != nil && !errdefs.IsNotFound(err) {
|
||||
fmt.Fprintln(context.App.ErrWriter, "Error cleaning up snapshot after mount error:", err)
|
||||
fmt.Fprintln(cliContext.App.ErrWriter, "Error cleaning up snapshot after mount error:", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintln(context.App.Writer, target)
|
||||
fmt.Fprintln(cliContext.App.Writer, target)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
@@ -85,46 +85,46 @@ command. As part of this process, we do the following:
|
||||
Usage: "Fetch content from local client rather than using transfer service",
|
||||
},
|
||||
),
|
||||
Action: func(context *cli.Context) error {
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
var (
|
||||
ref = context.Args().First()
|
||||
ref = cliContext.Args().First()
|
||||
)
|
||||
if ref == "" {
|
||||
return errors.New("please provide an image reference to pull")
|
||||
}
|
||||
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
if !context.Bool("local") {
|
||||
if !cliContext.Bool("local") {
|
||||
unsupportedFlags := []string{"max-concurrent-downloads", "print-chainid",
|
||||
"skip-verify", "tlscacert", "tlscert", "tlskey", "http-dump", "http-trace", // RegistryFlags
|
||||
}
|
||||
for _, s := range unsupportedFlags {
|
||||
if context.IsSet(s) {
|
||||
if cliContext.IsSet(s) {
|
||||
return fmt.Errorf("\"--%s\" requires \"--local\" flag", s)
|
||||
}
|
||||
}
|
||||
|
||||
ch, err := commands.NewStaticCredentials(ctx, context, ref)
|
||||
ch, err := commands.NewStaticCredentials(ctx, cliContext, ref)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var sopts []image.StoreOpt
|
||||
p, err := platforms.ParseAll(context.StringSlice("platform"))
|
||||
p, err := platforms.ParseAll(cliContext.StringSlice("platform"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set unpack configuration
|
||||
for _, platform := range p {
|
||||
sopts = append(sopts, image.WithUnpack(platform, context.String("snapshotter")))
|
||||
sopts = append(sopts, image.WithUnpack(platform, cliContext.String("snapshotter")))
|
||||
}
|
||||
if !context.Bool("all-platforms") {
|
||||
if !cliContext.Bool("all-platforms") {
|
||||
if len(p) == 0 {
|
||||
p = append(p, platforms.DefaultSpec())
|
||||
}
|
||||
@@ -133,21 +133,21 @@ command. As part of this process, we do the following:
|
||||
// TODO: Support unpack for all platforms..?
|
||||
// Pass in a *?
|
||||
|
||||
if context.Bool("metadata-only") {
|
||||
if cliContext.Bool("metadata-only") {
|
||||
sopts = append(sopts, image.WithAllMetadata)
|
||||
// Any with an empty set is None
|
||||
// TODO: Specify way to specify not default platform
|
||||
// config.PlatformMatcher = platforms.Any()
|
||||
} else if !context.Bool("skip-metadata") {
|
||||
} else if !cliContext.Bool("skip-metadata") {
|
||||
sopts = append(sopts, image.WithAllMetadata)
|
||||
}
|
||||
labels := context.StringSlice("label")
|
||||
labels := cliContext.StringSlice("label")
|
||||
if len(labels) > 0 {
|
||||
sopts = append(sopts, image.WithImageLabels(commands.LabelArgs(labels)))
|
||||
}
|
||||
|
||||
opts := []registry.Opt{registry.WithCredentials(ch), registry.WithHostDir(context.String("hosts-dir"))}
|
||||
if context.Bool("plain-http") {
|
||||
opts := []registry.Opt{registry.WithCredentials(ch), registry.WithHostDir(cliContext.String("hosts-dir"))}
|
||||
if cliContext.Bool("plain-http") {
|
||||
opts = append(opts, registry.WithDefaultScheme("http"))
|
||||
}
|
||||
reg, err := registry.NewOCIRegistry(ctx, ref, opts...)
|
||||
@@ -169,7 +169,7 @@ command. As part of this process, we do the following:
|
||||
defer done(ctx)
|
||||
|
||||
// TODO: Handle this locally via transfer config
|
||||
config, err := content.NewFetchConfig(ctx, context)
|
||||
config, err := content.NewFetchConfig(ctx, cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -184,13 +184,13 @@ command. As part of this process, we do the following:
|
||||
// TODO: Show unpack status
|
||||
|
||||
var p []ocispec.Platform
|
||||
if context.Bool("all-platforms") {
|
||||
if cliContext.Bool("all-platforms") {
|
||||
p, err = images.Platforms(ctx, client.ContentStore(), img.Target)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to resolve image platforms: %w", err)
|
||||
}
|
||||
} else {
|
||||
p, err = platforms.ParseAll(context.StringSlice("platform"))
|
||||
p, err = platforms.ParseAll(cliContext.StringSlice("platform"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -203,11 +203,11 @@ command. As part of this process, we do the following:
|
||||
for _, platform := range p {
|
||||
fmt.Printf("unpacking %s %s...\n", platforms.Format(platform), img.Target.Digest)
|
||||
i := containerd.NewImageWithPlatform(client, img, platforms.Only(platform))
|
||||
err = i.Unpack(ctx, context.String("snapshotter"))
|
||||
err = i.Unpack(ctx, cliContext.String("snapshotter"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if context.Bool("print-chainid") {
|
||||
if cliContext.Bool("print-chainid") {
|
||||
diffIDs, err := i.RootFS(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package images
|
||||
|
||||
import (
|
||||
gocontext "context"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http/httptrace"
|
||||
@@ -78,35 +78,35 @@ var pushCommand = &cli.Command{
|
||||
Name: "allow-non-distributable-blobs",
|
||||
Usage: "Allow pushing blobs that are marked as non-distributable",
|
||||
}),
|
||||
Action: func(context *cli.Context) error {
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
var (
|
||||
ref = context.Args().First()
|
||||
local = context.Args().Get(1)
|
||||
debug = context.Bool("debug")
|
||||
ref = cliContext.Args().First()
|
||||
local = cliContext.Args().Get(1)
|
||||
debug = cliContext.Bool("debug")
|
||||
desc ocispec.Descriptor
|
||||
)
|
||||
if ref == "" {
|
||||
return errors.New("please provide a remote image reference to push")
|
||||
}
|
||||
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
if !context.Bool("local") {
|
||||
if !cliContext.Bool("local") {
|
||||
unsupportedFlags := []string{
|
||||
"manifest", "manifest-type", "max-concurrent-uploaded-layers", "allow-non-distributable-blobs",
|
||||
"skip-verify", "tlscacert", "tlscert", "tlskey", "http-dump", "http-trace", // RegistryFlags
|
||||
}
|
||||
for _, s := range unsupportedFlags {
|
||||
if context.IsSet(s) {
|
||||
if cliContext.IsSet(s) {
|
||||
return fmt.Errorf("\"--%s\" requires \"--local\" flag", s)
|
||||
}
|
||||
}
|
||||
|
||||
ch, err := commands.NewStaticCredentials(ctx, context, ref)
|
||||
ch, err := commands.NewStaticCredentials(ctx, cliContext, ref)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -114,8 +114,8 @@ var pushCommand = &cli.Command{
|
||||
if local == "" {
|
||||
local = ref
|
||||
}
|
||||
opts := []registry.Opt{registry.WithCredentials(ch), registry.WithHostDir(context.String("hosts-dir"))}
|
||||
if context.Bool("plain-http") {
|
||||
opts := []registry.Opt{registry.WithCredentials(ch), registry.WithHostDir(cliContext.String("hosts-dir"))}
|
||||
if cliContext.Bool("plain-http") {
|
||||
opts = append(opts, registry.WithDefaultScheme("http"))
|
||||
}
|
||||
reg, err := registry.NewOCIRegistry(ctx, ref, opts...)
|
||||
@@ -123,7 +123,7 @@ var pushCommand = &cli.Command{
|
||||
return err
|
||||
}
|
||||
var p []ocispec.Platform
|
||||
if pss := context.StringSlice("platform"); len(pss) > 0 {
|
||||
if pss := cliContext.StringSlice("platform"); len(pss) > 0 {
|
||||
p, err = platforms.ParseAll(pss)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid platform %v: %w", pss, err)
|
||||
@@ -137,12 +137,12 @@ var pushCommand = &cli.Command{
|
||||
return client.Transfer(ctx, is, reg, transfer.WithProgress(pf))
|
||||
}
|
||||
|
||||
if manifest := context.String("manifest"); manifest != "" {
|
||||
if manifest := cliContext.String("manifest"); manifest != "" {
|
||||
desc.Digest, err = digest.Parse(manifest)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid manifest digest: %w", err)
|
||||
}
|
||||
desc.MediaType = context.String("manifest-type")
|
||||
desc.MediaType = cliContext.String("manifest-type")
|
||||
} else {
|
||||
if local == "" {
|
||||
local = ref
|
||||
@@ -153,7 +153,7 @@ var pushCommand = &cli.Command{
|
||||
}
|
||||
desc = img.Target
|
||||
|
||||
if pss := context.StringSlice("platform"); len(pss) == 1 {
|
||||
if pss := cliContext.StringSlice("platform"); len(pss) == 1 {
|
||||
p, err := platforms.Parse(pss[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid platform %q: %w", pss[0], err)
|
||||
@@ -175,10 +175,10 @@ var pushCommand = &cli.Command{
|
||||
}
|
||||
}
|
||||
|
||||
if context.Bool("http-trace") {
|
||||
if cliContext.Bool("http-trace") {
|
||||
ctx = httptrace.WithClientTrace(ctx, commands.NewDebugClientTrace(ctx))
|
||||
}
|
||||
resolver, err := commands.GetResolver(ctx, context)
|
||||
resolver, err := commands.GetResolver(ctx, cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -194,8 +194,8 @@ var pushCommand = &cli.Command{
|
||||
|
||||
log.G(ctx).WithField("image", ref).WithField("digest", desc.Digest).Debug("pushing")
|
||||
|
||||
jobHandler := images.HandlerFunc(func(ctx gocontext.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
|
||||
if !context.Bool("allow-non-distributable-blobs") && images.IsNonDistributable(desc.MediaType) {
|
||||
jobHandler := images.HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
|
||||
if !cliContext.Bool("allow-non-distributable-blobs") && images.IsNonDistributable(desc.MediaType) {
|
||||
return nil, nil
|
||||
}
|
||||
ongoing.add(remotes.MakeRefKey(ctx, desc))
|
||||
@@ -203,7 +203,7 @@ var pushCommand = &cli.Command{
|
||||
})
|
||||
|
||||
handler := jobHandler
|
||||
if !context.Bool("allow-non-distributable-blobs") {
|
||||
if !cliContext.Bool("allow-non-distributable-blobs") {
|
||||
handler = remotes.SkipNonDistributableBlobs(handler)
|
||||
}
|
||||
|
||||
@@ -212,8 +212,8 @@ var pushCommand = &cli.Command{
|
||||
containerd.WithImageHandler(handler),
|
||||
}
|
||||
|
||||
if context.IsSet("max-concurrent-uploaded-layers") {
|
||||
mcu := context.Int("max-concurrent-uploaded-layers")
|
||||
if cliContext.IsSet("max-concurrent-uploaded-layers") {
|
||||
mcu := cliContext.Int("max-concurrent-uploaded-layers")
|
||||
ropts = append(ropts, containerd.WithMaxConcurrentUploadedLayers(mcu))
|
||||
}
|
||||
|
||||
|
||||
@@ -47,26 +47,26 @@ var tagCommand = &cli.Command{
|
||||
Usage: "Skip the strict check for reference names",
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
var (
|
||||
ref = context.Args().First()
|
||||
ref = cliContext.Args().First()
|
||||
)
|
||||
if ref == "" {
|
||||
return errors.New("please provide an image reference to tag from")
|
||||
}
|
||||
if context.NArg() <= 1 {
|
||||
if cliContext.NArg() <= 1 {
|
||||
return errors.New("please provide an image reference to tag to")
|
||||
}
|
||||
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
if !context.Bool("local") {
|
||||
for _, targetRef := range context.Args().Slice()[1:] {
|
||||
if !context.Bool("skip-reference-check") {
|
||||
if !cliContext.Bool("local") {
|
||||
for _, targetRef := range cliContext.Args().Slice()[1:] {
|
||||
if !cliContext.Bool("skip-reference-check") {
|
||||
if _, err := reference.ParseAnyReference(targetRef); err != nil {
|
||||
return fmt.Errorf("error parsing reference: %q is not a valid repository/tag %v", targetRef, err)
|
||||
}
|
||||
@@ -92,8 +92,8 @@ var tagCommand = &cli.Command{
|
||||
return err
|
||||
}
|
||||
// Support multiple references for one command run
|
||||
for _, targetRef := range context.Args().Slice()[1:] {
|
||||
if !context.Bool("skip-reference-check") {
|
||||
for _, targetRef := range cliContext.Args().Slice()[1:] {
|
||||
if !cliContext.Bool("skip-reference-check") {
|
||||
if _, err := reference.ParseAnyReference(targetRef); err != nil {
|
||||
return fmt.Errorf("error parsing reference: %q is not a valid repository/tag %v", targetRef, err)
|
||||
}
|
||||
@@ -103,7 +103,7 @@ var tagCommand = &cli.Command{
|
||||
if _, err = imageService.Create(ctx, image); err != nil {
|
||||
// If user has specified force and the image already exists then
|
||||
// delete the original image and attempt to create the new one
|
||||
if errdefs.IsAlreadyExists(err) && context.Bool("force") {
|
||||
if errdefs.IsAlreadyExists(err) && cliContext.Bool("force") {
|
||||
if err = imageService.Delete(ctx, targetRef); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -38,15 +38,15 @@ var unmountCommand = &cli.Command{
|
||||
Usage: "Remove the snapshot after a successful unmount",
|
||||
},
|
||||
),
|
||||
Action: func(context *cli.Context) error {
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
var (
|
||||
target = context.Args().First()
|
||||
target = cliContext.Args().First()
|
||||
)
|
||||
if target == "" {
|
||||
return errors.New("please provide a target path to unmount from")
|
||||
}
|
||||
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -56,8 +56,8 @@ var unmountCommand = &cli.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
if context.Bool("rm") {
|
||||
snapshotter := context.String("snapshotter")
|
||||
if cliContext.Bool("rm") {
|
||||
snapshotter := cliContext.String("snapshotter")
|
||||
s := client.SnapshotService(snapshotter)
|
||||
if err := client.LeasesService().Delete(ctx, leases.Lease{ID: target}); err != nil && !errdefs.IsNotFound(err) {
|
||||
return fmt.Errorf("error deleting lease: %w", err)
|
||||
@@ -67,7 +67,7 @@ var unmountCommand = &cli.Command{
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintln(context.App.Writer, target)
|
||||
fmt.Fprintln(cliContext.App.Writer, target)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
@@ -36,19 +36,19 @@ var usageCommand = &cli.Command{
|
||||
Usage: "Display usage of snapshots for a given image ref",
|
||||
ArgsUsage: "[flags] <ref>",
|
||||
Flags: commands.SnapshotterFlags,
|
||||
Action: func(context *cli.Context) error {
|
||||
var ref = context.Args().First()
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
var ref = cliContext.Args().First()
|
||||
if ref == "" {
|
||||
return errors.New("please provide an image reference to mount")
|
||||
}
|
||||
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
snapshotter := context.String("snapshotter")
|
||||
snapshotter := cliContext.String("snapshotter")
|
||||
if snapshotter == "" {
|
||||
snapshotter = defaults.DefaultSnapshotter
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user