Merge pull request #10369 from thaJeztah/cmd_no_alias
cmd: don't alias context package, and use cliContext for cli.Context
This commit is contained in:
commit
8b5c218e5a
@ -187,13 +187,13 @@ func main() {
|
|||||||
Value: "overlayfs",
|
Value: "overlayfs",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
app.Before = func(context *cli.Context) error {
|
app.Before = func(cliContext *cli.Context) error {
|
||||||
if context.Bool("json") {
|
if cliContext.Bool("json") {
|
||||||
if err := log.SetLevel("warn"); err != nil {
|
if err := log.SetLevel("warn"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if context.Bool("debug") {
|
if cliContext.Bool("debug") {
|
||||||
if err := log.SetLevel("debug"); err != nil {
|
if err := log.SetLevel("debug"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -203,18 +203,18 @@ func main() {
|
|||||||
app.Commands = []*cli.Command{
|
app.Commands = []*cli.Command{
|
||||||
densityCommand,
|
densityCommand,
|
||||||
}
|
}
|
||||||
app.Action = func(context *cli.Context) error {
|
app.Action = func(cliContext *cli.Context) error {
|
||||||
config := config{
|
config := config{
|
||||||
Address: context.String("address"),
|
Address: cliContext.String("address"),
|
||||||
Duration: context.Duration("duration"),
|
Duration: cliContext.Duration("duration"),
|
||||||
Concurrency: context.Int("concurrent"),
|
Concurrency: cliContext.Int("concurrent"),
|
||||||
CRI: context.Bool("cri"),
|
CRI: cliContext.Bool("cri"),
|
||||||
Exec: context.Bool("exec"),
|
Exec: cliContext.Bool("exec"),
|
||||||
Image: context.String("image"),
|
Image: cliContext.String("image"),
|
||||||
JSON: context.Bool("json"),
|
JSON: cliContext.Bool("json"),
|
||||||
Metrics: context.String("metrics"),
|
Metrics: cliContext.String("metrics"),
|
||||||
Runtime: context.String("runtime"),
|
Runtime: cliContext.String("runtime"),
|
||||||
Snapshotter: context.String("snapshotter"),
|
Snapshotter: cliContext.String("snapshotter"),
|
||||||
}
|
}
|
||||||
if config.Metrics != "" {
|
if config.Metrics != "" {
|
||||||
return serve(config)
|
return serve(config)
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ import (
|
|||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func outputConfig(ctx gocontext.Context, config *srvconfig.Config) error {
|
func outputConfig(ctx context.Context, config *srvconfig.Config) error {
|
||||||
plugins, err := server.LoadPlugins(ctx, config)
|
plugins, err := server.LoadPlugins(ctx, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -86,17 +86,17 @@ var configCommand = &cli.Command{
|
|||||||
{
|
{
|
||||||
Name: "default",
|
Name: "default",
|
||||||
Usage: "See the output of the default config",
|
Usage: "See the output of the default config",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
return outputConfig(gocontext.Background(), defaultConfig())
|
return outputConfig(context.Background(), defaultConfig())
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "dump",
|
Name: "dump",
|
||||||
Usage: "See the output of the final main config with imported in subconfig files",
|
Usage: "See the output of the final main config with imported in subconfig files",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
config := defaultConfig()
|
config := defaultConfig()
|
||||||
ctx := gocontext.Background()
|
ctx := context.Background()
|
||||||
if err := srvconfig.LoadConfig(ctx, context.String("config"), config); err != nil && !os.IsNotExist(err) {
|
if err := srvconfig.LoadConfig(ctx, cliContext.String("config"), config); err != nil && !os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,10 +106,10 @@ var configCommand = &cli.Command{
|
|||||||
{
|
{
|
||||||
Name: "migrate",
|
Name: "migrate",
|
||||||
Usage: "Migrate the current configuration file to the latest version (does not migrate subconfig files)",
|
Usage: "Migrate the current configuration file to the latest version (does not migrate subconfig files)",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
config := defaultConfig()
|
config := defaultConfig()
|
||||||
ctx := gocontext.Background()
|
ctx := context.Background()
|
||||||
if err := srvconfig.LoadConfig(ctx, context.String("config"), config); err != nil && !os.IsNotExist(err) {
|
if err := srvconfig.LoadConfig(ctx, cliContext.String("config"), config); err != nil && !os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
@ -54,8 +54,8 @@ func init() {
|
|||||||
// Discard grpc logs so that they don't mess with our stdio
|
// Discard grpc logs so that they don't mess with our stdio
|
||||||
grpclog.SetLoggerV2(grpclog.NewLoggerV2(io.Discard, io.Discard, io.Discard))
|
grpclog.SetLoggerV2(grpclog.NewLoggerV2(io.Discard, io.Discard, io.Discard))
|
||||||
|
|
||||||
cli.VersionPrinter = func(c *cli.Context) {
|
cli.VersionPrinter = func(cliContext *cli.Context) {
|
||||||
fmt.Println(c.App.Name, version.Package, c.App.Version, version.Revision)
|
fmt.Println(cliContext.App.Name, version.Package, cliContext.App.Version, version.Revision)
|
||||||
}
|
}
|
||||||
cli.VersionFlag = &cli.BoolFlag{
|
cli.VersionFlag = &cli.BoolFlag{
|
||||||
Name: "version",
|
Name: "version",
|
||||||
@ -118,12 +118,12 @@ can be used and modified as necessary as a custom configuration.`
|
|||||||
publishCommand,
|
publishCommand,
|
||||||
ociHook,
|
ociHook,
|
||||||
}
|
}
|
||||||
app.Action = func(context *cli.Context) error {
|
app.Action = func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
start = time.Now()
|
start = time.Now()
|
||||||
signals = make(chan os.Signal, 2048)
|
signals = make(chan os.Signal, 2048)
|
||||||
serverC = make(chan *server.Server, 1)
|
serverC = make(chan *server.Server, 1)
|
||||||
ctx, cancel = gocontext.WithCancel(gocontext.Background())
|
ctx, cancel = context.WithCancel(context.Background())
|
||||||
config = defaultConfig()
|
config = defaultConfig()
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -131,16 +131,16 @@ can be used and modified as necessary as a custom configuration.`
|
|||||||
|
|
||||||
// Only try to load the config if it either exists, or the user explicitly
|
// Only try to load the config if it either exists, or the user explicitly
|
||||||
// told us to load this path.
|
// told us to load this path.
|
||||||
configPath := context.String("config")
|
configPath := cliContext.String("config")
|
||||||
_, err := os.Stat(configPath)
|
_, err := os.Stat(configPath)
|
||||||
if !os.IsNotExist(err) || context.IsSet("config") {
|
if !os.IsNotExist(err) || cliContext.IsSet("config") {
|
||||||
if err := srvconfig.LoadConfig(ctx, configPath, config); err != nil {
|
if err := srvconfig.LoadConfig(ctx, configPath, config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply flags to the config
|
// Apply flags to the config
|
||||||
if err := applyFlags(context, config); err != nil {
|
if err := applyFlags(cliContext, config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,7 +303,7 @@ can be used and modified as necessary as a custom configuration.`
|
|||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
func serve(ctx gocontext.Context, l net.Listener, serveFunc func(net.Listener) error) {
|
func serve(ctx context.Context, l net.Listener, serveFunc func(net.Listener) error) {
|
||||||
path := l.Addr().String()
|
path := l.Addr().String()
|
||||||
log.G(ctx).WithField("address", path).Info("serving...")
|
log.G(ctx).WithField("address", path).Info("serving...")
|
||||||
go func() {
|
go func() {
|
||||||
@ -314,10 +314,10 @@ func serve(ctx gocontext.Context, l net.Listener, serveFunc func(net.Listener) e
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyFlags(context *cli.Context, config *srvconfig.Config) error {
|
func applyFlags(cliContext *cli.Context, config *srvconfig.Config) error {
|
||||||
// the order for config vs flag values is that flags will always override
|
// the order for config vs flag values is that flags will always override
|
||||||
// the config values if they are set
|
// the config values if they are set
|
||||||
if err := setLogLevel(context, config); err != nil {
|
if err := setLogLevel(cliContext, config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := setLogFormat(config); err != nil {
|
if err := setLogFormat(config); err != nil {
|
||||||
@ -341,7 +341,7 @@ func applyFlags(context *cli.Context, config *srvconfig.Config) error {
|
|||||||
d: &config.GRPC.Address,
|
d: &config.GRPC.Address,
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
if s := context.String(v.name); s != "" {
|
if s := cliContext.String(v.name); s != "" {
|
||||||
*v.d = s
|
*v.d = s
|
||||||
if v.name == "root" || v.name == "state" {
|
if v.name == "root" || v.name == "state" {
|
||||||
absPath, err := filepath.Abs(s)
|
absPath, err := filepath.Abs(s)
|
||||||
@ -353,13 +353,13 @@ func applyFlags(context *cli.Context, config *srvconfig.Config) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
applyPlatformFlags(context)
|
applyPlatformFlags(cliContext)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setLogLevel(context *cli.Context, config *srvconfig.Config) error {
|
func setLogLevel(cliContext *cli.Context, config *srvconfig.Config) error {
|
||||||
l := context.String("log-level")
|
l := cliContext.String("log-level")
|
||||||
if l == "" {
|
if l == "" {
|
||||||
l = config.Debug.Level
|
l = config.Debug.Level
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ import (
|
|||||||
var ociHook = &cli.Command{
|
var ociHook = &cli.Command{
|
||||||
Name: "oci-hook",
|
Name: "oci-hook",
|
||||||
Usage: "Provides a base for OCI runtime hooks to allow arguments to be injected.",
|
Usage: "Provides a base for OCI runtime hooks to allow arguments to be injected.",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
state, err := loadHookState(os.Stdin)
|
state, err := loadHookState(os.Stdin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -45,7 +45,7 @@ var ociHook = &cli.Command{
|
|||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
ctx = newTemplateContext(state, spec)
|
ctx = newTemplateContext(state, spec)
|
||||||
args = context.Args().Slice()
|
args = cliContext.Args().Slice()
|
||||||
env = os.Environ()
|
env = os.Environ()
|
||||||
)
|
)
|
||||||
if err := newList(&args).render(ctx); err != nil {
|
if err := newList(&args).render(ctx); err != nil {
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
@ -49,9 +49,9 @@ var publishCommand = &cli.Command{
|
|||||||
Usage: "Topic of the event",
|
Usage: "Topic of the event",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
ctx := namespaces.WithNamespace(gocontext.Background(), context.String("namespace"))
|
ctx := namespaces.WithNamespace(context.Background(), cliContext.String("namespace"))
|
||||||
topic := context.String("topic")
|
topic := cliContext.String("topic")
|
||||||
if topic == "" {
|
if topic == "" {
|
||||||
return fmt.Errorf("topic required to publish event: %w", errdefs.ErrInvalidArgument)
|
return fmt.Errorf("topic required to publish event: %w", errdefs.ErrInvalidArgument)
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ var publishCommand = &cli.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
client, err := connectEvents(context.String("address"))
|
client, err := connectEvents(cliContext.String("address"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ func connectEvents(address string) (eventsapi.EventsClient, error) {
|
|||||||
return eventsapi.NewEventsClient(conn), nil
|
return eventsapi.NewEventsClient(conn), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func connect(address string, d func(gocontext.Context, string) (net.Conn, error)) (*grpc.ClientConn, error) {
|
func connect(address string, d func(context.Context, string) (net.Conn, error)) (*grpc.ClientConn, error) {
|
||||||
backoffConfig := backoff.DefaultConfig
|
backoffConfig := backoff.DefaultConfig
|
||||||
backoffConfig.MaxDelay = 3 * time.Second
|
backoffConfig.MaxDelay = 3 * time.Second
|
||||||
connParams := grpc.ConnectParams{
|
connParams := grpc.ConnectParams{
|
||||||
@ -106,7 +106,7 @@ func connect(address string, d func(gocontext.Context, string) (net.Conn, error)
|
|||||||
grpc.FailOnNonTempDialError(true),
|
grpc.FailOnNonTempDialError(true),
|
||||||
grpc.WithConnectParams(connParams),
|
grpc.WithConnectParams(connParams),
|
||||||
}
|
}
|
||||||
ctx, cancel := gocontext.WithTimeout(gocontext.Background(), 2*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
conn, err := grpc.DialContext(ctx, dialer.DialAddress(address), gopts...)
|
conn, err := grpc.DialContext(ctx, dialer.DialAddress(address), gopts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -30,7 +30,7 @@ func serviceFlags() []cli.Flag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// applyPlatformFlags applies platform-specific flags.
|
// applyPlatformFlags applies platform-specific flags.
|
||||||
func applyPlatformFlags(context *cli.Context) {
|
func applyPlatformFlags(cliContext *cli.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// registerUnregisterService is only relevant on Windows.
|
// registerUnregisterService is only relevant on Windows.
|
||||||
|
@ -79,8 +79,8 @@ func serviceFlags() []cli.Flag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// applyPlatformFlags applies platform-specific flags.
|
// applyPlatformFlags applies platform-specific flags.
|
||||||
func applyPlatformFlags(context *cli.Context) {
|
func applyPlatformFlags(cliContext *cli.Context) {
|
||||||
serviceNameFlag = context.String("service-name")
|
serviceNameFlag = cliContext.String("service-name")
|
||||||
if serviceNameFlag == "" {
|
if serviceNameFlag == "" {
|
||||||
serviceNameFlag = defaultServiceName
|
serviceNameFlag = defaultServiceName
|
||||||
}
|
}
|
||||||
@ -101,9 +101,9 @@ func applyPlatformFlags(context *cli.Context) {
|
|||||||
d: &runServiceFlag,
|
d: &runServiceFlag,
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
*v.d = context.Bool(v.name)
|
*v.d = cliContext.Bool(v.name)
|
||||||
}
|
}
|
||||||
logFileFlag = context.String("log-file")
|
logFileFlag = cliContext.String("log-file")
|
||||||
}
|
}
|
||||||
|
|
||||||
type handler struct {
|
type handler struct {
|
||||||
|
@ -52,8 +52,8 @@ func init() {
|
|||||||
// Discard grpc logs so that they don't mess with our stdio
|
// Discard grpc logs so that they don't mess with our stdio
|
||||||
grpclog.SetLoggerV2(grpclog.NewLoggerV2(io.Discard, io.Discard, io.Discard))
|
grpclog.SetLoggerV2(grpclog.NewLoggerV2(io.Discard, io.Discard, io.Discard))
|
||||||
|
|
||||||
cli.VersionPrinter = func(c *cli.Context) {
|
cli.VersionPrinter = func(cliContext *cli.Context) {
|
||||||
fmt.Println(c.App.Name, version.Package, c.App.Version)
|
fmt.Println(cliContext.App.Name, version.Package, cliContext.App.Version)
|
||||||
}
|
}
|
||||||
cli.VersionFlag = &cli.BoolFlag{
|
cli.VersionFlag = &cli.BoolFlag{
|
||||||
Name: "version",
|
Name: "version",
|
||||||
@ -135,8 +135,8 @@ containerd CLI
|
|||||||
info.Command,
|
info.Command,
|
||||||
deprecations.Command,
|
deprecations.Command,
|
||||||
}, extraCmds...)
|
}, extraCmds...)
|
||||||
app.Before = func(context *cli.Context) error {
|
app.Before = func(cliContext *cli.Context) error {
|
||||||
if context.Bool("debug") {
|
if cliContext.Bool("debug") {
|
||||||
return log.SetLevel("debug")
|
return log.SetLevel("debug")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@ -33,18 +33,18 @@ import (
|
|||||||
//
|
//
|
||||||
// This will ensure the namespace is picked up and set the timeout, if one is
|
// This will ensure the namespace is picked up and set the timeout, if one is
|
||||||
// defined.
|
// defined.
|
||||||
func AppContext(context *cli.Context) (gocontext.Context, gocontext.CancelFunc) {
|
func AppContext(cliContext *cli.Context) (context.Context, context.CancelFunc) {
|
||||||
var (
|
var (
|
||||||
ctx = gocontext.Background()
|
ctx = context.Background()
|
||||||
timeout = context.Duration("timeout")
|
timeout = cliContext.Duration("timeout")
|
||||||
namespace = context.String("namespace")
|
namespace = cliContext.String("namespace")
|
||||||
cancel gocontext.CancelFunc
|
cancel context.CancelFunc
|
||||||
)
|
)
|
||||||
ctx = namespaces.WithNamespace(ctx, namespace)
|
ctx = namespaces.WithNamespace(ctx, namespace)
|
||||||
if timeout > 0 {
|
if timeout > 0 {
|
||||||
ctx, cancel = gocontext.WithTimeout(ctx, timeout)
|
ctx, cancel = context.WithTimeout(ctx, timeout)
|
||||||
} else {
|
} else {
|
||||||
ctx, cancel = gocontext.WithCancel(ctx)
|
ctx, cancel = context.WithCancel(ctx)
|
||||||
}
|
}
|
||||||
if tm, err := epoch.SourceDateEpoch(); err != nil {
|
if tm, err := epoch.SourceDateEpoch(); err != nil {
|
||||||
log.L.WithError(err).Warn("Failed to read SOURCE_DATE_EPOCH")
|
log.L.WithError(err).Warn("Failed to read SOURCE_DATE_EPOCH")
|
||||||
@ -56,14 +56,14 @@ func AppContext(context *cli.Context) (gocontext.Context, gocontext.CancelFunc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewClient returns a new containerd client
|
// NewClient returns a new containerd client
|
||||||
func NewClient(context *cli.Context, opts ...containerd.Opt) (*containerd.Client, gocontext.Context, gocontext.CancelFunc, error) {
|
func NewClient(cliContext *cli.Context, opts ...containerd.Opt) (*containerd.Client, context.Context, context.CancelFunc, error) {
|
||||||
timeoutOpt := containerd.WithTimeout(context.Duration("connect-timeout"))
|
timeoutOpt := containerd.WithTimeout(cliContext.Duration("connect-timeout"))
|
||||||
opts = append(opts, timeoutOpt)
|
opts = append(opts, timeoutOpt)
|
||||||
client, err := containerd.New(context.String("address"), opts...)
|
client, err := containerd.New(cliContext.String("address"), opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
ctx, cancel := AppContext(context)
|
ctx, cancel := AppContext(cliContext)
|
||||||
var suppressDeprecationWarnings bool
|
var suppressDeprecationWarnings bool
|
||||||
if s := os.Getenv("CONTAINERD_SUPPRESS_DEPRECATION_WARNINGS"); s != "" {
|
if s := os.Getenv("CONTAINERD_SUPPRESS_DEPRECATION_WARNINGS"); s != "" {
|
||||||
suppressDeprecationWarnings, err = strconv.ParseBool(s)
|
suppressDeprecationWarnings, err = strconv.ParseBool(s)
|
||||||
|
@ -232,10 +232,10 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ObjectWithLabelArgs returns the first arg and a LabelArgs object
|
// ObjectWithLabelArgs returns the first arg and a LabelArgs object
|
||||||
func ObjectWithLabelArgs(clicontext *cli.Context) (string, map[string]string) {
|
func ObjectWithLabelArgs(cliContext *cli.Context) (string, map[string]string) {
|
||||||
var (
|
var (
|
||||||
first = clicontext.Args().First()
|
first = cliContext.Args().First()
|
||||||
labelStrings = clicontext.Args().Tail()
|
labelStrings = cliContext.Args().Tail()
|
||||||
)
|
)
|
||||||
|
|
||||||
return first, LabelArgs(labelStrings)
|
return first, LabelArgs(labelStrings)
|
||||||
|
@ -59,37 +59,37 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRuncOptions(context *cli.Context) (*options.Options, error) {
|
func getRuncOptions(cliContext *cli.Context) (*options.Options, error) {
|
||||||
runtimeOpts := &options.Options{}
|
runtimeOpts := &options.Options{}
|
||||||
if runcBinary := context.String("runc-binary"); runcBinary != "" {
|
if runcBinary := cliContext.String("runc-binary"); runcBinary != "" {
|
||||||
runtimeOpts.BinaryName = runcBinary
|
runtimeOpts.BinaryName = runcBinary
|
||||||
}
|
}
|
||||||
if context.Bool("runc-systemd-cgroup") {
|
if cliContext.Bool("runc-systemd-cgroup") {
|
||||||
if context.String("cgroup") == "" {
|
if cliContext.String("cgroup") == "" {
|
||||||
// runc maps "machine.slice:foo:deadbeef" to "/machine.slice/foo-deadbeef.scope"
|
// runc maps "machine.slice:foo:deadbeef" to "/machine.slice/foo-deadbeef.scope"
|
||||||
return nil, errors.New("option --runc-systemd-cgroup requires --cgroup to be set, e.g. \"machine.slice:foo:deadbeef\"")
|
return nil, errors.New("option --runc-systemd-cgroup requires --cgroup to be set, e.g. \"machine.slice:foo:deadbeef\"")
|
||||||
}
|
}
|
||||||
runtimeOpts.SystemdCgroup = true
|
runtimeOpts.SystemdCgroup = true
|
||||||
}
|
}
|
||||||
if root := context.String("runc-root"); root != "" {
|
if root := cliContext.String("runc-root"); root != "" {
|
||||||
runtimeOpts.Root = root
|
runtimeOpts.Root = root
|
||||||
}
|
}
|
||||||
|
|
||||||
return runtimeOpts, nil
|
return runtimeOpts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func RuntimeOptions(context *cli.Context) (interface{}, error) {
|
func RuntimeOptions(cliContext *cli.Context) (interface{}, error) {
|
||||||
// validate first
|
// validate first
|
||||||
if (context.String("runc-binary") != "" || context.Bool("runc-systemd-cgroup")) &&
|
if (cliContext.String("runc-binary") != "" || cliContext.Bool("runc-systemd-cgroup")) &&
|
||||||
context.String("runtime") != "io.containerd.runc.v2" {
|
cliContext.String("runtime") != "io.containerd.runc.v2" {
|
||||||
return nil, errors.New("specifying runc-binary and runc-systemd-cgroup is only supported for \"io.containerd.runc.v2\" runtime")
|
return nil, errors.New("specifying runc-binary and runc-systemd-cgroup is only supported for \"io.containerd.runc.v2\" runtime")
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.String("runtime") == "io.containerd.runc.v2" {
|
if cliContext.String("runtime") == "io.containerd.runc.v2" {
|
||||||
return getRuncOptions(context)
|
return getRuncOptions(cliContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
if configPath := context.String("runtime-config-path"); configPath != "" {
|
if configPath := cliContext.String("runtime-config-path"); configPath != "" {
|
||||||
return &runtimeoptions.Options{
|
return &runtimeoptions.Options{
|
||||||
ConfigPath: configPath,
|
ConfigPath: configPath,
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -37,6 +37,6 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func RuntimeOptions(context *cli.Context) (interface{}, error) {
|
func RuntimeOptions(cliContext *cli.Context) (interface{}, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -44,16 +44,16 @@ var checkpointCommand = &cli.Command{
|
|||||||
Usage: "Checkpoint container task",
|
Usage: "Checkpoint container task",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
id := context.Args().First()
|
id := cliContext.Args().First()
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return errors.New("container id must be provided")
|
return errors.New("container id must be provided")
|
||||||
}
|
}
|
||||||
ref := context.Args().Get(1)
|
ref := cliContext.Args().Get(1)
|
||||||
if ref == "" {
|
if ref == "" {
|
||||||
return errors.New("ref must be provided")
|
return errors.New("ref must be provided")
|
||||||
}
|
}
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -62,13 +62,13 @@ var checkpointCommand = &cli.Command{
|
|||||||
containerd.WithCheckpointRuntime,
|
containerd.WithCheckpointRuntime,
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.Bool("image") {
|
if cliContext.Bool("image") {
|
||||||
opts = append(opts, containerd.WithCheckpointImage)
|
opts = append(opts, containerd.WithCheckpointImage)
|
||||||
}
|
}
|
||||||
if context.Bool("rw") {
|
if cliContext.Bool("rw") {
|
||||||
opts = append(opts, containerd.WithCheckpointRW)
|
opts = append(opts, containerd.WithCheckpointRW)
|
||||||
}
|
}
|
||||||
if context.Bool("task") {
|
if cliContext.Bool("task") {
|
||||||
opts = append(opts, containerd.WithCheckpointTask)
|
opts = append(opts, containerd.WithCheckpointTask)
|
||||||
}
|
}
|
||||||
container, err := client.LoadContainer(ctx, id)
|
container, err := client.LoadContainer(ctx, id)
|
||||||
|
@ -55,21 +55,21 @@ var createCommand = &cli.Command{
|
|||||||
Usage: "Create container",
|
Usage: "Create container",
|
||||||
ArgsUsage: "[flags] Image|RootFS CONTAINER [COMMAND] [ARG...]",
|
ArgsUsage: "[flags] Image|RootFS CONTAINER [COMMAND] [ARG...]",
|
||||||
Flags: append(commands.RuntimeFlags, append(append(commands.SnapshotterFlags, []cli.Flag{commands.SnapshotterLabels}...), commands.ContainerFlags...)...),
|
Flags: append(commands.RuntimeFlags, append(append(commands.SnapshotterFlags, []cli.Flag{commands.SnapshotterLabels}...), commands.ContainerFlags...)...),
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
id string
|
id string
|
||||||
ref string
|
ref string
|
||||||
config = context.IsSet("config")
|
config = cliContext.IsSet("config")
|
||||||
)
|
)
|
||||||
|
|
||||||
if config {
|
if config {
|
||||||
id = context.Args().First()
|
id = cliContext.Args().First()
|
||||||
if context.NArg() > 1 {
|
if cliContext.NArg() > 1 {
|
||||||
return fmt.Errorf("with spec config file, only container id should be provided: %w", errdefs.ErrInvalidArgument)
|
return fmt.Errorf("with spec config file, only container id should be provided: %w", errdefs.ErrInvalidArgument)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
id = context.Args().Get(1)
|
id = cliContext.Args().Get(1)
|
||||||
ref = context.Args().First()
|
ref = cliContext.Args().First()
|
||||||
if ref == "" {
|
if ref == "" {
|
||||||
return fmt.Errorf("image ref must be provided: %w", errdefs.ErrInvalidArgument)
|
return fmt.Errorf("image ref must be provided: %w", errdefs.ErrInvalidArgument)
|
||||||
}
|
}
|
||||||
@ -77,12 +77,12 @@ var createCommand = &cli.Command{
|
|||||||
if id == "" {
|
if id == "" {
|
||||||
return fmt.Errorf("container id must be provided: %w", errdefs.ErrInvalidArgument)
|
return fmt.Errorf("container id must be provided: %w", errdefs.ErrInvalidArgument)
|
||||||
}
|
}
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
_, err = run.NewContainer(ctx, client, context)
|
_, err = run.NewContainer(ctx, client, cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -102,12 +102,12 @@ var listCommand = &cli.Command{
|
|||||||
Usage: "Print only the container id",
|
Usage: "Print only the container id",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
filters = context.Args().Slice()
|
filters = cliContext.Args().Slice()
|
||||||
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -156,22 +156,22 @@ var deleteCommand = &cli.Command{
|
|||||||
Usage: "Do not clean up snapshot with container",
|
Usage: "Do not clean up snapshot with container",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var exitErr error
|
var exitErr error
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
deleteOpts := []containerd.DeleteOpts{}
|
deleteOpts := []containerd.DeleteOpts{}
|
||||||
if !context.Bool("keep-snapshot") {
|
if !cliContext.Bool("keep-snapshot") {
|
||||||
deleteOpts = append(deleteOpts, containerd.WithSnapshotCleanup)
|
deleteOpts = append(deleteOpts, containerd.WithSnapshotCleanup)
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.NArg() == 0 {
|
if cliContext.NArg() == 0 {
|
||||||
return fmt.Errorf("must specify at least one container to delete: %w", errdefs.ErrInvalidArgument)
|
return fmt.Errorf("must specify at least one container to delete: %w", errdefs.ErrInvalidArgument)
|
||||||
}
|
}
|
||||||
for _, arg := range context.Args().Slice() {
|
for _, arg := range cliContext.Args().Slice() {
|
||||||
if err := deleteContainer(ctx, client, arg, deleteOpts...); err != nil {
|
if err := deleteContainer(ctx, client, arg, deleteOpts...); err != nil {
|
||||||
if exitErr == nil {
|
if exitErr == nil {
|
||||||
exitErr = err
|
exitErr = err
|
||||||
@ -212,12 +212,12 @@ var setLabelsCommand = &cli.Command{
|
|||||||
ArgsUsage: "[flags] CONTAINER [<key>=<value>, ...]",
|
ArgsUsage: "[flags] CONTAINER [<key>=<value>, ...]",
|
||||||
Description: "set and clear labels for a container",
|
Description: "set and clear labels for a container",
|
||||||
Flags: []cli.Flag{},
|
Flags: []cli.Flag{},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
containerID, labels := commands.ObjectWithLabelArgs(context)
|
containerID, labels := commands.ObjectWithLabelArgs(cliContext)
|
||||||
if containerID == "" {
|
if containerID == "" {
|
||||||
return fmt.Errorf("container id must be provided: %w", errdefs.ErrInvalidArgument)
|
return fmt.Errorf("container id must be provided: %w", errdefs.ErrInvalidArgument)
|
||||||
}
|
}
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -254,12 +254,12 @@ var infoCommand = &cli.Command{
|
|||||||
Usage: "Only display the spec",
|
Usage: "Only display the spec",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
id := context.Args().First()
|
id := cliContext.Args().First()
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return fmt.Errorf("container id must be provided: %w", errdefs.ErrInvalidArgument)
|
return fmt.Errorf("container id must be provided: %w", errdefs.ErrInvalidArgument)
|
||||||
}
|
}
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -272,7 +272,7 @@ var infoCommand = &cli.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if context.Bool("spec") {
|
if cliContext.Bool("spec") {
|
||||||
v, err := typeurl.UnmarshalAny(info.Spec)
|
v, err := typeurl.UnmarshalAny(info.Spec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -43,16 +43,16 @@ var restoreCommand = &cli.Command{
|
|||||||
Usage: "Restore the runtime and memory data from the checkpoint",
|
Usage: "Restore the runtime and memory data from the checkpoint",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
id := context.Args().First()
|
id := cliContext.Args().First()
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return errors.New("container id must be provided")
|
return errors.New("container id must be provided")
|
||||||
}
|
}
|
||||||
ref := context.Args().Get(1)
|
ref := cliContext.Args().Get(1)
|
||||||
if ref == "" {
|
if ref == "" {
|
||||||
return errors.New("ref must be provided")
|
return errors.New("ref must be provided")
|
||||||
}
|
}
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ var restoreCommand = &cli.Command{
|
|||||||
containerd.WithRestoreSpec,
|
containerd.WithRestoreSpec,
|
||||||
containerd.WithRestoreRuntime,
|
containerd.WithRestoreRuntime,
|
||||||
}
|
}
|
||||||
if context.Bool("rw") {
|
if cliContext.Bool("rw") {
|
||||||
opts = append(opts, containerd.WithRestoreRW)
|
opts = append(opts, containerd.WithRestoreRW)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ var restoreCommand = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
topts := []containerd.NewTaskOpts{}
|
topts := []containerd.NewTaskOpts{}
|
||||||
if context.Bool("live") {
|
if cliContext.Bool("live") {
|
||||||
topts = append(topts, containerd.WithTaskCheckpoint(checkpoint))
|
topts = append(topts, containerd.WithTaskCheckpoint(checkpoint))
|
||||||
}
|
}
|
||||||
spec, err := ctr.Spec(ctx)
|
spec, err := ctr.Spec(ctx)
|
||||||
|
@ -64,12 +64,12 @@ var (
|
|||||||
Usage: "Get the data for an object",
|
Usage: "Get the data for an object",
|
||||||
ArgsUsage: "[<digest>, ...]",
|
ArgsUsage: "[<digest>, ...]",
|
||||||
Description: "display the image object",
|
Description: "display the image object",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
dgst, err := digest.Parse(context.Args().First())
|
dgst, err := digest.Parse(cliContext.Args().First())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -103,11 +103,11 @@ var (
|
|||||||
Usage: "Verify content against expected digest",
|
Usage: "Verify content against expected digest",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
ref = context.Args().First()
|
ref = cliContext.Args().First()
|
||||||
expectedSize = context.Int64("expected-size")
|
expectedSize = cliContext.Int64("expected-size")
|
||||||
expectedDigest = digest.Digest(context.String("expected-digest"))
|
expectedDigest = digest.Digest(cliContext.String("expected-digest"))
|
||||||
)
|
)
|
||||||
if err := expectedDigest.Validate(); expectedDigest != "" && err != nil {
|
if err := expectedDigest.Validate(); expectedDigest != "" && err != nil {
|
||||||
return err
|
return err
|
||||||
@ -115,7 +115,7 @@ var (
|
|||||||
if ref == "" {
|
if ref == "" {
|
||||||
return errors.New("must specify a transaction reference")
|
return errors.New("must specify a transaction reference")
|
||||||
}
|
}
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -148,9 +148,9 @@ var (
|
|||||||
Value: "/tmp/content", // TODO(stevvooe): for now, just use the PWD/.content
|
Value: "/tmp/content", // TODO(stevvooe): for now, just use the PWD/.content
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
match := context.Args().First()
|
match := cliContext.Args().First()
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -186,12 +186,12 @@ var (
|
|||||||
Usage: "Print only the blob digest",
|
Usage: "Print only the blob digest",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
quiet = context.Bool("quiet")
|
quiet = cliContext.Bool("quiet")
|
||||||
args = context.Args().Slice()
|
args = cliContext.Args().Slice()
|
||||||
)
|
)
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -239,9 +239,9 @@ var (
|
|||||||
Usage: "Add labels to content",
|
Usage: "Add labels to content",
|
||||||
ArgsUsage: "<digest> [<label>=<value> ...]",
|
ArgsUsage: "<digest> [<label>=<value> ...]",
|
||||||
Description: "labels blobs in the content store",
|
Description: "labels blobs in the content store",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
object, labels := commands.ObjectWithLabelArgs(context)
|
object, labels := commands.ObjectWithLabelArgs(cliContext)
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -304,10 +304,10 @@ var (
|
|||||||
EnvVars: []string{"EDITOR"},
|
EnvVars: []string{"EDITOR"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
validate = context.String("validate")
|
validate = cliContext.String("validate")
|
||||||
object = context.Args().First()
|
object = cliContext.Args().First()
|
||||||
)
|
)
|
||||||
|
|
||||||
if validate != "" {
|
if validate != "" {
|
||||||
@ -321,7 +321,7 @@ var (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -333,7 +333,7 @@ var (
|
|||||||
}
|
}
|
||||||
defer ra.Close()
|
defer ra.Close()
|
||||||
|
|
||||||
nrc, err := edit(context, content.NewReader(ra))
|
nrc, err := edit(cliContext, content.NewReader(ra))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -364,12 +364,12 @@ var (
|
|||||||
ArgsUsage: "[<digest>, ...]",
|
ArgsUsage: "[<digest>, ...]",
|
||||||
Description: `Delete one or more blobs permanently. Successfully deleted
|
Description: `Delete one or more blobs permanently. Successfully deleted
|
||||||
blobs are printed to stdout.`,
|
blobs are printed to stdout.`,
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
args = context.Args().Slice()
|
args = cliContext.Args().Slice()
|
||||||
exitError error
|
exitError error
|
||||||
)
|
)
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -412,14 +412,14 @@ var (
|
|||||||
ArgsUsage: "[flags] <remote> <object> [<hint>, ...]",
|
ArgsUsage: "[flags] <remote> <object> [<hint>, ...]",
|
||||||
Description: `Fetch objects by identifier from a remote.`,
|
Description: `Fetch objects by identifier from a remote.`,
|
||||||
Flags: commands.RegistryFlags,
|
Flags: commands.RegistryFlags,
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
ref = context.Args().First()
|
ref = cliContext.Args().First()
|
||||||
)
|
)
|
||||||
ctx, cancel := commands.AppContext(context)
|
ctx, cancel := commands.AppContext(cliContext)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
resolver, err := commands.GetResolver(ctx, context)
|
resolver, err := commands.GetResolver(ctx, cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -459,18 +459,18 @@ var (
|
|||||||
Usage: "Specify target mediatype for request header",
|
Usage: "Specify target mediatype for request header",
|
||||||
},
|
},
|
||||||
}...),
|
}...),
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
ref = context.Args().First()
|
ref = cliContext.Args().First()
|
||||||
digests = context.Args().Tail()
|
digests = cliContext.Args().Tail()
|
||||||
)
|
)
|
||||||
if len(digests) == 0 {
|
if len(digests) == 0 {
|
||||||
return errors.New("must specify digests")
|
return errors.New("must specify digests")
|
||||||
}
|
}
|
||||||
ctx, cancel := commands.AppContext(context)
|
ctx, cancel := commands.AppContext(cliContext)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
resolver, err := commands.GetResolver(ctx, context)
|
resolver, err := commands.GetResolver(ctx, cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -493,7 +493,7 @@ var (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
rc, desc, err := fetcherByDigest.FetchByDigest(ctx, dgst, remotes.WithMediaType(context.String("media-type")))
|
rc, desc, err := fetcherByDigest.FetchByDigest(ctx, dgst, remotes.WithMediaType(cliContext.String("media-type")))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -514,23 +514,23 @@ var (
|
|||||||
ArgsUsage: "[flags] <remote> <object> <type>",
|
ArgsUsage: "[flags] <remote> <object> <type>",
|
||||||
Description: `Push objects by identifier to a remote.`,
|
Description: `Push objects by identifier to a remote.`,
|
||||||
Flags: commands.RegistryFlags,
|
Flags: commands.RegistryFlags,
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
ref = context.Args().Get(0)
|
ref = cliContext.Args().Get(0)
|
||||||
object = context.Args().Get(1)
|
object = cliContext.Args().Get(1)
|
||||||
media = context.Args().Get(2)
|
media = cliContext.Args().Get(2)
|
||||||
)
|
)
|
||||||
dgst, err := digest.Parse(object)
|
dgst, err := digest.Parse(object)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
resolver, err := commands.GetResolver(ctx, context)
|
resolver, err := commands.GetResolver(ctx, cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -578,8 +578,8 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func edit(context *cli.Context, rd io.Reader) (_ io.ReadCloser, retErr error) {
|
func edit(cliContext *cli.Context, rd io.Reader) (_ io.ReadCloser, retErr error) {
|
||||||
editor := context.String("editor")
|
editor := cliContext.String("editor")
|
||||||
if editor == "" {
|
if editor == "" {
|
||||||
return nil, errors.New("editor is required")
|
return nil, errors.New("editor is required")
|
||||||
}
|
}
|
||||||
|
@ -81,16 +81,16 @@ Most of this is experimental and there are few leaps to make this work.`,
|
|||||||
Usage: "Pull all metadata including manifests and configs",
|
Usage: "Pull all metadata including manifests and configs",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Action: func(clicontext *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
ref = clicontext.Args().First()
|
ref = cliContext.Args().First()
|
||||||
)
|
)
|
||||||
client, ctx, cancel, err := commands.NewClient(clicontext)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
config, err := NewFetchConfig(ctx, clicontext)
|
config, err := NewFetchConfig(ctx, cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -121,42 +121,42 @@ type FetchConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewFetchConfig returns the default FetchConfig from cli flags
|
// NewFetchConfig returns the default FetchConfig from cli flags
|
||||||
func NewFetchConfig(ctx context.Context, clicontext *cli.Context) (*FetchConfig, error) {
|
func NewFetchConfig(ctx context.Context, cliContext *cli.Context) (*FetchConfig, error) {
|
||||||
resolver, err := commands.GetResolver(ctx, clicontext)
|
resolver, err := commands.GetResolver(ctx, cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
config := &FetchConfig{
|
config := &FetchConfig{
|
||||||
Resolver: resolver,
|
Resolver: resolver,
|
||||||
Labels: clicontext.StringSlice("label"),
|
Labels: cliContext.StringSlice("label"),
|
||||||
TraceHTTP: clicontext.Bool("http-trace"),
|
TraceHTTP: cliContext.Bool("http-trace"),
|
||||||
}
|
}
|
||||||
if !clicontext.Bool("debug") {
|
if !cliContext.Bool("debug") {
|
||||||
config.ProgressOutput = os.Stdout
|
config.ProgressOutput = os.Stdout
|
||||||
}
|
}
|
||||||
if !clicontext.Bool("all-platforms") {
|
if !cliContext.Bool("all-platforms") {
|
||||||
p := clicontext.StringSlice("platform")
|
p := cliContext.StringSlice("platform")
|
||||||
if len(p) == 0 {
|
if len(p) == 0 {
|
||||||
p = append(p, platforms.DefaultString())
|
p = append(p, platforms.DefaultString())
|
||||||
}
|
}
|
||||||
config.Platforms = p
|
config.Platforms = p
|
||||||
}
|
}
|
||||||
|
|
||||||
if clicontext.Bool("metadata-only") {
|
if cliContext.Bool("metadata-only") {
|
||||||
config.AllMetadata = true
|
config.AllMetadata = true
|
||||||
// Any with an empty set is None
|
// Any with an empty set is None
|
||||||
config.PlatformMatcher = platforms.Any()
|
config.PlatformMatcher = platforms.Any()
|
||||||
} else if !clicontext.Bool("skip-metadata") {
|
} else if !cliContext.Bool("skip-metadata") {
|
||||||
config.AllMetadata = true
|
config.AllMetadata = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if clicontext.IsSet("max-concurrent-downloads") {
|
if cliContext.IsSet("max-concurrent-downloads") {
|
||||||
mcd := clicontext.Int("max-concurrent-downloads")
|
mcd := cliContext.Int("max-concurrent-downloads")
|
||||||
config.RemoteOpts = append(config.RemoteOpts, containerd.WithMaxConcurrentDownloads(mcd))
|
config.RemoteOpts = append(config.RemoteOpts, containerd.WithMaxConcurrentDownloads(mcd))
|
||||||
}
|
}
|
||||||
|
|
||||||
if clicontext.IsSet("max-concurrent-uploaded-layers") {
|
if cliContext.IsSet("max-concurrent-uploaded-layers") {
|
||||||
mcu := clicontext.Int("max-concurrent-uploaded-layers")
|
mcu := cliContext.Int("max-concurrent-uploaded-layers")
|
||||||
config.RemoteOpts = append(config.RemoteOpts, containerd.WithMaxConcurrentUploadedLayers(mcu))
|
config.RemoteOpts = append(config.RemoteOpts, containerd.WithMaxConcurrentUploadedLayers(mcu))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,21 +56,21 @@ var pruneReferencesCommand = &cli.Command{
|
|||||||
Name: "references",
|
Name: "references",
|
||||||
Usage: "Prunes preference labels from the content store (layers only by default)",
|
Usage: "Prunes preference labels from the content store (layers only by default)",
|
||||||
Flags: pruneFlags,
|
Flags: pruneFlags,
|
||||||
Action: func(clicontext *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client, ctx, cancel, err := commands.NewClient(clicontext)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
dryRun := clicontext.Bool("dry")
|
dryRun := cliContext.Bool("dry")
|
||||||
if dryRun {
|
if dryRun {
|
||||||
log.G(ctx).Logger.SetLevel(log.DebugLevel)
|
log.G(ctx).Logger.SetLevel(log.DebugLevel)
|
||||||
log.G(ctx).Debug("dry run, no changes will be applied")
|
log.G(ctx).Debug("dry run, no changes will be applied")
|
||||||
}
|
}
|
||||||
|
|
||||||
var deleteOpts []leases.DeleteOpt
|
var deleteOpts []leases.DeleteOpt
|
||||||
if !clicontext.Bool("async") {
|
if !cliContext.Bool("async") {
|
||||||
deleteOpts = append(deleteOpts, leases.SynchronousDelete)
|
deleteOpts = append(deleteOpts, leases.SynchronousDelete)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,11 +45,11 @@ var listCommand = &cli.Command{
|
|||||||
Usage: "output format to use (Examples: 'default', 'json')",
|
Usage: "output format to use (Examples: 'default', 'json')",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
// Suppress automatic warnings, since we print the warnings by ourselves.
|
// Suppress automatic warnings, since we print the warnings by ourselves.
|
||||||
os.Setenv("CONTAINERD_SUPPRESS_DEPRECATION_WARNINGS", "1")
|
os.Setenv("CONTAINERD_SUPPRESS_DEPRECATION_WARNINGS", "1")
|
||||||
|
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ var listCommand = &cli.Command{
|
|||||||
}
|
}
|
||||||
wrn := warnings(resp)
|
wrn := warnings(resp)
|
||||||
if len(wrn) > 0 {
|
if len(wrn) > 0 {
|
||||||
switch context.String("format") {
|
switch cliContext.String("format") {
|
||||||
case "json":
|
case "json":
|
||||||
commands.PrintAsJSON(warnings(resp))
|
commands.PrintAsJSON(warnings(resp))
|
||||||
return nil
|
return nil
|
||||||
|
@ -35,14 +35,14 @@ var Command = &cli.Command{
|
|||||||
Name: "events",
|
Name: "events",
|
||||||
Aliases: []string{"event"},
|
Aliases: []string{"event"},
|
||||||
Usage: "Display containerd events",
|
Usage: "Display containerd events",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
eventsClient := client.EventService()
|
eventsClient := client.EventService()
|
||||||
eventsCh, errCh := eventsClient.Subscribe(ctx, context.Args().Slice()...)
|
eventsCh, errCh := eventsClient.Subscribe(ctx, cliContext.Args().Slice()...)
|
||||||
for {
|
for {
|
||||||
var e *events.Envelope
|
var e *events.Envelope
|
||||||
select {
|
select {
|
||||||
|
@ -59,16 +59,16 @@ When '--all-platforms' is given all images in a manifest list must be available.
|
|||||||
Usage: "Exports content from all platforms",
|
Usage: "Exports content from all platforms",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var convertOpts []converter.Opt
|
var convertOpts []converter.Opt
|
||||||
srcRef := context.Args().Get(0)
|
srcRef := cliContext.Args().Get(0)
|
||||||
targetRef := context.Args().Get(1)
|
targetRef := cliContext.Args().Get(1)
|
||||||
if srcRef == "" || targetRef == "" {
|
if srcRef == "" || targetRef == "" {
|
||||||
return errors.New("src and target image need to be specified")
|
return errors.New("src and target image need to be specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !context.Bool("all-platforms") {
|
if !cliContext.Bool("all-platforms") {
|
||||||
if pss := context.StringSlice("platform"); len(pss) > 0 {
|
if pss := cliContext.StringSlice("platform"); len(pss) > 0 {
|
||||||
all, err := platforms.ParseAll(pss)
|
all, err := platforms.ParseAll(pss)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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))
|
convertOpts = append(convertOpts, converter.WithLayerConvertFunc(uncompress.LayerConvertFunc))
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.Bool("oci") {
|
if cliContext.Bool("oci") {
|
||||||
convertOpts = append(convertOpts, converter.WithDockerToOCI(true))
|
convertOpts = append(convertOpts, converter.WithDockerToOCI(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ When '--all-platforms' is given all images in a manifest list must be available.
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintln(context.App.Writer, newImg.Target.Digest.String())
|
fmt.Fprintln(cliContext.App.Writer, newImg.Target.Digest.String())
|
||||||
return nil
|
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",
|
Usage: "Run export locally rather than through transfer API",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
out = context.Args().First()
|
out = cliContext.Args().First()
|
||||||
images = context.Args().Tail()
|
images = cliContext.Args().Tail()
|
||||||
exportOpts = []archive.ExportOpt{}
|
exportOpts = []archive.ExportOpt{}
|
||||||
)
|
)
|
||||||
if out == "" || len(images) == 0 {
|
if out == "" || len(images) == 0 {
|
||||||
return errors.New("please provide both an output filename and an image reference to export")
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -93,12 +93,12 @@ When '--all-platforms' is given all images in a manifest list must be available.
|
|||||||
}
|
}
|
||||||
defer w.Close()
|
defer w.Close()
|
||||||
|
|
||||||
if !context.Bool("local") {
|
if !cliContext.Bool("local") {
|
||||||
pf, done := ProgressHandler(ctx, os.Stdout)
|
pf, done := ProgressHandler(ctx, os.Stdout)
|
||||||
defer done()
|
defer done()
|
||||||
|
|
||||||
exportOpts := []tarchive.ExportOpt{}
|
exportOpts := []tarchive.ExportOpt{}
|
||||||
if pss := context.StringSlice("platform"); len(pss) > 0 {
|
if pss := cliContext.StringSlice("platform"); len(pss) > 0 {
|
||||||
for _, ps := range pss {
|
for _, ps := range pss {
|
||||||
p, err := platforms.Parse(ps)
|
p, err := platforms.Parse(ps)
|
||||||
if err != nil {
|
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))
|
exportOpts = append(exportOpts, tarchive.WithPlatform(p))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if context.Bool("all-platforms") {
|
if cliContext.Bool("all-platforms") {
|
||||||
exportOpts = append(exportOpts, tarchive.WithAllPlatforms)
|
exportOpts = append(exportOpts, tarchive.WithAllPlatforms)
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.Bool("skip-manifest-json") {
|
if cliContext.Bool("skip-manifest-json") {
|
||||||
exportOpts = append(exportOpts, tarchive.WithSkipCompatibilityManifest)
|
exportOpts = append(exportOpts, tarchive.WithSkipCompatibilityManifest)
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.Bool("skip-non-distributable") {
|
if cliContext.Bool("skip-non-distributable") {
|
||||||
exportOpts = append(exportOpts, tarchive.WithSkipNonDistributableBlobs)
|
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)
|
all, err := platforms.ParseAll(pss)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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()))
|
exportOpts = append(exportOpts, archive.WithPlatform(platforms.DefaultStrict()))
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.Bool("all-platforms") {
|
if cliContext.Bool("all-platforms") {
|
||||||
exportOpts = append(exportOpts, archive.WithAllPlatforms())
|
exportOpts = append(exportOpts, archive.WithAllPlatforms())
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.Bool("skip-manifest-json") {
|
if cliContext.Bool("skip-manifest-json") {
|
||||||
exportOpts = append(exportOpts, archive.WithSkipDockerManifest())
|
exportOpts = append(exportOpts, archive.WithSkipDockerManifest())
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.Bool("skip-non-distributable") {
|
if cliContext.Bool("skip-non-distributable") {
|
||||||
exportOpts = append(exportOpts, archive.WithSkipNonDistributableBlobs())
|
exportOpts = append(exportOpts, archive.WithSkipNonDistributableBlobs())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,12 +70,12 @@ var listCommand = &cli.Command{
|
|||||||
Usage: "Print only the image refs",
|
Usage: "Print only the image refs",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
filters = context.Args().Slice()
|
filters = cliContext.Args().Slice()
|
||||||
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -154,12 +154,12 @@ var setLabelsCommand = &cli.Command{
|
|||||||
Usage: "Replace all labels",
|
Usage: "Replace all labels",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
replaceAll = context.Bool("replace-all")
|
replaceAll = cliContext.Bool("replace-all")
|
||||||
name, labels = commands.ObjectWithLabelArgs(context)
|
name, labels = commands.ObjectWithLabelArgs(cliContext)
|
||||||
)
|
)
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -214,12 +214,12 @@ var checkCommand = &cli.Command{
|
|||||||
Usage: "Print only the ready image refs (fully downloaded and unpacked)",
|
Usage: "Print only the ready image refs (fully downloaded and unpacked)",
|
||||||
},
|
},
|
||||||
}, commands.SnapshotterFlags...),
|
}, commands.SnapshotterFlags...),
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
exitErr error
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -227,7 +227,7 @@ var checkCommand = &cli.Command{
|
|||||||
|
|
||||||
var contentStore = client.ContentStore()
|
var contentStore = client.ContentStore()
|
||||||
|
|
||||||
args := context.Args().Slice()
|
args := cliContext.Args().Slice()
|
||||||
imageList, err := client.ListImages(ctx, args...)
|
imageList, err := client.ListImages(ctx, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed listing images: %w", err)
|
return fmt.Errorf("failed listing images: %w", err)
|
||||||
@ -287,7 +287,7 @@ var checkCommand = &cli.Command{
|
|||||||
size = "-"
|
size = "-"
|
||||||
}
|
}
|
||||||
|
|
||||||
unpacked, err := image.IsUnpacked(ctx, context.String("snapshotter"))
|
unpacked, err := image.IsUnpacked(ctx, cliContext.String("snapshotter"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if exitErr == nil {
|
if exitErr == nil {
|
||||||
exitErr = fmt.Errorf("unable to check unpack for %v: %w", image.Name(), err)
|
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",
|
Usage: "Synchronously remove image and all associated resources",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -338,9 +338,9 @@ var removeCommand = &cli.Command{
|
|||||||
exitErr error
|
exitErr error
|
||||||
imageStore = client.ImageService()
|
imageStore = client.ImageService()
|
||||||
)
|
)
|
||||||
for i, target := range context.Args().Slice() {
|
for i, target := range cliContext.Args().Slice() {
|
||||||
var opts []images.DeleteOpt
|
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())
|
opts = append(opts, images.SynchronousDelete())
|
||||||
}
|
}
|
||||||
if err := imageStore.Delete(ctx, target, opts...); err != nil {
|
if err := imageStore.Delete(ctx, target, opts...); err != nil {
|
||||||
@ -373,14 +373,14 @@ var pruneCommand = &cli.Command{
|
|||||||
},
|
},
|
||||||
// adapted from `nerdctl`:
|
// adapted from `nerdctl`:
|
||||||
// https://github.com/containerd/nerdctl/blob/272dc9c29fc1434839d3ec63194d7efa24d7c0ef/cmd/nerdctl/image_prune.go#L86
|
// https://github.com/containerd/nerdctl/blob/272dc9c29fc1434839d3ec63194d7efa24d7c0ef/cmd/nerdctl/image_prune.go#L86
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
all := context.Bool("all")
|
all := cliContext.Bool("all")
|
||||||
if !all {
|
if !all {
|
||||||
log.G(ctx).Warn("No images pruned. `image prune` requires --all to be specified.")
|
log.G(ctx).Warn("No images pruned. `image prune` requires --all to be specified.")
|
||||||
// NOP
|
// NOP
|
||||||
|
@ -101,28 +101,28 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
|
|||||||
},
|
},
|
||||||
}, append(commands.SnapshotterFlags, commands.LabelFlag)...),
|
}, append(commands.SnapshotterFlags, commands.LabelFlag)...),
|
||||||
|
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
in = context.Args().First()
|
in = cliContext.Args().First()
|
||||||
opts []containerd.ImportOpt
|
opts []containerd.ImportOpt
|
||||||
platformMatcher platforms.MatchComparer
|
platformMatcher platforms.MatchComparer
|
||||||
)
|
)
|
||||||
|
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
if !context.Bool("local") {
|
if !cliContext.Bool("local") {
|
||||||
unsupportedFlags := []string{"discard-unpacked-layers"}
|
unsupportedFlags := []string{"discard-unpacked-layers"}
|
||||||
for _, s := range unsupportedFlags {
|
for _, s := range unsupportedFlags {
|
||||||
if context.IsSet(s) {
|
if cliContext.IsSet(s) {
|
||||||
return fmt.Errorf("\"--%s\" requires \"--local\" flag", s)
|
return fmt.Errorf("\"--%s\" requires \"--local\" flag", s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var opts []image.StoreOpt
|
var opts []image.StoreOpt
|
||||||
prefix := context.String("base-name")
|
prefix := cliContext.String("base-name")
|
||||||
var overwrite bool
|
var overwrite bool
|
||||||
if prefix == "" {
|
if prefix == "" {
|
||||||
prefix = fmt.Sprintf("import-%s", time.Now().Format("2006-01-02"))
|
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
|
overwrite = true
|
||||||
}
|
}
|
||||||
|
|
||||||
labels := context.StringSlice("label")
|
labels := cliContext.StringSlice("label")
|
||||||
if len(labels) > 0 {
|
if len(labels) > 0 {
|
||||||
opts = append(opts, image.WithImageLabels(commands.LabelArgs(labels)))
|
opts = append(opts, image.WithImageLabels(commands.LabelArgs(labels)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.Bool("digests") {
|
if cliContext.Bool("digests") {
|
||||||
opts = append(opts, image.WithDigestRef(prefix, overwrite, !context.Bool("skip-digest-for-named")))
|
opts = append(opts, image.WithDigestRef(prefix, overwrite, !cliContext.Bool("skip-digest-for-named")))
|
||||||
} else {
|
} else {
|
||||||
opts = append(opts, image.WithNamedPrefix(prefix, overwrite))
|
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
|
var platSpec ocispec.Platform
|
||||||
// Only when all-platforms not specified, we will check platform value
|
// Only when all-platforms not specified, we will check platform value
|
||||||
// Implicitly if the platforms is empty, it means all-platforms
|
// 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 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)
|
platSpec, err = platforms.Parse(platform)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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))
|
opts = append(opts, image.WithPlatforms(platSpec))
|
||||||
}
|
}
|
||||||
|
|
||||||
if !context.Bool("no-unpack") {
|
if !cliContext.Bool("no-unpack") {
|
||||||
snapshotter := context.String("snapshotter")
|
snapshotter := cliContext.String("snapshotter")
|
||||||
// If OS field is not empty, it means platSpec was updated in the above block
|
// If OS field is not empty, it means platSpec was updated in the above block
|
||||||
// i.e all-platforms was not specified
|
// i.e all-platforms was not specified
|
||||||
if platSpec.OS != "" {
|
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
|
var iopts []tarchive.ImportOpt
|
||||||
|
|
||||||
if context.Bool("compress-blobs") {
|
if cliContext.Bool("compress-blobs") {
|
||||||
iopts = append(iopts, tarchive.WithForceCompression)
|
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
|
// Local logic
|
||||||
|
|
||||||
prefix := context.String("base-name")
|
prefix := cliContext.String("base-name")
|
||||||
if prefix == "" {
|
if prefix == "" {
|
||||||
prefix = fmt.Sprintf("import-%s", time.Now().Format("2006-01-02"))
|
prefix = fmt.Sprintf("import-%s", time.Now().Format("2006-01-02"))
|
||||||
opts = append(opts, containerd.WithImageRefTranslator(archive.AddRefPrefix(prefix)))
|
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)))
|
opts = append(opts, containerd.WithImageRefTranslator(archive.FilterRefPrefix(prefix)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.Bool("digests") {
|
if cliContext.Bool("digests") {
|
||||||
opts = append(opts, containerd.WithDigestRef(archive.DigestTranslator(prefix)))
|
opts = append(opts, containerd.WithDigestRef(archive.DigestTranslator(prefix)))
|
||||||
}
|
}
|
||||||
if context.Bool("skip-digest-for-named") {
|
if cliContext.Bool("skip-digest-for-named") {
|
||||||
if !context.Bool("digests") {
|
if !cliContext.Bool("digests") {
|
||||||
return errors.New("--skip-digest-for-named must be specified with --digests option")
|
return errors.New("--skip-digest-for-named must be specified with --digests option")
|
||||||
}
|
}
|
||||||
opts = append(opts, containerd.WithSkipDigestRef(func(name string) bool { return name != "" }))
|
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))
|
opts = append(opts, containerd.WithIndexName(idxName))
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.Bool("compress-blobs") {
|
if cliContext.Bool("compress-blobs") {
|
||||||
opts = append(opts, containerd.WithImportCompression())
|
opts = append(opts, containerd.WithImportCompression())
|
||||||
}
|
}
|
||||||
|
|
||||||
if platform := context.String("platform"); platform != "" {
|
if platform := cliContext.String("platform"); platform != "" {
|
||||||
platSpec, err := platforms.Parse(platform)
|
platSpec, err := platforms.Parse(platform)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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.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 cliContext.Bool("discard-unpacked-layers") {
|
||||||
if context.Bool("no-unpack") {
|
if cliContext.Bool("no-unpack") {
|
||||||
return errors.New("--discard-unpacked-layers and --no-unpack are incompatible options")
|
return errors.New("--discard-unpacked-layers and --no-unpack are incompatible options")
|
||||||
}
|
}
|
||||||
opts = append(opts, containerd.WithDiscardUnpackedLayers())
|
opts = append(opts, containerd.WithDiscardUnpackedLayers())
|
||||||
}
|
}
|
||||||
|
|
||||||
labels := context.StringSlice("label")
|
labels := cliContext.StringSlice("label")
|
||||||
if len(labels) > 0 {
|
if len(labels) > 0 {
|
||||||
opts = append(opts, containerd.WithImageLabels(commands.LabelArgs(labels)))
|
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
|
return closeErr
|
||||||
}
|
}
|
||||||
|
|
||||||
if !context.Bool("no-unpack") {
|
if !cliContext.Bool("no-unpack") {
|
||||||
log.G(ctx).Debugf("unpacking %d images", len(imgs))
|
log.G(ctx).Debugf("unpacking %d images", len(imgs))
|
||||||
|
|
||||||
for _, img := range 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
|
// TODO: Show unpack status
|
||||||
fmt.Printf("unpacking %s (%s)...", img.Name, img.Target.Digest)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -36,14 +36,14 @@ var inspectCommand = &cli.Command{
|
|||||||
Usage: "Show JSON content",
|
Usage: "Show JSON content",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(clicontext *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client, ctx, cancel, err := commands.NewClient(clicontext)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
var (
|
var (
|
||||||
ref = clicontext.Args().First()
|
ref = cliContext.Args().First()
|
||||||
imageStore = client.ImageService()
|
imageStore = client.ImageService()
|
||||||
cs = client.ContentStore()
|
cs = client.ContentStore()
|
||||||
)
|
)
|
||||||
@ -56,7 +56,7 @@ var inspectCommand = &cli.Command{
|
|||||||
opts := []display.PrintOpt{
|
opts := []display.PrintOpt{
|
||||||
display.WithWriter(os.Stdout),
|
display.WithWriter(os.Stdout),
|
||||||
}
|
}
|
||||||
if clicontext.Bool("content") {
|
if cliContext.Bool("content") {
|
||||||
opts = append(opts, display.Verbose)
|
opts = append(opts, display.Verbose)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,10 +51,10 @@ When you are done, use the unmount command.
|
|||||||
Value: platforms.DefaultString(),
|
Value: platforms.DefaultString(),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Action: func(context *cli.Context) (retErr error) {
|
Action: func(cliContext *cli.Context) (retErr error) {
|
||||||
var (
|
var (
|
||||||
ref = context.Args().First()
|
ref = cliContext.Args().First()
|
||||||
target = context.Args().Get(1)
|
target = cliContext.Args().Get(1)
|
||||||
)
|
)
|
||||||
if ref == "" {
|
if ref == "" {
|
||||||
return errors.New("please provide an image reference to mount")
|
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")
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
snapshotter := context.String("snapshotter")
|
snapshotter := cliContext.String("snapshotter")
|
||||||
if snapshotter == "" {
|
if snapshotter == "" {
|
||||||
snapshotter = defaults.DefaultSnapshotter
|
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)
|
p, err := platforms.Parse(ps)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to parse platform %s: %w", ps, err)
|
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)
|
s := client.SnapshotService(snapshotter)
|
||||||
|
|
||||||
var mounts []mount.Mount
|
var mounts []mount.Mount
|
||||||
if context.Bool("rw") {
|
if cliContext.Bool("rw") {
|
||||||
mounts, err = s.Prepare(ctx, target, chainID)
|
mounts, err = s.Prepare(ctx, target, chainID)
|
||||||
} else {
|
} else {
|
||||||
mounts, err = s.View(ctx, target, chainID)
|
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 := mount.All(mounts, target); err != nil {
|
||||||
if err := s.Remove(ctx, target); err != nil && !errdefs.IsNotFound(err) {
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintln(context.App.Writer, target)
|
fmt.Fprintln(cliContext.App.Writer, target)
|
||||||
return nil
|
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",
|
Usage: "Fetch content from local client rather than using transfer service",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
ref = context.Args().First()
|
ref = cliContext.Args().First()
|
||||||
)
|
)
|
||||||
if ref == "" {
|
if ref == "" {
|
||||||
return errors.New("please provide an image reference to pull")
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
if !context.Bool("local") {
|
if !cliContext.Bool("local") {
|
||||||
unsupportedFlags := []string{"max-concurrent-downloads", "print-chainid",
|
unsupportedFlags := []string{"max-concurrent-downloads", "print-chainid",
|
||||||
"skip-verify", "tlscacert", "tlscert", "tlskey", "http-dump", "http-trace", // RegistryFlags
|
"skip-verify", "tlscacert", "tlscert", "tlskey", "http-dump", "http-trace", // RegistryFlags
|
||||||
}
|
}
|
||||||
for _, s := range unsupportedFlags {
|
for _, s := range unsupportedFlags {
|
||||||
if context.IsSet(s) {
|
if cliContext.IsSet(s) {
|
||||||
return fmt.Errorf("\"--%s\" requires \"--local\" flag", 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var sopts []image.StoreOpt
|
var sopts []image.StoreOpt
|
||||||
p, err := platforms.ParseAll(context.StringSlice("platform"))
|
p, err := platforms.ParseAll(cliContext.StringSlice("platform"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set unpack configuration
|
// Set unpack configuration
|
||||||
for _, platform := range p {
|
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 {
|
if len(p) == 0 {
|
||||||
p = append(p, platforms.DefaultSpec())
|
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..?
|
// TODO: Support unpack for all platforms..?
|
||||||
// Pass in a *?
|
// Pass in a *?
|
||||||
|
|
||||||
if context.Bool("metadata-only") {
|
if cliContext.Bool("metadata-only") {
|
||||||
sopts = append(sopts, image.WithAllMetadata)
|
sopts = append(sopts, image.WithAllMetadata)
|
||||||
// Any with an empty set is None
|
// Any with an empty set is None
|
||||||
// TODO: Specify way to specify not default platform
|
// TODO: Specify way to specify not default platform
|
||||||
// config.PlatformMatcher = platforms.Any()
|
// config.PlatformMatcher = platforms.Any()
|
||||||
} else if !context.Bool("skip-metadata") {
|
} else if !cliContext.Bool("skip-metadata") {
|
||||||
sopts = append(sopts, image.WithAllMetadata)
|
sopts = append(sopts, image.WithAllMetadata)
|
||||||
}
|
}
|
||||||
labels := context.StringSlice("label")
|
labels := cliContext.StringSlice("label")
|
||||||
if len(labels) > 0 {
|
if len(labels) > 0 {
|
||||||
sopts = append(sopts, image.WithImageLabels(commands.LabelArgs(labels)))
|
sopts = append(sopts, image.WithImageLabels(commands.LabelArgs(labels)))
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := []registry.Opt{registry.WithCredentials(ch), registry.WithHostDir(context.String("hosts-dir"))}
|
opts := []registry.Opt{registry.WithCredentials(ch), registry.WithHostDir(cliContext.String("hosts-dir"))}
|
||||||
if context.Bool("plain-http") {
|
if cliContext.Bool("plain-http") {
|
||||||
opts = append(opts, registry.WithDefaultScheme("http"))
|
opts = append(opts, registry.WithDefaultScheme("http"))
|
||||||
}
|
}
|
||||||
reg, err := registry.NewOCIRegistry(ctx, ref, opts...)
|
reg, err := registry.NewOCIRegistry(ctx, ref, opts...)
|
||||||
@ -169,7 +169,7 @@ command. As part of this process, we do the following:
|
|||||||
defer done(ctx)
|
defer done(ctx)
|
||||||
|
|
||||||
// TODO: Handle this locally via transfer config
|
// TODO: Handle this locally via transfer config
|
||||||
config, err := content.NewFetchConfig(ctx, context)
|
config, err := content.NewFetchConfig(ctx, cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -184,13 +184,13 @@ command. As part of this process, we do the following:
|
|||||||
// TODO: Show unpack status
|
// TODO: Show unpack status
|
||||||
|
|
||||||
var p []ocispec.Platform
|
var p []ocispec.Platform
|
||||||
if context.Bool("all-platforms") {
|
if cliContext.Bool("all-platforms") {
|
||||||
p, err = images.Platforms(ctx, client.ContentStore(), img.Target)
|
p, err = images.Platforms(ctx, client.ContentStore(), img.Target)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to resolve image platforms: %w", err)
|
return fmt.Errorf("unable to resolve image platforms: %w", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
p, err = platforms.ParseAll(context.StringSlice("platform"))
|
p, err = platforms.ParseAll(cliContext.StringSlice("platform"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -203,11 +203,11 @@ command. As part of this process, we do the following:
|
|||||||
for _, platform := range p {
|
for _, platform := range p {
|
||||||
fmt.Printf("unpacking %s %s...\n", platforms.Format(platform), img.Target.Digest)
|
fmt.Printf("unpacking %s %s...\n", platforms.Format(platform), img.Target.Digest)
|
||||||
i := containerd.NewImageWithPlatform(client, img, platforms.Only(platform))
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if context.Bool("print-chainid") {
|
if cliContext.Bool("print-chainid") {
|
||||||
diffIDs, err := i.RootFS(ctx)
|
diffIDs, err := i.RootFS(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package images
|
package images
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http/httptrace"
|
"net/http/httptrace"
|
||||||
@ -78,35 +78,35 @@ var pushCommand = &cli.Command{
|
|||||||
Name: "allow-non-distributable-blobs",
|
Name: "allow-non-distributable-blobs",
|
||||||
Usage: "Allow pushing blobs that are marked as non-distributable",
|
Usage: "Allow pushing blobs that are marked as non-distributable",
|
||||||
}),
|
}),
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
ref = context.Args().First()
|
ref = cliContext.Args().First()
|
||||||
local = context.Args().Get(1)
|
local = cliContext.Args().Get(1)
|
||||||
debug = context.Bool("debug")
|
debug = cliContext.Bool("debug")
|
||||||
desc ocispec.Descriptor
|
desc ocispec.Descriptor
|
||||||
)
|
)
|
||||||
if ref == "" {
|
if ref == "" {
|
||||||
return errors.New("please provide a remote image reference to push")
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
if !context.Bool("local") {
|
if !cliContext.Bool("local") {
|
||||||
unsupportedFlags := []string{
|
unsupportedFlags := []string{
|
||||||
"manifest", "manifest-type", "max-concurrent-uploaded-layers", "allow-non-distributable-blobs",
|
"manifest", "manifest-type", "max-concurrent-uploaded-layers", "allow-non-distributable-blobs",
|
||||||
"skip-verify", "tlscacert", "tlscert", "tlskey", "http-dump", "http-trace", // RegistryFlags
|
"skip-verify", "tlscacert", "tlscert", "tlskey", "http-dump", "http-trace", // RegistryFlags
|
||||||
}
|
}
|
||||||
for _, s := range unsupportedFlags {
|
for _, s := range unsupportedFlags {
|
||||||
if context.IsSet(s) {
|
if cliContext.IsSet(s) {
|
||||||
return fmt.Errorf("\"--%s\" requires \"--local\" flag", 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -114,8 +114,8 @@ var pushCommand = &cli.Command{
|
|||||||
if local == "" {
|
if local == "" {
|
||||||
local = ref
|
local = ref
|
||||||
}
|
}
|
||||||
opts := []registry.Opt{registry.WithCredentials(ch), registry.WithHostDir(context.String("hosts-dir"))}
|
opts := []registry.Opt{registry.WithCredentials(ch), registry.WithHostDir(cliContext.String("hosts-dir"))}
|
||||||
if context.Bool("plain-http") {
|
if cliContext.Bool("plain-http") {
|
||||||
opts = append(opts, registry.WithDefaultScheme("http"))
|
opts = append(opts, registry.WithDefaultScheme("http"))
|
||||||
}
|
}
|
||||||
reg, err := registry.NewOCIRegistry(ctx, ref, opts...)
|
reg, err := registry.NewOCIRegistry(ctx, ref, opts...)
|
||||||
@ -123,7 +123,7 @@ var pushCommand = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var p []ocispec.Platform
|
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)
|
p, err = platforms.ParseAll(pss)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid platform %v: %w", pss, err)
|
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))
|
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)
|
desc.Digest, err = digest.Parse(manifest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid manifest digest: %w", err)
|
return fmt.Errorf("invalid manifest digest: %w", err)
|
||||||
}
|
}
|
||||||
desc.MediaType = context.String("manifest-type")
|
desc.MediaType = cliContext.String("manifest-type")
|
||||||
} else {
|
} else {
|
||||||
if local == "" {
|
if local == "" {
|
||||||
local = ref
|
local = ref
|
||||||
@ -153,7 +153,7 @@ var pushCommand = &cli.Command{
|
|||||||
}
|
}
|
||||||
desc = img.Target
|
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])
|
p, err := platforms.Parse(pss[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid platform %q: %w", pss[0], err)
|
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))
|
ctx = httptrace.WithClientTrace(ctx, commands.NewDebugClientTrace(ctx))
|
||||||
}
|
}
|
||||||
resolver, err := commands.GetResolver(ctx, context)
|
resolver, err := commands.GetResolver(ctx, cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -194,8 +194,8 @@ var pushCommand = &cli.Command{
|
|||||||
|
|
||||||
log.G(ctx).WithField("image", ref).WithField("digest", desc.Digest).Debug("pushing")
|
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) {
|
jobHandler := images.HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
|
||||||
if !context.Bool("allow-non-distributable-blobs") && images.IsNonDistributable(desc.MediaType) {
|
if !cliContext.Bool("allow-non-distributable-blobs") && images.IsNonDistributable(desc.MediaType) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
ongoing.add(remotes.MakeRefKey(ctx, desc))
|
ongoing.add(remotes.MakeRefKey(ctx, desc))
|
||||||
@ -203,7 +203,7 @@ var pushCommand = &cli.Command{
|
|||||||
})
|
})
|
||||||
|
|
||||||
handler := jobHandler
|
handler := jobHandler
|
||||||
if !context.Bool("allow-non-distributable-blobs") {
|
if !cliContext.Bool("allow-non-distributable-blobs") {
|
||||||
handler = remotes.SkipNonDistributableBlobs(handler)
|
handler = remotes.SkipNonDistributableBlobs(handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,8 +212,8 @@ var pushCommand = &cli.Command{
|
|||||||
containerd.WithImageHandler(handler),
|
containerd.WithImageHandler(handler),
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.IsSet("max-concurrent-uploaded-layers") {
|
if cliContext.IsSet("max-concurrent-uploaded-layers") {
|
||||||
mcu := context.Int("max-concurrent-uploaded-layers")
|
mcu := cliContext.Int("max-concurrent-uploaded-layers")
|
||||||
ropts = append(ropts, containerd.WithMaxConcurrentUploadedLayers(mcu))
|
ropts = append(ropts, containerd.WithMaxConcurrentUploadedLayers(mcu))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,26 +47,26 @@ var tagCommand = &cli.Command{
|
|||||||
Usage: "Skip the strict check for reference names",
|
Usage: "Skip the strict check for reference names",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
ref = context.Args().First()
|
ref = cliContext.Args().First()
|
||||||
)
|
)
|
||||||
if ref == "" {
|
if ref == "" {
|
||||||
return errors.New("please provide an image reference to tag from")
|
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")
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
if !context.Bool("local") {
|
if !cliContext.Bool("local") {
|
||||||
for _, targetRef := range context.Args().Slice()[1:] {
|
for _, targetRef := range cliContext.Args().Slice()[1:] {
|
||||||
if !context.Bool("skip-reference-check") {
|
if !cliContext.Bool("skip-reference-check") {
|
||||||
if _, err := reference.ParseAnyReference(targetRef); err != nil {
|
if _, err := reference.ParseAnyReference(targetRef); err != nil {
|
||||||
return fmt.Errorf("error parsing reference: %q is not a valid repository/tag %v", targetRef, err)
|
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
|
return err
|
||||||
}
|
}
|
||||||
// Support multiple references for one command run
|
// Support multiple references for one command run
|
||||||
for _, targetRef := range context.Args().Slice()[1:] {
|
for _, targetRef := range cliContext.Args().Slice()[1:] {
|
||||||
if !context.Bool("skip-reference-check") {
|
if !cliContext.Bool("skip-reference-check") {
|
||||||
if _, err := reference.ParseAnyReference(targetRef); err != nil {
|
if _, err := reference.ParseAnyReference(targetRef); err != nil {
|
||||||
return fmt.Errorf("error parsing reference: %q is not a valid repository/tag %v", targetRef, err)
|
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 _, err = imageService.Create(ctx, image); err != nil {
|
||||||
// If user has specified force and the image already exists then
|
// If user has specified force and the image already exists then
|
||||||
// delete the original image and attempt to create the new one
|
// 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 {
|
if err = imageService.Delete(ctx, targetRef); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -38,15 +38,15 @@ var unmountCommand = &cli.Command{
|
|||||||
Usage: "Remove the snapshot after a successful unmount",
|
Usage: "Remove the snapshot after a successful unmount",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
target = context.Args().First()
|
target = cliContext.Args().First()
|
||||||
)
|
)
|
||||||
if target == "" {
|
if target == "" {
|
||||||
return errors.New("please provide a target path to unmount from")
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -56,8 +56,8 @@ var unmountCommand = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.Bool("rm") {
|
if cliContext.Bool("rm") {
|
||||||
snapshotter := context.String("snapshotter")
|
snapshotter := cliContext.String("snapshotter")
|
||||||
s := client.SnapshotService(snapshotter)
|
s := client.SnapshotService(snapshotter)
|
||||||
if err := client.LeasesService().Delete(ctx, leases.Lease{ID: target}); err != nil && !errdefs.IsNotFound(err) {
|
if err := client.LeasesService().Delete(ctx, leases.Lease{ID: target}); err != nil && !errdefs.IsNotFound(err) {
|
||||||
return fmt.Errorf("error deleting lease: %w", 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
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -36,19 +36,19 @@ var usageCommand = &cli.Command{
|
|||||||
Usage: "Display usage of snapshots for a given image ref",
|
Usage: "Display usage of snapshots for a given image ref",
|
||||||
ArgsUsage: "[flags] <ref>",
|
ArgsUsage: "[flags] <ref>",
|
||||||
Flags: commands.SnapshotterFlags,
|
Flags: commands.SnapshotterFlags,
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var ref = context.Args().First()
|
var ref = cliContext.Args().First()
|
||||||
if ref == "" {
|
if ref == "" {
|
||||||
return errors.New("please provide an image reference to mount")
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
snapshotter := context.String("snapshotter")
|
snapshotter := cliContext.String("snapshotter")
|
||||||
if snapshotter == "" {
|
if snapshotter == "" {
|
||||||
snapshotter = defaults.DefaultSnapshotter
|
snapshotter = defaults.DefaultSnapshotter
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,8 @@ type Info struct {
|
|||||||
var Command = &cli.Command{
|
var Command = &cli.Command{
|
||||||
Name: "info",
|
Name: "info",
|
||||||
Usage: "Print the server info",
|
Usage: "Print the server info",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -44,25 +44,25 @@ var Command = &cli.Command{
|
|||||||
Usage: "Set an optional install path other than the managed opt directory",
|
Usage: "Set an optional install path other than the managed opt directory",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
ref := context.Args().First()
|
ref := cliContext.Args().First()
|
||||||
image, err := client.GetImage(ctx, ref)
|
image, err := client.GetImage(ctx, ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var opts []containerd.InstallOpts
|
var opts []containerd.InstallOpts
|
||||||
if context.Bool("libs") {
|
if cliContext.Bool("libs") {
|
||||||
opts = append(opts, containerd.WithInstallLibs)
|
opts = append(opts, containerd.WithInstallLibs)
|
||||||
}
|
}
|
||||||
if context.Bool("replace") {
|
if cliContext.Bool("replace") {
|
||||||
opts = append(opts, containerd.WithInstallReplace)
|
opts = append(opts, containerd.WithInstallReplace)
|
||||||
}
|
}
|
||||||
if path := context.String("path"); path != "" {
|
if path := cliContext.String("path"); path != "" {
|
||||||
opts = append(opts, containerd.WithInstallPath(path))
|
opts = append(opts, containerd.WithInstallPath(path))
|
||||||
}
|
}
|
||||||
return client.Install(ctx, image, opts...)
|
return client.Install(ctx, image, opts...)
|
||||||
|
@ -54,12 +54,12 @@ var listCommand = &cli.Command{
|
|||||||
Usage: "Print only the blob digest",
|
Usage: "Print only the blob digest",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
filters = context.Args().Slice()
|
filters = cliContext.Args().Slice()
|
||||||
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -117,9 +117,9 @@ var createCommand = &cli.Command{
|
|||||||
Value: 24 * time.Hour,
|
Value: 24 * time.Hour,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var labelstr = context.Args().Slice()
|
var labelstr = cliContext.Args().Slice()
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -136,10 +136,10 @@ var createCommand = &cli.Command{
|
|||||||
opts = append(opts, leases.WithLabels(labels))
|
opts = append(opts, leases.WithLabels(labels))
|
||||||
}
|
}
|
||||||
|
|
||||||
if id := context.String("id"); id != "" {
|
if id := cliContext.String("id"); id != "" {
|
||||||
opts = append(opts, leases.WithID(id))
|
opts = append(opts, leases.WithID(id))
|
||||||
}
|
}
|
||||||
if exp := context.Duration("expires"); exp > 0 {
|
if exp := cliContext.Duration("expires"); exp > 0 {
|
||||||
opts = append(opts, leases.WithExpiration(exp))
|
opts = append(opts, leases.WithExpiration(exp))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,19 +166,19 @@ var deleteCommand = &cli.Command{
|
|||||||
Usage: "Synchronously remove leases and all unreferenced resources",
|
Usage: "Synchronously remove leases and all unreferenced resources",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var lids = context.Args().Slice()
|
var lids = cliContext.Args().Slice()
|
||||||
if len(lids) == 0 {
|
if len(lids) == 0 {
|
||||||
return cli.ShowSubcommandHelp(context)
|
return cli.ShowSubcommandHelp(cliContext)
|
||||||
}
|
}
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
ls := client.LeasesService()
|
ls := client.LeasesService()
|
||||||
sync := context.Bool("sync")
|
sync := cliContext.Bool("sync")
|
||||||
for i, lid := range lids {
|
for i, lid := range lids {
|
||||||
var opts []leases.DeleteOpt
|
var opts []leases.DeleteOpt
|
||||||
if sync && i == len(lids)-1 {
|
if sync && i == len(lids)-1 {
|
||||||
|
@ -49,12 +49,12 @@ var createCommand = &cli.Command{
|
|||||||
Usage: "Create a new namespace",
|
Usage: "Create a new namespace",
|
||||||
ArgsUsage: "<name> [<key>=<value>]",
|
ArgsUsage: "<name> [<key>=<value>]",
|
||||||
Description: "create a new namespace. it must be unique",
|
Description: "create a new namespace. it must be unique",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
namespace, labels := commands.ObjectWithLabelArgs(context)
|
namespace, labels := commands.ObjectWithLabelArgs(cliContext)
|
||||||
if namespace == "" {
|
if namespace == "" {
|
||||||
return errors.New("please specify a namespace")
|
return errors.New("please specify a namespace")
|
||||||
}
|
}
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -69,12 +69,12 @@ var setLabelsCommand = &cli.Command{
|
|||||||
Usage: "Set and clear labels for a namespace",
|
Usage: "Set and clear labels for a namespace",
|
||||||
ArgsUsage: "<name> [<key>=<value>, ...]",
|
ArgsUsage: "<name> [<key>=<value>, ...]",
|
||||||
Description: "set and clear labels for a namespace. empty value clears the label",
|
Description: "set and clear labels for a namespace. empty value clears the label",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
namespace, labels := commands.ObjectWithLabelArgs(context)
|
namespace, labels := commands.ObjectWithLabelArgs(cliContext)
|
||||||
if namespace == "" {
|
if namespace == "" {
|
||||||
return errors.New("please specify a namespace")
|
return errors.New("please specify a namespace")
|
||||||
}
|
}
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -102,9 +102,9 @@ var listCommand = &cli.Command{
|
|||||||
Usage: "Print only the namespace name",
|
Usage: "Print only the namespace name",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -155,17 +155,17 @@ var removeCommand = &cli.Command{
|
|||||||
Usage: "Delete the namespace's cgroup",
|
Usage: "Delete the namespace's cgroup",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var exitErr error
|
var exitErr error
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
opts := deleteOpts(context)
|
opts := deleteOpts(cliContext)
|
||||||
namespaces := client.NamespaceService()
|
namespaces := client.NamespaceService()
|
||||||
for _, target := range context.Args().Slice() {
|
for _, target := range cliContext.Args().Slice() {
|
||||||
if err := namespaces.Delete(ctx, target, opts...); err != nil {
|
if err := namespaces.Delete(ctx, target, opts...); err != nil {
|
||||||
if !errdefs.IsNotFound(err) {
|
if !errdefs.IsNotFound(err) {
|
||||||
if exitErr == nil {
|
if exitErr == nil {
|
||||||
|
@ -22,9 +22,9 @@ import (
|
|||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func deleteOpts(context *cli.Context) []namespaces.DeleteOpts {
|
func deleteOpts(cliContext *cli.Context) []namespaces.DeleteOpts {
|
||||||
var delOpts []namespaces.DeleteOpts
|
var delOpts []namespaces.DeleteOpts
|
||||||
if context.Bool("cgroup") {
|
if cliContext.Bool("cgroup") {
|
||||||
delOpts = append(delOpts, opts.WithNamespaceCgroupDeletion)
|
delOpts = append(delOpts, opts.WithNamespaceCgroupDeletion)
|
||||||
}
|
}
|
||||||
return delOpts
|
return delOpts
|
||||||
|
@ -23,6 +23,6 @@ import (
|
|||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func deleteOpts(context *cli.Context) []namespaces.DeleteOpts {
|
func deleteOpts(cliContext *cli.Context) []namespaces.DeleteOpts {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -45,12 +45,12 @@ var defaultSpecCommand = &cli.Command{
|
|||||||
Usage: "Platform of the spec to print (Examples: 'linux/arm64', 'windows/amd64')",
|
Usage: "Platform of the spec to print (Examples: 'linux/arm64', 'windows/amd64')",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
ctx, cancel := commands.AppContext(context)
|
ctx, cancel := commands.AppContext(cliContext)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
platform := platforms.DefaultString()
|
platform := platforms.DefaultString()
|
||||||
if plat := context.String("platform"); plat != "" {
|
if plat := cliContext.String("platform"); plat != "" {
|
||||||
platform = plat
|
platform = plat
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,18 +60,18 @@ var listCommand = &cli.Command{
|
|||||||
Usage: "Print detailed information about each plugin",
|
Usage: "Print detailed information about each plugin",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
quiet = context.Bool("quiet")
|
quiet = cliContext.Bool("quiet")
|
||||||
detailed = context.Bool("detailed")
|
detailed = cliContext.Bool("detailed")
|
||||||
)
|
)
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
ps := client.IntrospectionService()
|
ps := client.IntrospectionService()
|
||||||
response, err := ps.Plugins(ctx, context.Args().Slice()...)
|
response, err := ps.Plugins(ctx, cliContext.Args().Slice()...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -172,13 +172,13 @@ var inspectRuntimeCommand = &cli.Command{
|
|||||||
Usage: "Display runtime info",
|
Usage: "Display runtime info",
|
||||||
ArgsUsage: "[flags]",
|
ArgsUsage: "[flags]",
|
||||||
Flags: commands.RuntimeFlags,
|
Flags: commands.RuntimeFlags,
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
rt := context.String("runtime")
|
rt := cliContext.String("runtime")
|
||||||
rtOptions, err := commands.RuntimeOptions(context)
|
rtOptions, err := commands.RuntimeOptions(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -191,7 +191,7 @@ var inspectRuntimeCommand = &cli.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = fmt.Fprintln(context.App.Writer, string(j))
|
_, err = fmt.Fprintln(cliContext.App.Writer, string(j))
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -64,10 +64,10 @@ var pprofGoroutinesCommand = &cli.Command{
|
|||||||
Value: 2,
|
Value: 2,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client := getPProfClient(context)
|
client := getPProfClient(cliContext)
|
||||||
|
|
||||||
debug := context.Uint("debug")
|
debug := cliContext.Uint("debug")
|
||||||
output, err := httpGetRequest(client, fmt.Sprintf("/debug/pprof/goroutine?debug=%d", debug))
|
output, err := httpGetRequest(client, fmt.Sprintf("/debug/pprof/goroutine?debug=%d", debug))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -88,10 +88,10 @@ var pprofHeapCommand = &cli.Command{
|
|||||||
Value: 0,
|
Value: 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client := getPProfClient(context)
|
client := getPProfClient(cliContext)
|
||||||
|
|
||||||
debug := context.Uint("debug")
|
debug := cliContext.Uint("debug")
|
||||||
output, err := httpGetRequest(client, fmt.Sprintf("/debug/pprof/heap?debug=%d", debug))
|
output, err := httpGetRequest(client, fmt.Sprintf("/debug/pprof/heap?debug=%d", debug))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -118,11 +118,11 @@ var pprofProfileCommand = &cli.Command{
|
|||||||
Value: 0,
|
Value: 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client := getPProfClient(context)
|
client := getPProfClient(cliContext)
|
||||||
|
|
||||||
seconds := context.Duration("seconds").Seconds()
|
seconds := cliContext.Duration("seconds").Seconds()
|
||||||
debug := context.Uint("debug")
|
debug := cliContext.Uint("debug")
|
||||||
output, err := httpGetRequest(client, fmt.Sprintf("/debug/pprof/profile?seconds=%v&debug=%d", seconds, debug))
|
output, err := httpGetRequest(client, fmt.Sprintf("/debug/pprof/profile?seconds=%v&debug=%d", seconds, debug))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -149,11 +149,11 @@ var pprofTraceCommand = &cli.Command{
|
|||||||
Value: 0,
|
Value: 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client := getPProfClient(context)
|
client := getPProfClient(cliContext)
|
||||||
|
|
||||||
seconds := context.Duration("seconds").Seconds()
|
seconds := cliContext.Duration("seconds").Seconds()
|
||||||
debug := context.Uint("debug")
|
debug := cliContext.Uint("debug")
|
||||||
uri := fmt.Sprintf("/debug/pprof/trace?seconds=%v&debug=%d", seconds, debug)
|
uri := fmt.Sprintf("/debug/pprof/trace?seconds=%v&debug=%d", seconds, debug)
|
||||||
output, err := httpGetRequest(client, uri)
|
output, err := httpGetRequest(client, uri)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -175,10 +175,10 @@ var pprofBlockCommand = &cli.Command{
|
|||||||
Value: 0,
|
Value: 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client := getPProfClient(context)
|
client := getPProfClient(cliContext)
|
||||||
|
|
||||||
debug := context.Uint("debug")
|
debug := cliContext.Uint("debug")
|
||||||
output, err := httpGetRequest(client, fmt.Sprintf("/debug/pprof/block?debug=%d", debug))
|
output, err := httpGetRequest(client, fmt.Sprintf("/debug/pprof/block?debug=%d", debug))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -199,10 +199,10 @@ var pprofThreadcreateCommand = &cli.Command{
|
|||||||
Value: 0,
|
Value: 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client := getPProfClient(context)
|
client := getPProfClient(cliContext)
|
||||||
|
|
||||||
debug := context.Uint("debug")
|
debug := cliContext.Uint("debug")
|
||||||
output, err := httpGetRequest(client, fmt.Sprintf("/debug/pprof/threadcreate?debug=%d", debug))
|
output, err := httpGetRequest(client, fmt.Sprintf("/debug/pprof/threadcreate?debug=%d", debug))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -213,8 +213,8 @@ var pprofThreadcreateCommand = &cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPProfClient(context *cli.Context) *http.Client {
|
func getPProfClient(cliContext *cli.Context) *http.Client {
|
||||||
dialer := getPProfDialer(context.String("debug-socket"))
|
dialer := getPProfDialer(cliContext.String("debug-socket"))
|
||||||
|
|
||||||
tr := &http.Transport{
|
tr := &http.Transport{
|
||||||
Dial: dialer.pprofDial,
|
Dial: dialer.pprofDial,
|
||||||
|
@ -18,7 +18,7 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
gocontext "context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"errors"
|
"errors"
|
||||||
@ -58,8 +58,8 @@ func passwordPrompt() (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetResolver prepares the resolver from the environment and options
|
// GetResolver prepares the resolver from the environment and options
|
||||||
func GetResolver(ctx gocontext.Context, clicontext *cli.Context) (remotes.Resolver, error) {
|
func GetResolver(ctx context.Context, cliContext *cli.Context) (remotes.Resolver, error) {
|
||||||
username := clicontext.String("user")
|
username := cliContext.String("user")
|
||||||
var secret string
|
var secret string
|
||||||
if i := strings.IndexByte(username, ':'); i > 0 {
|
if i := strings.IndexByte(username, ':'); i > 0 {
|
||||||
secret = username[i+1:]
|
secret = username[i+1:]
|
||||||
@ -80,7 +80,7 @@ func GetResolver(ctx gocontext.Context, clicontext *cli.Context) (remotes.Resolv
|
|||||||
|
|
||||||
fmt.Print("\n")
|
fmt.Print("\n")
|
||||||
}
|
}
|
||||||
} else if rt := clicontext.String("refresh"); rt != "" {
|
} else if rt := cliContext.String("refresh"); rt != "" {
|
||||||
secret = rt
|
secret = rt
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,19 +90,19 @@ func GetResolver(ctx gocontext.Context, clicontext *cli.Context) (remotes.Resolv
|
|||||||
// Only one host
|
// Only one host
|
||||||
return username, secret, nil
|
return username, secret, nil
|
||||||
}
|
}
|
||||||
if clicontext.Bool("plain-http") {
|
if cliContext.Bool("plain-http") {
|
||||||
hostOptions.DefaultScheme = "http"
|
hostOptions.DefaultScheme = "http"
|
||||||
}
|
}
|
||||||
defaultTLS, err := resolverDefaultTLS(clicontext)
|
defaultTLS, err := resolverDefaultTLS(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
hostOptions.DefaultTLS = defaultTLS
|
hostOptions.DefaultTLS = defaultTLS
|
||||||
if hostDir := clicontext.String("hosts-dir"); hostDir != "" {
|
if hostDir := cliContext.String("hosts-dir"); hostDir != "" {
|
||||||
hostOptions.HostDir = config.HostDirFromRoot(hostDir)
|
hostOptions.HostDir = config.HostDirFromRoot(hostDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
if clicontext.Bool("http-dump") {
|
if cliContext.Bool("http-dump") {
|
||||||
hostOptions.UpdateClient = func(client *http.Client) error {
|
hostOptions.UpdateClient = func(client *http.Client) error {
|
||||||
client.Transport = &DebugTransport{
|
client.Transport = &DebugTransport{
|
||||||
transport: client.Transport,
|
transport: client.Transport,
|
||||||
@ -117,27 +117,27 @@ func GetResolver(ctx gocontext.Context, clicontext *cli.Context) (remotes.Resolv
|
|||||||
return docker.NewResolver(options), nil
|
return docker.NewResolver(options), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolverDefaultTLS(clicontext *cli.Context) (*tls.Config, error) {
|
func resolverDefaultTLS(cliContext *cli.Context) (*tls.Config, error) {
|
||||||
config := &tls.Config{}
|
tlsConfig := &tls.Config{}
|
||||||
|
|
||||||
if clicontext.Bool("skip-verify") {
|
if cliContext.Bool("skip-verify") {
|
||||||
config.InsecureSkipVerify = true
|
tlsConfig.InsecureSkipVerify = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if tlsRootPath := clicontext.String("tlscacert"); tlsRootPath != "" {
|
if tlsRootPath := cliContext.String("tlscacert"); tlsRootPath != "" {
|
||||||
tlsRootData, err := os.ReadFile(tlsRootPath)
|
tlsRootData, err := os.ReadFile(tlsRootPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read %q: %w", tlsRootPath, err)
|
return nil, fmt.Errorf("failed to read %q: %w", tlsRootPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
config.RootCAs = x509.NewCertPool()
|
tlsConfig.RootCAs = x509.NewCertPool()
|
||||||
if !config.RootCAs.AppendCertsFromPEM(tlsRootData) {
|
if !tlsConfig.RootCAs.AppendCertsFromPEM(tlsRootData) {
|
||||||
return nil, fmt.Errorf("failed to load TLS CAs from %q: invalid data", tlsRootPath)
|
return nil, fmt.Errorf("failed to load TLS CAs from %q: invalid data", tlsRootPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tlsCertPath := clicontext.String("tlscert")
|
tlsCertPath := cliContext.String("tlscert")
|
||||||
tlsKeyPath := clicontext.String("tlskey")
|
tlsKeyPath := cliContext.String("tlskey")
|
||||||
if tlsCertPath != "" || tlsKeyPath != "" {
|
if tlsCertPath != "" || tlsKeyPath != "" {
|
||||||
if tlsCertPath == "" || tlsKeyPath == "" {
|
if tlsCertPath == "" || tlsKeyPath == "" {
|
||||||
return nil, errors.New("flags --tlscert and --tlskey must be set together")
|
return nil, errors.New("flags --tlscert and --tlskey must be set together")
|
||||||
@ -146,15 +146,15 @@ func resolverDefaultTLS(clicontext *cli.Context) (*tls.Config, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to load TLS client credentials (cert=%q, key=%q): %w", tlsCertPath, tlsKeyPath, err)
|
return nil, fmt.Errorf("failed to load TLS client credentials (cert=%q, key=%q): %w", tlsCertPath, tlsKeyPath, err)
|
||||||
}
|
}
|
||||||
config.Certificates = []tls.Certificate{keyPair}
|
tlsConfig.Certificates = []tls.Certificate{keyPair}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If nothing was set, return nil rather than empty config
|
// If nothing was set, return nil rather than empty config
|
||||||
if !config.InsecureSkipVerify && config.RootCAs == nil && config.Certificates == nil {
|
if !tlsConfig.InsecureSkipVerify && tlsConfig.RootCAs == nil && tlsConfig.Certificates == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return config, nil
|
return tlsConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DebugTransport wraps the underlying http.RoundTripper interface and dumps all requests/responses to the writer.
|
// DebugTransport wraps the underlying http.RoundTripper interface and dumps all requests/responses to the writer.
|
||||||
@ -193,7 +193,7 @@ func (t DebugTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|||||||
|
|
||||||
// NewDebugClientTrace returns a Go http trace client predefined to write DNS and connection
|
// NewDebugClientTrace returns a Go http trace client predefined to write DNS and connection
|
||||||
// information to the log. This is used via the --http-trace flag on push and pull operations in ctr.
|
// information to the log. This is used via the --http-trace flag on push and pull operations in ctr.
|
||||||
func NewDebugClientTrace(ctx gocontext.Context) *httptrace.ClientTrace {
|
func NewDebugClientTrace(ctx context.Context) *httptrace.ClientTrace {
|
||||||
return &httptrace.ClientTrace{
|
return &httptrace.ClientTrace{
|
||||||
DNSStart: func(dnsInfo httptrace.DNSStartInfo) {
|
DNSStart: func(dnsInfo httptrace.DNSStartInfo) {
|
||||||
log.G(ctx).WithField("host", dnsInfo.Host).Debugf("DNS lookup")
|
log.G(ctx).WithField("host", dnsInfo.Host).Debugf("DNS lookup")
|
||||||
@ -223,8 +223,8 @@ type staticCredentials struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewStaticCredentials gets credentials from passing in cli context
|
// NewStaticCredentials gets credentials from passing in cli context
|
||||||
func NewStaticCredentials(ctx gocontext.Context, clicontext *cli.Context, ref string) (registry.CredentialHelper, error) {
|
func NewStaticCredentials(ctx context.Context, cliContext *cli.Context, ref string) (registry.CredentialHelper, error) {
|
||||||
username := clicontext.String("user")
|
username := cliContext.String("user")
|
||||||
var secret string
|
var secret string
|
||||||
if i := strings.IndexByte(username, ':'); i > 0 {
|
if i := strings.IndexByte(username, ':'); i > 0 {
|
||||||
secret = username[i+1:]
|
secret = username[i+1:]
|
||||||
@ -242,7 +242,7 @@ func NewStaticCredentials(ctx gocontext.Context, clicontext *cli.Context, ref st
|
|||||||
|
|
||||||
fmt.Print("\n")
|
fmt.Print("\n")
|
||||||
}
|
}
|
||||||
} else if rt := clicontext.String("refresh"); rt != "" {
|
} else if rt := cliContext.String("refresh"); rt != "" {
|
||||||
secret = rt
|
secret = rt
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,7 +253,7 @@ func NewStaticCredentials(ctx gocontext.Context, clicontext *cli.Context, ref st
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sc *staticCredentials) GetCredentials(ctx gocontext.Context, ref, host string) (registry.Credentials, error) {
|
func (sc *staticCredentials) GetCredentials(ctx context.Context, ref, host string) (registry.Credentials, error) {
|
||||||
if ref == sc.ref {
|
if ref == sc.ref {
|
||||||
return registry.Credentials{
|
return registry.Credentials{
|
||||||
Username: sc.username,
|
Username: sc.username,
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package run
|
package run
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
"context"
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -39,11 +39,11 @@ import (
|
|||||||
"github.com/containerd/log"
|
"github.com/containerd/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func withMounts(context *cli.Context) oci.SpecOpts {
|
func withMounts(cliContext *cli.Context) oci.SpecOpts {
|
||||||
return func(ctx gocontext.Context, client oci.Client, container *containers.Container, s *specs.Spec) error {
|
return func(ctx context.Context, client oci.Client, container *containers.Container, s *specs.Spec) error {
|
||||||
mounts := make([]specs.Mount, 0)
|
mounts := make([]specs.Mount, 0)
|
||||||
dests := make([]string, 0)
|
dests := make([]string, 0)
|
||||||
for _, mount := range context.StringSlice("mount") {
|
for _, mount := range cliContext.StringSlice("mount") {
|
||||||
m, err := parseMountFlag(mount)
|
m, err := parseMountFlag(mount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -131,27 +131,27 @@ var Command = &cli.Command{
|
|||||||
append(commands.RuntimeFlags,
|
append(commands.RuntimeFlags,
|
||||||
append(append(commands.SnapshotterFlags, []cli.Flag{commands.SnapshotterLabels}...),
|
append(append(commands.SnapshotterFlags, []cli.Flag{commands.SnapshotterLabels}...),
|
||||||
commands.ContainerFlags...)...)...)...),
|
commands.ContainerFlags...)...)...)...),
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
id string
|
id string
|
||||||
ref string
|
ref string
|
||||||
|
|
||||||
rm = context.Bool("rm")
|
rm = cliContext.Bool("rm")
|
||||||
tty = context.Bool("tty")
|
tty = cliContext.Bool("tty")
|
||||||
detach = context.Bool("detach")
|
detach = cliContext.Bool("detach")
|
||||||
config = context.IsSet("config")
|
config = cliContext.IsSet("config")
|
||||||
enableCNI = context.Bool("cni")
|
enableCNI = cliContext.Bool("cni")
|
||||||
)
|
)
|
||||||
|
|
||||||
if config {
|
if config {
|
||||||
id = context.Args().First()
|
id = cliContext.Args().First()
|
||||||
if context.NArg() > 1 {
|
if cliContext.NArg() > 1 {
|
||||||
return errors.New("with spec config file, only container id should be provided")
|
return errors.New("with spec config file, only container id should be provided")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
id = context.Args().Get(1)
|
id = cliContext.Args().Get(1)
|
||||||
ref = context.Args().First()
|
ref = cliContext.Args().First()
|
||||||
|
|
||||||
if ref == "" {
|
if ref == "" {
|
||||||
return errors.New("image ref must be provided")
|
return errors.New("image ref must be provided")
|
||||||
@ -164,13 +164,13 @@ var Command = &cli.Command{
|
|||||||
return errors.New("flags --detach and --rm cannot be specified together")
|
return errors.New("flags --detach and --rm cannot be specified together")
|
||||||
}
|
}
|
||||||
|
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
container, err := NewContainer(ctx, client, context)
|
container, err := NewContainer(ctx, client, cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -196,9 +196,9 @@ var Command = &cli.Command{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := tasks.GetNewTaskOpts(context)
|
opts := tasks.GetNewTaskOpts(cliContext)
|
||||||
ioOpts := []cio.Opt{cio.WithFIFODir(context.String("fifo-dir"))}
|
ioOpts := []cio.Opt{cio.WithFIFODir(cliContext.String("fifo-dir"))}
|
||||||
task, err := tasks.NewTask(ctx, client, container, context.String("checkpoint"), con, context.Bool("null-io"), context.String("log-uri"), ioOpts, opts...)
|
task, err := tasks.NewTask(ctx, client, container, cliContext.String("checkpoint"), con, cliContext.Bool("null-io"), cliContext.String("log-uri"), ioOpts, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -221,8 +221,8 @@ var Command = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if context.IsSet("pid-file") {
|
if cliContext.IsSet("pid-file") {
|
||||||
if err := commands.WritePidFile(context.String("pid-file"), int(task.Pid())); err != nil {
|
if err := commands.WritePidFile(cliContext.String("pid-file"), int(task.Pid())); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
package run
|
package run
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@ -82,15 +82,15 @@ var platformRunFlags = []cli.Flag{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewContainer creates a new container
|
// NewContainer creates a new container
|
||||||
func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli.Context) (containerd.Container, error) {
|
func NewContainer(ctx context.Context, client *containerd.Client, cliContext *cli.Context) (containerd.Container, error) {
|
||||||
var (
|
var (
|
||||||
id string
|
id string
|
||||||
config = context.IsSet("config")
|
config = cliContext.IsSet("config")
|
||||||
)
|
)
|
||||||
if config {
|
if config {
|
||||||
id = context.Args().First()
|
id = cliContext.Args().First()
|
||||||
} else {
|
} else {
|
||||||
id = context.Args().Get(1)
|
id = cliContext.Args().Get(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -99,41 +99,41 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
spec containerd.NewContainerOpts
|
spec containerd.NewContainerOpts
|
||||||
)
|
)
|
||||||
|
|
||||||
if sandbox := context.String("sandbox"); sandbox != "" {
|
if sandbox := cliContext.String("sandbox"); sandbox != "" {
|
||||||
cOpts = append(cOpts, containerd.WithSandbox(sandbox))
|
cOpts = append(cOpts, containerd.WithSandbox(sandbox))
|
||||||
}
|
}
|
||||||
|
|
||||||
if config {
|
if config {
|
||||||
cOpts = append(cOpts, containerd.WithContainerLabels(commands.LabelArgs(context.StringSlice("label"))))
|
cOpts = append(cOpts, containerd.WithContainerLabels(commands.LabelArgs(cliContext.StringSlice("label"))))
|
||||||
opts = append(opts, oci.WithSpecFromFile(context.String("config")))
|
opts = append(opts, oci.WithSpecFromFile(cliContext.String("config")))
|
||||||
} else {
|
} else {
|
||||||
var (
|
var (
|
||||||
ref = context.Args().First()
|
ref = cliContext.Args().First()
|
||||||
// for container's id is Args[1]
|
// for container's id is Args[1]
|
||||||
args = context.Args().Slice()[2:]
|
args = cliContext.Args().Slice()[2:]
|
||||||
)
|
)
|
||||||
opts = append(opts, oci.WithDefaultSpec(), oci.WithDefaultUnixDevices)
|
opts = append(opts, oci.WithDefaultSpec(), oci.WithDefaultUnixDevices)
|
||||||
if ef := context.String("env-file"); ef != "" {
|
if ef := cliContext.String("env-file"); ef != "" {
|
||||||
opts = append(opts, oci.WithEnvFile(ef))
|
opts = append(opts, oci.WithEnvFile(ef))
|
||||||
}
|
}
|
||||||
opts = append(opts, oci.WithEnv(context.StringSlice("env")))
|
opts = append(opts, oci.WithEnv(cliContext.StringSlice("env")))
|
||||||
opts = append(opts, withMounts(context))
|
opts = append(opts, withMounts(cliContext))
|
||||||
|
|
||||||
if context.Bool("rootfs") {
|
if cliContext.Bool("rootfs") {
|
||||||
rootfs, err := filepath.Abs(ref)
|
rootfs, err := filepath.Abs(ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
opts = append(opts, oci.WithRootFSPath(rootfs))
|
opts = append(opts, oci.WithRootFSPath(rootfs))
|
||||||
cOpts = append(cOpts, containerd.WithContainerLabels(commands.LabelArgs(context.StringSlice("label"))))
|
cOpts = append(cOpts, containerd.WithContainerLabels(commands.LabelArgs(cliContext.StringSlice("label"))))
|
||||||
} else {
|
} else {
|
||||||
snapshotter := context.String("snapshotter")
|
snapshotter := cliContext.String("snapshotter")
|
||||||
var image containerd.Image
|
var image containerd.Image
|
||||||
i, err := client.ImageService().Get(ctx, ref)
|
i, err := client.ImageService().Get(ctx, ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if ps := context.String("platform"); ps != "" {
|
if ps := cliContext.String("platform"); ps != "" {
|
||||||
platform, err := platforms.Parse(ps)
|
platform, err := platforms.Parse(ps)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -152,14 +152,14 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
labels := buildLabels(commands.LabelArgs(context.StringSlice("label")), image.Labels())
|
labels := buildLabels(commands.LabelArgs(cliContext.StringSlice("label")), image.Labels())
|
||||||
opts = append(opts, oci.WithImageConfig(image))
|
opts = append(opts, oci.WithImageConfig(image))
|
||||||
cOpts = append(cOpts,
|
cOpts = append(cOpts,
|
||||||
containerd.WithImage(image),
|
containerd.WithImage(image),
|
||||||
containerd.WithImageConfigLabels(image),
|
containerd.WithImageConfigLabels(image),
|
||||||
containerd.WithAdditionalContainerLabels(labels),
|
containerd.WithAdditionalContainerLabels(labels),
|
||||||
containerd.WithSnapshotter(snapshotter))
|
containerd.WithSnapshotter(snapshotter))
|
||||||
if uidmap, gidmap := context.String("uidmap"), context.String("gidmap"); uidmap != "" && gidmap != "" {
|
if uidmap, gidmap := cliContext.String("uidmap"), cliContext.String("gidmap"); uidmap != "" && gidmap != "" {
|
||||||
uidMap, err := parseIDMapping(uidmap)
|
uidMap, err := parseIDMapping(uidmap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -174,7 +174,7 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
// currently the snapshotters known to support the labels are:
|
// currently the snapshotters known to support the labels are:
|
||||||
// fuse-overlayfs - https://github.com/containerd/fuse-overlayfs-snapshotter
|
// fuse-overlayfs - https://github.com/containerd/fuse-overlayfs-snapshotter
|
||||||
// overlay - in case of idmapped mount points are supported by host kernel (Linux kernel 5.19)
|
// overlay - in case of idmapped mount points are supported by host kernel (Linux kernel 5.19)
|
||||||
if context.Bool("remap-labels") {
|
if cliContext.Bool("remap-labels") {
|
||||||
cOpts = append(cOpts, containerd.WithNewSnapshot(id, image,
|
cOpts = append(cOpts, containerd.WithNewSnapshot(id, image,
|
||||||
containerd.WithRemapperLabels(0, uidMap.HostID, 0, gidMap.HostID, uidMap.Size)))
|
containerd.WithRemapperLabels(0, uidMap.HostID, 0, gidMap.HostID, uidMap.Size)))
|
||||||
} else {
|
} else {
|
||||||
@ -187,28 +187,28 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
// For some snapshotter, such as overlaybd, it can provide 2 kind of writable snapshot(overlayfs dir or block-device)
|
// For some snapshotter, such as overlaybd, it can provide 2 kind of writable snapshot(overlayfs dir or block-device)
|
||||||
// by command label values.
|
// by command label values.
|
||||||
cOpts = append(cOpts, containerd.WithNewSnapshot(id, image,
|
cOpts = append(cOpts, containerd.WithNewSnapshot(id, image,
|
||||||
snapshots.WithLabels(commands.LabelArgs(context.StringSlice("snapshotter-label")))))
|
snapshots.WithLabels(commands.LabelArgs(cliContext.StringSlice("snapshotter-label")))))
|
||||||
}
|
}
|
||||||
cOpts = append(cOpts, containerd.WithImageStopSignal(image, "SIGTERM"))
|
cOpts = append(cOpts, containerd.WithImageStopSignal(image, "SIGTERM"))
|
||||||
}
|
}
|
||||||
if context.Bool("read-only") {
|
if cliContext.Bool("read-only") {
|
||||||
opts = append(opts, oci.WithRootFSReadonly())
|
opts = append(opts, oci.WithRootFSReadonly())
|
||||||
}
|
}
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
opts = append(opts, oci.WithProcessArgs(args...))
|
opts = append(opts, oci.WithProcessArgs(args...))
|
||||||
}
|
}
|
||||||
if cwd := context.String("cwd"); cwd != "" {
|
if cwd := cliContext.String("cwd"); cwd != "" {
|
||||||
opts = append(opts, oci.WithProcessCwd(cwd))
|
opts = append(opts, oci.WithProcessCwd(cwd))
|
||||||
}
|
}
|
||||||
if user := context.String("user"); user != "" {
|
if user := cliContext.String("user"); user != "" {
|
||||||
opts = append(opts, oci.WithUser(user), oci.WithAdditionalGIDs(user))
|
opts = append(opts, oci.WithUser(user), oci.WithAdditionalGIDs(user))
|
||||||
}
|
}
|
||||||
if context.Bool("tty") {
|
if cliContext.Bool("tty") {
|
||||||
opts = append(opts, oci.WithTTY)
|
opts = append(opts, oci.WithTTY)
|
||||||
}
|
}
|
||||||
|
|
||||||
privileged := context.Bool("privileged")
|
privileged := cliContext.Bool("privileged")
|
||||||
privilegedWithoutHostDevices := context.Bool("privileged-without-host-devices")
|
privilegedWithoutHostDevices := cliContext.Bool("privileged-without-host-devices")
|
||||||
if privilegedWithoutHostDevices && !privileged {
|
if privilegedWithoutHostDevices && !privileged {
|
||||||
return nil, errors.New("can't use 'privileged-without-host-devices' without 'privileged' specified")
|
return nil, errors.New("can't use 'privileged-without-host-devices' without 'privileged' specified")
|
||||||
}
|
}
|
||||||
@ -220,7 +220,7 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.Bool("net-host") {
|
if cliContext.Bool("net-host") {
|
||||||
hostname, err := os.Hostname()
|
hostname, err := os.Hostname()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("get hostname: %w", err)
|
return nil, fmt.Errorf("get hostname: %w", err)
|
||||||
@ -232,7 +232,7 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
oci.WithEnv([]string{fmt.Sprintf("HOSTNAME=%s", hostname)}),
|
oci.WithEnv([]string{fmt.Sprintf("HOSTNAME=%s", hostname)}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if annoStrings := context.StringSlice("annotation"); len(annoStrings) > 0 {
|
if annoStrings := cliContext.StringSlice("annotation"); len(annoStrings) > 0 {
|
||||||
annos, err := commands.AnnotationArgs(annoStrings)
|
annos, err := commands.AnnotationArgs(annoStrings)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -240,7 +240,7 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
opts = append(opts, oci.WithAnnotations(annos))
|
opts = append(opts, oci.WithAnnotations(annos))
|
||||||
}
|
}
|
||||||
|
|
||||||
if caps := context.StringSlice("cap-add"); len(caps) > 0 {
|
if caps := cliContext.StringSlice("cap-add"); len(caps) > 0 {
|
||||||
for _, cap := range caps {
|
for _, cap := range caps {
|
||||||
if !strings.HasPrefix(cap, "CAP_") {
|
if !strings.HasPrefix(cap, "CAP_") {
|
||||||
return nil, errors.New("capabilities must be specified with 'CAP_' prefix")
|
return nil, errors.New("capabilities must be specified with 'CAP_' prefix")
|
||||||
@ -249,7 +249,7 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
opts = append(opts, oci.WithAddedCapabilities(caps))
|
opts = append(opts, oci.WithAddedCapabilities(caps))
|
||||||
}
|
}
|
||||||
|
|
||||||
if caps := context.StringSlice("cap-drop"); len(caps) > 0 {
|
if caps := cliContext.StringSlice("cap-drop"); len(caps) > 0 {
|
||||||
for _, cap := range caps {
|
for _, cap := range caps {
|
||||||
if !strings.HasPrefix(cap, "CAP_") {
|
if !strings.HasPrefix(cap, "CAP_") {
|
||||||
return nil, errors.New("capabilities must be specified with 'CAP_' prefix")
|
return nil, errors.New("capabilities must be specified with 'CAP_' prefix")
|
||||||
@ -258,13 +258,13 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
opts = append(opts, oci.WithDroppedCapabilities(caps))
|
opts = append(opts, oci.WithDroppedCapabilities(caps))
|
||||||
}
|
}
|
||||||
|
|
||||||
seccompProfile := context.String("seccomp-profile")
|
seccompProfile := cliContext.String("seccomp-profile")
|
||||||
|
|
||||||
if !context.Bool("seccomp") && seccompProfile != "" {
|
if !cliContext.Bool("seccomp") && seccompProfile != "" {
|
||||||
return nil, errors.New("seccomp must be set to true, if using a custom seccomp-profile")
|
return nil, errors.New("seccomp must be set to true, if using a custom seccomp-profile")
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.Bool("seccomp") {
|
if cliContext.Bool("seccomp") {
|
||||||
if seccompProfile != "" {
|
if seccompProfile != "" {
|
||||||
opts = append(opts, seccomp.WithProfile(seccompProfile))
|
opts = append(opts, seccomp.WithProfile(seccompProfile))
|
||||||
} else {
|
} else {
|
||||||
@ -272,18 +272,18 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if s := context.String("apparmor-default-profile"); len(s) > 0 {
|
if s := cliContext.String("apparmor-default-profile"); len(s) > 0 {
|
||||||
opts = append(opts, apparmor.WithDefaultProfile(s))
|
opts = append(opts, apparmor.WithDefaultProfile(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
if s := context.String("apparmor-profile"); len(s) > 0 {
|
if s := cliContext.String("apparmor-profile"); len(s) > 0 {
|
||||||
if len(context.String("apparmor-default-profile")) > 0 {
|
if len(cliContext.String("apparmor-default-profile")) > 0 {
|
||||||
return nil, errors.New("apparmor-profile conflicts with apparmor-default-profile")
|
return nil, errors.New("apparmor-profile conflicts with apparmor-default-profile")
|
||||||
}
|
}
|
||||||
opts = append(opts, apparmor.WithProfile(s))
|
opts = append(opts, apparmor.WithProfile(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
if cpus := context.Float64("cpus"); cpus > 0.0 {
|
if cpus := cliContext.Float64("cpus"); cpus > 0.0 {
|
||||||
var (
|
var (
|
||||||
period = uint64(100000)
|
period = uint64(100000)
|
||||||
quota = int64(cpus * 100000.0)
|
quota = int64(cpus * 100000.0)
|
||||||
@ -291,32 +291,32 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
opts = append(opts, oci.WithCPUCFS(quota, period))
|
opts = append(opts, oci.WithCPUCFS(quota, period))
|
||||||
}
|
}
|
||||||
|
|
||||||
if cpusetCpus := context.String("cpuset-cpus"); len(cpusetCpus) > 0 {
|
if cpusetCpus := cliContext.String("cpuset-cpus"); len(cpusetCpus) > 0 {
|
||||||
opts = append(opts, oci.WithCPUs(cpusetCpus))
|
opts = append(opts, oci.WithCPUs(cpusetCpus))
|
||||||
}
|
}
|
||||||
|
|
||||||
if cpusetMems := context.String("cpuset-mems"); len(cpusetMems) > 0 {
|
if cpusetMems := cliContext.String("cpuset-mems"); len(cpusetMems) > 0 {
|
||||||
opts = append(opts, oci.WithCPUsMems(cpusetMems))
|
opts = append(opts, oci.WithCPUsMems(cpusetMems))
|
||||||
}
|
}
|
||||||
|
|
||||||
if shares := context.Int("cpu-shares"); shares > 0 {
|
if shares := cliContext.Int("cpu-shares"); shares > 0 {
|
||||||
opts = append(opts, oci.WithCPUShares(uint64(shares)))
|
opts = append(opts, oci.WithCPUShares(uint64(shares)))
|
||||||
}
|
}
|
||||||
|
|
||||||
quota := context.Int64("cpu-quota")
|
quota := cliContext.Int64("cpu-quota")
|
||||||
period := context.Uint64("cpu-period")
|
period := cliContext.Uint64("cpu-period")
|
||||||
if quota != -1 || period != 0 {
|
if quota != -1 || period != 0 {
|
||||||
if cpus := context.Float64("cpus"); cpus > 0.0 {
|
if cpus := cliContext.Float64("cpus"); cpus > 0.0 {
|
||||||
return nil, errors.New("cpus and quota/period should be used separately")
|
return nil, errors.New("cpus and quota/period should be used separately")
|
||||||
}
|
}
|
||||||
opts = append(opts, oci.WithCPUCFS(quota, period))
|
opts = append(opts, oci.WithCPUCFS(quota, period))
|
||||||
}
|
}
|
||||||
|
|
||||||
if burst := context.Uint64("cpu-burst"); burst != 0 {
|
if burst := cliContext.Uint64("cpu-burst"); burst != 0 {
|
||||||
opts = append(opts, oci.WithCPUBurst(burst))
|
opts = append(opts, oci.WithCPUBurst(burst))
|
||||||
}
|
}
|
||||||
|
|
||||||
joinNs := context.StringSlice("with-ns")
|
joinNs := cliContext.StringSlice("with-ns")
|
||||||
for _, ns := range joinNs {
|
for _, ns := range joinNs {
|
||||||
nsType, nsPath, ok := strings.Cut(ns, ":")
|
nsType, nsPath, ok := strings.Cut(ns, ":")
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -330,22 +330,22 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
Path: nsPath,
|
Path: nsPath,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
if context.IsSet("gpus") {
|
if cliContext.IsSet("gpus") {
|
||||||
opts = append(opts, nvidia.WithGPUs(nvidia.WithDevices(context.IntSlice("gpus")...), nvidia.WithAllCapabilities))
|
opts = append(opts, nvidia.WithGPUs(nvidia.WithDevices(cliContext.IntSlice("gpus")...), nvidia.WithAllCapabilities))
|
||||||
}
|
}
|
||||||
if context.IsSet("allow-new-privs") {
|
if cliContext.IsSet("allow-new-privs") {
|
||||||
opts = append(opts, oci.WithNewPrivileges)
|
opts = append(opts, oci.WithNewPrivileges)
|
||||||
}
|
}
|
||||||
if context.IsSet("cgroup") {
|
if cliContext.IsSet("cgroup") {
|
||||||
// NOTE: can be set to "" explicitly for disabling cgroup.
|
// NOTE: can be set to "" explicitly for disabling cgroup.
|
||||||
opts = append(opts, oci.WithCgroup(context.String("cgroup")))
|
opts = append(opts, oci.WithCgroup(cliContext.String("cgroup")))
|
||||||
}
|
}
|
||||||
limit := context.Uint64("memory-limit")
|
limit := cliContext.Uint64("memory-limit")
|
||||||
if limit != 0 {
|
if limit != 0 {
|
||||||
opts = append(opts, oci.WithMemoryLimit(limit))
|
opts = append(opts, oci.WithMemoryLimit(limit))
|
||||||
}
|
}
|
||||||
var cdiDeviceIDs []string
|
var cdiDeviceIDs []string
|
||||||
for _, dev := range context.StringSlice("device") {
|
for _, dev := range cliContext.StringSlice("device") {
|
||||||
if parser.IsQualifiedName(dev) {
|
if parser.IsQualifiedName(dev) {
|
||||||
cdiDeviceIDs = append(cdiDeviceIDs, dev)
|
cdiDeviceIDs = append(cdiDeviceIDs, dev)
|
||||||
continue
|
continue
|
||||||
@ -357,9 +357,9 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
}
|
}
|
||||||
opts = append(opts, oci.WithCDIDevices(cdiDeviceIDs...))
|
opts = append(opts, oci.WithCDIDevices(cdiDeviceIDs...))
|
||||||
|
|
||||||
rootfsPropagation := context.String("rootfs-propagation")
|
rootfsPropagation := cliContext.String("rootfs-propagation")
|
||||||
if rootfsPropagation != "" {
|
if rootfsPropagation != "" {
|
||||||
opts = append(opts, func(_ gocontext.Context, _ oci.Client, _ *containers.Container, s *oci.Spec) error {
|
opts = append(opts, func(_ context.Context, _ oci.Client, _ *containers.Container, s *oci.Spec) error {
|
||||||
if s.Linux != nil {
|
if s.Linux != nil {
|
||||||
s.Linux.RootfsPropagation = rootfsPropagation
|
s.Linux.RootfsPropagation = rootfsPropagation
|
||||||
} else {
|
} else {
|
||||||
@ -372,39 +372,39 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if c := context.String("blockio-config-file"); c != "" {
|
if c := cliContext.String("blockio-config-file"); c != "" {
|
||||||
if err := blockio.SetConfigFromFile(c, false); err != nil {
|
if err := blockio.SetConfigFromFile(c, false); err != nil {
|
||||||
return nil, fmt.Errorf("blockio-config-file error: %w", err)
|
return nil, fmt.Errorf("blockio-config-file error: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if c := context.String("blockio-class"); c != "" {
|
if c := cliContext.String("blockio-class"); c != "" {
|
||||||
if linuxBlockIO, err := blockio.OciLinuxBlockIO(c); err == nil {
|
if linuxBlockIO, err := blockio.OciLinuxBlockIO(c); err == nil {
|
||||||
opts = append(opts, oci.WithBlockIO(linuxBlockIO))
|
opts = append(opts, oci.WithBlockIO(linuxBlockIO))
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("blockio-class error: %w", err)
|
return nil, fmt.Errorf("blockio-class error: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if c := context.String("rdt-class"); c != "" {
|
if c := cliContext.String("rdt-class"); c != "" {
|
||||||
opts = append(opts, oci.WithRdt(c, "", ""))
|
opts = append(opts, oci.WithRdt(c, "", ""))
|
||||||
}
|
}
|
||||||
if hostname := context.String("hostname"); hostname != "" {
|
if hostname := cliContext.String("hostname"); hostname != "" {
|
||||||
opts = append(opts, oci.WithHostname(hostname))
|
opts = append(opts, oci.WithHostname(hostname))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.Bool("cni") {
|
if cliContext.Bool("cni") {
|
||||||
cniMeta := &commands.NetworkMetaData{EnableCni: true}
|
cniMeta := &commands.NetworkMetaData{EnableCni: true}
|
||||||
cOpts = append(cOpts, containerd.WithContainerExtension(commands.CtrCniMetadataExtension, cniMeta))
|
cOpts = append(cOpts, containerd.WithContainerExtension(commands.CtrCniMetadataExtension, cniMeta))
|
||||||
}
|
}
|
||||||
|
|
||||||
runtimeOpts, err := commands.RuntimeOptions(context)
|
runtimeOpts, err := commands.RuntimeOptions(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
cOpts = append(cOpts, containerd.WithRuntime(context.String("runtime"), runtimeOpts))
|
cOpts = append(cOpts, containerd.WithRuntime(cliContext.String("runtime"), runtimeOpts))
|
||||||
|
|
||||||
opts = append(opts, oci.WithAnnotations(commands.LabelArgs(context.StringSlice("label"))))
|
opts = append(opts, oci.WithAnnotations(commands.LabelArgs(cliContext.StringSlice("label"))))
|
||||||
var s specs.Spec
|
var s specs.Spec
|
||||||
spec = containerd.WithSpec(&s, opts...)
|
spec = containerd.WithSpec(&s, opts...)
|
||||||
|
|
||||||
@ -456,7 +456,7 @@ func validNamespace(ns string) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getNetNSPath(_ gocontext.Context, task containerd.Task) (string, error) {
|
func getNetNSPath(_ context.Context, task containerd.Task) (string, error) {
|
||||||
return fmt.Sprintf("/proc/%d/ns/net", task.Pid()), nil
|
return fmt.Sprintf("/proc/%d/ns/net", task.Pid()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -464,7 +464,7 @@ func getNetNSPath(_ gocontext.Context, task containerd.Task) (string, error) {
|
|||||||
// This is used from the `run` command to avoid creating a registry with auto-refresh enabled.
|
// This is used from the `run` command to avoid creating a registry with auto-refresh enabled.
|
||||||
// It also provides a way to override the CDI spec file paths if required.
|
// It also provides a way to override the CDI spec file paths if required.
|
||||||
func withStaticCDIRegistry() oci.SpecOpts {
|
func withStaticCDIRegistry() oci.SpecOpts {
|
||||||
return func(ctx gocontext.Context, _ oci.Client, _ *containers.Container, s *oci.Spec) error {
|
return func(ctx context.Context, _ oci.Client, _ *containers.Container, s *oci.Spec) error {
|
||||||
_ = cdi.Configure(cdi.WithAutoRefresh(false))
|
_ = cdi.Configure(cdi.WithAutoRefresh(false))
|
||||||
if err := cdi.Refresh(); err != nil {
|
if err := cdi.Refresh(); err != nil {
|
||||||
// We don't consider registry refresh failure a fatal error.
|
// We don't consider registry refresh failure a fatal error.
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package run
|
package run
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -41,32 +41,32 @@ var platformRunFlags = []cli.Flag{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewContainer creates a new container
|
// NewContainer creates a new container
|
||||||
func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli.Context) (containerd.Container, error) {
|
func NewContainer(ctx context.Context, client *containerd.Client, cliContext *cli.Context) (containerd.Container, error) {
|
||||||
var (
|
var (
|
||||||
id string
|
id string
|
||||||
opts []oci.SpecOpts
|
opts []oci.SpecOpts
|
||||||
cOpts []containerd.NewContainerOpts
|
cOpts []containerd.NewContainerOpts
|
||||||
spec containerd.NewContainerOpts
|
spec containerd.NewContainerOpts
|
||||||
|
|
||||||
config = context.IsSet("config")
|
config = cliContext.IsSet("config")
|
||||||
)
|
)
|
||||||
|
|
||||||
if sandbox := context.String("sandbox"); sandbox != "" {
|
if sandbox := cliContext.String("sandbox"); sandbox != "" {
|
||||||
cOpts = append(cOpts, containerd.WithSandbox(sandbox))
|
cOpts = append(cOpts, containerd.WithSandbox(sandbox))
|
||||||
}
|
}
|
||||||
|
|
||||||
if config {
|
if config {
|
||||||
id = context.Args().First()
|
id = cliContext.Args().First()
|
||||||
opts = append(opts, oci.WithSpecFromFile(context.String("config")))
|
opts = append(opts, oci.WithSpecFromFile(cliContext.String("config")))
|
||||||
cOpts = append(cOpts, containerd.WithContainerLabels(commands.LabelArgs(context.StringSlice("label"))))
|
cOpts = append(cOpts, containerd.WithContainerLabels(commands.LabelArgs(cliContext.StringSlice("label"))))
|
||||||
} else {
|
} else {
|
||||||
var (
|
var (
|
||||||
ref = context.Args().First()
|
ref = cliContext.Args().First()
|
||||||
args = context.Args().Slice()[2:]
|
args = cliContext.Args().Slice()[2:]
|
||||||
)
|
)
|
||||||
|
|
||||||
id = context.Args().Get(1)
|
id = cliContext.Args().Get(1)
|
||||||
snapshotter := context.String("snapshotter")
|
snapshotter := cliContext.String("snapshotter")
|
||||||
if snapshotter == "windows-lcow" {
|
if snapshotter == "windows-lcow" {
|
||||||
opts = append(opts, oci.WithDefaultSpecForPlatform("linux/amd64"))
|
opts = append(opts, oci.WithDefaultSpecForPlatform("linux/amd64"))
|
||||||
// Clear the rootfs section.
|
// Clear the rootfs section.
|
||||||
@ -76,11 +76,11 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
opts = append(opts, oci.WithWindowNetworksAllowUnqualifiedDNSQuery())
|
opts = append(opts, oci.WithWindowNetworksAllowUnqualifiedDNSQuery())
|
||||||
opts = append(opts, oci.WithWindowsIgnoreFlushesDuringBoot())
|
opts = append(opts, oci.WithWindowsIgnoreFlushesDuringBoot())
|
||||||
}
|
}
|
||||||
if ef := context.String("env-file"); ef != "" {
|
if ef := cliContext.String("env-file"); ef != "" {
|
||||||
opts = append(opts, oci.WithEnvFile(ef))
|
opts = append(opts, oci.WithEnvFile(ef))
|
||||||
}
|
}
|
||||||
opts = append(opts, oci.WithEnv(context.StringSlice("env")))
|
opts = append(opts, oci.WithEnv(cliContext.StringSlice("env")))
|
||||||
opts = append(opts, withMounts(context))
|
opts = append(opts, withMounts(cliContext))
|
||||||
|
|
||||||
image, err := client.GetImage(ctx, ref)
|
image, err := client.GetImage(ctx, ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -96,7 +96,7 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
opts = append(opts, oci.WithImageConfig(image))
|
opts = append(opts, oci.WithImageConfig(image))
|
||||||
labels := buildLabels(commands.LabelArgs(context.StringSlice("label")), image.Labels())
|
labels := buildLabels(commands.LabelArgs(cliContext.StringSlice("label")), image.Labels())
|
||||||
cOpts = append(cOpts,
|
cOpts = append(cOpts,
|
||||||
containerd.WithImage(image),
|
containerd.WithImage(image),
|
||||||
containerd.WithImageConfigLabels(image),
|
containerd.WithImageConfigLabels(image),
|
||||||
@ -104,19 +104,19 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
containerd.WithNewSnapshot(
|
containerd.WithNewSnapshot(
|
||||||
id,
|
id,
|
||||||
image,
|
image,
|
||||||
snapshots.WithLabels(commands.LabelArgs(context.StringSlice("snapshotter-label")))),
|
snapshots.WithLabels(commands.LabelArgs(cliContext.StringSlice("snapshotter-label")))),
|
||||||
containerd.WithAdditionalContainerLabels(labels))
|
containerd.WithAdditionalContainerLabels(labels))
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
opts = append(opts, oci.WithProcessArgs(args...))
|
opts = append(opts, oci.WithProcessArgs(args...))
|
||||||
}
|
}
|
||||||
if cwd := context.String("cwd"); cwd != "" {
|
if cwd := cliContext.String("cwd"); cwd != "" {
|
||||||
opts = append(opts, oci.WithProcessCwd(cwd))
|
opts = append(opts, oci.WithProcessCwd(cwd))
|
||||||
}
|
}
|
||||||
if user := context.String("user"); user != "" {
|
if user := cliContext.String("user"); user != "" {
|
||||||
opts = append(opts, oci.WithUser(user))
|
opts = append(opts, oci.WithUser(user))
|
||||||
}
|
}
|
||||||
if context.Bool("tty") {
|
if cliContext.Bool("tty") {
|
||||||
opts = append(opts, oci.WithTTY)
|
opts = append(opts, oci.WithTTY)
|
||||||
|
|
||||||
con := console.Current()
|
con := console.Current()
|
||||||
@ -126,36 +126,36 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
}
|
}
|
||||||
opts = append(opts, oci.WithTTYSize(int(size.Width), int(size.Height)))
|
opts = append(opts, oci.WithTTYSize(int(size.Width), int(size.Height)))
|
||||||
}
|
}
|
||||||
if context.Bool("net-host") {
|
if cliContext.Bool("net-host") {
|
||||||
return nil, errors.New("Cannot use host mode networking with Windows containers")
|
return nil, errors.New("Cannot use host mode networking with Windows containers")
|
||||||
}
|
}
|
||||||
if context.Bool("cni") {
|
if cliContext.Bool("cni") {
|
||||||
ns, err := netns.NewNetNS("")
|
ns, err := netns.NewNetNS("")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
opts = append(opts, oci.WithWindowsNetworkNamespace(ns.GetPath()))
|
opts = append(opts, oci.WithWindowsNetworkNamespace(ns.GetPath()))
|
||||||
}
|
}
|
||||||
if context.Bool("isolated") {
|
if cliContext.Bool("isolated") {
|
||||||
opts = append(opts, oci.WithWindowsHyperV)
|
opts = append(opts, oci.WithWindowsHyperV)
|
||||||
}
|
}
|
||||||
limit := context.Uint64("memory-limit")
|
limit := cliContext.Uint64("memory-limit")
|
||||||
if limit != 0 {
|
if limit != 0 {
|
||||||
opts = append(opts, oci.WithMemoryLimit(limit))
|
opts = append(opts, oci.WithMemoryLimit(limit))
|
||||||
}
|
}
|
||||||
ccount := context.Uint64("cpu-count")
|
ccount := cliContext.Uint64("cpu-count")
|
||||||
if ccount != 0 {
|
if ccount != 0 {
|
||||||
opts = append(opts, oci.WithWindowsCPUCount(ccount))
|
opts = append(opts, oci.WithWindowsCPUCount(ccount))
|
||||||
}
|
}
|
||||||
cshares := context.Uint64("cpu-shares")
|
cshares := cliContext.Uint64("cpu-shares")
|
||||||
if cshares != 0 {
|
if cshares != 0 {
|
||||||
opts = append(opts, oci.WithWindowsCPUShares(uint16(cshares)))
|
opts = append(opts, oci.WithWindowsCPUShares(uint16(cshares)))
|
||||||
}
|
}
|
||||||
cmax := context.Uint64("cpu-max")
|
cmax := cliContext.Uint64("cpu-max")
|
||||||
if cmax != 0 {
|
if cmax != 0 {
|
||||||
opts = append(opts, oci.WithWindowsCPUMaximum(uint16(cmax)))
|
opts = append(opts, oci.WithWindowsCPUMaximum(uint16(cmax)))
|
||||||
}
|
}
|
||||||
for _, dev := range context.StringSlice("device") {
|
for _, dev := range cliContext.StringSlice("device") {
|
||||||
idType, devID, ok := strings.Cut(dev, "://")
|
idType, devID, ok := strings.Cut(dev, "://")
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("devices must be in the format IDType://ID")
|
return nil, errors.New("devices must be in the format IDType://ID")
|
||||||
@ -167,16 +167,16 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.Bool("cni") {
|
if cliContext.Bool("cni") {
|
||||||
cniMeta := &commands.NetworkMetaData{EnableCni: true}
|
cniMeta := &commands.NetworkMetaData{EnableCni: true}
|
||||||
cOpts = append(cOpts, containerd.WithContainerExtension(commands.CtrCniMetadataExtension, cniMeta))
|
cOpts = append(cOpts, containerd.WithContainerExtension(commands.CtrCniMetadataExtension, cniMeta))
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime := context.String("runtime")
|
runtime := cliContext.String("runtime")
|
||||||
var runtimeOpts interface{}
|
var runtimeOpts interface{}
|
||||||
if runtime == "io.containerd.runhcs.v1" {
|
if runtime == "io.containerd.runhcs.v1" {
|
||||||
runtimeOpts = &options.Options{
|
runtimeOpts = &options.Options{
|
||||||
Debug: context.Bool("debug"),
|
Debug: cliContext.Bool("debug"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cOpts = append(cOpts, containerd.WithRuntime(runtime, runtimeOpts))
|
cOpts = append(cOpts, containerd.WithRuntime(runtime, runtimeOpts))
|
||||||
@ -189,7 +189,7 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
return client.NewContainer(ctx, id, cOpts...)
|
return client.NewContainer(ctx, id, cOpts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getNetNSPath(ctx gocontext.Context, t containerd.Task) (string, error) {
|
func getNetNSPath(ctx context.Context, t containerd.Task) (string, error) {
|
||||||
s, err := t.Spec(ctx)
|
s, err := t.Spec(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -54,16 +54,16 @@ var runCommand = &cli.Command{
|
|||||||
Value: defaults.DefaultRuntime,
|
Value: defaults.DefaultRuntime,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
if context.NArg() != 2 {
|
if cliContext.NArg() != 2 {
|
||||||
return cli.ShowSubcommandHelp(context)
|
return cli.ShowSubcommandHelp(cliContext)
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
id = context.Args().Get(1)
|
id = cliContext.Args().Get(1)
|
||||||
runtime = context.String("runtime")
|
runtime = cliContext.String("runtime")
|
||||||
)
|
)
|
||||||
|
|
||||||
spec, err := os.ReadFile(context.Args().First())
|
spec, err := os.ReadFile(cliContext.Args().First())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to read sandbox config: %w", err)
|
return fmt.Errorf("failed to read sandbox config: %w", err)
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ var runCommand = &cli.Command{
|
|||||||
return fmt.Errorf("failed to parse sandbox config: %w", err)
|
return fmt.Errorf("failed to parse sandbox config: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -107,8 +107,8 @@ var listCommand = &cli.Command{
|
|||||||
Usage: "The list of filters to apply when querying sandboxes from the store",
|
Usage: "The list of filters to apply when querying sandboxes from the store",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ var listCommand = &cli.Command{
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
writer = tabwriter.NewWriter(os.Stdout, 1, 8, 1, ' ', 0)
|
writer = tabwriter.NewWriter(os.Stdout, 1, 8, 1, ' ', 0)
|
||||||
filters = context.StringSlice("filters")
|
filters = cliContext.StringSlice("filters")
|
||||||
)
|
)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -155,16 +155,16 @@ var removeCommand = &cli.Command{
|
|||||||
Usage: "Ignore shutdown errors when removing sandbox",
|
Usage: "Ignore shutdown errors when removing sandbox",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
force := context.Bool("force")
|
force := cliContext.Bool("force")
|
||||||
|
|
||||||
for _, id := range context.Args().Slice() {
|
for _, id := range cliContext.Args().Slice() {
|
||||||
sandbox, err := client.LoadSandbox(ctx, id)
|
sandbox, err := client.LoadSandbox(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.G(ctx).WithError(err).Errorf("failed to load sandbox %s", id)
|
log.G(ctx).WithError(err).Errorf("failed to load sandbox %s", id)
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
package shim
|
package shim
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
@ -37,7 +37,7 @@ var bufPool = sync.Pool{
|
|||||||
|
|
||||||
func prepareStdio(stdin, stdout, stderr string, console bool) (wg *sync.WaitGroup, err error) {
|
func prepareStdio(stdin, stdout, stderr string, console bool) (wg *sync.WaitGroup, err error) {
|
||||||
wg = &sync.WaitGroup{}
|
wg = &sync.WaitGroup{}
|
||||||
ctx := gocontext.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
f, err := fifo.OpenFifo(ctx, stdin, unix.O_WRONLY|unix.O_CREAT|unix.O_NONBLOCK, 0700)
|
f, err := fifo.OpenFifo(ctx, stdin, unix.O_WRONLY|unix.O_CREAT|unix.O_NONBLOCK, 0700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
package shim
|
package shim
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
@ -81,13 +81,13 @@ var Command = &cli.Command{
|
|||||||
var startCommand = &cli.Command{
|
var startCommand = &cli.Command{
|
||||||
Name: "start",
|
Name: "start",
|
||||||
Usage: "Start a container with a task",
|
Usage: "Start a container with a task",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
service, err := getTaskService(context)
|
service, err := getTaskService(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = service.Start(gocontext.Background(), &task.StartRequest{
|
_, err = service.Start(context.Background(), &task.StartRequest{
|
||||||
ID: context.Args().First(),
|
ID: cliContext.Args().First(),
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
@ -96,13 +96,13 @@ var startCommand = &cli.Command{
|
|||||||
var deleteCommand = &cli.Command{
|
var deleteCommand = &cli.Command{
|
||||||
Name: "delete",
|
Name: "delete",
|
||||||
Usage: "Delete a container with a task",
|
Usage: "Delete a container with a task",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
service, err := getTaskService(context)
|
service, err := getTaskService(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
r, err := service.Delete(gocontext.Background(), &task.DeleteRequest{
|
r, err := service.Delete(context.Background(), &task.DeleteRequest{
|
||||||
ID: context.Args().First(),
|
ID: cliContext.Args().First(),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -115,13 +115,13 @@ var deleteCommand = &cli.Command{
|
|||||||
var stateCommand = &cli.Command{
|
var stateCommand = &cli.Command{
|
||||||
Name: "state",
|
Name: "state",
|
||||||
Usage: "Get the state of all the processes of the task",
|
Usage: "Get the state of all the processes of the task",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
service, err := getTaskService(context)
|
service, err := getTaskService(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
r, err := service.State(gocontext.Background(), &task.StateRequest{
|
r, err := service.State(context.Background(), &task.StateRequest{
|
||||||
ID: context.String("id"),
|
ID: cliContext.String("id"),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -155,28 +155,28 @@ var execCommand = &cli.Command{
|
|||||||
Usage: "Runtime spec",
|
Usage: "Runtime spec",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
service, err := getTaskService(context)
|
service, err := getTaskService(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
id = context.Args().First()
|
id = cliContext.Args().First()
|
||||||
ctx = gocontext.Background()
|
ctx = context.Background()
|
||||||
)
|
)
|
||||||
|
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return errors.New("exec id must be provided")
|
return errors.New("exec id must be provided")
|
||||||
}
|
}
|
||||||
|
|
||||||
tty := context.Bool("tty")
|
tty := cliContext.Bool("tty")
|
||||||
wg, err := prepareStdio(context.String("stdin"), context.String("stdout"), context.String("stderr"), tty)
|
wg, err := prepareStdio(cliContext.String("stdin"), cliContext.String("stdout"), cliContext.String("stderr"), tty)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// read spec file and extract Any object
|
// read spec file and extract Any object
|
||||||
spec, err := os.ReadFile(context.String("spec"))
|
spec, err := os.ReadFile(cliContext.String("spec"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -191,9 +191,9 @@ var execCommand = &cli.Command{
|
|||||||
TypeUrl: url,
|
TypeUrl: url,
|
||||||
Value: spec,
|
Value: spec,
|
||||||
},
|
},
|
||||||
Stdin: context.String("stdin"),
|
Stdin: cliContext.String("stdin"),
|
||||||
Stdout: context.String("stdout"),
|
Stdout: cliContext.String("stdout"),
|
||||||
Stderr: context.String("stderr"),
|
Stderr: cliContext.String("stderr"),
|
||||||
Terminal: tty,
|
Terminal: tty,
|
||||||
}
|
}
|
||||||
if _, err := service.Exec(ctx, rq); err != nil {
|
if _, err := service.Exec(ctx, rq); err != nil {
|
||||||
@ -206,7 +206,7 @@ var execCommand = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Printf("exec running with pid %d\n", r.Pid)
|
fmt.Printf("exec running with pid %d\n", r.Pid)
|
||||||
if context.Bool("attach") {
|
if cliContext.Bool("attach") {
|
||||||
log.L.Info("attaching")
|
log.L.Info("attaching")
|
||||||
if tty {
|
if tty {
|
||||||
current := console.Current()
|
current := console.Current()
|
||||||
@ -232,19 +232,19 @@ var execCommand = &cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTaskService(context *cli.Context) (task.TTRPCTaskService, error) {
|
func getTaskService(cliContext *cli.Context) (task.TTRPCTaskService, error) {
|
||||||
id := context.String("id")
|
id := cliContext.String("id")
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return nil, fmt.Errorf("container id must be specified")
|
return nil, fmt.Errorf("container id must be specified")
|
||||||
}
|
}
|
||||||
ns := context.String("namespace")
|
ns := cliContext.String("namespace")
|
||||||
|
|
||||||
// /containerd-shim/ns/id/shim.sock is the old way to generate shim socket,
|
// /containerd-shim/ns/id/shim.sock is the old way to generate shim socket,
|
||||||
// compatible it
|
// compatible it
|
||||||
s1 := filepath.Join(string(filepath.Separator), "containerd-shim", ns, id, "shim.sock")
|
s1 := filepath.Join(string(filepath.Separator), "containerd-shim", ns, id, "shim.sock")
|
||||||
// this should not error, ctr always get a default ns
|
// this should not error, ctr always get a default ns
|
||||||
ctx := namespaces.WithNamespace(gocontext.Background(), ns)
|
ctx := namespaces.WithNamespace(context.Background(), ns)
|
||||||
s2, _ := shim.SocketAddress(ctx, context.String("address"), id)
|
s2, _ := shim.SocketAddress(ctx, cliContext.String("address"), id)
|
||||||
s2 = strings.TrimPrefix(s2, "unix://")
|
s2 = strings.TrimPrefix(s2, "unix://")
|
||||||
|
|
||||||
for _, socket := range []string{s2, "\x00" + s1} {
|
for _, socket := range []string{s2, "\x00" + s1} {
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -28,11 +28,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type killer interface {
|
type killer interface {
|
||||||
Kill(gocontext.Context, syscall.Signal, ...containerd.KillOpts) error
|
Kill(context.Context, syscall.Signal, ...containerd.KillOpts) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// ForwardAllSignals forwards signals
|
// ForwardAllSignals forwards signals
|
||||||
func ForwardAllSignals(ctx gocontext.Context, task killer) chan os.Signal {
|
func ForwardAllSignals(ctx context.Context, task killer) chan os.Signal {
|
||||||
sigc := make(chan os.Signal, 128)
|
sigc := make(chan os.Signal, 128)
|
||||||
signal.Notify(sigc)
|
signal.Notify(sigc)
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package snapshots
|
package snapshots
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -67,18 +67,18 @@ var listCommand = &cli.Command{
|
|||||||
Name: "list",
|
Name: "list",
|
||||||
Aliases: []string{"ls"},
|
Aliases: []string{"ls"},
|
||||||
Usage: "List snapshots",
|
Usage: "List snapshots",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
var (
|
var (
|
||||||
snapshotter = client.SnapshotService(context.String("snapshotter"))
|
snapshotter = client.SnapshotService(cliContext.String("snapshotter"))
|
||||||
tw = tabwriter.NewWriter(os.Stdout, 1, 8, 1, ' ', 0)
|
tw = tabwriter.NewWriter(os.Stdout, 1, 8, 1, ' ', 0)
|
||||||
)
|
)
|
||||||
fmt.Fprintln(tw, "KEY\tPARENT\tKIND\t")
|
fmt.Fprintln(tw, "KEY\tPARENT\tKIND\t")
|
||||||
if err := snapshotter.Walk(ctx, func(ctx gocontext.Context, info snapshots.Info) error {
|
if err := snapshotter.Walk(ctx, func(ctx context.Context, info snapshots.Info) error {
|
||||||
fmt.Fprintf(tw, "%v\t%v\t%v\t\n",
|
fmt.Fprintf(tw, "%v\t%v\t%v\t\n",
|
||||||
info.Name,
|
info.Name,
|
||||||
info.Parent,
|
info.Parent,
|
||||||
@ -111,15 +111,15 @@ var diffCommand = &cli.Command{
|
|||||||
Usage: "Keep diff content. up to creator to delete it.",
|
Usage: "Keep diff content. up to creator to delete it.",
|
||||||
},
|
},
|
||||||
}, commands.LabelFlag),
|
}, commands.LabelFlag),
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
idA = context.Args().First()
|
idA = cliContext.Args().First()
|
||||||
idB = context.Args().Get(1)
|
idB = cliContext.Args().Get(1)
|
||||||
)
|
)
|
||||||
if idA == "" {
|
if idA == "" {
|
||||||
return errors.New("snapshot id must be provided")
|
return errors.New("snapshot id must be provided")
|
||||||
}
|
}
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -132,15 +132,15 @@ var diffCommand = &cli.Command{
|
|||||||
defer done(ctx)
|
defer done(ctx)
|
||||||
|
|
||||||
var desc ocispec.Descriptor
|
var desc ocispec.Descriptor
|
||||||
labels := commands.LabelArgs(context.StringSlice("label"))
|
labels := commands.LabelArgs(cliContext.StringSlice("label"))
|
||||||
snapshotter := client.SnapshotService(context.String("snapshotter"))
|
snapshotter := client.SnapshotService(cliContext.String("snapshotter"))
|
||||||
|
|
||||||
if context.Bool("keep") {
|
if cliContext.Bool("keep") {
|
||||||
labels["containerd.io/gc.root"] = time.Now().UTC().Format(time.RFC3339)
|
labels["containerd.io/gc.root"] = time.Now().UTC().Format(time.RFC3339)
|
||||||
}
|
}
|
||||||
opts := []diff.Opt{
|
opts := []diff.Opt{
|
||||||
diff.WithMediaType(context.String("media-type")),
|
diff.WithMediaType(cliContext.String("media-type")),
|
||||||
diff.WithReference(context.String("ref")),
|
diff.WithReference(cliContext.String("ref")),
|
||||||
diff.WithLabels(labels),
|
diff.WithLabels(labels),
|
||||||
}
|
}
|
||||||
// SOURCE_DATE_EPOCH is propagated via the ctx, so no need to specify diff.WithSourceDateEpoch here
|
// SOURCE_DATE_EPOCH is propagated via the ctx, so no need to specify diff.WithSourceDateEpoch here
|
||||||
@ -172,7 +172,7 @@ var diffCommand = &cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func withMounts(ctx gocontext.Context, id string, sn snapshots.Snapshotter, f func(mounts []mount.Mount) (ocispec.Descriptor, error)) (ocispec.Descriptor, error) {
|
func withMounts(ctx context.Context, id string, sn snapshots.Snapshotter, f func(mounts []mount.Mount) (ocispec.Descriptor, error)) (ocispec.Descriptor, error) {
|
||||||
var mounts []mount.Mount
|
var mounts []mount.Mount
|
||||||
info, err := sn.Stat(ctx, id)
|
info, err := sn.Stat(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -204,9 +204,9 @@ var usageCommand = &cli.Command{
|
|||||||
Usage: "Display size in bytes",
|
Usage: "Display size in bytes",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var displaySize func(int64) string
|
var displaySize func(int64) string
|
||||||
if context.Bool("b") {
|
if cliContext.Bool("b") {
|
||||||
displaySize = func(s int64) string {
|
displaySize = func(s int64) string {
|
||||||
return strconv.FormatInt(s, 10)
|
return strconv.FormatInt(s, 10)
|
||||||
}
|
}
|
||||||
@ -215,18 +215,18 @@ var usageCommand = &cli.Command{
|
|||||||
return progress.Bytes(s).String()
|
return progress.Bytes(s).String()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
var (
|
var (
|
||||||
snapshotter = client.SnapshotService(context.String("snapshotter"))
|
snapshotter = client.SnapshotService(cliContext.String("snapshotter"))
|
||||||
tw = tabwriter.NewWriter(os.Stdout, 1, 8, 1, ' ', 0)
|
tw = tabwriter.NewWriter(os.Stdout, 1, 8, 1, ' ', 0)
|
||||||
)
|
)
|
||||||
fmt.Fprintln(tw, "KEY\tSIZE\tINODES\t")
|
fmt.Fprintln(tw, "KEY\tSIZE\tINODES\t")
|
||||||
if context.NArg() == 0 {
|
if cliContext.NArg() == 0 {
|
||||||
if err := snapshotter.Walk(ctx, func(ctx gocontext.Context, info snapshots.Info) error {
|
if err := snapshotter.Walk(ctx, func(ctx context.Context, info snapshots.Info) error {
|
||||||
usage, err := snapshotter.Usage(ctx, info.Name)
|
usage, err := snapshotter.Usage(ctx, info.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -237,7 +237,7 @@ var usageCommand = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, id := range context.Args().Slice() {
|
for _, id := range cliContext.Args().Slice() {
|
||||||
usage, err := snapshotter.Usage(ctx, id)
|
usage, err := snapshotter.Usage(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -255,14 +255,14 @@ var removeCommand = &cli.Command{
|
|||||||
Aliases: []string{"del", "remove", "rm"},
|
Aliases: []string{"del", "remove", "rm"},
|
||||||
ArgsUsage: "<key> [<key>, ...]",
|
ArgsUsage: "<key> [<key>, ...]",
|
||||||
Usage: "Remove snapshots",
|
Usage: "Remove snapshots",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
snapshotter := client.SnapshotService(context.String("snapshotter"))
|
snapshotter := client.SnapshotService(cliContext.String("snapshotter"))
|
||||||
for _, key := range context.Args().Slice() {
|
for _, key := range cliContext.Args().Slice() {
|
||||||
err = snapshotter.Remove(ctx, key)
|
err = snapshotter.Remove(ctx, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to remove %q: %w", key, err)
|
return fmt.Errorf("failed to remove %q: %w", key, err)
|
||||||
@ -288,22 +288,22 @@ var prepareCommand = &cli.Command{
|
|||||||
Usage: "Print out snapshot mounts as JSON",
|
Usage: "Print out snapshot mounts as JSON",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
if narg := context.NArg(); narg < 1 || narg > 2 {
|
if narg := cliContext.NArg(); narg < 1 || narg > 2 {
|
||||||
return cli.ShowSubcommandHelp(context)
|
return cli.ShowSubcommandHelp(cliContext)
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
target = context.String("target")
|
target = cliContext.String("target")
|
||||||
key = context.Args().Get(0)
|
key = cliContext.Args().Get(0)
|
||||||
parent = context.Args().Get(1)
|
parent = cliContext.Args().Get(1)
|
||||||
)
|
)
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
snapshotter := client.SnapshotService(context.String("snapshotter"))
|
snapshotter := client.SnapshotService(cliContext.String("snapshotter"))
|
||||||
labels := map[string]string{
|
labels := map[string]string{
|
||||||
"containerd.io/gc.root": time.Now().UTC().Format(time.RFC3339),
|
"containerd.io/gc.root": time.Now().UTC().Format(time.RFC3339),
|
||||||
}
|
}
|
||||||
@ -317,7 +317,7 @@ var prepareCommand = &cli.Command{
|
|||||||
printMounts(target, mounts)
|
printMounts(target, mounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.Bool("mounts") {
|
if cliContext.Bool("mounts") {
|
||||||
commands.PrintAsJSON(mounts)
|
commands.PrintAsJSON(mounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,22 +340,22 @@ var viewCommand = &cli.Command{
|
|||||||
Usage: "Print out snapshot mounts as JSON",
|
Usage: "Print out snapshot mounts as JSON",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
if narg := context.NArg(); narg < 1 || narg > 2 {
|
if narg := cliContext.NArg(); narg < 1 || narg > 2 {
|
||||||
return cli.ShowSubcommandHelp(context)
|
return cli.ShowSubcommandHelp(cliContext)
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
target = context.String("target")
|
target = cliContext.String("target")
|
||||||
key = context.Args().Get(0)
|
key = cliContext.Args().Get(0)
|
||||||
parent = context.Args().Get(1)
|
parent = cliContext.Args().Get(1)
|
||||||
)
|
)
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
snapshotter := client.SnapshotService(context.String("snapshotter"))
|
snapshotter := client.SnapshotService(cliContext.String("snapshotter"))
|
||||||
mounts, err := snapshotter.View(ctx, key, parent)
|
mounts, err := snapshotter.View(ctx, key, parent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -365,7 +365,7 @@ var viewCommand = &cli.Command{
|
|||||||
printMounts(target, mounts)
|
printMounts(target, mounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.Bool("mounts") {
|
if cliContext.Bool("mounts") {
|
||||||
commands.PrintAsJSON(mounts)
|
commands.PrintAsJSON(mounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,20 +378,20 @@ var mountCommand = &cli.Command{
|
|||||||
Aliases: []string{"m", "mount"},
|
Aliases: []string{"m", "mount"},
|
||||||
Usage: "Mount gets mount commands for the snapshots",
|
Usage: "Mount gets mount commands for the snapshots",
|
||||||
ArgsUsage: "<target> <key>",
|
ArgsUsage: "<target> <key>",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
if context.NArg() != 2 {
|
if cliContext.NArg() != 2 {
|
||||||
return cli.ShowSubcommandHelp(context)
|
return cli.ShowSubcommandHelp(cliContext)
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
target = context.Args().Get(0)
|
target = cliContext.Args().Get(0)
|
||||||
key = context.Args().Get(1)
|
key = cliContext.Args().Get(1)
|
||||||
)
|
)
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
snapshotter := client.SnapshotService(context.String("snapshotter"))
|
snapshotter := client.SnapshotService(cliContext.String("snapshotter"))
|
||||||
mounts, err := snapshotter.Mounts(ctx, key)
|
mounts, err := snapshotter.Mounts(ctx, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -407,20 +407,20 @@ var commitCommand = &cli.Command{
|
|||||||
Name: "commit",
|
Name: "commit",
|
||||||
Usage: "Commit an active snapshot into the provided name",
|
Usage: "Commit an active snapshot into the provided name",
|
||||||
ArgsUsage: "<key> <active>",
|
ArgsUsage: "<key> <active>",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
if context.NArg() != 2 {
|
if cliContext.NArg() != 2 {
|
||||||
return cli.ShowSubcommandHelp(context)
|
return cli.ShowSubcommandHelp(cliContext)
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
key = context.Args().Get(0)
|
key = cliContext.Args().Get(0)
|
||||||
active = context.Args().Get(1)
|
active = cliContext.Args().Get(1)
|
||||||
)
|
)
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
snapshotter := client.SnapshotService(context.String("snapshotter"))
|
snapshotter := client.SnapshotService(cliContext.String("snapshotter"))
|
||||||
labels := map[string]string{
|
labels := map[string]string{
|
||||||
"containerd.io/gc.root": time.Now().UTC().Format(time.RFC3339),
|
"containerd.io/gc.root": time.Now().UTC().Format(time.RFC3339),
|
||||||
}
|
}
|
||||||
@ -431,18 +431,18 @@ var commitCommand = &cli.Command{
|
|||||||
var treeCommand = &cli.Command{
|
var treeCommand = &cli.Command{
|
||||||
Name: "tree",
|
Name: "tree",
|
||||||
Usage: "Display tree view of snapshot branches",
|
Usage: "Display tree view of snapshot branches",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
var (
|
var (
|
||||||
snapshotter = client.SnapshotService(context.String("snapshotter"))
|
snapshotter = client.SnapshotService(cliContext.String("snapshotter"))
|
||||||
tree = newSnapshotTree()
|
tree = newSnapshotTree()
|
||||||
)
|
)
|
||||||
|
|
||||||
if err := snapshotter.Walk(ctx, func(ctx gocontext.Context, info snapshots.Info) error {
|
if err := snapshotter.Walk(ctx, func(ctx context.Context, info snapshots.Info) error {
|
||||||
// Get or create node and add node details
|
// Get or create node and add node details
|
||||||
tree.add(info)
|
tree.add(info)
|
||||||
return nil
|
return nil
|
||||||
@ -460,18 +460,18 @@ var infoCommand = &cli.Command{
|
|||||||
Name: "info",
|
Name: "info",
|
||||||
Usage: "Get info about a snapshot",
|
Usage: "Get info about a snapshot",
|
||||||
ArgsUsage: "<key>",
|
ArgsUsage: "<key>",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
if context.NArg() != 1 {
|
if cliContext.NArg() != 1 {
|
||||||
return cli.ShowSubcommandHelp(context)
|
return cli.ShowSubcommandHelp(cliContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
key := context.Args().Get(0)
|
key := cliContext.Args().Get(0)
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
snapshotter := client.SnapshotService(context.String("snapshotter"))
|
snapshotter := client.SnapshotService(cliContext.String("snapshotter"))
|
||||||
info, err := snapshotter.Stat(ctx, key)
|
info, err := snapshotter.Stat(ctx, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -488,15 +488,15 @@ var setLabelCommand = &cli.Command{
|
|||||||
Usage: "Add labels to content",
|
Usage: "Add labels to content",
|
||||||
ArgsUsage: "<name> [<label>=<value> ...]",
|
ArgsUsage: "<name> [<label>=<value> ...]",
|
||||||
Description: "labels snapshots in the snapshotter",
|
Description: "labels snapshots in the snapshotter",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
key, labels := commands.ObjectWithLabelArgs(context)
|
key, labels := commands.ObjectWithLabelArgs(cliContext)
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
snapshotter := client.SnapshotService(context.String("snapshotter"))
|
snapshotter := client.SnapshotService(cliContext.String("snapshotter"))
|
||||||
|
|
||||||
info := snapshots.Info{
|
info := snapshots.Info{
|
||||||
Name: key,
|
Name: key,
|
||||||
@ -537,12 +537,12 @@ var unpackCommand = &cli.Command{
|
|||||||
Usage: "Unpack applies layers from a manifest to a snapshot",
|
Usage: "Unpack applies layers from a manifest to a snapshot",
|
||||||
ArgsUsage: "[flags] <digest>",
|
ArgsUsage: "[flags] <digest>",
|
||||||
Flags: commands.SnapshotterFlags,
|
Flags: commands.SnapshotterFlags,
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
dgst, err := digest.Parse(context.Args().First())
|
dgst, err := digest.Parse(cliContext.Args().First())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -557,7 +557,7 @@ var unpackCommand = &cli.Command{
|
|||||||
for _, image := range images {
|
for _, image := range images {
|
||||||
if image.Target().Digest == dgst {
|
if image.Target().Digest == dgst {
|
||||||
fmt.Printf("unpacking %s (%s)...", dgst, image.Target().MediaType)
|
fmt.Printf("unpacking %s (%s)...", dgst, image.Target().MediaType)
|
||||||
if err := image.Unpack(ctx, context.String("snapshotter")); err != nil {
|
if err := image.Unpack(ctx, cliContext.String("snapshotter")); err != nil {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -570,7 +570,7 @@ var unpackCommand = &cli.Command{
|
|||||||
return errors.New("manifest not found")
|
return errors.New("manifest not found")
|
||||||
}
|
}
|
||||||
// TODO: Get rootfs from Image
|
// TODO: Get rootfs from Image
|
||||||
//log.G(ctx).Infof("chain ID: %s", chainID.String())
|
// log.G(ctx).Infof("chain ID: %s", chainID.String())
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -28,13 +28,13 @@ var attachCommand = &cli.Command{
|
|||||||
Name: "attach",
|
Name: "attach",
|
||||||
Usage: "Attach to the IO of a running container",
|
Usage: "Attach to the IO of a running container",
|
||||||
ArgsUsage: "CONTAINER",
|
ArgsUsage: "CONTAINER",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
container, err := client.LoadContainer(ctx, context.Args().First())
|
container, err := client.LoadContainer(ctx, cliContext.Args().First())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -44,12 +44,12 @@ var checkpointCommand = &cli.Command{
|
|||||||
Usage: "Path to criu work files and logs",
|
Usage: "Path to criu work files and logs",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
id := context.Args().First()
|
id := cliContext.Args().First()
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return errors.New("container id must be provided")
|
return errors.New("container id must be provided")
|
||||||
}
|
}
|
||||||
client, ctx, cancel, err := commands.NewClient(context, containerd.WithDefaultRuntime(context.String("runtime")))
|
client, ctx, cancel, err := commands.NewClient(cliContext, containerd.WithDefaultRuntime(cliContext.String("runtime")))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -66,12 +66,12 @@ var checkpointCommand = &cli.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
opts := []containerd.CheckpointTaskOpts{withCheckpointOpts(info.Runtime.Name, context)}
|
opts := []containerd.CheckpointTaskOpts{withCheckpointOpts(info.Runtime.Name, cliContext)}
|
||||||
checkpoint, err := task.Checkpoint(ctx, opts...)
|
checkpoint, err := task.Checkpoint(ctx, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if context.String("image-path") == "" {
|
if cliContext.String("image-path") == "" {
|
||||||
fmt.Println(checkpoint.Name())
|
fmt.Println(checkpoint.Name())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -79,17 +79,17 @@ var checkpointCommand = &cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// withCheckpointOpts only suitable for runc runtime now
|
// withCheckpointOpts only suitable for runc runtime now
|
||||||
func withCheckpointOpts(rt string, context *cli.Context) containerd.CheckpointTaskOpts {
|
func withCheckpointOpts(rt string, cliContext *cli.Context) containerd.CheckpointTaskOpts {
|
||||||
return func(r *containerd.CheckpointTaskInfo) error {
|
return func(r *containerd.CheckpointTaskInfo) error {
|
||||||
imagePath := context.String("image-path")
|
imagePath := cliContext.String("image-path")
|
||||||
workPath := context.String("work-path")
|
workPath := cliContext.String("work-path")
|
||||||
|
|
||||||
if r.Options == nil {
|
if r.Options == nil {
|
||||||
r.Options = &options.CheckpointOptions{}
|
r.Options = &options.CheckpointOptions{}
|
||||||
}
|
}
|
||||||
opts, _ := r.Options.(*options.CheckpointOptions)
|
opts, _ := r.Options.(*options.CheckpointOptions)
|
||||||
|
|
||||||
if context.Bool("exit") {
|
if cliContext.Bool("exit") {
|
||||||
opts.Exit = true
|
opts.Exit = true
|
||||||
}
|
}
|
||||||
if imagePath != "" {
|
if imagePath != "" {
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package tasks
|
package tasks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
"context"
|
||||||
|
|
||||||
containerd "github.com/containerd/containerd/v2/client"
|
containerd "github.com/containerd/containerd/v2/client"
|
||||||
"github.com/containerd/containerd/v2/cmd/ctr/commands"
|
"github.com/containerd/containerd/v2/cmd/ctr/commands"
|
||||||
@ -42,12 +42,12 @@ var deleteCommand = &cli.Command{
|
|||||||
Usage: "Process ID to kill",
|
Usage: "Process ID to kill",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
execID = context.String("exec-id")
|
execID = cliContext.String("exec-id")
|
||||||
force = context.Bool("force")
|
force = cliContext.Bool("force")
|
||||||
)
|
)
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ var deleteCommand = &cli.Command{
|
|||||||
}
|
}
|
||||||
var exitErr error
|
var exitErr error
|
||||||
if execID != "" {
|
if execID != "" {
|
||||||
task, err := loadTask(ctx, client, context.Args().First())
|
task, err := loadTask(ctx, client, cliContext.Args().First())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ var deleteCommand = &cli.Command{
|
|||||||
return cli.Exit("", int(ec))
|
return cli.Exit("", int(ec))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, target := range context.Args().Slice() {
|
for _, target := range cliContext.Args().Slice() {
|
||||||
task, err := loadTask(ctx, client, target)
|
task, err := loadTask(ctx, client, target)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if exitErr == nil {
|
if exitErr == nil {
|
||||||
@ -100,7 +100,7 @@ var deleteCommand = &cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadTask(ctx gocontext.Context, client *containerd.Client, containerID string) (containerd.Task, error) {
|
func loadTask(ctx context.Context, client *containerd.Client, containerID string) (containerd.Task, error) {
|
||||||
container, err := client.LoadContainer(ctx, containerID)
|
container, err := client.LoadContainer(ctx, containerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -68,17 +68,17 @@ var execCommand = &cli.Command{
|
|||||||
Usage: "User id or name",
|
Usage: "User id or name",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
id = context.Args().First()
|
id = cliContext.Args().First()
|
||||||
args = context.Args().Tail()
|
args = cliContext.Args().Tail()
|
||||||
tty = context.Bool("tty")
|
tty = cliContext.Bool("tty")
|
||||||
detach = context.Bool("detach")
|
detach = cliContext.Bool("detach")
|
||||||
)
|
)
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return errors.New("container id must be provided")
|
return errors.New("container id must be provided")
|
||||||
}
|
}
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ var execCommand = &cli.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if user := context.String("user"); user != "" {
|
if user := cliContext.String("user"); user != "" {
|
||||||
c, err := container.Info(ctx)
|
c, err := container.Info(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -105,7 +105,7 @@ var execCommand = &cli.Command{
|
|||||||
pspec.Terminal = tty
|
pspec.Terminal = tty
|
||||||
pspec.Args = args
|
pspec.Args = args
|
||||||
|
|
||||||
if cwd := context.String("cwd"); cwd != "" {
|
if cwd := cliContext.String("cwd"); cwd != "" {
|
||||||
pspec.Cwd = cwd
|
pspec.Cwd = cwd
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,8 +122,8 @@ var execCommand = &cli.Command{
|
|||||||
con console.Console
|
con console.Console
|
||||||
)
|
)
|
||||||
|
|
||||||
fifoDir := context.String("fifo-dir")
|
fifoDir := cliContext.String("fifo-dir")
|
||||||
logURI := context.String("log-uri")
|
logURI := cliContext.String("log-uri")
|
||||||
ioOpts := []cio.Opt{cio.WithFIFODir(fifoDir)}
|
ioOpts := []cio.Opt{cio.WithFIFODir(fifoDir)}
|
||||||
switch {
|
switch {
|
||||||
case tty && logURI != "":
|
case tty && logURI != "":
|
||||||
@ -150,7 +150,7 @@ var execCommand = &cli.Command{
|
|||||||
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(stdinC, os.Stdout, os.Stderr)}, ioOpts...)...)
|
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(stdinC, os.Stdout, os.Stderr)}, ioOpts...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
process, err := task.Exec(ctx, context.String("exec-id"), pspec, ioCreator)
|
process, err := task.Exec(ctx, cliContext.String("exec-id"), pspec, ioCreator)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -82,8 +82,8 @@ var killCommand = &cli.Command{
|
|||||||
Usage: "Send signal to all processes inside the container",
|
Usage: "Send signal to all processes inside the container",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
id := context.Args().First()
|
id := cliContext.Args().First()
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return errors.New("container id must be provided")
|
return errors.New("container id must be provided")
|
||||||
}
|
}
|
||||||
@ -92,14 +92,14 @@ var killCommand = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
all = context.Bool("all")
|
all = cliContext.Bool("all")
|
||||||
execID = context.String("exec-id")
|
execID = cliContext.String("exec-id")
|
||||||
opts []containerd.KillOpts
|
opts []containerd.KillOpts
|
||||||
)
|
)
|
||||||
if all && execID != "" {
|
if all && execID != "" {
|
||||||
return errors.New("specify an exec-id or all; not both")
|
return errors.New("specify an exec-id or all; not both")
|
||||||
}
|
}
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -114,8 +114,8 @@ var killCommand = &cli.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if context.String("signal") != "" {
|
if cliContext.String("signal") != "" {
|
||||||
sig, err = signal.ParseSignal(context.String("signal"))
|
sig, err = signal.ParseSignal(cliContext.String("signal"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,9 @@ var listCommand = &cli.Command{
|
|||||||
Usage: "Print only the task id",
|
Usage: "Print only the task id",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -49,13 +49,13 @@ var metricsCommand = &cli.Command{
|
|||||||
Value: formatTable,
|
Value: formatTable,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
container, err := client.LoadContainer(ctx, context.Args().First())
|
container, err := client.LoadContainer(ctx, cliContext.Args().First())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -83,7 +83,7 @@ var metricsCommand = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch context.String(formatFlag) {
|
switch cliContext.String(formatFlag) {
|
||||||
case formatTable:
|
case formatTable:
|
||||||
w := tabwriter.NewWriter(os.Stdout, 1, 8, 4, ' ', 0)
|
w := tabwriter.NewWriter(os.Stdout, 1, 8, 4, ' ', 0)
|
||||||
fmt.Fprintf(w, "ID\tTIMESTAMP\t\n")
|
fmt.Fprintf(w, "ID\tTIMESTAMP\t\n")
|
||||||
|
@ -25,13 +25,13 @@ var pauseCommand = &cli.Command{
|
|||||||
Name: "pause",
|
Name: "pause",
|
||||||
Usage: "Pause an existing container",
|
Usage: "Pause an existing container",
|
||||||
ArgsUsage: "CONTAINER",
|
ArgsUsage: "CONTAINER",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
container, err := client.LoadContainer(ctx, context.Args().First())
|
container, err := client.LoadContainer(ctx, cliContext.Args().First())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -31,12 +31,12 @@ var psCommand = &cli.Command{
|
|||||||
Name: "ps",
|
Name: "ps",
|
||||||
Usage: "List processes for container",
|
Usage: "List processes for container",
|
||||||
ArgsUsage: "CONTAINER",
|
ArgsUsage: "CONTAINER",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
id := context.Args().First()
|
id := cliContext.Args().First()
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return errors.New("container id must be provided")
|
return errors.New("container id must be provided")
|
||||||
}
|
}
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -25,13 +25,13 @@ var resumeCommand = &cli.Command{
|
|||||||
Name: "resume",
|
Name: "resume",
|
||||||
Usage: "Resume a paused container",
|
Usage: "Resume a paused container",
|
||||||
ArgsUsage: "CONTAINER",
|
ArgsUsage: "CONTAINER",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
container, err := client.LoadContainer(ctx, context.Args().First())
|
container, err := client.LoadContainer(ctx, cliContext.Args().First())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -55,16 +55,16 @@ var startCommand = &cli.Command{
|
|||||||
Usage: "Detach from the task after it has started execution",
|
Usage: "Detach from the task after it has started execution",
|
||||||
},
|
},
|
||||||
}...),
|
}...),
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
id = context.Args().Get(0)
|
id = cliContext.Args().Get(0)
|
||||||
detach = context.Bool("detach")
|
detach = cliContext.Bool("detach")
|
||||||
)
|
)
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return errors.New("container id must be provided")
|
return errors.New("container id must be provided")
|
||||||
}
|
}
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -80,8 +80,8 @@ var startCommand = &cli.Command{
|
|||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
tty = spec.Process.Terminal
|
tty = spec.Process.Terminal
|
||||||
opts = GetNewTaskOpts(context)
|
opts = GetNewTaskOpts(cliContext)
|
||||||
ioOpts = []cio.Opt{cio.WithFIFODir(context.String("fifo-dir"))}
|
ioOpts = []cio.Opt{cio.WithFIFODir(cliContext.String("fifo-dir"))}
|
||||||
)
|
)
|
||||||
var con console.Console
|
var con console.Console
|
||||||
if tty {
|
if tty {
|
||||||
@ -92,7 +92,7 @@ var startCommand = &cli.Command{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task, err := NewTask(ctx, client, container, "", con, context.Bool("null-io"), context.String("log-uri"), ioOpts, opts...)
|
task, err := NewTask(ctx, client, container, "", con, cliContext.Bool("null-io"), cliContext.String("log-uri"), ioOpts, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -108,8 +108,8 @@ var startCommand = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if context.IsSet("pid-file") {
|
if cliContext.IsSet("pid-file") {
|
||||||
if err := commands.WritePidFile(context.String("pid-file"), int(task.Pid())); err != nil {
|
if err := commands.WritePidFile(cliContext.String("pid-file"), int(task.Pid())); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,13 @@
|
|||||||
package tasks
|
package tasks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
"context"
|
||||||
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type resizer interface {
|
type resizer interface {
|
||||||
Resize(ctx gocontext.Context, w, h uint32) error
|
Resize(ctx context.Context, w, h uint32) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command is the cli command for managing tasks
|
// Command is the cli command for managing tasks
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
package tasks
|
package tasks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@ -41,7 +41,7 @@ var platformStartFlags = []cli.Flag{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HandleConsoleResize resizes the console
|
// HandleConsoleResize resizes the console
|
||||||
func HandleConsoleResize(ctx gocontext.Context, task resizer, con console.Console) error {
|
func HandleConsoleResize(ctx context.Context, task resizer, con console.Console) error {
|
||||||
// do an initial resize of the console
|
// do an initial resize of the console
|
||||||
size, err := con.Size()
|
size, err := con.Size()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -68,7 +68,7 @@ func HandleConsoleResize(ctx gocontext.Context, task resizer, con console.Consol
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewTask creates a new task
|
// NewTask creates a new task
|
||||||
func NewTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, checkpoint string, con console.Console, nullIO bool, logURI string, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
|
func NewTask(ctx context.Context, client *containerd.Client, container containerd.Container, checkpoint string, con console.Console, nullIO bool, logURI string, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
|
||||||
stdinC := &stdinCloser{
|
stdinC := &stdinCloser{
|
||||||
stdin: os.Stdin,
|
stdin: os.Stdin,
|
||||||
}
|
}
|
||||||
@ -121,8 +121,8 @@ func NewTask(ctx gocontext.Context, client *containerd.Client, container contain
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetNewTaskOpts resolves containerd.NewTaskOpts from cli.Context
|
// GetNewTaskOpts resolves containerd.NewTaskOpts from cli.Context
|
||||||
func GetNewTaskOpts(context *cli.Context) []containerd.NewTaskOpts {
|
func GetNewTaskOpts(cliContext *cli.Context) []containerd.NewTaskOpts {
|
||||||
if context.Bool("no-pivot") {
|
if cliContext.Bool("no-pivot") {
|
||||||
return []containerd.NewTaskOpts{containerd.WithNoPivotRoot}
|
return []containerd.NewTaskOpts{containerd.WithNoPivotRoot}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package tasks
|
package tasks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
@ -32,7 +32,7 @@ import (
|
|||||||
var platformStartFlags = []cli.Flag{}
|
var platformStartFlags = []cli.Flag{}
|
||||||
|
|
||||||
// HandleConsoleResize resizes the console
|
// HandleConsoleResize resizes the console
|
||||||
func HandleConsoleResize(ctx gocontext.Context, task resizer, con console.Console) error {
|
func HandleConsoleResize(ctx context.Context, task resizer, con console.Console) error {
|
||||||
// do an initial resize of the console
|
// do an initial resize of the console
|
||||||
size, err := con.Size()
|
size, err := con.Size()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -61,7 +61,7 @@ func HandleConsoleResize(ctx gocontext.Context, task resizer, con console.Consol
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewTask creates a new task
|
// NewTask creates a new task
|
||||||
func NewTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, _ string, con console.Console, nullIO bool, logURI string, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
|
func NewTask(ctx context.Context, client *containerd.Client, container containerd.Container, _ string, con console.Console, nullIO bool, logURI string, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
|
||||||
var ioCreator cio.Creator
|
var ioCreator cio.Creator
|
||||||
if con != nil {
|
if con != nil {
|
||||||
if nullIO {
|
if nullIO {
|
||||||
|
@ -29,9 +29,9 @@ import (
|
|||||||
var Command = &cli.Command{
|
var Command = &cli.Command{
|
||||||
Name: "version",
|
Name: "version",
|
||||||
Usage: "Print the client and server versions",
|
Usage: "Print the client and server versions",
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(cliContext *cli.Context) error {
|
||||||
if context.NArg() != 0 {
|
if cliContext.NArg() != 0 {
|
||||||
return fmt.Errorf("extra arguments: %v", context.Args())
|
return fmt.Errorf("extra arguments: %v", cliContext.Args())
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Client:")
|
fmt.Println("Client:")
|
||||||
@ -39,7 +39,7 @@ var Command = &cli.Command{
|
|||||||
fmt.Println(" Revision:", version.Revision)
|
fmt.Println(" Revision:", version.Revision)
|
||||||
fmt.Println(" Go version:", version.GoVersion)
|
fmt.Println(" Go version:", version.GoVersion)
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
gocontext "context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/containerd/typeurl/v2"
|
"github.com/containerd/typeurl/v2"
|
||||||
@ -147,7 +146,7 @@ func updateContainerSpec(ctx context.Context, cntr containerd.Container, spec *r
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to marshal spec %+v: %w", spec, err)
|
return fmt.Errorf("failed to marshal spec %+v: %w", spec, err)
|
||||||
}
|
}
|
||||||
if err := cntr.Update(ctx, func(ctx gocontext.Context, client *containerd.Client, c *containers.Container) error {
|
if err := cntr.Update(ctx, func(ctx context.Context, client *containerd.Client, c *containers.Container) error {
|
||||||
c.Spec = s
|
c.Spec = s
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user