Merge pull request #1683 from crosbymichael/ctr-moving
[ctr] move version and plugin commands
This commit is contained in:
commit
8c77d9ac72
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/containerd/containerd/archive"
|
||||
"github.com/containerd/containerd/archive/compression"
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -18,7 +19,7 @@ var applyCommand = cli.Command{
|
||||
var (
|
||||
dir = context.Args().First()
|
||||
)
|
||||
ctx, cancel := appContext(context)
|
||||
ctx, cancel := commands.AppContext(context)
|
||||
defer cancel()
|
||||
|
||||
log.G(ctx).Info("applying layer from stdin")
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/containerd/console"
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -14,7 +15,7 @@ var taskAttachCommand = cli.Command{
|
||||
Usage: "attach to the IO of a running container",
|
||||
ArgsUsage: "CONTAINER",
|
||||
Action: func(context *cli.Context) error {
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -23,7 +24,7 @@ var taskCheckpointCommand = cli.Command{
|
||||
if id == "" {
|
||||
return errors.New("container id must be provided")
|
||||
}
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
40
cmd/ctr/commands/client.go
Normal file
40
cmd/ctr/commands/client.go
Normal file
@ -0,0 +1,40 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
gocontext "context"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/namespaces"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
// AppContext returns the context for a command. Should only be called once per
|
||||
// command, near the start.
|
||||
//
|
||||
// This will ensure the namespace is picked up and set the timeout, if one is
|
||||
// defined.
|
||||
func AppContext(context *cli.Context) (gocontext.Context, gocontext.CancelFunc) {
|
||||
var (
|
||||
ctx = gocontext.Background()
|
||||
timeout = context.GlobalDuration("timeout")
|
||||
namespace = context.GlobalString("namespace")
|
||||
cancel gocontext.CancelFunc
|
||||
)
|
||||
ctx = namespaces.WithNamespace(ctx, namespace)
|
||||
if timeout > 0 {
|
||||
ctx, cancel = gocontext.WithTimeout(ctx, timeout)
|
||||
} else {
|
||||
ctx, cancel = gocontext.WithCancel(ctx)
|
||||
}
|
||||
return ctx, cancel
|
||||
}
|
||||
|
||||
// NewClient returns a new containerd client
|
||||
func NewClient(context *cli.Context) (*containerd.Client, gocontext.Context, gocontext.CancelFunc, error) {
|
||||
client, err := containerd.New(context.GlobalString("address"))
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
ctx, cancel := AppContext(context)
|
||||
return client, ctx, cancel, nil
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -9,22 +9,24 @@ import (
|
||||
|
||||
introspection "github.com/containerd/containerd/api/services/introspection/v1"
|
||||
"github.com/containerd/containerd/api/types"
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/urfave/cli"
|
||||
"google.golang.org/grpc/codes"
|
||||
)
|
||||
|
||||
var pluginsCommand = cli.Command{
|
||||
// Command is a cli command that outputs plugin information
|
||||
var Command = cli.Command{
|
||||
Name: "plugins",
|
||||
Usage: "Provides information about containerd plugins",
|
||||
Usage: "provides information about containerd plugins",
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "quiet, q",
|
||||
Name: "quiet,q",
|
||||
Usage: "print only the plugin ids",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "detailed, d",
|
||||
Name: "detailed,d",
|
||||
Usage: "print detailed information about each plugin",
|
||||
},
|
||||
},
|
||||
@ -33,7 +35,7 @@ var pluginsCommand = cli.Command{
|
||||
quiet = context.Bool("quiet")
|
||||
detailed = context.Bool("detailed")
|
||||
)
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -51,7 +53,6 @@ var pluginsCommand = cli.Command{
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
w := tabwriter.NewWriter(os.Stdout, 4, 8, 4, ' ', 0)
|
||||
if detailed {
|
||||
first := true
|
||||
@ -104,7 +105,6 @@ var pluginsCommand = cli.Command{
|
||||
if len(plugin.Platforms) > 0 {
|
||||
platformColumn = prettyPlatforms(plugin.Platforms)
|
||||
}
|
||||
|
||||
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t\n",
|
||||
plugin.Type,
|
||||
plugin.ID,
|
||||
@ -121,7 +121,7 @@ var pluginsCommand = cli.Command{
|
||||
func prettyPlatforms(pspb []types.Platform) string {
|
||||
psm := map[string]struct{}{}
|
||||
for _, p := range pspb {
|
||||
psm[platforms.Format(ocispec.Platform{
|
||||
psm[platforms.Format(v1.Platform{
|
||||
OS: p.OS,
|
||||
Architecture: p.Architecture,
|
||||
Variant: p.Variant,
|
||||
@ -132,6 +132,5 @@ func prettyPlatforms(pspb []types.Platform) string {
|
||||
ps = append(ps, p)
|
||||
}
|
||||
sort.Stable(sort.StringSlice(ps))
|
||||
|
||||
return strings.Join(ps, ",")
|
||||
}
|
@ -1,25 +1,24 @@
|
||||
package main
|
||||
package version
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
"github.com/containerd/containerd/version"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var versionCommand = cli.Command{
|
||||
// Command is a cli ommand to output the client and containerd server version
|
||||
var Command = cli.Command{
|
||||
Name: "version",
|
||||
Usage: "print the version",
|
||||
Usage: "print the client and server versions",
|
||||
Action: func(context *cli.Context) error {
|
||||
if context.NArg() > 0 {
|
||||
return fmt.Errorf("no argument expected")
|
||||
}
|
||||
fmt.Println("Client:")
|
||||
fmt.Printf(" Version: %s\n", version.Version)
|
||||
fmt.Printf(" Revision: %s\n", version.Revision)
|
||||
fmt.Println("")
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -28,7 +27,6 @@ var versionCommand = cli.Command{
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println("Server:")
|
||||
fmt.Printf(" Version: %s\n", v.Version)
|
||||
fmt.Printf(" Revision: %s\n", v.Revision)
|
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -23,7 +24,7 @@ var containersDeleteCommand = cli.Command{
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
var exitErr error
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -29,7 +30,7 @@ var containersCommand = cli.Command{
|
||||
filters = context.Args()
|
||||
quiet = context.Bool("quiet")
|
||||
)
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ var (
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -90,7 +90,7 @@ var (
|
||||
if ref == "" {
|
||||
return errors.New("must specify a transaction reference")
|
||||
}
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -124,7 +124,7 @@ var (
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
match := context.Args().First()
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -164,7 +164,7 @@ var (
|
||||
quiet = context.Bool("quiet")
|
||||
args = []string(context.Args())
|
||||
)
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -214,7 +214,7 @@ var (
|
||||
Flags: []cli.Flag{},
|
||||
Action: func(context *cli.Context) error {
|
||||
object, labels := commands.ObjectWithLabelArgs(context)
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -289,7 +289,7 @@ var (
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -338,7 +338,7 @@ var (
|
||||
args = []string(context.Args())
|
||||
exitError error
|
||||
)
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
eventsapi "github.com/containerd/containerd/api/services/events/v1"
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
"github.com/containerd/typeurl"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -13,7 +14,7 @@ var eventsCommand = cli.Command{
|
||||
Name: "events",
|
||||
Usage: "display containerd events",
|
||||
Action: func(context *cli.Context) error {
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/containerd/console"
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -36,7 +37,7 @@ var taskExecCommand = cli.Command{
|
||||
if id == "" {
|
||||
return errors.New("container id must be provided")
|
||||
}
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
"github.com/containerd/containerd/reference"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
@ -38,7 +39,7 @@ var imagesExportCommand = cli.Command{
|
||||
local = context.Args().Get(1)
|
||||
desc ocispec.Descriptor
|
||||
)
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ Most of this is experimental and there are few leaps to make this work.`,
|
||||
}
|
||||
|
||||
func fetch(ref string, cliContext *cli.Context) (containerd.Image, error) {
|
||||
client, ctx, cancel, err := newClient(cliContext)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ var fetchObjectCommand = cli.Command{
|
||||
var (
|
||||
ref = context.Args().First()
|
||||
)
|
||||
ctx, cancel := appContext(context)
|
||||
ctx, cancel := commands.AppContext(context)
|
||||
defer cancel()
|
||||
|
||||
resolver, err := getResolver(ctx, context)
|
||||
|
@ -47,7 +47,7 @@ var imagesListCommand = cli.Command{
|
||||
filters = context.Args()
|
||||
quiet = context.Bool("quiet")
|
||||
)
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -130,7 +130,7 @@ var imagesSetLabelsCommand = cli.Command{
|
||||
replaceAll = context.Bool("replace-all")
|
||||
name, labels = commands.ObjectWithLabelArgs(context)
|
||||
)
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -183,7 +183,7 @@ var imagesCheckCommand = cli.Command{
|
||||
var (
|
||||
exitErr error
|
||||
)
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -263,7 +263,7 @@ var imageRemoveCommand = cli.Command{
|
||||
Description: `Remove one or more images by reference.`,
|
||||
Flags: []cli.Flag{},
|
||||
Action: func(context *cli.Context) error {
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ var imagesImportCommand = cli.Command{
|
||||
refObject = context.String("ref-object")
|
||||
labels = commands.LabelArgs(context.StringSlice("label"))
|
||||
)
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ var containerInfoCommand = cli.Command{
|
||||
if id == "" {
|
||||
return errors.New("container id must be provided")
|
||||
}
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -41,7 +42,7 @@ var taskKillCommand = cli.Command{
|
||||
if pid > 0 && all {
|
||||
return errors.New("enter a pid or all; not both")
|
||||
}
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ var containersSetLabelsCommand = cli.Command{
|
||||
if containerID == "" {
|
||||
return errors.New("please specify a container")
|
||||
}
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/containerd/containerd/cmd/ctr/commands/plugins"
|
||||
versionCmd "github.com/containerd/containerd/cmd/ctr/commands/version"
|
||||
"github.com/containerd/containerd/namespaces"
|
||||
"github.com/containerd/containerd/server"
|
||||
"github.com/containerd/containerd/version"
|
||||
@ -64,6 +66,8 @@ containerd CLI
|
||||
},
|
||||
}
|
||||
app.Commands = append([]cli.Command{
|
||||
plugins.Command,
|
||||
versionCmd.Command,
|
||||
applyCommand,
|
||||
containersCommand,
|
||||
contentCommand,
|
||||
@ -80,8 +84,6 @@ containerd CLI
|
||||
runCommand,
|
||||
snapshotCommand,
|
||||
tasksCommand,
|
||||
pluginsCommand,
|
||||
versionCommand,
|
||||
}, extraCmds...)
|
||||
app.Before = func(context *cli.Context) error {
|
||||
if context.GlobalBool("debug") {
|
||||
|
@ -35,7 +35,7 @@ var namespacesCreateCommand = cli.Command{
|
||||
if namespace == "" {
|
||||
return errors.New("please specify a namespace")
|
||||
}
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -56,7 +56,7 @@ var namespacesSetLabelsCommand = cli.Command{
|
||||
if namespace == "" {
|
||||
return errors.New("please specify a namespace")
|
||||
}
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -85,7 +85,7 @@ var namespacesListCommand = cli.Command{
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
quiet := context.Bool("quiet")
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -131,7 +131,7 @@ var namespacesRemoveCommand = cli.Command{
|
||||
Description: "Remove one or more namespaces. For now, the namespace must be empty.",
|
||||
Action: func(context *cli.Context) error {
|
||||
var exitErr error
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1,13 +1,16 @@
|
||||
package main
|
||||
|
||||
import "github.com/urfave/cli"
|
||||
import (
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var taskPauseCommand = cli.Command{
|
||||
Name: "pause",
|
||||
Usage: "pause an existing container",
|
||||
ArgsUsage: "CONTAINER",
|
||||
Action: func(context *cli.Context) error {
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
"github.com/containerd/containerd/windows/hcsshimtypes"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
@ -19,7 +20,7 @@ var taskPsCommand = cli.Command{
|
||||
if id == "" {
|
||||
return errors.New("container id must be provided")
|
||||
}
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ command. As part of this process, we do the following:
|
||||
ref = context.Args().First()
|
||||
)
|
||||
|
||||
ctx, cancel := appContext(context)
|
||||
ctx, cancel := commands.AppContext(context)
|
||||
defer cancel()
|
||||
|
||||
img, err := fetch(ref, context)
|
||||
|
@ -52,7 +52,7 @@ var pushCommand = cli.Command{
|
||||
local = context.Args().Get(1)
|
||||
desc ocispec.Descriptor
|
||||
)
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ var pushObjectCommand = cli.Command{
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1,13 +1,16 @@
|
||||
package main
|
||||
|
||||
import "github.com/urfave/cli"
|
||||
import (
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var taskResumeCommand = cli.Command{
|
||||
Name: "resume",
|
||||
Usage: "resume a paused container",
|
||||
ArgsUsage: "CONTAINER",
|
||||
Action: func(context *cli.Context) error {
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ var rootfsUnpackCommand = cli.Command{
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ var runCommand = cli.Command{
|
||||
if id == "" {
|
||||
return errors.New("container id must be provided")
|
||||
}
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ var listSnapshotCommand = cli.Command{
|
||||
Aliases: []string{"ls"},
|
||||
Usage: "list snapshots",
|
||||
Action: func(context *cli.Context) error {
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -83,7 +83,7 @@ var usageSnapshotCommand = cli.Command{
|
||||
return progress.Bytes(s).String()
|
||||
}
|
||||
}
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -124,7 +124,7 @@ var removeSnapshotCommand = cli.Command{
|
||||
ArgsUsage: "<key> [<key>, ...]",
|
||||
Usage: "remove snapshots",
|
||||
Action: func(context *cli.Context) error {
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -160,7 +160,7 @@ var prepareSnapshotCommand = cli.Command{
|
||||
key = context.Args().Get(0)
|
||||
parent = context.Args().Get(1)
|
||||
)
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -199,7 +199,7 @@ var viewSnapshotCommand = cli.Command{
|
||||
key = context.Args().Get(0)
|
||||
parent = context.Args().Get(1)
|
||||
)
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -232,7 +232,7 @@ var mountSnapshotCommand = cli.Command{
|
||||
target = context.Args().Get(0)
|
||||
key = context.Args().Get(1)
|
||||
)
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -261,7 +261,7 @@ var commitSnapshotCommand = cli.Command{
|
||||
key = context.Args().Get(0)
|
||||
active = context.Args().Get(1)
|
||||
)
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -275,7 +275,7 @@ var treeSnapshotCommand = cli.Command{
|
||||
Name: "tree",
|
||||
Usage: "display tree view of snapshot branches",
|
||||
Action: func(context *cli.Context) error {
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -315,7 +315,7 @@ var infoSnapshotCommand = cli.Command{
|
||||
}
|
||||
|
||||
key := context.Args().Get(0)
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -340,7 +340,7 @@ var labelSnapshotCommand = cli.Command{
|
||||
Flags: []cli.Flag{},
|
||||
Action: func(context *cli.Context) error {
|
||||
key, labels := commands.ObjectWithLabelArgs(context)
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/containerd/console"
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
@ -25,7 +26,7 @@ var taskStartCommand = cli.Command{
|
||||
if id == "" {
|
||||
return errors.New("container id must be provided")
|
||||
}
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"text/tabwriter"
|
||||
|
||||
tasks "github.com/containerd/containerd/api/services/tasks/v1"
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -32,7 +33,7 @@ var tasksCommand = cli.Command{
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
quiet := context.Bool("quiet")
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1,13 +1,16 @@
|
||||
package main
|
||||
|
||||
import "github.com/urfave/cli"
|
||||
import (
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var taskDeleteCommand = cli.Command{
|
||||
Name: "delete",
|
||||
Usage: "delete a task",
|
||||
ArgsUsage: "CONTAINER",
|
||||
Action: func(context *cli.Context) error {
|
||||
client, ctx, cancel, err := newClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -16,8 +16,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/containerd/console"
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/namespaces"
|
||||
"github.com/containerd/containerd/remotes"
|
||||
"github.com/containerd/containerd/remotes/docker"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
@ -26,39 +24,6 @@ import (
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
// appContext returns the context for a command. Should only be called once per
|
||||
// command, near the start.
|
||||
//
|
||||
// This will ensure the namespace is picked up and set the timeout, if one is
|
||||
// defined.
|
||||
func appContext(clicontext *cli.Context) (gocontext.Context, gocontext.CancelFunc) {
|
||||
var (
|
||||
ctx = gocontext.Background()
|
||||
timeout = clicontext.GlobalDuration("timeout")
|
||||
namespace = clicontext.GlobalString("namespace")
|
||||
cancel gocontext.CancelFunc
|
||||
)
|
||||
|
||||
ctx = namespaces.WithNamespace(ctx, namespace)
|
||||
|
||||
if timeout > 0 {
|
||||
ctx, cancel = gocontext.WithTimeout(ctx, timeout)
|
||||
} else {
|
||||
ctx, cancel = gocontext.WithCancel(ctx)
|
||||
}
|
||||
|
||||
return ctx, cancel
|
||||
}
|
||||
|
||||
func newClient(context *cli.Context) (*containerd.Client, gocontext.Context, gocontext.CancelFunc, error) {
|
||||
client, err := containerd.New(context.GlobalString("address"))
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
ctx, cancel := appContext(context)
|
||||
return client, ctx, cancel, nil
|
||||
}
|
||||
|
||||
func passwordPrompt() (string, error) {
|
||||
c := console.Current()
|
||||
defer c.Reset()
|
||||
|
Loading…
Reference in New Issue
Block a user