Merge pull request #4700 from thaJeztah/wire_up_contexts
Plumb contexts through commands
This commit is contained in:
@ -26,7 +26,7 @@ func newDiskUsageCommand(dockerCli command.Cli) *cobra.Command {
|
||||
Short: "Show docker disk usage",
|
||||
Args: cli.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runDiskUsage(dockerCli, opts)
|
||||
return runDiskUsage(cmd.Context(), dockerCli, opts)
|
||||
},
|
||||
Annotations: map[string]string{"version": "1.25"},
|
||||
ValidArgsFunction: completion.NoComplete,
|
||||
@ -40,9 +40,9 @@ func newDiskUsageCommand(dockerCli command.Cli) *cobra.Command {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func runDiskUsage(dockerCli command.Cli, opts diskUsageOptions) error {
|
||||
func runDiskUsage(ctx context.Context, dockerCli command.Cli, opts diskUsageOptions) error {
|
||||
// TODO expose types.DiskUsageOptions.Types as flag on the command-line and/or as separate commands (docker container df / docker container usage)
|
||||
du, err := dockerCli.Client().DiskUsage(context.Background(), types.DiskUsageOptions{})
|
||||
du, err := dockerCli.Client().DiskUsage(ctx, types.DiskUsageOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -21,16 +21,17 @@ func newDialStdioCommand(dockerCli command.Cli) *cobra.Command {
|
||||
Args: cli.NoArgs,
|
||||
Hidden: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runDialStdio(dockerCli)
|
||||
return runDialStdio(cmd.Context(), dockerCli)
|
||||
},
|
||||
ValidArgsFunction: completion.NoComplete,
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func runDialStdio(dockerCli command.Cli) error {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
func runDialStdio(ctx context.Context, dockerCli command.Cli) error {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
dialer := dockerCli.Client().Dialer()
|
||||
conn, err := dialer(ctx)
|
||||
if err != nil {
|
||||
|
||||
@ -37,7 +37,7 @@ func NewEventsCommand(dockerCli command.Cli) *cobra.Command {
|
||||
Short: "Get real time events from the server",
|
||||
Args: cli.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runEvents(dockerCli, &options)
|
||||
return runEvents(cmd.Context(), dockerCli, &options)
|
||||
},
|
||||
Annotations: map[string]string{
|
||||
"aliases": "docker system events, docker events",
|
||||
@ -54,7 +54,7 @@ func NewEventsCommand(dockerCli command.Cli) *cobra.Command {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func runEvents(dockerCli command.Cli, options *eventsOptions) error {
|
||||
func runEvents(ctx context.Context, dockerCli command.Cli, options *eventsOptions) error {
|
||||
tmpl, err := makeTemplate(options.format)
|
||||
if err != nil {
|
||||
return cli.StatusError{
|
||||
@ -62,7 +62,7 @@ func runEvents(dockerCli command.Cli, options *eventsOptions) error {
|
||||
Status: "Error parsing format: " + err.Error(),
|
||||
}
|
||||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
evts, errs := dockerCli.Client().Events(ctx, types.EventsOptions{
|
||||
Since: options.since,
|
||||
Until: options.until,
|
||||
|
||||
@ -64,7 +64,7 @@ func NewInfoCommand(dockerCli command.Cli) *cobra.Command {
|
||||
Short: "Display system-wide information",
|
||||
Args: cli.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runInfo(cmd, dockerCli, &opts)
|
||||
return runInfo(cmd.Context(), cmd, dockerCli, &opts)
|
||||
},
|
||||
Annotations: map[string]string{
|
||||
"category-top": "12",
|
||||
@ -77,7 +77,7 @@ func NewInfoCommand(dockerCli command.Cli) *cobra.Command {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func runInfo(cmd *cobra.Command, dockerCli command.Cli, opts *infoOptions) error {
|
||||
func runInfo(ctx context.Context, cmd *cobra.Command, dockerCli command.Cli, opts *infoOptions) error {
|
||||
info := dockerInfo{
|
||||
ClientInfo: &clientInfo{
|
||||
// Don't pass a dockerCLI to newClientVersion(), because we currently
|
||||
@ -95,7 +95,6 @@ func runInfo(cmd *cobra.Command, dockerCli command.Cli, opts *infoOptions) error
|
||||
}
|
||||
|
||||
if needsServerInfo(opts.format, info) {
|
||||
ctx := context.Background()
|
||||
if dinfo, err := dockerCli.Client().Info(ctx); err == nil {
|
||||
info.Info = &dinfo
|
||||
} else {
|
||||
|
||||
@ -32,7 +32,7 @@ func NewInspectCommand(dockerCli command.Cli) *cobra.Command {
|
||||
Args: cli.RequiresMinArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
opts.ids = args
|
||||
return runInspect(dockerCli, opts)
|
||||
return runInspect(cmd.Context(), dockerCli, opts)
|
||||
},
|
||||
}
|
||||
|
||||
@ -44,11 +44,11 @@ func NewInspectCommand(dockerCli command.Cli) *cobra.Command {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func runInspect(dockerCli command.Cli, opts inspectOptions) error {
|
||||
func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions) error {
|
||||
var elementSearcher inspect.GetRefFunc
|
||||
switch opts.inspectType {
|
||||
case "", "container", "image", "node", "network", "service", "volume", "task", "plugin", "secret":
|
||||
elementSearcher = inspectAll(context.Background(), dockerCli, opts.size, opts.inspectType)
|
||||
elementSearcher = inspectAll(ctx, dockerCli, opts.size, opts.inspectType)
|
||||
default:
|
||||
return errors.Errorf("%q is not a valid value for --type", opts.inspectType)
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package system
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"text/template"
|
||||
@ -39,7 +40,7 @@ func newPruneCommand(dockerCli command.Cli) *cobra.Command {
|
||||
Args: cli.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
options.pruneBuildCache = versions.GreaterThanOrEqualTo(dockerCli.Client().ClientVersion(), "1.31")
|
||||
return runPrune(dockerCli, options)
|
||||
return runPrune(cmd.Context(), dockerCli, options)
|
||||
},
|
||||
Annotations: map[string]string{"version": "1.25"},
|
||||
ValidArgsFunction: completion.NoComplete,
|
||||
@ -68,7 +69,7 @@ const confirmationTemplate = `WARNING! This will remove:
|
||||
{{end}}
|
||||
Are you sure you want to continue?`
|
||||
|
||||
func runPrune(dockerCli command.Cli, options pruneOptions) error {
|
||||
func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) error {
|
||||
// TODO version this once "until" filter is supported for volumes
|
||||
if options.pruneVolumes && options.filter.Value().Contains("until") {
|
||||
return fmt.Errorf(`ERROR: The "until" filter is not supported with "--volumes"`)
|
||||
@ -76,7 +77,7 @@ func runPrune(dockerCli command.Cli, options pruneOptions) error {
|
||||
if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), confirmationMessage(dockerCli, options)) {
|
||||
return nil
|
||||
}
|
||||
pruneFuncs := []func(dockerCli command.Cli, all bool, filter opts.FilterOpt) (uint64, string, error){
|
||||
pruneFuncs := []func(ctx context.Context, dockerCli command.Cli, all bool, filter opts.FilterOpt) (uint64, string, error){
|
||||
container.RunPrune,
|
||||
network.RunPrune,
|
||||
}
|
||||
@ -90,7 +91,7 @@ func runPrune(dockerCli command.Cli, options pruneOptions) error {
|
||||
|
||||
var spaceReclaimed uint64
|
||||
for _, pruneFn := range pruneFuncs {
|
||||
spc, output, err := pruneFn(dockerCli, options.all, options.filter)
|
||||
spc, output, err := pruneFn(ctx, dockerCli, options.all, options.filter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -116,7 +116,7 @@ func NewVersionCommand(dockerCli command.Cli) *cobra.Command {
|
||||
Short: "Show the Docker version information",
|
||||
Args: cli.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runVersion(dockerCli, &opts)
|
||||
return runVersion(cmd.Context(), dockerCli, &opts)
|
||||
},
|
||||
Annotations: map[string]string{
|
||||
"category-top": "10",
|
||||
@ -144,7 +144,7 @@ func arch() string {
|
||||
return arch
|
||||
}
|
||||
|
||||
func runVersion(dockerCli command.Cli, opts *versionOptions) error {
|
||||
func runVersion(ctx context.Context, dockerCli command.Cli, opts *versionOptions) error {
|
||||
var err error
|
||||
tmpl, err := newVersionTemplate(opts.format)
|
||||
if err != nil {
|
||||
@ -156,7 +156,7 @@ func runVersion(dockerCli command.Cli, opts *versionOptions) error {
|
||||
vd := versionInfo{
|
||||
Client: newClientVersion(dockerCli.CurrentContext(), dockerCli),
|
||||
}
|
||||
sv, err := dockerCli.Client().ServerVersion(context.Background())
|
||||
sv, err := dockerCli.Client().ServerVersion(ctx)
|
||||
if err == nil {
|
||||
vd.Server = &sv
|
||||
foundEngine := false
|
||||
|
||||
Reference in New Issue
Block a user