From 62d1f13217c25cf5b194788cb325c5c20fdbed25 Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Thu, 15 Mar 2018 23:21:32 +0000 Subject: [PATCH] Update containerd to 3c1ef1a714cf5b0104f340f76d539802fc24c75f Signed-off-by: Lantao Liu --- vendor.conf | 5 +- .../containerd/containerd/client.go | 12 +- .../containerd/containerd/client_opts.go | 15 + .../containerd/cmd/ctr/command/main.go | 113 ++ .../containerd/cmd/ctr/command/main_unix.go | 25 + .../containerd/cmd/ctr/commands/client.go | 56 + .../containerd/cmd/ctr/commands/commands.go | 121 ++ .../cmd/ctr/commands/containers/containers.go | 257 +++ .../cmd/ctr/commands/content/content.go | 560 +++++++ .../cmd/ctr/commands/content/fetch.go | 340 ++++ .../cmd/ctr/commands/events/events.go | 79 + .../cmd/ctr/commands/images/export.go | 125 ++ .../cmd/ctr/commands/images/images.go | 330 ++++ .../cmd/ctr/commands/images/import.go | 114 ++ .../cmd/ctr/commands/images/pull.go | 78 + .../cmd/ctr/commands/images/push.go | 212 +++ .../cmd/ctr/commands/namespaces/namespaces.go | 173 ++ .../cmd/ctr/commands/plugins/plugins.go | 153 ++ .../cmd/ctr/commands/pprof/pprof.go | 181 +++ .../cmd/ctr/commands/pprof/pprof_unix.go | 29 + .../cmd/ctr/commands/pprof/pprof_windows.go | 31 + .../containerd/cmd/ctr/commands/resolver.go | 108 ++ .../containerd/cmd/ctr/commands/run/run.go | 258 +++ .../cmd/ctr/commands/run/run_unix.go | 161 ++ .../cmd/ctr/commands/run/run_windows.go | 99 ++ .../cmd/ctr/commands/shim/io_unix.go | 93 ++ .../containerd/cmd/ctr/commands/shim/shim.go | 246 +++ .../cmd/ctr/commands/signal_map_linux.go | 60 + .../cmd/ctr/commands/signal_map_unix.go | 58 + .../cmd/ctr/commands/signal_map_windows.go | 39 + .../containerd/cmd/ctr/commands/signals.go | 75 + .../cmd/ctr/commands/snapshots/snapshots.go | 629 ++++++++ .../cmd/ctr/commands/tasks/attach.go | 86 + .../cmd/ctr/commands/tasks/checkpoint.go | 67 + .../cmd/ctr/commands/tasks/delete.go | 63 + .../containerd/cmd/ctr/commands/tasks/exec.go | 129 ++ .../containerd/cmd/ctr/commands/tasks/kill.go | 83 + .../containerd/cmd/ctr/commands/tasks/list.go | 71 + .../cmd/ctr/commands/tasks/pause.go | 44 + .../containerd/cmd/ctr/commands/tasks/ps.go | 72 + .../cmd/ctr/commands/tasks/resume.go | 44 + .../cmd/ctr/commands/tasks/start.go | 122 ++ .../cmd/ctr/commands/tasks/tasks.go | 46 + .../cmd/ctr/commands/tasks/tasks_unix.go | 98 ++ .../cmd/ctr/commands/tasks/tasks_windows.go | 77 + .../cmd/ctr/commands/version/version.go | 57 + .../containerd/containerd/content/helpers.go | 18 +- .../containerd/containerd/images/handlers.go | 41 +- .../containerd/containerd/images/image.go | 2 +- .../containerd/images/oci/exporter.go | 204 +++ .../containerd/images/oci/importer.go | 204 +++ .../containerd/containerd/metadata/buckets.go | 18 +- .../containerd/containerd/metadata/content.go | 246 ++- .../containerd/containerd/metadata/db.go | 2 +- .../containerd/metadata/migrations.go | 55 + .../containerd/metadata/snapshot.go | 11 +- .../containerd/namespaces/context.go | 2 +- .../containerd/containerd/progress/bar.go | 82 + .../containerd/containerd/progress/doc.go | 18 + .../containerd/containerd/progress/escape.go | 24 + .../containerd/containerd/progress/humaans.go | 45 + .../containerd/containerd/progress/writer.go | 115 ++ .../containerd/containerd/remotes/handlers.go | 5 +- .../containerd/services/content/service.go | 4 +- .../containerd/snapshots/overlay/overlay.go | 203 ++- .../containerd/snapshots/storage/bolt.go | 20 + .../containerd/containerd/vendor.conf | 8 +- .../inconshreveable/mousetrap/LICENSE | 13 - .../inconshreveable/mousetrap/README.md | 23 - .../inconshreveable/mousetrap/trap_others.go | 15 - .../inconshreveable/mousetrap/trap_windows.go | 98 -- .../mousetrap/trap_windows_1.4.go | 46 - vendor/github.com/renstrom/dedent/LICENSE | 21 - vendor/github.com/renstrom/dedent/README.md | 50 - vendor/github.com/renstrom/dedent/dedent.go | 49 - vendor/github.com/spf13/cobra/LICENSE.txt | 174 -- vendor/github.com/spf13/cobra/README.md | 721 --------- vendor/github.com/spf13/cobra/args.go | 98 -- .../spf13/cobra/bash_completions.go | 537 ------- vendor/github.com/spf13/cobra/cobra.go | 190 --- vendor/github.com/spf13/cobra/command.go | 1409 ----------------- .../github.com/spf13/cobra/command_notwin.go | 5 - vendor/github.com/spf13/cobra/command_win.go | 20 - .../github.com/spf13/cobra/zsh_completions.go | 126 -- 84 files changed, 7068 insertions(+), 3748 deletions(-) create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/command/main.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/command/main_unix.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/client.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/commands.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/containers/containers.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/content/content.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/content/fetch.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/events/events.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/images/export.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/images/images.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/images/import.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/images/pull.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/images/push.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/namespaces/namespaces.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/plugins/plugins.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/pprof/pprof.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/pprof/pprof_unix.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/pprof/pprof_windows.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/resolver.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/run/run.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/run/run_unix.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/run/run_windows.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/shim/io_unix.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/shim/shim.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/signal_map_linux.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/signal_map_unix.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/signal_map_windows.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/signals.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/snapshots/snapshots.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/tasks/attach.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/tasks/checkpoint.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/tasks/delete.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/tasks/exec.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/tasks/kill.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/tasks/list.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/tasks/pause.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/tasks/ps.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/tasks/resume.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/tasks/start.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/tasks/tasks.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/tasks/tasks_unix.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/tasks/tasks_windows.go create mode 100644 vendor/github.com/containerd/containerd/cmd/ctr/commands/version/version.go create mode 100644 vendor/github.com/containerd/containerd/images/oci/exporter.go create mode 100644 vendor/github.com/containerd/containerd/images/oci/importer.go create mode 100644 vendor/github.com/containerd/containerd/progress/bar.go create mode 100644 vendor/github.com/containerd/containerd/progress/doc.go create mode 100644 vendor/github.com/containerd/containerd/progress/escape.go create mode 100644 vendor/github.com/containerd/containerd/progress/humaans.go create mode 100644 vendor/github.com/containerd/containerd/progress/writer.go delete mode 100644 vendor/github.com/inconshreveable/mousetrap/LICENSE delete mode 100644 vendor/github.com/inconshreveable/mousetrap/README.md delete mode 100644 vendor/github.com/inconshreveable/mousetrap/trap_others.go delete mode 100644 vendor/github.com/inconshreveable/mousetrap/trap_windows.go delete mode 100644 vendor/github.com/inconshreveable/mousetrap/trap_windows_1.4.go delete mode 100644 vendor/github.com/renstrom/dedent/LICENSE delete mode 100644 vendor/github.com/renstrom/dedent/README.md delete mode 100644 vendor/github.com/renstrom/dedent/dedent.go delete mode 100644 vendor/github.com/spf13/cobra/LICENSE.txt delete mode 100644 vendor/github.com/spf13/cobra/README.md delete mode 100644 vendor/github.com/spf13/cobra/args.go delete mode 100644 vendor/github.com/spf13/cobra/bash_completions.go delete mode 100644 vendor/github.com/spf13/cobra/cobra.go delete mode 100644 vendor/github.com/spf13/cobra/command.go delete mode 100644 vendor/github.com/spf13/cobra/command_notwin.go delete mode 100644 vendor/github.com/spf13/cobra/command_win.go delete mode 100644 vendor/github.com/spf13/cobra/zsh_completions.go diff --git a/vendor.conf b/vendor.conf index 73d63e523..eb5cfe90e 100644 --- a/vendor.conf +++ b/vendor.conf @@ -4,7 +4,7 @@ github.com/boltdb/bolt e9cf4fae01b5a8ff89d0ec6b32f0d9c9f79aefdd github.com/BurntSushi/toml a368813c5e648fee92e5f6c30e3944ff9d5e8895 github.com/containerd/cgroups fe281dd265766145e943a034aa41086474ea6130 github.com/containerd/console 84eeaae905fa414d03e07bcd6c8d3f19e7cf180e -github.com/containerd/containerd 3013762fc58941e33ba70e8f8d9256911f134124 +github.com/containerd/containerd 3c1ef1a714cf5b0104f340f76d539802fc24c75f github.com/containerd/continuity d8fb8589b0e8e85b8c8bbaa8840226d0dfeb7371 github.com/containerd/fifo fbfb6a11ec671efbe94ad1c12c2e98773f19e1e6 github.com/containerd/go-runc 4f6e87ae043f859a38255247b49c9abc262d002f @@ -31,7 +31,6 @@ github.com/google/gofuzz 44d81051d367757e1c7c6a5a86423ece9afcf63c github.com/grpc-ecosystem/go-grpc-prometheus 6b7015e65d366bf3f19b2b2a000a831940f0f7e0 github.com/hashicorp/errwrap 7554cd9344cec97297fa6649b055a8c98c2a1e55 github.com/hashicorp/go-multierror ed905158d87462226a13fe39ddf685ea65f1c11f -github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 github.com/json-iterator/go 1.0.4 github.com/matttproud/golang_protobuf_extensions v1.0.0 github.com/Microsoft/go-winio v0.4.5 @@ -48,10 +47,8 @@ github.com/prometheus/client_golang f4fb1b73fb099f396a7f0036bf86aa8def4ed823 github.com/prometheus/client_model 99fa1f4be8e564e8a6b613da7fa6f46c9edafc6c github.com/prometheus/common 89604d197083d4781071d3c65855d24ecfb0a563 github.com/prometheus/procfs cb4147076ac75738c9a7d279075a253c0cc5acbd -github.com/renstrom/dedent 020d11c3b9c0c7a3c2efcc8e5cf5b9ef7bcea21f github.com/seccomp/libseccomp-golang 32f571b70023028bd57d9288c20efbcb237f3ce0 github.com/sirupsen/logrus v1.0.0 -github.com/spf13/cobra v0.0.1 github.com/spf13/pflag v1.0.0 github.com/stevvooe/ttrpc d4528379866b0ce7e9d71f3eb96f0582fc374577 github.com/stretchr/testify v1.1.4 diff --git a/vendor/github.com/containerd/containerd/client.go b/vendor/github.com/containerd/containerd/client.go index 1ec0eb549..7aebd1ced 100644 --- a/vendor/github.com/containerd/containerd/client.go +++ b/vendor/github.com/containerd/containerd/client.go @@ -43,7 +43,6 @@ import ( "github.com/containerd/containerd/events" "github.com/containerd/containerd/images" "github.com/containerd/containerd/namespaces" - "github.com/containerd/containerd/platforms" "github.com/containerd/containerd/plugin" "github.com/containerd/containerd/remotes" "github.com/containerd/containerd/remotes/docker" @@ -236,6 +235,10 @@ type RemoteContext struct { // If no resolver is provided, defaults to Docker registry resolver. Resolver remotes.Resolver + // Platforms defines which platforms to handle when doing the image operation. + // If this field is empty, content for all platforms will be pulled. + Platforms []string + // Unpack is done after an image is pulled to extract into a snapshotter. // If an image is not unpacked on pull, it can be unpacked any time // afterwards. Unpacking is required to run an image. @@ -287,6 +290,7 @@ func (c *Client) Pull(ctx context.Context, ref string, opts ...RemoteOpt) (Image if err != nil { return nil, errors.Wrapf(err, "failed to resolve reference %q", ref) } + fetcher, err := pullCtx.Resolver.Fetcher(ctx, name) if err != nil { return nil, errors.Wrapf(err, "failed to get fetcher for %q", name) @@ -304,8 +308,8 @@ func (c *Client) Pull(ctx context.Context, ref string, opts ...RemoteOpt) (Image childrenHandler := images.ChildrenHandler(store) // Set any children labels for that content childrenHandler = images.SetChildrenLabels(store, childrenHandler) - // Filter the childen by the platform - childrenHandler = images.FilterPlatform(platforms.Default(), childrenHandler) + // Filter childen by platforms + childrenHandler = images.FilterPlatforms(childrenHandler, pullCtx.Platforms...) handler = images.Handlers(append(pullCtx.BaseHandlers, remotes.FetchHandler(store, fetcher), @@ -371,7 +375,7 @@ func (c *Client) Push(ctx context.Context, ref string, desc ocispec.Descriptor, return err } - return remotes.PushContent(ctx, pusher, desc, c.ContentStore(), pushCtx.BaseHandlers...) + return remotes.PushContent(ctx, pusher, desc, c.ContentStore(), pushCtx.Platforms, pushCtx.BaseHandlers...) } // GetImage returns an existing image diff --git a/vendor/github.com/containerd/containerd/client_opts.go b/vendor/github.com/containerd/containerd/client_opts.go index 1859c4865..52f670d75 100644 --- a/vendor/github.com/containerd/containerd/client_opts.go +++ b/vendor/github.com/containerd/containerd/client_opts.go @@ -64,6 +64,21 @@ func WithServices(opts ...ServicesOpt) ClientOpt { // RemoteOpt allows the caller to set distribution options for a remote type RemoteOpt func(*Client, *RemoteContext) error +// WithPlatform allows the caller to specify a platform to retrieve +// content for +func WithPlatform(platform string) RemoteOpt { + return func(_ *Client, c *RemoteContext) error { + for _, p := range c.Platforms { + if p == platform { + return nil + } + } + + c.Platforms = append(c.Platforms, platform) + return nil + } +} + // WithPullUnpack is used to unpack an image after pull. This // uses the snapshotter, content store, and diff service // configured for the client. diff --git a/vendor/github.com/containerd/containerd/cmd/ctr/command/main.go b/vendor/github.com/containerd/containerd/cmd/ctr/command/main.go new file mode 100644 index 000000000..8fd1a5a51 --- /dev/null +++ b/vendor/github.com/containerd/containerd/cmd/ctr/command/main.go @@ -0,0 +1,113 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package command + +import ( + "fmt" + "io/ioutil" + "log" + + "github.com/containerd/containerd/cmd/ctr/commands/containers" + "github.com/containerd/containerd/cmd/ctr/commands/content" + "github.com/containerd/containerd/cmd/ctr/commands/events" + "github.com/containerd/containerd/cmd/ctr/commands/images" + namespacesCmd "github.com/containerd/containerd/cmd/ctr/commands/namespaces" + "github.com/containerd/containerd/cmd/ctr/commands/plugins" + "github.com/containerd/containerd/cmd/ctr/commands/pprof" + "github.com/containerd/containerd/cmd/ctr/commands/run" + "github.com/containerd/containerd/cmd/ctr/commands/snapshots" + "github.com/containerd/containerd/cmd/ctr/commands/tasks" + versionCmd "github.com/containerd/containerd/cmd/ctr/commands/version" + "github.com/containerd/containerd/defaults" + "github.com/containerd/containerd/namespaces" + "github.com/containerd/containerd/version" + "github.com/sirupsen/logrus" + "github.com/urfave/cli" + "google.golang.org/grpc/grpclog" +) + +var extraCmds = []cli.Command{} + +func init() { + // Discard grpc logs so that they don't mess with our stdio + grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags)) + + cli.VersionPrinter = func(c *cli.Context) { + fmt.Println(c.App.Name, version.Package, c.App.Version) + } +} + +// App returns a *cli.App instance. +func App() *cli.App { + app := cli.NewApp() + app.Name = "ctr" + app.Version = version.Version + app.Usage = ` + __ + _____/ /______ + / ___/ __/ ___/ +/ /__/ /_/ / +\___/\__/_/ + +containerd CLI +` + app.Flags = []cli.Flag{ + cli.BoolFlag{ + Name: "debug", + Usage: "enable debug output in logs", + }, + cli.StringFlag{ + Name: "address, a", + Usage: "address for containerd's GRPC server", + Value: defaults.DefaultAddress, + }, + cli.DurationFlag{ + Name: "timeout", + Usage: "total timeout for ctr commands", + }, + cli.DurationFlag{ + Name: "connect-timeout", + Usage: "timeout for connecting to containerd", + }, + cli.StringFlag{ + Name: "namespace, n", + Usage: "namespace to use with commands", + Value: namespaces.Default, + EnvVar: namespaces.NamespaceEnvVar, + }, + } + app.Commands = append([]cli.Command{ + plugins.Command, + versionCmd.Command, + containers.Command, + content.Command, + events.Command, + images.Command, + namespacesCmd.Command, + pprof.Command, + run.Command, + snapshots.Command, + tasks.Command, + }, extraCmds...) + app.Before = func(context *cli.Context) error { + if context.GlobalBool("debug") { + logrus.SetLevel(logrus.DebugLevel) + } + return nil + } + return app +} diff --git a/vendor/github.com/containerd/containerd/cmd/ctr/command/main_unix.go b/vendor/github.com/containerd/containerd/cmd/ctr/command/main_unix.go new file mode 100644 index 000000000..80f2f41dc --- /dev/null +++ b/vendor/github.com/containerd/containerd/cmd/ctr/command/main_unix.go @@ -0,0 +1,25 @@ +// +build !windows + +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package command + +import "github.com/containerd/containerd/cmd/ctr/commands/shim" + +func init() { + extraCmds = append(extraCmds, shim.Command) +} diff --git a/vendor/github.com/containerd/containerd/cmd/ctr/commands/client.go b/vendor/github.com/containerd/containerd/cmd/ctr/commands/client.go new file mode 100644 index 000000000..e940aea66 --- /dev/null +++ b/vendor/github.com/containerd/containerd/cmd/ctr/commands/client.go @@ -0,0 +1,56 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +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 +} diff --git a/vendor/github.com/containerd/containerd/cmd/ctr/commands/commands.go b/vendor/github.com/containerd/containerd/cmd/ctr/commands/commands.go new file mode 100644 index 000000000..1a0c3b6b3 --- /dev/null +++ b/vendor/github.com/containerd/containerd/cmd/ctr/commands/commands.go @@ -0,0 +1,121 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package commands + +import ( + "encoding/json" + "fmt" + "os" + "path/filepath" + "strings" + + "github.com/containerd/containerd" + "github.com/urfave/cli" +) + +var ( + // SnapshotterFlags are cli flags specifying snapshotter names + SnapshotterFlags = []cli.Flag{ + cli.StringFlag{ + Name: "snapshotter", + Usage: "snapshotter name. Empty value stands for the default value.", + Value: containerd.DefaultSnapshotter, + EnvVar: "CONTAINERD_SNAPSHOTTER", + }, + } + + // LabelFlag is a cli flag specifying labels + LabelFlag = cli.StringSliceFlag{ + Name: "label", + Usage: "labels to attach to the image", + } + + // RegistryFlags are cli flags specifying registry options + RegistryFlags = []cli.Flag{ + cli.BoolFlag{ + Name: "skip-verify,k", + Usage: "skip SSL certificate validation", + }, + cli.BoolFlag{ + Name: "plain-http", + Usage: "allow connections using plain HTTP", + }, + cli.StringFlag{ + Name: "user,u", + Usage: "user[:password] Registry user and password", + }, + cli.StringFlag{ + Name: "refresh", + Usage: "refresh token for authorization server", + }, + } +) + +// ObjectWithLabelArgs returns the first arg and a LabelArgs object +func ObjectWithLabelArgs(clicontext *cli.Context) (string, map[string]string) { + var ( + first = clicontext.Args().First() + labelStrings = clicontext.Args().Tail() + ) + + return first, LabelArgs(labelStrings) +} + +// LabelArgs returns a map of label key,value pairs +func LabelArgs(labelStrings []string) map[string]string { + labels := make(map[string]string, len(labelStrings)) + for _, label := range labelStrings { + parts := strings.SplitN(label, "=", 2) + key := parts[0] + value := "true" + if len(parts) > 1 { + value = parts[1] + } + + labels[key] = value + } + + return labels +} + +// PrintAsJSON prints input in JSON format +func PrintAsJSON(x interface{}) { + b, err := json.MarshalIndent(x, "", " ") + if err != nil { + fmt.Fprintf(os.Stderr, "can't marshal %+v as a JSON string: %v\n", x, err) + } + fmt.Println(string(b)) +} + +// WritePidFile writes the pid atomically to a file +func WritePidFile(path string, pid int) error { + path, err := filepath.Abs(path) + if err != nil { + return err + } + tempPath := filepath.Join(filepath.Dir(path), fmt.Sprintf(".%s", filepath.Base(path))) + f, err := os.OpenFile(tempPath, os.O_RDWR|os.O_CREATE|os.O_EXCL|os.O_SYNC, 0666) + if err != nil { + return err + } + _, err = fmt.Fprintf(f, "%d", pid) + f.Close() + if err != nil { + return err + } + return os.Rename(tempPath, path) +} diff --git a/vendor/github.com/containerd/containerd/cmd/ctr/commands/containers/containers.go b/vendor/github.com/containerd/containerd/cmd/ctr/commands/containers/containers.go new file mode 100644 index 000000000..05d0d7e2f --- /dev/null +++ b/vendor/github.com/containerd/containerd/cmd/ctr/commands/containers/containers.go @@ -0,0 +1,257 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package containers + +import ( + "context" + "errors" + "fmt" + "os" + "strings" + "text/tabwriter" + + "github.com/containerd/containerd" + "github.com/containerd/containerd/cmd/ctr/commands" + "github.com/containerd/containerd/cmd/ctr/commands/run" + "github.com/containerd/containerd/log" + "github.com/urfave/cli" +) + +// Command is the cli command for managing containers +var Command = cli.Command{ + Name: "containers", + Usage: "manage containers", + Aliases: []string{"c", "container"}, + Subcommands: []cli.Command{ + createCommand, + deleteCommand, + infoCommand, + listCommand, + setLabelsCommand, + }, +} + +var createCommand = cli.Command{ + Name: "create", + Usage: "create container", + ArgsUsage: "[flags] Image|RootFS CONTAINER", + Flags: append(commands.SnapshotterFlags, run.ContainerFlags...), + Action: func(context *cli.Context) error { + var ( + id = context.Args().Get(1) + ref = context.Args().First() + ) + if ref == "" { + return errors.New("image ref must be provided") + } + if id == "" { + return errors.New("container id must be provided") + } + client, ctx, cancel, err := commands.NewClient(context) + if err != nil { + return err + } + defer cancel() + _, err = run.NewContainer(ctx, client, context) + if err != nil { + return err + } + return nil + }, +} + +var listCommand = cli.Command{ + Name: "list", + Aliases: []string{"ls"}, + Usage: "list containers", + ArgsUsage: "[flags] [, ...]", + Flags: []cli.Flag{ + cli.BoolFlag{ + Name: "quiet, q", + Usage: "print only the container id", + }, + }, + Action: func(context *cli.Context) error { + var ( + filters = context.Args() + quiet = context.Bool("quiet") + ) + client, ctx, cancel, err := commands.NewClient(context) + if err != nil { + return err + } + defer cancel() + containers, err := client.Containers(ctx, filters...) + if err != nil { + return err + } + if quiet { + for _, c := range containers { + fmt.Printf("%s\n", c.ID()) + } + return nil + } + w := tabwriter.NewWriter(os.Stdout, 4, 8, 4, ' ', 0) + fmt.Fprintln(w, "CONTAINER\tIMAGE\tRUNTIME\t") + for _, c := range containers { + info, err := c.Info(ctx) + if err != nil { + return err + } + imageName := info.Image + if imageName == "" { + imageName = "-" + } + if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t\n", + c.ID(), + imageName, + info.Runtime.Name, + ); err != nil { + return err + } + } + return w.Flush() + }, +} + +var deleteCommand = cli.Command{ + Name: "delete", + Usage: "delete one or more existing containers", + ArgsUsage: "[flags] CONTAINER [CONTAINER, ...]", + Aliases: []string{"del", "rm"}, + Flags: []cli.Flag{ + cli.BoolFlag{ + Name: "keep-snapshot", + Usage: "do not clean up snapshot with container", + }, + }, + Action: func(context *cli.Context) error { + var exitErr error + client, ctx, cancel, err := commands.NewClient(context) + if err != nil { + return err + } + defer cancel() + deleteOpts := []containerd.DeleteOpts{} + if !context.Bool("keep-snapshot") { + deleteOpts = append(deleteOpts, containerd.WithSnapshotCleanup) + } + + if context.NArg() == 0 { + return errors.New("must specify at least one container to delete") + } + for _, arg := range context.Args() { + if err := deleteContainer(ctx, client, arg, deleteOpts...); err != nil { + if exitErr == nil { + exitErr = err + } + log.G(ctx).WithError(err).Errorf("failed to delete container %q", arg) + } + } + + return exitErr + }, +} + +func deleteContainer(ctx context.Context, client *containerd.Client, id string, opts ...containerd.DeleteOpts) error { + container, err := client.LoadContainer(ctx, id) + if err != nil { + return err + } + task, err := container.Task(ctx, nil) + if err != nil { + return container.Delete(ctx, opts...) + } + status, err := task.Status(ctx) + if err != nil { + return err + } + if status.Status == containerd.Stopped || status.Status == containerd.Created { + if _, err := task.Delete(ctx); err != nil { + return err + } + return container.Delete(ctx, opts...) + } + return fmt.Errorf("cannot delete a non stopped container: %v", status) + +} + +var setLabelsCommand = cli.Command{ + Name: "label", + Usage: "set and clear labels for a container", + ArgsUsage: "[flags] CONTAINER [=, ...]", + Description: "set and clear labels for a container", + Flags: []cli.Flag{}, + Action: func(context *cli.Context) error { + containerID, labels := commands.ObjectWithLabelArgs(context) + if containerID == "" { + return errors.New("container id must be provided") + } + client, ctx, cancel, err := commands.NewClient(context) + if err != nil { + return err + } + defer cancel() + + container, err := client.LoadContainer(ctx, containerID) + if err != nil { + return err + } + + setlabels, err := container.SetLabels(ctx, labels) + if err != nil { + return err + } + + var labelStrings []string + for k, v := range setlabels { + labelStrings = append(labelStrings, fmt.Sprintf("%s=%s", k, v)) + } + + fmt.Println(strings.Join(labelStrings, ",")) + + return nil + }, +} + +var infoCommand = cli.Command{ + Name: "info", + Usage: "get info about a container", + ArgsUsage: "CONTAINER", + Action: func(context *cli.Context) error { + id := context.Args().First() + if id == "" { + return errors.New("container id must be provided") + } + client, ctx, cancel, err := commands.NewClient(context) + if err != nil { + return err + } + defer cancel() + container, err := client.LoadContainer(ctx, id) + if err != nil { + return err + } + info, err := container.Info(ctx) + if err != nil { + return err + } + commands.PrintAsJSON(info) + + return nil + }, +} diff --git a/vendor/github.com/containerd/containerd/cmd/ctr/commands/content/content.go b/vendor/github.com/containerd/containerd/cmd/ctr/commands/content/content.go new file mode 100644 index 000000000..6e4b26a14 --- /dev/null +++ b/vendor/github.com/containerd/containerd/cmd/ctr/commands/content/content.go @@ -0,0 +1,560 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package content + +import ( + "fmt" + "io" + "io/ioutil" + "os" + "os/exec" + "strings" + "text/tabwriter" + "time" + + "github.com/containerd/containerd/cmd/ctr/commands" + "github.com/containerd/containerd/content" + "github.com/containerd/containerd/errdefs" + "github.com/containerd/containerd/log" + units "github.com/docker/go-units" + digest "github.com/opencontainers/go-digest" + ocispec "github.com/opencontainers/image-spec/specs-go/v1" + "github.com/pkg/errors" + "github.com/urfave/cli" +) + +var ( + // Command is the cli command for managing content + Command = cli.Command{ + Name: "content", + Usage: "manage content", + Subcommands: cli.Commands{ + activeIngestCommand, + deleteCommand, + editCommand, + fetchCommand, + fetchObjectCommand, + getCommand, + ingestCommand, + listCommand, + pushObjectCommand, + setLabelsCommand, + }, + } + + getCommand = cli.Command{ + Name: "get", + Usage: "get the data for an object", + ArgsUsage: "[, ...]", + Description: "display the image object", + Action: func(context *cli.Context) error { + dgst, err := digest.Parse(context.Args().First()) + if err != nil { + return err + } + client, ctx, cancel, err := commands.NewClient(context) + if err != nil { + return err + } + defer cancel() + cs := client.ContentStore() + ra, err := cs.ReaderAt(ctx, dgst) + if err != nil { + return err + } + defer ra.Close() + + _, err = io.Copy(os.Stdout, content.NewReader(ra)) + return err + }, + } + + ingestCommand = cli.Command{ + Name: "ingest", + Usage: "accept content into the store", + ArgsUsage: "[flags] ", + 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 ( + ref = context.Args().First() + expectedSize = context.Int64("expected-size") + expectedDigest = digest.Digest(context.String("expected-digest")) + ) + if err := expectedDigest.Validate(); expectedDigest != "" && err != nil { + return err + } + if ref == "" { + return errors.New("must specify a transaction reference") + } + client, ctx, cancel, err := commands.NewClient(context) + if err != nil { + return err + } + defer cancel() + + cs := client.ContentStore() + + // 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, cs, ref, os.Stdin, expectedSize, expectedDigest) + }, + } + + activeIngestCommand = cli.Command{ + Name: "active", + Usage: "display active transfers", + ArgsUsage: "[flags] []", + Description: "display the ongoing transfers", + Flags: []cli.Flag{ + cli.DurationFlag{ + Name: "timeout, t", + Usage: "total timeout for fetch", + EnvVar: "CONTAINERD_FETCH_TIMEOUT", + }, + cli.StringFlag{ + Name: "root", + Usage: "path to content store root", + Value: "/tmp/content", // TODO(stevvooe): for now, just use the PWD/.content + }, + }, + Action: func(context *cli.Context) error { + match := context.Args().First() + client, ctx, cancel, err := commands.NewClient(context) + if err != nil { + return err + } + defer cancel() + cs := client.ContentStore() + active, err := cs.ListStatuses(ctx, match) + if err != nil { + return err + } + tw := tabwriter.NewWriter(os.Stdout, 1, 8, 1, '\t', 0) + fmt.Fprintln(tw, "REF\tSIZE\tAGE\t") + for _, active := range active { + fmt.Fprintf(tw, "%s\t%s\t%s\t\n", + active.Ref, + units.HumanSize(float64(active.Offset)), + units.HumanDuration(time.Since(active.StartedAt))) + } + + return tw.Flush() + }, + } + + listCommand = cli.Command{ + Name: "list", + Aliases: []string{"ls"}, + Usage: "list all blobs in the store", + ArgsUsage: "[flags]", + Description: "list blobs in the content store", + Flags: []cli.Flag{ + cli.BoolFlag{ + Name: "quiet, q", + Usage: "print only the blob digest", + }, + }, + Action: func(context *cli.Context) error { + var ( + quiet = context.Bool("quiet") + args = []string(context.Args()) + ) + client, ctx, cancel, err := commands.NewClient(context) + if err != nil { + return err + } + defer cancel() + cs := client.ContentStore() + + var walkFn content.WalkFunc + if quiet { + walkFn = func(info content.Info) error { + fmt.Println(info.Digest) + return nil + } + } else { + tw := tabwriter.NewWriter(os.Stdout, 1, 8, 1, '\t', 0) + defer tw.Flush() + + fmt.Fprintln(tw, "DIGEST\tSIZE\tAGE\tLABELS") + walkFn = func(info content.Info) error { + 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.CreatedAt)), + labels) + return nil + } + + } + + return cs.Walk(ctx, walkFn, args...) + }, + } + + setLabelsCommand = cli.Command{ + Name: "label", + Usage: "add labels to content", + ArgsUsage: " [