Compare commits

...

455 Commits

Author SHA1 Message Date
Paweł Gronowski 27b316fc0d
Merge pull request #6421 from vvoland/update-go
update to go1.24.7
2025-09-03 21:28:52 +02:00
Paweł Gronowski f64b8a332d
update to go1.24.7
This includes 1 security fix:

- net/http: CrossOriginProtection bypass patterns are over-broad

    When passing patterns to CrossOriginProtection.AddInsecureBypassPattern,
    requests that would have redirected to those patterns (e.g. without a trailing
    slash) were also exempted, which might be unexpected.

    Thanks to Marco Gazerro for reporting this issue.

    This is CVE-2025-47910 and Go issue https://go.dev/issue/75054.

View the release notes for more information:
https://go.dev/doc/devel/release#go1.24.7

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-09-03 20:40:59 +02:00
Sebastiaan van Stijn 06ed23d5fe
Merge pull request #6419 from thaJeztah/complete_pull
add completion for docker image pull
2025-09-03 17:34:50 +02:00
Sebastiaan van Stijn 5bf3c6793d
add completion for docker image pull
With this patch, completion is provided for images already present
in the local image cache to help pulling the latest version of the
same tag;

    docker pull go<tab>
    golang:1.12    golang:1.18.0  golang:1.21    golang:1.24    gopher:latest
    golang:1.13    golang:1.20    golang:1.23    golang:latest

    docker pull golang:<tab>
    1.12    1.13    1.18.0  1.20    1.21    1.23    1.24    latest

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-03 15:39:41 +02:00
Austin Vazquez 5bce5e17af
Merge pull request #6415 from thaJeztah/plugin_no_regex
cli-plugins/manager: replace pluginNameRe for isValidPluginName utility
2025-09-02 16:48:11 -07:00
Austin Vazquez 0640306406
Merge pull request #6417 from thaJeztah/context_no_regex
cli/context/store: replace restrictedNamePattern for isValidName utility
2025-09-02 16:45:21 -07:00
Sebastiaan van Stijn ab7018b590
cli/context/store: replace restrictedNamePattern for isValidName utility
The restrictedNamePattern was a basic regular expression. Replace it
with a minimal utility to do the same, without having to use regular
expressions (or the "lazyregexp" package).

Some quick benchmarking (not committed) show that the non-regex approach
is ~18x faster:

    BenchmarkIsValidName_Regex_Valid-10        8516511        119.4   ns/op      0 B/op        0 allocs/op
    BenchmarkIsValidName_Manual_Valid-10     172426240          6.964 ns/op      0 B/op        0 allocs/op

    BenchmarkIsValidName_Regex_Invalid-10     34824540         34.22  ns/op      0 B/op        0 allocs/op
    BenchmarkIsValidName_Manual_Invalid-10   550804021          2.173 ns/op      0 B/op        0 allocs/op

    BenchmarkIsValidName_Regex_Parallel-10    69289900         17.30   ns/op     0 B/op        0 allocs/op
    BenchmarkIsValidName_Manual_Parallel-10 1000000000          0.9296 ns/op     0 B/op        0 allocs/op

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-02 23:09:12 +02:00
Sebastiaan van Stijn 2351f5b915
cli-plugins/manager: replace pluginNameRe for isValidPluginName utility
The pluginNameRe was a basic regular expression, effectively only checking
if the name consisted of lowercase alphanumeric characters. Replace it
with a minimal utility to do the same, without having to use regular
expressions (or the "lazyregexp" package).

Some quick benchmarking (not committed) show that the non-regex approach
is ~25x faster:

    BenchmarkIsValidPluginName_Regex_Valid-10       13956240        81.39  ns/op       0 B/op        0 allocs/op
    BenchmarkIsValidPluginName_Manual_Valid-10     360003060         3.318 ns/op       0 B/op        0 allocs/op

    BenchmarkIsValidPluginName_Regex_Invalid-10     35281794        33.74  ns/op       0 B/op        0 allocs/op
    BenchmarkIsValidPluginName_Manual_Invalid-10   906072663         1.320 ns/op       0 B/op        0 allocs/op

    BenchmarkIsValidPluginName_Regex_Parallel-10    96595677        12.04  ns/op       0 B/op        0 allocs/op
    BenchmarkIsValidPluginName_Manual_Parallel-10  1000000000        0.4541 ns/op      0 B/op        0 allocs/op

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-02 22:58:32 +02:00
Sebastiaan van Stijn 153bd95158
Merge pull request #6414 from thaJeztah/plugin_rm_deprecated
cli-plugins/manager: remove deprecated types, functions and aliases
2025-09-02 12:17:31 +02:00
Sebastiaan van Stijn ce72a5c28b
cli-plugins/manager: remove deprecated metadata aliases
These consts and types were moved to a separate metadata package in commits
292713c887 and 4321293972,
and deprecated in 72f76f2720, 5876b2941c,
and 6fa7d18320.

This removes the deprecated aliases in `cli-plugins/manager` in favor of
their equivalent in `cli-plugins/manager/metadata`:

- `CommandAnnotationPlugin`
- `CommandAnnotationPluginVendor`
- `CommandAnnotationPluginVersion`
- `CommandAnnotationPluginInvalid`
- `CommandAnnotationPluginCommandPath`
- `NamePrefix`
- `MetadataSubcommandName`
- `HookSubcommandName`
- `Metadata`
- `ReexecEnvvar`

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-02 11:43:32 +02:00
Sebastiaan van Stijn d54c7f9e63
cli-plugins/manager: remove deprecated IsNotFound
These errors satisfy errdefs.IsNotFound, which can be used instead. This
function was deprecated in 71460215d3 and
is no longer used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-01 18:31:41 +02:00
Paweł Gronowski 6ec32660e9
Merge pull request #6412 from thaJeztah/deprecate_OauthLoginEscapeHatchEnvVar
cli/command/registry: deprecate OauthLoginEscapeHatchEnvVar
2025-09-01 17:57:31 +02:00
Paweł Gronowski 9e52a2817c
Merge pull request #6410 from thaJeztah/deprecate_ReexecEnvvar
cli-plugins/manager: deprecate ReexecEnvvar
2025-09-01 17:56:42 +02:00
Sebastiaan van Stijn 18cdc25bb4
cli/command/registry: deprecate OauthLoginEscapeHatchEnvVar
This const was added in 846ecf59ff, but
only used internally. This patch deprecates the const, to be removed
in the next release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-01 17:43:39 +02:00
Sebastiaan van Stijn 6fa7d18320
cli-plugins/manager: deprecate ReexecEnvvar
This alias was added in 4321293972, which is
part of v28.0, but did not deprecate them. They are no longer used in the
CLI itself, but may be used by cli-plugin implementations.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-01 17:33:32 +02:00
Sebastiaan van Stijn 89874983c8
Merge pull request #6401 from thaJeztah/check_DisableFlagsInUseLine
verify that DisableFlagsInUseLine is set for all commands
2025-09-01 13:55:57 +02:00
Sebastiaan van Stijn 88f68273fd
Merge pull request #6406 from thaJeztah/rm_GetStacks_StackWrite
cli/command/stack: move GetStacks and StackWrite internal
2025-09-01 13:55:09 +02:00
Sebastiaan van Stijn a2c886251c
Merge pull request #6407 from thaJeztah/rm_exported_context_funcs
cli/command/context: remove deprecated types and functions
2025-09-01 12:58:49 +02:00
Sebastiaan van Stijn 9a6cbbc586
Merge pull request #6408 from thaJeztah/rm_NoComplete
cli/command/completion: remove deprecated NoComplete
2025-09-01 12:58:20 +02:00
Sebastiaan van Stijn 70915196cb
cli/command/completion: remove deprecated NoComplete
This function was an exact duplicate of [cobra.NoFileCompletions], and
was deprecated in 2827d037ba.

[cobra.NoFileCompletions]: https://pkg.go.dev/github.com/spf13/cobra@v1.9.1#NoFileCompletions

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-01 10:27:34 +02:00
Sebastiaan van Stijn 9477941c20
cli/command/context: remove deprecated types and functions
These functions and types are shallow wrappers around the context
store and were intended for internal use as implementation for the
CLI itself.

They were exported in 3126920af1 to be
used by plugins and Docker Desktop. However, there's currently no public
uses of this, and Docker Desktop does not use these functions. These were
deprecated in 95eeafa551 and are no longer
used.

This patch removes the deprecated functions as they were meant to be
implementation specific for the CLI. If there's a need to provide
utilities for manipulating the context-store other than through the
CLI itself, we can consider creating an SDK for that purpose.

This removes:

- `RunCreate` and `CreateOptions`
- `RunExport` and `ExportOptions`
- `RunImport`
- `RunRemove` and `RemoveOptions`
- `RunUpdate` and `UpdateOptions`
- `RunUse`

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-01 10:22:28 +02:00
Sebastiaan van Stijn 6647e229be
cli/command/stack: move GetStacks and StackWrite internal
These were deprecated in 036d3a6bab and
30774ed1f2, and were originally in the
cli/command/stack package, but moved for the (now deprecated) Compose
on Kubernetes feature in 4d947de292.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-01 09:40:44 +02:00
Sebastiaan van Stijn 0adaf6be3b
verify that DisableFlagsInUseLine is set for all commands
This replaces the visitAll recursive function with a test that verifies that
the option is set for all commands and subcommands, so that it doesn't have
to be modified at runtime.

We currently still have to loop over all functions for the setValidateArgs
call, but that can be looked at separately.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-01 09:39:46 +02:00
Sebastiaan van Stijn ba21666654
Merge pull request #6404 from thaJeztah/deprecate_nocomplete
cli/command/completion: deprecate NoComplete
2025-09-01 09:13:18 +02:00
Sebastiaan van Stijn 321100e38b
Merge pull request #6402 from thaJeztah/deprecate_context_funcs
cli/command/context: deprecate exported types and functions
2025-09-01 09:11:28 +02:00
Sebastiaan van Stijn 5dd52a9efa
Merge pull request #6397 from thaJeztah/compose_clean
cli/compose/convert: split exported AddStackLabel from implementation
2025-09-01 09:10:42 +02:00
Sebastiaan van Stijn 2827d037ba
cli/command/completion: deprecate NoComplete
This function was an exact duplicate of [cobra.NoFileCompletions], so
deprecating it in favor of that.

[cobra.NoFileCompletions]: https://pkg.go.dev/github.com/spf13/cobra@v1.9.1#NoFileCompletions

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-30 12:00:34 +02:00
Sebastiaan van Stijn 95eeafa551
cli/command/context: deprecate exported types and functions
These functions and types are shallow wrappers around the context
store and were intended for internal use as implementation for the
CLI itself.

They were exported in 3126920af1 to be
used by plugins and Docker Desktop. However, there's currently no public
uses of this, and Docker Desktop does not use these functions.

This patch deprecates the exported functions as they were meant to be
implementation specific for the CLI. If there's a need to provide
utilities for manipulating the context-store other than through the
CLI itself, we can consider creating an SDK for that purpose.

This deprecates:

- `RunCreate` and `CreateOptions`
- `RunExport` and `ExportOptions`
- `RunImport`
- `RunRemove` and `RemoveOptions`
- `RunUpdate` and `UpdateOptions`
- `RunUse`

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-30 01:51:12 +02:00
Rob Murray 81ea282e00
Merge pull request #6398 from thaJeztah/rm_deprecated_stack
cli/command/stack: remove some deprecated functions
2025-08-29 17:23:29 +01:00
Paweł Gronowski 0155c264ae
Merge pull request #6371 from Benehiko/support-fallback-negative-certs
Add escape hatch for GODEBUG=x509negativeserial
2025-08-29 15:59:24 +02:00
Sebastiaan van Stijn 77205e782a
cli/command/stack/swarm: deployServices: use struct-literal for options
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-29 14:52:38 +02:00
Sebastiaan van Stijn 580c3aa218
cli/compose/convert: Networks: use struct-literal for IPAM config
Use a struct-literal for the IPAM config, and combine some of the checks.
Also use the Name field as a default, and only construct a scoped name
if the given name is empty (instead of the reverse).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-29 14:50:49 +02:00
Sebastiaan van Stijn f8d33f4602
cli/compose/convert: split exported AddStackLabel from implementation
This function is currently only used within the package; create a non-exported
version of it, to make it clear it's not used elsewhere. This patch keeps
the exported function for now, but we can decide if we need to keep it
in future.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-29 14:50:46 +02:00
Sebastiaan van Stijn 2066dbcfe8
cli/command/stack/swarm: inline validateResolveImageFlag
It was only used in a single place, and possibly incorrect. Let's inline
it to put the logic where it's used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-29 14:39:06 +02:00
Sebastiaan van Stijn c3be589c16
cli/command/stack/swarm: remove deprecated RunPS and options.PS
These were deprecated in f0e5a0d654 and
036d3a6bab and were only used internally.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-29 14:39:06 +02:00
Sebastiaan van Stijn 2a05951680
cli/command/stack: remove deprecated RunServices and swarm.GetServices
These were deprecated in f0e5a0d654,
036d3a6bab, and
d16c560664 and were only used internally.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-29 14:39:00 +02:00
Alano Terblanche 72f79333e5
return early if GODEBUG set or context is default
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-29 14:31:21 +02:00
Alano Terblanche 6163c03b11
rename function to fit what it is doing
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-29 14:08:15 +02:00
Alano Terblanche 467305fcea
Test setAllowNegativex509
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-29 12:15:49 +02:00
Alano Terblanche 65a6c35d90
Cleanup setAllowNegativex509
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-29 12:15:29 +02:00
Sebastiaan van Stijn c4df0d17bb
cli/command/stack: remove deprecated RunList and options.List
These were deprecated in f0e5a0d654 and
d16c560664 and were only used internally.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-29 11:46:21 +02:00
Sebastiaan van Stijn b3cd9d48fe
Merge pull request #6393 from thaJeztah/cleanup_stacks
cli/command/stack: cleanups and optimizations
2025-08-29 11:22:11 +02:00
Sebastiaan van Stijn 581cb2b70a
cli/command/stack/swarm: GetStacks: don't use pointers for values
These are very small structs, so using pointers doesn't bring much
advantage and makes it slightly more cumbersome to use.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-28 15:44:09 +02:00
Sebastiaan van Stijn 6b86aac02e
cli/command/stack/formatter: StackWrite: remove intermediate vars
- inline the closure
- remove newStackContext() constructor and inline it

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-28 15:37:52 +02:00
Sebastiaan van Stijn 8b01d8e74c
cli/command/stack: runList: remove intermediate slice
This intermediate slice was a left-over from the "Compose on Kubernetes"
feature, which required some conversions, but that code was removed in
193ede9b12, so the intermediate slice no
longer has a purpose.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-28 15:23:40 +02:00
Sebastiaan van Stijn 047ea37054
cli/command/stack/swarm: pruneServices: fix typo and minor cleanup
- fix typo in argument name
- rename var that shadowed function
- pre-allocate slice

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-28 15:22:16 +02:00
Sebastiaan van Stijn 4f7f42df0e
cli/command/stack/swarm: GetStacks: tidy up
Preserve the original order by avoiding the intermediate map[string] and
keeping an index for the first occurrence of a stack; this also avoids
looping multiple times.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-28 15:22:12 +02:00
Sebastiaan van Stijn 5a23ff9b17
cli/command/stack/formatter: TestStackContextWrite: cleanup test
- Include name in test-table
- Don't use un-keyed values in struct
- Simplify test-table to take a format string instead of a whole formatter.Context

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-28 15:21:16 +02:00
Paweł Gronowski 8f25f4fb24
Merge pull request #6389 from thaJeztah/deprecate_stack_commands
cli/command/stack/*: deprecate exported functions and types
2025-08-28 13:55:46 +02:00
Sebastiaan van Stijn d16c560664
cli/command/stack: deprecate RunList, RunServices
Functions and types in this package were exported as part of the "compose
on kubernetes" feature, which was deprecated and removed. These functions
are meant for internal use, and will be removed in the next release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-28 10:21:47 +02:00
Sebastiaan van Stijn 036d3a6bab
deprecate cli/command/stack/swarm
Functions and types in this package were exported as part of the "compose
on kubernetes" feature, which was deprecated and removed. These functions
are meant for internal use, and will be removed in the next release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-28 10:21:47 +02:00
Sebastiaan van Stijn f0e5a0d654
deprecate cli/command/stack/options
Functions and types in this package were exported as part of the "compose
on kubernetes" feature, which was deprecated and removed. These functions
are meant for internal use, and will be removed in the next release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-28 10:21:47 +02:00
Sebastiaan van Stijn ad6ab189a6
deprecate cli/command/stack/loader
Functions and types in this package were exported as part of the "compose
on kubernetes" feature, which was deprecated and removed. These functions
are meant for internal use, and will be removed in the next release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-28 10:21:47 +02:00
Sebastiaan van Stijn 30774ed1f2
deprecate cli/command/stack/formatter
Functions and types in this package were exported as part of the "compose
on kubernetes" feature, which was deprecated and removed. These functions
are meant for internal use, and will be removed in the next release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-28 10:21:42 +02:00
Austin Vazquez 306b7445a1
Merge pull request #6377 from thaJeztah/trust_unconvert
cli/command/trust: unconvert
2025-08-27 12:31:52 -07:00
Austin Vazquez ef0a67551a
Merge pull request #6382 from thaJeztah/rm_ParseEnvFile
opts: remove deprecated ParseEnvFile
2025-08-27 12:25:54 -07:00
Austin Vazquez a7df96501f
Merge pull request #6378 from thaJeztah/system_no_deprecated
cli/command/system: don't use deprecated fields in test
2025-08-27 12:21:41 -07:00
Austin Vazquez 5a2f87f6f6
Merge pull request #6385 from thaJeztah/bump_go_events
vendor: github.com/docker/go-events v0.0.0-20250114142523-c867878c5e32
2025-08-27 11:14:04 -07:00
Sebastiaan van Stijn b8507d71e8
Merge pull request #6387 from thaJeztah/bump_modules2
vendor: github.com/moby/moby/api, github.com/moby/moby/client master
2025-08-27 17:38:15 +02:00
Sebastiaan van Stijn cdf705ce66
vendor: github.com/moby/moby/api, github.com/moby/moby/client master
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-27 17:12:11 +02:00
Sebastiaan van Stijn 05220c5f19
vendor: github.com/docker/go-events v0.0.0-20250114142523-c867878c5e32
full diff: e31b211e4f...c867878c5e

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-27 15:51:19 +02:00
Sebastiaan van Stijn 9e331b55d6
opts: remove deprecated ParseEnvFile
This was deprecated in e650803f09 and
no longer used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-27 15:03:34 +02:00
Sebastiaan van Stijn f40caed86c
Merge pull request #6376 from thaJeztah/update_TestEventsFormat
cli/command/system: TestEventsFormat: remove use of deprecated fields
2025-08-27 14:45:44 +02:00
Sebastiaan van Stijn 3d87aa441f
cli/command/system: don't use deprecated fields in test
This only impacts the JSON marshaled output; the "regular" output
of `docker info` already ignores these fields.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-27 14:43:37 +02:00
Sebastiaan van Stijn 4d9017d789
cli/command/trust: unconvert
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-27 14:40:56 +02:00
Sebastiaan van Stijn c558c30056
Merge pull request #6374 from thaJeztah/plugin_errs
cli/command/image: remove special handling for plugin errors on pull
2025-08-27 13:47:39 +02:00
Sebastiaan van Stijn 823c6a75b3
cli/command/system: TestEventsFormat: remove use of deprecated fields
These were just testing JSON marshaling fields that are deprecated, but
may be present in a response; these fields will be removed in future
API versions, so stop testing for them.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-27 13:45:05 +02:00
Sebastiaan van Stijn 7dfa471387
Merge pull request #6375 from thaJeztah/bump_modules
vendor: github.com/moby/moby/api, github.com/moby/moby/client 62884141100c
2025-08-27 12:14:47 +02:00
Sebastiaan van Stijn 10072c3548
vendor: github.com/moby/moby/api, github.com/moby/moby/client 62884141100c
full diffs:

- 7145e7666b...6288414110

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-27 10:21:32 +02:00
Sebastiaan van Stijn 323fbc485e
cli/command/image: remove special handling for plugin errors on pull
This special handling was added in [moby@9b6dcc8], and later updated in
[moby@c127d96], but it fully depended on string-matching, which is brittle.
Testing the original ticket that lead to this handling, it looks like the
string matching no longer works, and the daemon error is returned as-is:

With graphdrivers:

    docker pull tiborvass/no-remove
    Using default tag: latest
    Error response from daemon: Encountered remote "application/vnd.docker.plugin.v0+json"(unknown) when fetching

With containerd snapshotters enabled:

    docker pull tiborvass/no-remove
    Using default tag: latest
    latest: Pulling from tiborvass/no-remove
    cf635291f7c9: Download complete
    failed to unpack image on snapshotter overlayfs: mismatched image rootfs and manifest layers

The error-message for containerd can probably be improved, but as the special
handling in the CLI no longer works, we can remove it.

[moby@9b6dcc8]: 9b6dcc8b9d
[moby@c127d96]: c127d9614f

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-26 23:47:17 +02:00
Austin Vazquez 701b678104
Merge pull request #6255 from thaJeztah/bump_modules
vendor: github.com/moby/moby/api, moby/moby/client 7145e7666b8f (master)
2025-08-26 13:37:06 -07:00
Sebastiaan van Stijn 7118f1fb4b
vendor: github.com/moby/moby/api, moby/moby/client 7145e7666b8f (master)
full diff:

- https://github.com/docker/docker/compare/api/v1.52.0-alpha.1...7145e7666b8f
- https://github.com/docker/docker/compare/client/v0.1.0-alpha.0...7145e7666b8f

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

WIP latest

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-26 20:02:30 +02:00
Sebastiaan van Stijn 212deb412d
Merge pull request #6373 from thaJeztah/rm_image_AuthResolver
cli/command/image: remove deprecated AuthResolver utility
2025-08-26 19:27:22 +02:00
Sebastiaan van Stijn 481e792773
cli/command/image: remove deprecated AuthResolver utility
This function was used to share it between "trust" and "image",
but was only a shallow wrapper, so split the implementations where
used.

It was deprecated in 7ad113ccc2 and is
no longer used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-26 17:46:02 +02:00
Sebastiaan van Stijn 6bc7ed8b65
Merge pull request #6372 from thaJeztah/plugin_simplify_auth
cli/command/plugin: simplify auth
2025-08-26 17:32:23 +02:00
Austin Vazquez a2198ecd14
Merge pull request #6366 from thaJeztah/fix_email_deprecation
cli/config/types: update deprecation comment for AuthConfig.Email
2025-08-26 08:25:03 -07:00
Sebastiaan van Stijn f2c8b9dfd3
cli/command/plugin: simplify auth
Now that 3f5b1bdd32 removed DCT, which
needed some of the intermediate types (indexInfo), we can simplify the
auth code further and just get the base64-encoded AuthConfig to be set
as header.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-26 16:42:34 +02:00
Sebastiaan van Stijn cfd7e543fc
Merge pull request #6370 from thaJeztah/remove_exported_config_funcs
cli/command/config: remove deprecated types and functions
2025-08-26 16:35:23 +02:00
Alano Terblanche 7d7a7aac4d
Add escape hatch for GODEBUG=x509negativeserial
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-26 16:07:47 +02:00
Sebastiaan van Stijn 250e4a564c
cli/command/config: remove deprecated types and functions
These were deprecated in a5f4ba08d9 and only
used internally.

This removes the deprecated types and functions:

- `RunConfigCreate` and  `CreateOptions`
- `RunConfigInspect` and `InspectOptions`
- `RunConfigList` and `ListOptions`
- `RunConfigRemove` and `RemoveOptions`

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-26 13:17:53 +02:00
Sebastiaan van Stijn fda64ebc64
Merge pull request #6368 from thaJeztah/deprecate_exported_config_funcs
cli/command/config: deprecate exported types and functions
2025-08-26 13:17:12 +02:00
Sebastiaan van Stijn a5f4ba08d9
cli/command/config: deprecate exported types and functions
These were exported in f60369dfe6 to be
used in docker enterprise, but this never happened, and there's no
known consumers of these, so we should deprecate these. External
consumers can still call the API-client directly, which should've
been the correct thing to do in the first place.

This deprecates:

- `RunConfigCreate` and  `CreateOptions`
- `RunConfigInspect` and `InspectOptions`
- `RunConfigList` and `ListOptions`
- `RunConfigRemove` and `RemoveOptions`

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-25 18:54:20 +02:00
Sebastiaan van Stijn 09cd4ea26c
Merge pull request #6362 from thaJeztah/cleanup_formatter
cli/command/formatter: ContainerContext: assorted cleanups, fixes
2025-08-25 16:22:06 +02:00
Sebastiaan van Stijn a6826de3e2
Merge pull request #6361 from thaJeztah/cli_trust_cleanups
cli/trust: some cleanups
2025-08-25 16:20:56 +02:00
Sebastiaan van Stijn 5bcb60aaa6
Merge pull request #6356 from thaJeztah/unexport_authresolver_util
cli/command/image: deprecate AuthResolver and un-export
2025-08-25 16:19:45 +02:00
Sebastiaan van Stijn 1beb3d4d5b
Merge pull request #6355 from thaJeztah/rm_image_pull
cli/command/image: remove exported RunPull, PullOptions
2025-08-25 16:00:38 +02:00
Sebastiaan van Stijn 0395cdbd71
Merge pull request #6353 from thaJeztah/rm_json_deprecated
internal/jsonstream: remove uses of deprecated fields
2025-08-25 15:52:08 +02:00
Sebastiaan van Stijn aab947de8f
cli/config/types: update deprecation comment for AuthConfig.Email
Relates to [cli@27b2797], which forked this type from the Moby API, and
[moby@6cfff7e], which made the same change on the API side.

The Email field was originally used to create a new Docker Hub account
through the `docker login` command. The `docker login` command could be
used both to log in to an existing account (providing only username and
password), or to create a new account (providing desired username and
password, and an e-mail address to use for the new account).

This functionality was confusing, because it was implemented when Docker
Hub was the only registry, but the same functionality could not be used
for other registries. This functionality was removed in Docker 1.11 (API
version 1.23) through [moby@aee260d], which also removed the Email field
([engine-api@9a9e468]) as it was no longer used.

However, this caused issues when using a new CLI connecting with an old
daemon, as the field would no longer be serialized, and the deprecation
may not yet be picked up by custom registries, so [engine-api@167efc7]
added the field back, deprecated it, and added an "omitempty". There
was no official "deprecated" format yet at the time, so let's make sure
the deprecation follows the proper format to make sure it gets noticed.

[cli@27b2797]: 27b2797f7d
[moby@6cfff7e]: 6cfff7e880
[moby@aee260d]: aee260d4eb
[engine-api@9a9e468]: 9a9e468f50
[engine-api@167efc7]: 167efc72bb

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-25 15:44:04 +02:00
Sebastiaan van Stijn 5ab12e6262
Merge pull request #6365 from thaJeztah/fix_version_annotations
cli/command/service: fix API annotations for generic resource flags
2025-08-25 13:33:12 +02:00
Sebastiaan van Stijn 104b07647f
Merge pull request #6363 from thaJeztah/image_push_cleanups
cli/command/image: runPush: minor cleanups and linting issues
2025-08-25 11:47:21 +02:00
Sebastiaan van Stijn 27734fdf4d
Merge pull request #6349 from thaJeztah/rm_RegistryAuthenticationPrivilegedFunc
cli/command: remove deprecated RegistryAuthenticationPrivilegedFunc
2025-08-25 11:00:30 +02:00
Sebastiaan van Stijn dcc3d25dc2
cli/command/service: fix API annotations for generic resource flags
These flags were added in 20a6ff32ee, and require
API version v1.32 or up, but they accidentally copied the flag-name from another
flag, so were not setting the annotation correctly.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-25 10:59:47 +02:00
Sebastiaan van Stijn c36e67d7b6
cli/command/image: runPush: minor cleanups and linting issues
- Remove redundant intermediate variables
- Explicitly use an early return on error instead of combining with
  other checks.
- Fix unhandled errors and combine defers
- Remove outstanding TODO that unlikely will be addressed

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-24 19:38:24 +02:00
Sebastiaan van Stijn 4f944e245b
cli/command/formatter: ContainerContext.Image: explicitly strip digest
The `reference.TrimNamed` function strips both digests and tags; the
formatter function only wants to remove the digest, but preserve any
tags present.

Update the implementation to only trim the reference if there's a digest
present, otherwise use it as-is.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-24 19:31:47 +02:00
Sebastiaan van Stijn 7ac3e0e0bf
cli/command/formatter: ContainerContext.Image: use early returns
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-24 19:31:47 +02:00
Sebastiaan van Stijn 0e7d422e5f
cli/command/formatter: TestContainerPsContext: add test-cases
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-24 19:31:46 +02:00
Sebastiaan van Stijn 7cb8147e77
cli/trust: GetNotaryRepository: inline variables
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-24 16:01:08 +02:00
Sebastiaan van Stijn 35a41c39a4
cli/trust: check for Digested, Tagged reference instead of Canonical
The [Canonical] interface defines images that are both [Named] and
[Digested], but in all places where it was used, we were only interested
whether the reference contained a digest. Similarly [NamedTagged] is
a superset of [Tagged], so checking for [Tagged] is sufficient if we're
already dealing with a [Named] reference.

This patch changes those checks to check for [Digested] and [Tagged]
references, as that's what's relevant for these checks.

[Named]: https://pkg.go.dev/github.com/distribution/reference#Named
[NamedTagged]: https://pkg.go.dev/github.com/distribution/reference#NamedTagged
[Canonical]: https://pkg.go.dev/github.com/distribution/reference#Canonical
[Digested]: https://pkg.go.dev/github.com/distribution/reference#Digested

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-24 16:00:54 +02:00
Sebastiaan van Stijn abe4aa7893
Merge pull request #6360 from hsnabszhdn/add-missing-backticks
docs: add missing backticks in 'run.md'
2025-08-23 14:14:58 +02:00
Sebastiaan van Stijn 08f876d6e8
Merge pull request #6359 from hsnabszhdn/fix-sentence-structures-in-run-md
docs: fix sentence structures in 'run.md'
2025-08-23 14:14:24 +02:00
Austin Vazquez 0f875ba9ad
Merge pull request #6351 from thaJeztah/avoid_shadowing
cli/command: rename vars for consistency and prevent shadowing
2025-08-23 02:56:49 -07:00
Hossein Abbasi d9cafa759f docs: add missing backticks in 'run.md'
Signed-off-by: Hossein Abbasi <16090309+hsnabszhdn@users.noreply.github.com>
2025-08-23 16:14:53 +10:00
Hossein Abbasi ba2c1c94ab docs: fix sentence structures in 'run.md'
Signed-off-by: Hossein Abbasi <16090309+hsnabszhdn@users.noreply.github.com>
2025-08-23 15:54:56 +10:00
Sebastiaan van Stijn 7ad113ccc2
cli/command/image: deprecate AuthResolver and un-export
This function was exported to share it between "trust" and "image",
but was only a shallow wrapper, so split the implementations where
used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-23 03:46:14 +02:00
Sebastiaan van Stijn 9216f04eb6
cli/command/image: remove exported RunPull, PullOptions
These were exported in 812f113685, but
while the function and options are exported, the option-fields were
all un-exported, so these were not usable.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-23 03:35:51 +02:00
Sebastiaan van Stijn 9fd71c8347
cli/command: rename vars for consistency and prevent shadowing
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-23 03:04:36 +02:00
Sebastiaan van Stijn 045ac0b159
internal/jsonstream: remove uses of deprecated fields
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-23 02:17:20 +02:00
Sebastiaan van Stijn 03da6ad2d1
cli/command: remove deprecated RegistryAuthenticationPrivilegedFunc
This function was deprecated in 29263e865b
and is no longer used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-23 00:41:07 +02:00
Sebastiaan van Stijn 1df8feb2e4
Merge pull request #6345 from thaJeztah/bump_x_sync
vendor: golang.org/x/sync v0.16.0
2025-08-22 21:05:54 +02:00
Sebastiaan van Stijn c7cbac58b3
vendor: golang.org/x/sync v0.16.0
Brings in the errgroup implementation for reverted auto-recover from panics.

full diff: https://github.com/golang/sync/compare/v0.14.0...v0.16.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 14:26:38 +02:00
Sebastiaan van Stijn e8e4588f64
Merge pull request #6344 from thaJeztah/remove_builder_newprunecommand
cli/command/trust: remove deprecated NewPruneCommand
2025-08-22 12:41:14 +02:00
Sebastiaan van Stijn d317bc30be
cli/command/trust: remove deprecated NewPruneCommand
These were deprecated in 7032f5922e, which
is part of the v28.4 release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 12:35:36 +02:00
Sebastiaan van Stijn 832a3754e5
Merge pull request #6342 from thaJeztah/deprecate_builder_NewPruneCommand
cli/command/builder: deprecate NewPruneCommand
2025-08-22 12:35:08 +02:00
Sebastiaan van Stijn 4d4533abaa
Merge pull request #6338 from thaJeztah/cleanup_formatters
cli/command: inline vars and use struct literals in formatting functions
2025-08-22 12:25:14 +02:00
Sebastiaan van Stijn 7032f5922e
cli/command/builder: deprecate NewPruneCommand
This patch deprecates exported NewPruneCommand and moves the
implementation details to an unexported function.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 12:18:27 +02:00
Sebastiaan van Stijn 2966159873
Merge pull request #6339 from thaJeztah/rm_deprecated_formatting
cli/command/*: remove deprecated formatting-related functions and types
2025-08-22 12:10:26 +02:00
Sebastiaan van Stijn 65e7ece518
Merge pull request #6337 from thaJeztah/pretty_io
cli/command/system: prettyPrintVersion: accept a plain io.Writer
2025-08-22 11:31:33 +02:00
Sebastiaan van Stijn 5bb8ab4e6f
cli/command/trust: remove deprecated formatting functions
These were deprecated in 95c9b1b13b, which
is part of the v28.4 release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:43:27 +02:00
Sebastiaan van Stijn 8969b57500
cli/command/task: remove deprecated formatting functions
These were deprecated in c3ee82fdc3, which
is part of the v28.4 release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:42:53 +02:00
Sebastiaan van Stijn c6f4573153
cli/command/service: remove deprecated formatting functions
These were deprecated in 9f453d3fea, which
is part of the v28.4 release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:42:24 +02:00
Sebastiaan van Stijn 04bcae3a8c
cli/command/secret: remove deprecated formatting functions
These were deprecated in f3088e37a0, which
is part of the v28.4 release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:41:52 +02:00
Sebastiaan van Stijn c592932f47
cli/command/registry: remove deprecated formatting functions
These were deprecated in 83371c2014, which
is part of the v28.4 release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:41:11 +02:00
Sebastiaan van Stijn 264080d2fc
cli/command/plugin: remove deprecated formatting functions
These were deprecated in bf47419852, which
is part of the v28.4 release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:40:43 +02:00
Sebastiaan van Stijn e5a0fb09a3
cli/command/node: remove deprecated formatting functions
These were deprecated in 123ef81f7d, which
is part of the v28.4 release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:40:09 +02:00
Sebastiaan van Stijn 7b172fcf53
cli/command/network: remove deprecated formatting functions
These were deprecated in e3903a1ac8, which
is part of the v28.4 release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:39:35 +02:00
Sebastiaan van Stijn d223ec3b56
cli/command/image: remove deprecated formatting functions
These were deprecated in 15cf4fa912, which
is part of the v28.4 release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:38:56 +02:00
Sebastiaan van Stijn 206a8da307
cli/command/container: remove deprecated formatting functions
These were deprecated in 907507e22a and
fdc90caeee, which are part of the v28.4
release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:38:09 +02:00
Sebastiaan van Stijn f969adf63f
cli/command/config: remove deprecated formatting functions
These were deprecated in e626f778ec, which
is part of the v28.4 release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:36:11 +02:00
Sebastiaan van Stijn e416418e70
cli/command/checkpoint: remove deprecated formatting functions
These were deprecated in d861b78a8a, which
is part of the v28.4 release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:34:17 +02:00
Sebastiaan van Stijn efd6e7b6e0
cli/command/system: prettyPrintVersion: accept a plain io.Writer
We're only writing to a single stream, so may as well just let it
take an io.writer.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:22:56 +02:00
Sebastiaan van Stijn f72ec26693
cli/command/trust: inline vars and use struct literals
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:19:11 +02:00
Sebastiaan van Stijn 6de2cdd1af
cli/command/task: inline vars and use struct literals
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:19:11 +02:00
Sebastiaan van Stijn e308036440
cli/command/service: inline vars and use struct literals
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:19:11 +02:00
Sebastiaan van Stijn 12d30bb50c
cli/command/secret: inline vars and use struct literals
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:19:11 +02:00
Sebastiaan van Stijn 863b5633f3
cli/command/registry: inline vars and use struct literals
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:19:11 +02:00
Sebastiaan van Stijn aa39a7e7be
cli/command/plugin: inline vars and use struct literals
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:19:10 +02:00
Sebastiaan van Stijn 1a433cdbdb
cli/command/node: inline vars and use struct literals
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:19:10 +02:00
Sebastiaan van Stijn 3d2bd97a82
cli/command/config: formatWrite: inline vars and use struct literals
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:19:10 +02:00
Sebastiaan van Stijn 70033b78d4
cli/command/checkpoint: formatWrite: inline vars and use struct literals
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:19:10 +02:00
Sebastiaan van Stijn 8cb8056efa
cli/command/image: historyWrite: inline vars and use struct literals
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:19:10 +02:00
Sebastiaan van Stijn 7589722e93
cli/command/network: formatWrite: inline vars and use struct literals
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:19:09 +02:00
Sebastiaan van Stijn e06e758d5f
cli/command/system: TestVersionFormat: use table-test and struct literal
- Use a table-test to more easily allow adding test-cases
- Use the test-name itself as name for the golden file
- Use a struct-literal to create the fixture for formatting.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:11:35 +02:00
Sebastiaan van Stijn 58bb45c37f
Merge pull request #6336 from thaJeztah/internalize_formatters
cli/command/*: deprecate formatting-related functions and types
2025-08-22 08:29:16 +02:00
Sebastiaan van Stijn 95c9b1b13b
cli/command/trust: deprecate formatting-related functions and types
It's part of the presentation logic of the cli, and only used internally.
We can consider providing utilities for these, but better as part of
separate packages.

This deprecates the following types and functions:

- `SignedTagInfo`
- `SignerInfo`
- `NewTrustTagFormat`
- `NewSignerInfoFormat`
- `TagWrite`
- `SignerInfoWrite`

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-21 15:25:26 +02:00
Sebastiaan van Stijn c3ee82fdc3
cli/command/task: deprecate NewTaskFormat, FormatWrite
It's part of the presentation logic of the cli, and only used internally.
We can consider providing utilities for these, but better as part of
separate packages.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-21 15:25:26 +02:00
Sebastiaan van Stijn 9f453d3fea
cli/command/service: deprecate NewFormat, InspectFormatWrite
It's part of the presentation logic of the cli, and only used internally.
We can consider providing utilities for these, but better as part of
separate packages.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-21 15:25:26 +02:00
Sebastiaan van Stijn f3088e37a0
cli/command/secret: deprecate NewFormat, FormatWrite, InspectFormatWrite
It's part of the presentation logic of the cli, and only used internally.
We can consider providing utilities for these, but better as part of
separate packages.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-21 15:25:25 +02:00
Sebastiaan van Stijn 83371c2014
cli/command/registry: deprecate NewSearchFormat, SearchWrite
It's part of the presentation logic of the cli, and only used internally.
We can consider providing utilities for these, but better as part of
separate packages.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-21 15:25:25 +02:00
Sebastiaan van Stijn bf47419852
cli/command/plugin: deprecate NewFormat, FormatWrite
It's part of the presentation logic of the cli, and only used internally.
We can consider providing utilities for these, but better as part of
separate packages.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-21 15:25:25 +02:00
Sebastiaan van Stijn 123ef81f7d
cli/command/node: deprecate NewFormat, FormatWrite, InspectFormatWrite
It's part of the presentation logic of the cli, and only used internally.
We can consider providing utilities for these, but better as part of
separate packages.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-21 15:25:25 +02:00
Sebastiaan van Stijn e626f778ec
cli/command/config: deprecate NewFormat, FormatWrite, InspectFormatWrite
It's part of the presentation logic of the cli, and only used internally.
We can consider providing utilities for these, but better as part of
separate packages.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-21 15:25:25 +02:00
Sebastiaan van Stijn d861b78a8a
cli/command/checkpoint: deprecate NewFormat, FormatWrite
It's part of the presentation logic of the cli, and only used internally.
We can consider providing utilities for these, but better as part of
separate packages.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-21 15:25:24 +02:00
Sebastiaan van Stijn 15cf4fa912
cli/command/image: deprecate NewHistoryFormat, HistoryWrite
It's part of the presentation logic of the cli, and only used internally.
We can consider providing utilities for these, but better as part of
separate packages.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-21 15:25:24 +02:00
Sebastiaan van Stijn e3903a1ac8
cli/command/network: deprecate NewFormat, FormatWrite
It's part of the presentation logic of the cli, and only used internally.
We can consider providing utilities for these, but better as part of
separate packages.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-21 14:31:27 +02:00
Sebastiaan van Stijn b0d1d94711
Merge pull request #6330 from thaJeztah/internalize_ParseEnvFile
opts: deprecate ParseEnvFile
2025-08-21 13:35:39 +02:00
Sebastiaan van Stijn 8c0440a653
Merge pull request #6335 from thaJeztah/rm_exported_cobra_funcs
cli/command/*: remove deprecated cobra command constructors
2025-08-21 13:13:19 +02:00
Sebastiaan van Stijn 40e605a3b2
Merge pull request #6334 from thaJeztah/commands_nolock
internal/commands: remove mutexes / synchronisation and copy
2025-08-21 13:11:17 +02:00
Sebastiaan van Stijn 873609d790
cli/command/*: remove deprecated cobra command constructors
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-21 11:12:28 +02:00
Sebastiaan van Stijn 570a17b3bc
internal/commands: RegisterLegacy: remove redundant copy
The RegisterLegacy and Register functions register constructors for
commands, so we should expect them to be a fresh copy that is not
shared, which means that we can mutate the command in-place.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-21 10:47:26 +02:00
Sebastiaan van Stijn 4405c0bd50
internal/commands: remove mutexes / synchronisation
The Register and RegisterLegacy functions are designed to be used
in package init() functions, which are guaranteed to be run
sequentially.

From the documentation (https://go.dev/ref/mem#init);

> Program initialization runs in a single goroutine, but that goroutine
> may create other goroutines, which run concurrently. If a package `p`
> imports package `q`, the completion of `q`'s `init` functions happens
> before the start of any of `p`'s.
>
> The completion of all `init` functions is synchronized before the
> start of the function `main.main`.

This patch removes the synchonisation as no concurrency should happen
if these functions are used as intended.

As the internal queue is not expected to be mutated after use, we also
don't have to return a copy.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-21 10:42:02 +02:00
Sebastiaan van Stijn 942a6c4c76
Merge pull request #6329 from Benehiko/cli/commands
Register CLI commands implicitly
2025-08-21 09:23:30 +02:00
Alano Terblanche 56cab16779
Register CLI commands implicitly
This patch removes the explicit `commands.AddCommands` function and
instead relies upon the `internal/commands` package which registers each
CLI command using `init()` instead.

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-21 07:16:35 +02:00
Sebastiaan van Stijn 76c405cfdb
Merge pull request #6327 from thaJeztah/registryclient_simplify_repositoryEndpoint
internal/registryclient: repositoryEndpoint: memoize repoName
2025-08-20 15:04:16 +02:00
Sebastiaan van Stijn e650803f09
opts: deprecate ParseEnvFile
It was a wrapper around kvfile.Load, which should be used instead.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 15:03:05 +02:00
Alano Terblanche 4d93a6486e
Merge pull request #6328 from Benehiko/command/trust
Unexport trust commands
2025-08-20 12:18:16 +00:00
Alano Terblanche d071c29d4a
Merge pull request #6326 from Benehiko/command/plugin
Unexport plugin commands
2025-08-20 12:13:18 +00:00
Alano Terblanche 8d99b45d4a
Merge pull request #6325 from Benehiko/command/swarm
Unexport swarm commands
2025-08-20 12:08:40 +00:00
Alano Terblanche bd8e3e4440
Unexport trust commands
This patch deprecates exported trust commands and moves the implementation
details to an unexported function.

Commands that are affected include:

- trust.NewTrustCommand

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-20 14:07:45 +02:00
Alano Terblanche c6b7268932
Unexport plugin commands
This patch deprecates exported plugin commands and moves the implementation
details to an unexported function.

Commands that are affected include:

- plugin.NewPluginCommand

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-20 14:03:57 +02:00
Sebastiaan van Stijn 2ce94e4fff
internal/registryclient: repositoryEndpoint: memoize repoName
- Parse/format the repository name when constructing and store the
  result.
- Remove the Name() accessor, as this type is only used internally,
  and no longer had any special handling.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 14:02:26 +02:00
Alano Terblanche bf39340294
Unexport swarm commands
This patch deprecates exported swarm commands and moves the implementation
details to an unexported function.

Commands that are affected include:

- swarm.NewSwarmCommand

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-20 13:59:30 +02:00
Alano Terblanche b2b7187244
Merge pull request #6324 from Benehiko/command/registry
Unexport registry commands
2025-08-20 11:43:43 +00:00
Alano Terblanche 7dfcb06587
Merge pull request #6322 from Benehiko/command/context
Unexport context command
2025-08-20 11:40:09 +00:00
Alano Terblanche d4588c711c
Unexport registry commands
This patch deprecates exported registry commands and moves the implementation
details to an unexported function.

Commands that are affected include:

- registry.NewLoginCommand
- registry.NewLogoutCommand
- registry.NewSearchCommand

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-20 13:39:06 +02:00
Alano Terblanche bf9173f383
Merge pull request #6323 from Benehiko/command/stack
Unexport stack commands
2025-08-20 11:36:40 +00:00
Alano Terblanche 630fe430ff
Unexport stack commands
This patch deprecates exported stack commands and moves the implementation
details to an unexported function.

Commands that are affected include:

- stack.NewStackCommand

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-20 13:27:11 +02:00
Alano Terblanche 3b0edc794c
Unexport context command
This patch deprecates exported context commands and moves the implementation
details to an unexported function.

Commands that are affected include:

- context.NewContextCommand

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-20 13:22:47 +02:00
Alano Terblanche 89316e18fc
Merge pull request #6321 from Benehiko/command/volume
Unexport volume commands
2025-08-20 11:18:35 +00:00
Alano Terblanche 7a50955006
Merge pull request #6320 from Benehiko/command/service
Unexport service commands
2025-08-20 10:57:33 +00:00
Alano Terblanche 9961e39d40
Unexport volume commands
This patch deprecates exported volume commands and moves the implementation
details to an unexported function.

Commands that are affected include:

- volume.NewVolumeCommand
- volume.NewPruneCommand

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-20 12:57:33 +02:00
Alano Terblanche 88178eda32
Unexport service commands
This patch deprecates exported service commands and moves the implementation
details to an unexported function.

Commands that are affected include:

- service.NewServiceCommand

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-20 12:51:55 +02:00
Sebastiaan van Stijn cd859b33b4
Merge pull request #6318 from Benehiko/command/manifest
Unexport manifest command
2025-08-20 12:51:14 +02:00
Alano Terblanche 1d34432676
Merge pull request #6319 from Benehiko/command/secret
Unexport secret commands
2025-08-20 10:49:06 +00:00
Alano Terblanche e00762ed7d
Unexport secret commands
This patch deprecates exported secret commands and moves the implementation
details to an unexported function.

Commands that are affected include:

- secrets.NewSecretCommand

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-20 12:45:11 +02:00
Sebastiaan van Stijn 6b58c4d545
Merge pull request #6317 from Benehiko/command/node
Unexport node commands
2025-08-20 12:43:50 +02:00
Sebastiaan van Stijn 642adae0c0
Merge pull request #6316 from Benehiko/command/network
Unexport network commands
2025-08-20 12:42:57 +02:00
Alano Terblanche 02fda07211
Unexport manifest command
This patch deprecates exported manifest commands and moves the implementation
details to an unexported function.

Commands that are affected include:

- manifest.NewManifestCommand

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-20 12:40:26 +02:00
Alano Terblanche ab3fcf9f9b
Unexport node commands
This patch deprecates exported node commands and moves the implementation
details to an unexported function.

Commands that are affected include:

- node.NewNodeCommand

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-20 12:34:49 +02:00
Alano Terblanche 78a8856c14
Unexport network commands
This patch deprecates exported network commands and moves the
implementation details to an unexported function.

Commands that are affected include:

- network.NewNetworkCommand
- network.NewPruneCommand

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-20 12:32:09 +02:00
Sebastiaan van Stijn 4643b42e1d
Merge pull request #6314 from thaJeztah/auth_cleanups
cli/command: fix godoc links and inline resolveAuthConfigFromImage
2025-08-20 11:57:34 +02:00
Paweł Gronowski 86e2a06f1b
Merge pull request #6296 from thaJeztah/cli_rm_deprecated_utils
cli: remove deprecated VisitAll, DisableFlagsInUseLine utilities
2025-08-20 11:42:45 +02:00
Sebastiaan van Stijn 4286883b95
cli/command: inline resolveAuthConfigFromImage
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-19 23:42:07 +02:00
Sebastiaan van Stijn 2d3b0b33b4
cli/command: fix godoc links
- Use versioned links to github.com/docker/docker packages
- Fix links to RFC 4648, section 5

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-19 23:42:03 +02:00
Sebastiaan van Stijn c3170f1c81
Merge pull request #6293 from thaJeztah/remove_deprecated_opts
opts: remove deprecated types and functions
2025-08-19 21:03:59 +02:00
Austin Vazquez 73d88f514b
Merge pull request #6306 from thaJeztah/remove_quote_handling
cli/flags: remove special quote handling for `--tlsXXX` flags
2025-08-19 11:36:23 -07:00
Sebastiaan van Stijn 9ca4ae9e70
Merge pull request #6305 from Benehiko/commands/system
Unexport system commands
2025-08-19 15:27:15 +02:00
Sebastiaan van Stijn 11a60e871e
Merge pull request #6304 from thaJeztah/internalize_registryclient
cli/registry/client: deprecate and move internal
2025-08-19 15:26:10 +02:00
Sebastiaan van Stijn 57ef7eed46
Merge pull request #6303 from thaJeztah/deprecated_nit
docs: deprecated: fix formatting of deprecated/removed in
2025-08-19 15:23:39 +02:00
Sebastiaan van Stijn 9b9d103b29
cli/flags: remove special quote handling for `--tlsXXX` flags
This non-standard handling for these options was added in [moby@e4c1f07]
and [moby@abe32de] to work around a regression in Docker 1.13 that caused
`docker-machine` to fail. Preserving quotes in such cases is expected (and
standard behavior), but versions of Docker before 1.13 used a custom "mflag"
package for flag parsing, and that package contained custom handling for
quotes (added in [moby@0e9c40e]).

Given that Docker Machine reached EOL a long time ago and other options,
such as `docker context`, have been added to configure the CLI to connect
to a specific host (with corresponding TLS configuration), we can remove
the special handling for these flags, as it's inconsistent with all other
flags, and not worth maintaining for a tool that no longer exists.

[moby@e4c1f07]: e4c1f07729
[moby@abe32de]: abe32de6b4
[moby@0e9c40e]: 0e9c40eb82

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-19 15:21:17 +02:00
Alano Terblanche cfb8cb91f2
Unexport system commands
This patch deprecates exported system commands and moves the
implementation details to an unexported function.

Commands that are affected include:

- system.NewVersionCommand
- system.NewInfoCommand
- system.NewSystemCommand
- system.NewEventsCommand
- system.NewInspectCommand

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-19 15:17:41 +02:00
Sebastiaan van Stijn 1d571d178d
docs: deprecated: fix formatting of deprecated/removed in
- Use sentence-case to follow our docs guidelines.
- Add newlines to prevent these being rendered on a
  single line.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-19 15:04:53 +02:00
Sebastiaan van Stijn 2e3d021912
Merge pull request #6263 from akerouanton/deprecate-legacy-links-env-vars
docs/deprecated: legacy links env vars
2025-08-19 15:01:18 +02:00
Sebastiaan van Stijn 13010ba673
cli/registry/client: deprecate and move internal
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-19 14:57:00 +02:00
Albin Kerouanton 5c76f7f2d8
docs/deprecated: legacy links env vars
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
Co-authored-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-19 14:45:53 +02:00
Sebastiaan van Stijn c2a042e0ed
Merge pull request #6301 from Benehiko/commands/image
Unexport image commands
2025-08-19 14:37:12 +02:00
Alano Terblanche e66a1456d3
Unexport image commands
This patch deprecates exported image commands and moves the
implementation details to an unexported function.

Commands that are affected include:

- image.NewBuildCommand
- image.NewPullCommand
- image.NewPushCommand
- image.NewImagesCommand
- image.NewImageCommand
- image.NewHistoryCommand
- image.NewImportCommand
- image.NewLoadCommand
- image.NewRemoveCommand
- image.NewSaveCommand
- image.NewTagCommand
- image.NewPruneCommand

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-19 14:25:15 +02:00
Sebastiaan van Stijn fcb260df1b
Merge pull request #6299 from Benehiko/commands/container
Unexport container commands
2025-08-19 13:03:55 +02:00
Sebastiaan van Stijn 6e5ce4df55
Merge pull request #6300 from thaJeztah/rm_decodeauthconfig
cli/command: TestRetrieveAuthTokenFromImage: don't decode authconfig
2025-08-19 12:48:50 +02:00
Sebastiaan van Stijn ae1727c41e
cli/command: TestRetrieveAuthTokenFromImage: don't decode authconfig
Rewrite the test to not depend on registry.DecodeAuthConfig, which
may be moved internal to the daemon as part of the modules transition.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-19 12:39:10 +02:00
Alano Terblanche 38595fecb6
Unexport container commands
This patch deprecates exported container commands and moves the
implementation details to an unexported function.

Commands that are affected include:
- container.NewRunCommand
- container.NewExecCommand
- container.NewPsCommand
- container.NewContainerCommand
- container.NewAttachCommand
- container.NewCommitCommand
- container.NewCopyCommand
- container.NewCreateCommand
- container.NewDiffCommand
- container.NewExportCommand
- container.NewKillCommand
- container.NewLogsCommand
- container.NewPauseCommand
- container.NewPortCommand
- container.NewRenameCommand
- container.NewRestartCommand
- container.NewRmCommand
- container.NewStartCommand
- container.NewStatsCommand
- container.NewStopCommand
- container.NewTopCommand
- container.NewUnpauseCommand
- container.NewUpdateCommand
- container.NewWaitCommand
- container.NewPruneCommand

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-19 11:12:19 +02:00
Sebastiaan van Stijn 4c3fa4ac3c
Merge pull request #6286 from Benehiko/commands/config
Unexport config command
2025-08-19 10:28:52 +02:00
Sebastiaan van Stijn 6ad1d4617a
Merge pull request #6285 from Benehiko/commands/checkpoint
Unexport checkpoint command
2025-08-19 10:27:49 +02:00
Sebastiaan van Stijn 2d979220cc
Merge pull request #6284 from Benehiko/commands/builder
Unexport the builder and bake stub command
2025-08-19 10:26:25 +02:00
Alano Terblanche cce29da061
Unexport config command
This patch unexports the `config` command.

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-19 08:49:31 +02:00
Alano Terblanche 3265cead1d
Unexport checkpoint command
This patch unexports the `checkpoint` command.

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-19 08:49:05 +02:00
Alano Terblanche 1b9d0762a5
Unexport the builder command and bake stub command
This patch unexports the `builder` and `bake` stub command and it adds
deprecation notices on the exported functions.

It also registers the commands using the new `cli/internal/commands`
package when the init function executes.

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-19 08:48:30 +02:00
Austin Vazquez 6dcf9ac843
Merge pull request #6297 from thaJeztah/plugin_manager_more_deprecations
cli-plugins/manager: deprecate annotation metadata aliases
2025-08-18 20:30:02 -07:00
Sebastiaan van Stijn 72f76f2720
cli-plugins/manager: deprecate annotation metadata aliases
These aliases were added in 292713c887
(part of v28.0), but did not deprecate them. They are no longer used
in the CLI itself, but may be used by cli-plugin implementations.

This deprecates the aliases in `cli-plugins/manager` in favor of
their equivalent in `cli-plugins/manager/metadata`:

- `CommandAnnotationPlugin`
- `CommandAnnotationPluginVendor`
- `CommandAnnotationPluginVersion`
- `CommandAnnotationPluginInvalid`
- `CommandAnnotationPluginCommandPath`

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-18 21:50:53 +02:00
Sebastiaan van Stijn f9777d2517
cli: remove deprecated VisitAll, DisableFlagsInUseLine utilities
These were deprecated in 6bd8a4b2b5, and
are no longer used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-18 21:35:05 +02:00
Sebastiaan van Stijn 5934553198
opts: remove deprecated NewNamedListOptsRef, NewNamedMapOpts
These were deprecated in 6f0c66c152 and are
no longer used.

This removes the deprecated:

- `NewNamedListOptsRef`
- `NewNamedMapOpts`
- `NamedListOpts`
- `NamedMapOpts`
- `NamedOption`

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-18 18:55:54 +02:00
Sebastiaan van Stijn a056cc6164
opts: remove deprecated ListOpts.GetAll
It's no longer used and replaced by `ListOpts.GetSlice`. It was deprecated
in 5215b1eca4

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-18 18:55:50 +02:00
Sebastiaan van Stijn 15f3e910d1
opts: remove deprecated ValidateHost
This function is no longer used, and was deprecated in
d0ac0acff0.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-18 18:40:05 +02:00
Sebastiaan van Stijn 0c07d81a03
opts: remove deprecated QuotedString
This type is no longer used, and was deprecated in
187a942a88

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-18 18:37:15 +02:00
Sebastiaan van Stijn e0af501e30
Merge pull request #6288 from thaJeztah/deprecate_opts
opts: deprecate NewNamedListOptsRef, NewNamedMapOpts
2025-08-18 18:20:04 +02:00
Sebastiaan van Stijn 5f5a5e1297
Merge pull request #6290 from thaJeztah/deprecate_quoted_values
Deprecate special handling for quoted values for TLS flags
2025-08-18 18:16:56 +02:00
Sebastiaan van Stijn ee05a71513
Deprecate special handling for quoted values for TLS flags
The `--tlscacert`, `--tlscert`, and `--tlskey` command-line flags had
non-standard behavior for handling values contained in quotes (`"` or `'`).
Normally, quotes are handled by the shell, for example, in the following
example, the shell takes care of handling quotes before passing the values
to the `docker` CLI:

    docker --some-option "some-value-in-quotes" ...

However, when passing values using an equal sign (`=`), this may not happen
and values may be handled including quotes;

    docker --some-option="some-value-in-quotes" ...

This caused issues with "Docker Machine", which used this format as part
of its `docker-machine config` output, and the CLI carried special, non-standard
handling for these flags.

Docker Machine reached EOL, and this special handling made the processing
of flag values inconsistent with other flags used, so this behavior is
deprecated. Users depending on this behavior are recommended to specify
the quoted values using a space between the flag and its value, as illustrated
above.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-18 17:59:16 +02:00
Sebastiaan van Stijn 6f0c66c152
opts: deprecate NewNamedListOptsRef, NewNamedMapOpts
The `NewNamedListOptsRef`, `NewNamedMapOpts` and related `NamedListOpts`,
`NamedMapOpts`, and `NamedOption` interface were added in [moby@677a6b3],
which added support for a `daemon.json` configuration file. That change
required a way to correlate command-line flags with their corresponding
fields in the `daemon.json` to detect conflicting options. At the time,
the CLI and daemon were produced from the same code, and shared packages
for command-line options, but when the CLI was moved to a separate
repository, these options were inherited.

[moby@677a6b3]: 677a6b3506

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-18 17:27:02 +02:00
Sebastiaan van Stijn 5f6dfb00d8
Merge pull request #6287 from thaJeztah/progress_test
cli/command/container: TestRunPullTermination: rewrite with streamformatter
2025-08-18 17:07:32 +02:00
Alano Terblanche c06074b22f
Merge pull request #6283 from Benehiko/command/registration
Add command registration helpers
2025-08-18 15:02:15 +00:00
Alano Terblanche 4ead8784d0
Add command registration helpers
This patch adds helper methods to the CLI to register cobra commands.

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-08-18 16:56:35 +02:00
Sebastiaan van Stijn 69854c4e08
cli/command/container: TestRunPullTermination: rewrite with streamformatter
This makes the test slightly closer to the actual code in the daemon producing
the progress response;
cd844fd0b2/daemon/images/image_pull.go (L58-L70)
cd844fd0b2/daemon/internal/distribution/utils/progress.go (L14-L34)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-18 15:21:14 +02:00
Sebastiaan van Stijn 877a6ef29f
Merge pull request #6273 from thaJeztah/cli_internalize_utils
cli: deprecate VisitAll, DisableFlagsInUseLine utilities, remove HasCompletionArg
2025-08-18 11:40:47 +02:00
Sebastiaan van Stijn 2bcf433605
Merge pull request #6281 from thaJeztah/hosts_regular_stringarray
cli/flags: add "hostVar" to handle --host / -H as a single string
2025-08-18 11:24:10 +02:00
Sebastiaan van Stijn f14eeeb361
cli/flags: add "hostVar" to handle --host / -H as a single string
hostVar is used for the '--host' / '-H' flag to set [ClientOptions.Hosts].
The [ClientOptions.Hosts] field is a slice because it was originally shared
with the daemon config. However, the CLI only allows for a single host to
be specified.

hostVar presents itself as a "string", but stores the value in a string
slice. It produces an error when trying to set multiple values, matching
the check in [getServerHost].

[getServerHost]: 7eab668982/cli/command/cli.go (L542-L551)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-18 11:01:39 +02:00
Sebastiaan van Stijn 5ee2906e78
cli/flags: use a regular StringArray for the `--host` / `-H` flag
The ClientOptions struct and related flags were inherited from the Moby
repository, where originally the CLI and Daemon used the same implementation
and had a "Common" options struct. When the CLI moved to a separate repository,
those structs were duplicated, but some daemon-specific logic remained. For
example, the daemon can be configured to listen on multiple ports and sockets
([moby@dede158]), but the CLI [can only connect to a single host][1]. The
daemon config also had to account for flags conflicting with `daemon.json`,
and use special flag-vars for this ([moby@677a6b3]).

Unfortunately, the `ClientConfig` struct became part of the public API and
is used as argument in various places, but we can remove the use of the
special flag var. This patch replaces the use of `NewNamedListOptsRef`
for a regular `StringArray`.

Unfortunately this changes the flag's type description from `list` to
`stringArray`, but we can look at changing that separately.

[moby@dede158]: dede1585ee
[1]: 0af135e906/docker/docker.go (L191-L193)
[moby@677a6b3]: 677a6b3506

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-16 19:13:27 +02:00
Austin Vazquez 7eab668982
Merge pull request #6279 from thaJeztah/deprecate_ValidateHost
opts: deprecate ValidateHost utility
2025-08-16 07:21:40 -07:00
Austin Vazquez ccc1c65859
Merge pull request #6270 from thaJeztah/fix_prune_example
docs: fix output example for docker system prune
2025-08-16 07:20:13 -07:00
Austin Vazquez 842f8beb00
Merge pull request #6274 from thaJeztah/deprecate_quotedstring
opts: deprecate QuotedString
2025-08-15 13:19:26 -07:00
Sebastiaan van Stijn d0ac0acff0
opts: deprecate ValidateHost utility
The `ValidateHost` option was introduced in [moby@1ba1138] to be used
as validation func for the `--host` flag on the daemon in and CLI in
[moby@5e3f6e7], but is no longer used since [cli@6f61cf0]. which added
support for `ssh://` connections, and required validation elsewhere.

[moby@1ba1138]: 1ba11384bf
[moby@5e3f6e7]: 5e3f6e7023
[cli@6f61cf0]: 6f61cf053a

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 22:16:11 +02:00
Sebastiaan van Stijn 187a942a88
opts: deprecate QuotedString
The `QuotedString` option was added in [moby@e4c1f07] and [moby@abe32de]
to work around a regression in Docker 1.13 that caused `docker-machine`
to fail. `docker-machine` produced instructions on how to set up a cli
to connect to the Machine it produced. These instructions used quotes
around the paths for TLS certificates, but with an `=` for the flag's
values instead of a space; due to this the shell would not handle
stripping quotes, so the CLI would now get the value including quotes.

Preserving quotes in such cases is expected (and standard behavior), but
versions of Docker before 1.13 used a custom "mflag" package for flag
parsing, and that package contained custom handling for quotes (added
in [moby@0e9c40e]).

For other flags, this problem could be solved by the user, but as these
instructions were produced by `docker-machine`'s `config` command, an
exception was made for the `--tls-xxx` flags. From [moby-29761]:

> The flag trimming behaviour is really unusual, and I would say unexpected.
> I think removing it is generally the right idea. Since we have one very
> common case where it's necessary for backwards compatibility we need to
> add a special case, but I don't think we should apply that case to every
> flag.

The `QuotedString` implementation has various limitations, as it doesn't
follow the same handling of quotes as a shell would.

Given that Docker Machine reached EOL a long time ago and other options,
such as `docker context`, have been added to configure the CLI to connect
to a specific host (with corresponding TLS configuration), we should remove
the special handling for these flags, as it's inconsitent with all other
flags, and not worth maintaining for a tool that no longer exists.

This patch deprecates the `QuotedString` option and removes its use. A
temporary, non-exported copy is added, but will be removed in the next
release.

[moby-29761]: https://github.com/moby/moby/issues/29761#issuecomment-270211265
[moby@e4c1f07]: e4c1f07729
[moby@abe32de]: abe32de6b4
[moby@0e9c40e]: 0e9c40eb82
[moby@c79a169]: c79a169a35

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 18:58:09 +02:00
Sebastiaan van Stijn 5a38118956
cmd/docker: fix some minor linting issues
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 17:45:26 +02:00
Sebastiaan van Stijn 6bd8a4b2b5
cli: deprecate VisitAll, DisableFlagsInUseLine utilities
These utilities were only used internally; create a local copy
where used, and deprecate the ones in cli.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 17:45:21 +02:00
Sebastiaan van Stijn 5a99022556
cli: remove HasCompletionArg utility
It was only used in a single place and has no external consumers.
Move it to where it's used to keep things together.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 14:21:47 +02:00
Sebastiaan van Stijn bf13010df8
docs: fix output example for docker system prune
The example shows that the `--volumes` option is used, which in current
versions of docker only removes "anonymous" volumes, but preserves named
volume:

    $ docker system prune -a --volumes
    ...
            - all anonymous volumes not used by at least one container
    ...

But the example output showed that a named volume ("named-vol") was
deleted;

    Deleted Volumes:
    named-vol

Co-authored-by: Roberto Villarreal <rrjjvv@yahoo.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 12:55:03 +02:00
Sebastiaan van Stijn 53b6fddced
Merge pull request #6261 from vvoland/gha-fix
gha/validate-pr: Replace `continue-on-error`
2025-08-14 14:17:43 +02:00
Paweł Gronowski 4cd9833d7c
gha/validate-pr: Replace `continue-on-error`
The label validation steps now properly fail the workflow when required
labels are missing, instead of continuing with errors.

This change removes the `continue-on-error: true` directives and adds
`always()` conditions to ensure the validation steps run regardless of
previous step outcomes.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-08-14 12:50:00 +02:00
Paweł Gronowski 4bff12f476
Merge pull request #6260 from vvoland/gha-changelog-kind
.github/workflows: Add kind label validation to PR workflow
2025-08-14 11:25:41 +02:00
Paweł Gronowski 1456b53e4e
.github/workflows: Add kind label validation to PR workflow
The PR validation workflow now enforces that every PR with an 'impact/*'
label must also have a corresponding 'kind/*' label, in addition to the
existing 'area/*' label requirement.

This change helps ensure proper categorization of pull requests by
requiring contributors to specify both the impact area and the kind of
change being made.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-08-14 10:34:07 +02:00
Paweł Gronowski 6d9b06d227
gha/validate-pr: Run on synchronize
Align with moby/moby

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-08-14 10:33:59 +02:00
Sebastiaan van Stijn e8876edcc2
Merge pull request #6254 from thaJeztah/cp_cleanup
cli/command/container: copyToContainer: improve error-handling
2025-08-13 11:22:30 +02:00
Sebastiaan van Stijn eb5b03a8a3
cli/command/container: copyToContainer: improve error-handling
The logic used in this function was confusing; some errors were ignored,
but responses handled regardless. The intent here is to try to detect
whether the destination exists inside the container and is of the right
"type" (otherwise produce an error).

Failing to "stat" the path in the container means we can't produce a
nice error for the user, but we'll continue the request, which either
would succeed or produce an error returned by the daemon.

While working on this patch, I noticed that some error-handling on the
daemon side is incorrect. This patch does not fix those cases, but
makes the logic slightly easier to follow (we should consider extracting
the "stat" code to a separate function though).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-13 00:24:31 +02:00
Sebastiaan van Stijn b71a055a11
Merge pull request #6253 from docker/dependabot/github_actions/actions/checkout-5
build(deps): bump actions/checkout from 4 to 5
2025-08-13 00:14:50 +02:00
Sebastiaan van Stijn c5ea9079af
cli/command/container: copyToContainer rename error-return
Make it more clearly identifiable where we're dealing with the
named error-return

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-12 18:53:12 +02:00
dependabot[bot] f2af519f2e
build(deps): bump actions/checkout from 4 to 5
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-12 16:52:05 +00:00
Sebastiaan van Stijn bd0546ad5b
Merge pull request #6252 from thaJeztah/less_pkg_errors
reduce uses of pkg/errors
2025-08-12 07:44:16 +02:00
Sebastiaan van Stijn 27a7947535
cli/command/image/build/internal/git: use stdlib errors
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-11 19:00:09 +02:00
Sebastiaan van Stijn 53183396d7
internal/volumespec: use stdlib errors
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-11 19:00:08 +02:00
Sebastiaan van Stijn 70f1147394
cli/command/trust: use stdlib errors
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-11 19:00:08 +02:00
Sebastiaan van Stijn a8f11a2fa2
cli/command/formatter: use stdlib errors
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-11 19:00:08 +02:00
Sebastiaan van Stijn c612e141b5
cli/command/registry: use stdlib errors
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-11 19:00:08 +02:00
Sebastiaan van Stijn 9b7ee0e201
cli/config: use stdlib errors
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-11 19:00:08 +02:00
Sebastiaan van Stijn 3b677449d8
cli/context: use stdlib errors
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-11 19:00:08 +02:00
Sebastiaan van Stijn d38317c781
cli/compose: use stdlib errors
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-11 19:00:07 +02:00
Sebastiaan van Stijn 2dd462cc36
cli/command/idresolver: use stdlib errors
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-11 19:00:07 +02:00
Sebastiaan van Stijn 4c89455378
cli/registry/client: use stdlib errors
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-11 19:00:07 +02:00
Sebastiaan van Stijn adbe04b5fc
cli/manifest, cli/command/manifest: use stdlib errors
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-11 19:00:07 +02:00
Sebastiaan van Stijn 097cc9ca64
cli/trust: use stdlib errors
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-11 19:00:07 +02:00
Sebastiaan van Stijn e069ded4c3
cli: reduce uses of pkg/errors for stdlib errors
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-11 19:00:02 +02:00
Sebastiaan van Stijn 44eba133d6
Merge pull request #6250 from thaJeztah/bump_go_connections
vendor: github.com/docker/go-connections v0.6.0
2025-08-11 15:56:03 +02:00
Sebastiaan van Stijn 3529651fa7
vendor: github.com/docker/go-connections v0.6.0
- deprecate sockets.GetProxyEnv, sockets.DialerFromEnvironment
- add support for unix sockets on Windows
- remove legacy CBC cipher suites from client config
- align client and server defaults to be the same.
- remove support for encrypted TLS private keys.
- nat: optimize ParsePortSpec

full diff: https://github.com/docker/go-connections/compare/v0.5.0...v0.6.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-11 15:33:22 +02:00
Sebastiaan van Stijn 8324b17f9a
Merge pull request #6249 from thaJeztah/skip_TestPromptExitCode
e2d skip flaky test: TestPromptExitCode/plugin_upgrade, plugin_install
2025-08-11 15:06:56 +02:00
Sebastiaan van Stijn d16defd9e2
Merge pull request #6247 from austinvazquez/update-golang-1.24.6
update to go1.24.6
2025-08-08 19:56:53 +02:00
Sebastiaan van Stijn 3035b6685b
e2d skip flaky test: TestPromptExitCode/plugin_upgrade, plugin_install
This test was recently rewritten from testing plugin upgrade with
DCT enabled to just "plugin upgrade", but there's a fair amount of
complexity in the e2e tests that set up different daemons and registries.

It's possible that tests are affecting each-other, and some state (config)
is left behind.

Let's skip the test for now, and add a tracking ticket to dig deeper.

    === FAIL: e2e/global TestPromptExitCode/plugin_upgrade (7.55s)
        cli_test.go:205: assertion failed:
            Command:  docker plugin push registry:5000/plugin-upgrade-test:latest
            ExitCode: 1
            Error:    exit status 1
            Stdout:   The push refers to repository [registry:5000/plugin-upgrade-test]
            459089aa5943: Preparing
            adc41078d1d9: Preparing
            d7bff979db13: Preparing
            459089aa5943: Preparing

            Stderr:   error pushing plugin: failed to do request: Head "https://registry:5000/v2/plugin-upgrade-test/blobs/sha256:adc41078d1d937495df2f90444e5414a01db31e5a080f8aa4f163c64d41abd11": http: server gave HTTP response to HTTPS client

            Failures:
            ExitCode was 1 expected 0
            Expected no error

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-08 19:07:00 +02:00
Austin Vazquez 6769f62746
update to go1.24.6
- https://github.com/golang/go/issues?q=milestone%3AGo1.24.6+label%3ACherryPickApproved
- full diff: golang/go@go1.24.5...go1.24.6

These minor releases include 2 security fixes following the security policy:

- os/exec: LookPath may return unexpected paths

If the PATH environment variable contains paths which are executables (rather
than just directories), passing certain strings to LookPath ("", ".", and ".."),
can result in the binaries listed in the PATH being unexpectedly returned.

Thanks to Olivier Mengué for reporting this issue.

This is CVE-2025-47906 and Go issue https://go.dev/issue/74466.

- database/sql: incorrect results returned from Rows.Scan

Cancelling a query (e.g. by cancelling the context passed to one of the query
methods) during a call to the Scan method of the returned Rows can result in
unexpected results if other queries are being made in parallel. This can result
in a race condition that may overwrite the expected results with those of
another query, causing the call to Scan to return either unexpected results
from the other query or an error.

We believe this affects most database/sql drivers.

Thanks to Spike Curtis from Coder for reporting this issue.

This is CVE-2025-47907 and https://go.dev/issue/74831.

View the release notes for more information:
https://go.dev/doc/devel/release#go1.24.6

Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
2025-08-08 10:15:50 -05:00
Sebastiaan van Stijn ef38d81fdb
Merge pull request #6245 from thaJeztah/rm_completion
cli/command/completion: remove deprecated ValidArgsFn
2025-08-07 13:52:04 +02:00
Sebastiaan van Stijn 5052a39915
cli/command/completion: remove deprecated ValidArgsFn
This was deprecated in 9f19820f88, which
is part of v28.x, and unlikely used externally.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-06 23:53:56 +02:00
Sebastiaan van Stijn 4beddd3e25
Merge pull request #6244 from thaJeztah/remove_trust_flag_helpers
cli/command: remove `AddTrustSigningFlags`, `AddTrustVerificationFlags`, `AddPlatformFlag` utilities
2025-08-06 19:37:36 +02:00
Sebastiaan van Stijn 7026e68a71
cli/command: remove AddPlatformFlag utility
It was only used internally and has no external users. It should not be
used for new uses, because it also adds a minimum API version constraint
and a default from env-var, which must be evaluated for each individual
use of such flags.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-06 17:15:32 +02:00
Sebastiaan van Stijn c0fbbe05ca
cli/command: remove AddTrustVerificationFlags
It was only used internally; inline it where used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-06 17:00:25 +02:00
Sebastiaan van Stijn 8c22927978
cli/command: remove AddTrustSigningFlags
it was only used internally in a single location, so inline the
code where it's used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-06 16:55:42 +02:00
Sebastiaan van Stijn c1cc6b61a3
Merge pull request #6233 from thaJeztah/plugin_no_dct
cli/command/plugin: remove DCT
2025-08-06 14:04:01 +02:00
Sebastiaan van Stijn 3f5b1bdd32
cli/command/plugin: remove DCT
Plugins are not widely used, and there's no known plugins that use
content-trust. We're working on updating the authentication stack
in the CLI, and the trust implementation hinders us in making
changes, so removing parts that are not high-priority (ahead of
full deprecation of DCT).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-06 12:33:27 +02:00
Sebastiaan van Stijn 845870e669
Merge pull request #6243 from thaJeztah/remove_prompt_utils
cli/command: remove prompt utilities that were for internal use
2025-08-06 12:30:31 +02:00
Sebastiaan van Stijn 8683664b29
Merge pull request #6238 from thaJeztah/e2e_touchups
e2e: minor cleanups in `TestPromptExitCode`
2025-08-06 12:30:08 +02:00
Sebastiaan van Stijn d3c23a223c
e2e/global: TestPromptExitCode: group plugin preparation steps
Use names for the plugin that don't refer to content-trust, as that's
not related to this test.

Make it slightly more clear which steps are preparation and which
are the actual test. The test sometimes fails in the preparation
step, and we could consider moving those separate and XFail the
test if the preparation fails;

        Stderr:   error pushing plugin: failed to do request: Head "https://registry:5000/v2/plugin-content-trust-upgrade/blobs/sha256:af932a31d4df3a2890f900bcf28e16cea87b2b440b8036ba86ab3418f3e50a35": http: server gave HTTP response to HTTPS client

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-06 10:57:01 +02:00
Sebastiaan van Stijn 081add2fc5
e2e/testutils: SetupPlugin: return path of directory
The gotest.tools `fs.NewDir` utility already sets up a `t.Cleanup`,
so we can treat it the same as `t.TempDir()` and let it handle
cleaning up by itself.

We should probably consider replacing some of this with `t.TempDir`.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-06 10:57:01 +02:00
Sebastiaan van Stijn 8972e53ad0
cli/command: remove prompt utilities that were for internal use
- The `DisableInputEcho` and `PromptForInput` utilities were added in
  c15ade0c64 as part of a bug-fix, which
  was part of v28.x. [There are no (publicly visible) users][1] of either.
- The `ErrPromptTerminated` was added in v26.x (originally added in
  10bf91a02d, later updated in commit
  7c722c08d0. [It is not used][2]
- The `PromptForConfirmation` was added in [moby@280c872] (docker v1.13.0)
  as part of the `docker <object> prune` subcommands. It was meant for
  internal use but exported to allow re-using it in the `container`,
  `image` (etc.) packages. However, a breaking change to its signature
  was made in 10bf91a02d. It currently
  does [not appear to have any (public) users][2].

This patch removes the `ErrPromptTerminated`, `DisableInputEcho`,
`PromptForInput`, and `PromptForConfirmation` utilities from the
`cli/command` package. The core functionality of these is still
available in the `internal/prompt` package, which we may make
public at some point, but still needs some refining / decoupling.

[moby@280c872]: 280c872366
[1]: https://grep.app/search?f.lang=Go&regexp=true&q=%5C.%28DisableInputEcho%7CPromptForInput%29%5C%28
[2]: https://grep.app/search?f.lang=Go&q=%5C.ErrPromptTerminated
[3]: https://grep.app/search?f.lang=Go&q=.PromptForConfirmation%28

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-06 10:50:31 +02:00
Sebastiaan van Stijn f2c64c123f
Merge pull request #6241 from thaJeztah/deprecate_bind_nonrecursive
remove deprecated `bind-nonrecursive` option for `--mount`
2025-08-06 10:48:58 +02:00
Sebastiaan van Stijn 25f95877b5
Merge pull request #6219 from thaJeztah/cleanup_credentialSpecOpt
cli/command/service: credentialSpecOpt: use strings.Cut
2025-08-06 10:09:26 +02:00
Sebastiaan van Stijn 14ed619736
Merge pull request #6240 from thaJeztah/remove_deprecated
cli/command: remove deprecated CopyToFile, ConfigureAuth utilities
2025-08-06 10:08:33 +02:00
Sebastiaan van Stijn 7dd9c20cac
Merge pull request #6235 from thaJeztah/remove_cli_experimental_remnants
remove some remnants from CLI "experimental" config option
2025-08-06 09:50:27 +02:00
Paweł Gronowski 39829affbe
Merge pull request #6242 from thaJeztah/bump_mergo
vendor: dario.cat/mergo v1.0.2
2025-08-06 07:33:22 +00:00
Sebastiaan van Stijn a93ed48d06
vendor: dario.cat/mergo v1.0.2
drops gopkg.in/yaml.v3 as dependency

full diff: https://github.com/darccio/mergo/compare/v1.0.1...v1.0.2

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-06 01:16:17 +02:00
Sebastiaan van Stijn f1ceb8c55d
Merge pull request #6236 from thaJeztah/system_prune_register
system prune: refactor to use "register" functions
2025-08-05 23:25:51 +02:00
Sebastiaan van Stijn abfe4d4629
remove deprecated `bind-nonrecursive` option for `--mount`
The `bind-nonrecursive` option was replaced with the [`bind-recursive`]
option (see [cli-4316], [cli-4671]). The option was still accepted, but
printed a deprecation warning:

    bind-nonrecursive is deprecated, use bind-recursive=disabled instead

In the v29.0 release, this warning is removed, and returned as an error.
Users should use the equivalent `bind-recursive=disabled` option instead.

[`bind-recursive`]: https://docs.docker.com/engine/storage/bind-mounts/#recursive-mounts
[cli-4316]: https://github.com/docker/cli/pull/4316
[cli-4671]: https://github.com/docker/cli/pull/4671

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-05 23:23:38 +02:00
Sebastiaan van Stijn 68fc942fd2
Merge pull request #6232 from thaJeztah/bump_engine
vendor: moby/moby/api v1.52.0-alpha.1, moby/moby/client v0.1.0-alpha.0
2025-08-05 22:42:19 +02:00
Sebastiaan van Stijn f9431e3b35
vendor: moby/moby/api v1.52.0-alpha.1, moby/moby/client v0.1.0-alpha.0
full diff: 4faedf2bec...37d0204d7f

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-05 22:01:50 +02:00
Sebastiaan van Stijn 22cc0e90ae
cli/command: remove deprecated ConfigureAuth utility
It was deprecated in 6e4818e7d6, which
is part of v28.x and backported to v27.x.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-05 21:22:59 +02:00
Sebastiaan van Stijn de54347518
cli/command: remove deprecated CopyToFile utility
It was deprecated in 7cc6b8ebf4, which is
part of v28.x

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-05 21:11:47 +02:00
Sebastiaan van Stijn b01d359cc9
Merge pull request #6239 from thaJeztah/no_pkg_process
cli/connhelper: remove dependency on pkg/process
2025-08-05 16:57:54 +02:00
Sebastiaan van Stijn 2abcbf842f
cli/connhelper: remove dependency on pkg/process
This package will not be included in the api or client modules, and
we're currently only using a single function of it, and only the
unix implementation, so let's fork it for now (although the package
may be moved to moby/sys).

This removes the last dependency on github.com/docker/docker.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-05 16:30:09 +02:00
Sebastiaan van Stijn fcfaa8daeb
Merge pull request #6234 from thaJeztah/ParseRepositoryInfo_no_err_step2
internal/registry: remove RepositoryInfo, add NewIndexInfo
2025-08-04 15:21:49 +02:00
Sebastiaan van Stijn a629a840a8
Merge pull request #6237 from thaJeztah/plugin_manager_unexport
cli-plugins/manager: various fixes and deprecations
2025-08-04 14:00:21 +02:00
Sebastiaan van Stijn 513ceeec0a
cli-plugins/manager: remove deprecated ResourceAttributesEnvvar
This const was deprecated in 9dc175d6ef,
which is part of v28.0, so let's remove it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-04 12:26:22 +02:00
Sebastiaan van Stijn 5876b2941c
cli-plugins/manager: deprecate metadata aliases
These aliases were added in 4321293972
(part of v28.0), but did not deprecate them. They are no longer used
in the CLI itself, but may be used by cli-plugin implementations.

This deprecates the aliases in `cli-plugins/manager` in favor of
their equivalent in `cli-plugins/manager/metadata`:

- `NamePrefix`
- `MetadataSubcommandName`
- `HookSubcommandName`
- `Metadata`
- `ReexecEnvvar`

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-04 12:26:22 +02:00
Sebastiaan van Stijn 50963accec
cli-plugins/manager: wrapAsPluginError: don't special-case nil
This was a pattern inheritted from pkg/errors.Wrapf, which ignored
nil errors for convenience. However, it is error-prone, as it is
not obvious when returning a nil-error.

All call-sites using `wrapAsPluginError` already do a check for
nil errors, so remove this code to prevent hard to find bugs.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-04 12:26:14 +02:00
Sebastiaan van Stijn d789bac04a
cli-plugins/manager: pluginError: remove Causer interface
We no longer depend on this interface and it implements Unwrap for
native handling by go stdlib.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-04 11:11:52 +02:00
Sebastiaan van Stijn 71460215d3
cli-plugins/manager: deprecate "IsNotFound"
These errors satisfy errdefs.IsNotFound, so make it a wrapper, and
deprecate it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-04 11:06:49 +02:00
Sebastiaan van Stijn 1cc698c68f
cli-plugins/manager: un-export "NewPluginError"
It is for internal use, and no longer needed for testing, now that
the `Plugin` type handles marshalling errors.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-04 11:01:24 +02:00
Sebastiaan van Stijn 549d39a89f
cli-plugins/manager: fix Plugin marshaling with regular errors
Go does not by default marshal `error` type fields to JSON. The manager
package therefore implemented a `pluginError` type that implements
[encoding.TextMarshaler]. However, the field was marked as a regular
`error`, which made it brittle; assining any other type of error would
result in the error being discarded in the marshaled JSON (as used in
`docker info` output), resulting in the error being marshaled as `{}`.

This patch adds a custom `MarshalJSON()` on the `Plugin` type itself
so that any error is rendered. It checks if the error used already
implements [encoding.TextMarshaler], otherwise wraps the error in
a `pluginError`.

[encoding.TextMarshaler]: https://pkg.go.dev/encoding#TextMarshaler

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-04 10:55:16 +02:00
Sebastiaan van Stijn 54367b3283
cli-plugins/manager: un-export "Candidate" interface
It is for internal use for mocking purposes, and is not part
of any public interface / signature.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-04 09:14:13 +02:00
Sebastiaan van Stijn 057f3128b6
cli-plugins/manager: reformat TestValidateCandidate table
Slightly more verbose, but makes it easier to see properties
of each test.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-04 08:50:07 +02:00
Sebastiaan van Stijn dfbac70efa
remove some remnants from CLI "experimental" config option
Experimental is always enabled (977d3ae046),
and the `Experimental` field in plugin metadata was deprecated in
977d3ae046 and removed in commit
6a50c4f700.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-04 08:48:29 +02:00
Sebastiaan van Stijn 3b6a556533
cli/command: remove exported "RunPrune" functions
These are no longer used, and unlikely to be used externally.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-04 00:08:03 +02:00
Sebastiaan van Stijn bf8cb43025
system prune: delegate version check
Move the version-check for pruners to the pruner, which can
return a [ErrNotImplemented] error to indicate they won't
be run with the API version that's used.

This helps separating concerns, and doesn't enforce knowledge
about what's supported by each content-type onto the system
prune command.

[ErrNotImplemented]: https://pkg.go.dev/github.com/docker/docker@v28.3.3+incompatible/errdefs#ErrNotImplemented

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-04 00:08:02 +02:00
Sebastiaan van Stijn a888c4091c
system prune: delegate confirmation message and validation
This adds a "dry-run" / "pre-check" option for prune-functions,
which delegates constructing the confirmation message (what is
about to be pruned) and validation of the given options to the
prune-functions.

This helps separating concerns, and doesn't enforce knowledge
about what's supported by each content-type onto the system
prune command.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-04 00:07:54 +02:00
Sebastiaan van Stijn 02d578b637
system prune: use register function for prune functions
Introduce a "prune" package in which we maintain a list of prune
functions that are registered. Known prune "content-types" are
included in a pre-defined order, after which additional content
can be registered.

Using this approach no longer requires the "RunPrune" functions
to be exported, and allows additional content-types to be
introduced without having to import those packages into the
system package, so keeping things more decoupled.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-03 23:52:47 +02:00
Sebastiaan van Stijn 21e8bbc8a2
internal/registry: remove RepositoryInfo, add NewIndexInfo
Most places only use IndexInfo (and may not even need that), so replace
the use of ParseRepositoryInfo for NewIndexInfo, and move the RepositoryInfo
type to the trust package, which uses it as part of its ImageRefAndAuth
struct.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-03 15:32:51 +02:00
Sebastiaan van Stijn f86ad2ea4c
Merge pull request #6228 from thaJeztah/bump_version
bump version to v29.0.0-dev
2025-07-31 18:28:28 +02:00
Sebastiaan van Stijn a4bf9e78e5
Merge pull request #6227 from thaJeztah/cleanup_swarmopts
opts/swarmopts: minor cleanup and refactor
2025-07-31 18:28:07 +02:00
Sebastiaan van Stijn a1ea79444b
Merge pull request #6230 from robmry/moby29_dockerd_reference
dockerd.md: --firewall-backend and --bridge-accept-fwmark
2025-07-31 18:27:03 +02:00
Sebastiaan van Stijn 066710ba7b
opts/swarmopts: minor cleanup and refactor
- Use strong-typed switches for validating options
- Initialize defaults instead of setting them after
  parsing the ports. Each option should be validated
  as part of the parsing, so no invalid (or empty)
  values should be set.
- Put variables closer to where they're used, and
  pre-allocate slices.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-31 18:19:58 +02:00
Sebastiaan van Stijn b8df4abeb5
bump version to v29.0.0-dev
This file is only used as default if no version is specified. We
should probably get rid of this, but let's update it to better
reflect the version that developer builds are building.

d48fb9f9f7/docker.Makefile (L22)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-31 18:17:29 +02:00
Rob Murray 3f0ccd1b71 dockerd.md: Add --firewall-backend
Related to 39ab393274

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-07-31 17:11:47 +01:00
Rob Murray 6176a7686e dockerd.md: add --bridge-accept-fwmark
Related to cf1695bef1

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-07-31 17:11:47 +01:00
Sebastiaan van Stijn 66aca29f7d
Merge pull request #6226 from thaJeztah/bump_engine
vendor: docker/docker, moby/moby/api and moby/moby/client 4faedf2bec36
2025-07-31 18:10:08 +02:00
Sebastiaan van Stijn f937e62c89
replace direct uses of github.com/docker/go-connections/nat types
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-31 17:37:34 +02:00
Sebastiaan van Stijn bf16dd1251
vendor: docker/docker, moby/moby/api and moby/moby/client 4faedf2bec36
notable changes:

- api: remove deprecated NoBaseImageSpecifier
- api/stdcopy: move to api/pkg/stdcopy
- api/types/container: add aliases for go-connections/nat types
- pkg/progress: move to api/pkg/progress
- pkg/jsonmessage: move JSONError to api/types/jsonstream
- pkg/jsonmessage: move JSONProgress to api/types/jsonstream
- pkg/jsonmessage: move to client/pkg/jsonmessage
- pkg/jsonmessage: remove github.com/morikuni/aec dependency
- pkg/jsonmessage: stop printing deprecated progressDetail, errorDetail,
  remove DisplayJSONMessagesToStream and Stream interface
- pkg/streamformatter: move to api/pkg/streamformatter
- pkg/streamformatter: split from pkg/jsonmessage

full diff: 2574c2b2e9...4faedf2bec

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-31 17:31:01 +02:00
Sebastiaan van Stijn 2199a05e08
Merge pull request #6212 from carsontham/e2e-test-container-rename
intergration-cli: migrate TestContainerAPIRename to cli e2e test
2025-07-29 20:17:38 +02:00
carsontham 149503a32c
migrate e2e container rename test
Signed-off-by: carsontham <carsontham@outlook.com>
2025-07-29 20:07:15 +02:00
Sebastiaan van Stijn 5c3577ff9f
cli/command/service: credentialSpecOpt: use strings.Cut
- Rewrite the function to use strings.Cut instead of checking for,
  and trimming prefixes for each option.
- More explicitly set the value, instead of setting an empty value,
  then propagating the struct.
- Define a "type" to provide a more enum-like construct.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-29 19:55:50 +02:00
Sebastiaan van Stijn 14203bbc77
Merge pull request #6216 from thaJeztah/bump_engine
vendor: docker/docker, moby/moby/api and moby/moby/client 2574c2b2e917
2025-07-29 19:51:52 +02:00
Sebastiaan van Stijn b6d7ac34be
vendor: docker/docker, moby/moby/api and moby/moby/client 2574c2b2e917
notable changes;

- api/types/container: move StateStatus, NewStateStatus internal again
- daemon/server/httputils: remove ContainerDecoder interface
- runconfig: move to daemon/internal/runconfig
- pkg/stack: move to daemon/internal
- remove pkg/stringid as it has moved to the client module
- remove pkg/stdcopy as it has moved to the api module
- pkg/rootless: move to daemon/internal
- move api/types/plugins/logdriver to daemon/internal
- move api/types/plugins/logdriver to daemon/internal
- pkg/system: move to daemon/internal
- remove pkg/fileutils

full diff: 25e2b4d485...2574c2b2e9

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-29 18:56:56 +02:00
Sebastiaan van Stijn 83e507377a
vendor: docker/docker, moby/moby/api and moby/moby/client 25e2b4d48551
notable changes:

- api/types/container.StatsResponseReader: move to client
- api/types: move backend types to daemon/server
- runconfig: remove exported errors

full diff: c4afa77157...25e2b4d485

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-29 18:48:18 +02:00
Sebastiaan van Stijn a0ae6e6a5a
Merge pull request #6215 from thaJeztah/ParseRepositoryInfo_no_err
internal/registry: ParseRepositoryInfo: remove unused error return
2025-07-29 18:41:18 +02:00
Sebastiaan van Stijn 86b5b528a6
internal/registry: ParseRepositoryInfo: remove unused error return
Removed the error return from the `ParseRepositoryInfo` function.
There are no validation steps inside `ParseRepositoryInfo` which
could cause an error, so we always returned a nil error.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-29 18:32:15 +02:00
Sebastiaan van Stijn f0030712e9
Merge pull request #6217 from thaJeztah/errdefs_unalias
remove aliases for containerd/errdefs, disallow docker/errdefs
2025-07-28 20:12:39 +02:00
Sebastiaan van Stijn 89d8c8a2a7
remove aliases for containerd/errdefs, disallow docker/errdefs
We transitioned most functionality of docker/errdefs to containerd
errdefs module, and the docker/errdefs package should no longer be
used.

Because of that, there will no longer be ambiguity, so we can remove
the aliases for this package, and use it as "errdefs".

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-28 14:55:43 +02:00
Sebastiaan van Stijn e2a4e429bc
Merge pull request #6211 from thaJeztah/bump_engine
vendor: update docker, api, client to master, consume client/pkg/stringid
2025-07-28 14:25:36 +02:00
Sebastiaan van Stijn fdc4397906
Merge pull request #6214 from thaJeztah/template_deprecate_newparse
templates: deprecate NewParse()
2025-07-28 11:26:37 +02:00
Sebastiaan van Stijn d63cae6f1c
cli/command/formatter: use alias/wrapper for TruncateID
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-28 08:50:15 +02:00
Sebastiaan van Stijn 4bd6b6897f
vendor: update docker, api, client to master
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-28 08:50:13 +02:00
Sebastiaan van Stijn a1035b0796
Merge pull request #6213 from thaJeztah/cleanup_plugins
cli/command/plugin: fix linting issues, and assorted cleanups
2025-07-28 08:49:00 +02:00
Sebastiaan van Stijn 7ab3e7e774
templates: deprecate NewParse()
It it just a chain of `New("sometag").Parse(...)`, and most of our
uses don't use a tag for the template, so can call Parse.

There's no public users of this function, but deprecating it first
just in case.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-28 08:25:02 +02:00
Sebastiaan van Stijn c6f935eba5
cli/command/plugin: fix linting issues, and assorted cleanups
- fix various unhandled errors
- remove some locally defined option-types in favor of option-types
  defined by the client / api
- don't use unkeyed structs in tests, and add docs for some subtests
- fix some values in tests that triggered "spellcheck" warnings
- inline vars / functions that only had a single use.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-26 16:45:04 +02:00
Sebastiaan van Stijn 2f87a11e96
Merge pull request #6202 from Mewsen/issue/6188
refactor(cli/compose/loader): extract ParseVolume() to its own package
2025-07-25 17:08:54 +02:00
Michael Tews ef7fd8bb67
refactor(cli/compose/loader): extract ParseVolume() to its own package
Moves ParseVolume() to a new internal package to remove the dependency
on cli/compose/loader in cli/command/container/opts.go

refactor to keep types isolated

- rename the package to "volumespec" to reuse the name of the package
  as part of the name (parsevolume.ParseVolume() -> volumespec.Parse())
- move the related compose types to the internal package as well,
  and rename them to be more generic (not associated with "compose");
  - ServiceVolumeConfig -> VolumeConfig
  - ServiceVolumeBind -> BindOpts
  - ServiceVolumeVolume -> VolumeOpts
  - ServiceVolumeImage -> ImageOpts
  - ServiceVolumeTmpfs -> TmpFsOpts
  - ServiceVolumeCluster -> ClusterOpts
- alias the internal types inside cli/compose/types to keep backward
  compatibility (for any external consumers); even though the implementation
  is internal, Go allows aliasing types to use them externally.

Signed-off-by: Michael Tews <michael@tews.dev>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-25 16:56:17 +02:00
Paweł Gronowski 3046019d3b
Merge pull request #6209 from vvoland/image-tree-nonexp
image/tree: Unmark as experimental, warn when redirected
2025-07-25 12:58:37 +02:00
Sebastiaan van Stijn 1eeb0cc3e1
Merge pull request #6207 from thaJeztah/fork_registry
add internal fork of docker/docker/registry
2025-07-25 12:57:47 +02:00
Paweł Gronowski 9257cc7f68
image/tree: Unmark as experimental, warn when redirected
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-07-25 12:07:54 +02:00
Paweł Gronowski f214f860b6
image/tree: Remove extra newline after legend
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-07-25 12:04:42 +02:00
Sebastiaan van Stijn f907c7a4b0
internal/registry: fix linting issues (revive)
internal/registry/errors.go:26:43: use-any: since Go 1.18 'interface{}' can be replaced by 'any' (revive)
    func invalidParamf(format string, args ...interface{}) error {
                                              ^
    internal/registry/registry_mock_test.go:52:51: use-any: since Go 1.18 'interface{}' can be replaced by 'any' (revive)
    func writeResponse(w http.ResponseWriter, message interface{}, code int) {
                                                      ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-25 00:08:26 +02:00
Sebastiaan van Stijn cd277a5815
cli/command/system: remove use of Mirrors field in test
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-24 23:29:48 +02:00
Sebastiaan van Stijn c297770d2d
internal/registry: remove pkg/errors
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-24 23:29:47 +02:00
Sebastiaan van Stijn 219cfc8b7d
internal/registry: define local serviceConfig
The registry.ServiceConfig struct in the API types was meant for the
registry configuration on the daemon side; it has variuos fields we
don't use, defines methods for (un)marshaling JSON, and a custom version
of `net.IPNet`, also to (un)marshal JSON.

None of that is needed, so let's change it to a local type, and implement
a constructor (as we now only have "insecure registries" to care
about).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-24 23:29:47 +02:00
Sebastiaan van Stijn 2607ba8062
internal/registry: remove ValidateIndexName
It was written to be used as validate-func for command-line flags, which
we don't use it for (which for CLI-flags includes normalizing the value).

The validation itself didn't add much; it only checked the registry didn't
start or end with a hyphen (which would still fail when parsing).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-24 23:29:36 +02:00
Sebastiaan van Stijn 5322affc9f
internal/registry: remove duplicate endpoint methods
now that we no longer need to account for mirrors, these were
identical, so just use a single one.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-24 23:23:11 +02:00
Sebastiaan van Stijn dc41365b56
internal/registry: remove NewStaticCredentialStore
It was only used in a single place; inline it there.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-24 23:23:10 +02:00
Sebastiaan van Stijn dad2e67860
internal/registry: remove PingResponseError
It's not matched anywhere, so we can just return a plain error.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-24 23:23:10 +02:00
Sebastiaan van Stijn 7cf245d2f7
internal/registry: Service.Auth remove unused statusmessage return
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-24 23:23:10 +02:00
Sebastiaan van Stijn e0b351b3d9
internal/registry: remove code related to mirrors
The CLI does not have information about mirrors, and doesn't
configure them, so we can remove these parts.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-24 23:23:02 +02:00
Sebastiaan van Stijn 7716219e17
internal/registry: remove dead code
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-24 22:14:25 +02:00
Sebastiaan van Stijn f6b90bc253
add internal fork of docker/docker/registry
This adds an internal fork of [github.com/docker/docker/registry], taken
at commit [moby@f651a5d]. Git history  was not preserved in this fork,
but can be found using the URLs provided.

This fork was created to remove the dependency on the "Moby" codebase,
and because the CLI only needs a subset of its features. The original
package was written specifically for use in the daemon code, and includes
functionality that cannot be used in the CLI.

[github.com/docker/docker/registry]: https://pkg.go.dev/github.com/docker/docker@v28.3.2+incompatible/registry
[moby@49306c6]: 49306c607b/registry

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-24 19:59:17 +02:00
Sebastiaan van Stijn 636a4cf2dc
Merge pull request #6208 from thaJeztah/bump_moby
vendor: github.com/docker/docker master
2025-07-24 19:45:06 +02:00
Sebastiaan van Stijn 20181d4363
vendor: github.com/docker/docker master
forgot to update this dependency (only updated the api and client)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-24 18:12:28 +02:00
Paweł Gronowski d29d719c42
Merge pull request #6204 from thaJeztah/bump_engine
vendor: docker/docker, moby/api, and moby/client master
2025-07-24 17:25:47 +02:00
Sebastiaan van Stijn fa169b6933
vendor: docker/docker, moby/api, and moby/client master
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-24 16:06:08 +02:00
Paweł Gronowski 1ca6c946d5
Merge pull request #6126 from ctalledo/fix-for-moby-48759
Add support for multiple platform options in image load and save
2025-07-24 11:48:11 +02:00
Sebastiaan van Stijn c2586d68cf
Merge pull request #6206 from thaJeztah/remove_RepoNameForReference
cli/registry/client: remove deprecated RepoNameForReference
2025-07-24 11:35:03 +02:00
Sebastiaan van Stijn a87bde0068
cli/registry/client: remove deprecated RepoNameForReference
This was deprecated in 6f46cd2f4b,
which is part of v28.x, and no longer used, so we can remove it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-24 01:33:55 +02:00
Sebastiaan van Stijn df9950aa06
Merge pull request #6201 from thaJeztah/bump_engine
vendor: docker/docker, moby/api, moby/client to latest
2025-07-23 13:40:13 +02:00
Sebastiaan van Stijn 323ef1997f
vendor: docker/docker, moby/api, moby/client to latest
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-23 09:45:51 +02:00
Sebastiaan van Stijn 80be02c72b
Merge pull request #6200 from thaJeztah/search_no_registrypkg
cli/command/registry: remove uses of registry.ParseSearchIndexInfo
2025-07-22 23:01:28 +02:00
Sebastiaan van Stijn e504faf6da
cli/command/registry: remove uses of registry.ParseSearchIndexInfo
This utility was only used in the CLI, but the implementation was
based on it being used on the daemon side, so included resolving
the host's IP-address, mirrors, etc.

The only reason it's used in the CLI is to provide credentials for
the registry that's being searched, so reduce it to just that.

There's more cleaning up to do in this area, so to make our lives
easier, it's implemented locally as non-exported functions; likely
to be replaced with something else.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-22 22:13:38 +02:00
Sebastiaan van Stijn 03ff54b8ba
Merge pull request #6193 from thaJeztah/bump_engine
vendor: github.com/docker/docker master (v29.0-dev)
2025-07-22 09:19:13 +02:00
Sebastiaan van Stijn 644dc16b16
vendor: github.com/docker/docker master (v29.0-dev)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-21 23:04:50 +02:00
Sebastiaan van Stijn 2a2748a94c
Merge pull request #6195 from thaJeztah/build_no_dct
build: remove DCT support for classic builder
2025-07-21 22:03:46 +02:00
Sebastiaan van Stijn 7609dde8d0
build: remove DCT support for classic builder
Docker Content Trust is currently only implemented for the classic
builder, but is known to not work with multi-stage builds, and
requires rewriting the Dockerfile, which is brittle because the
Dockerfile syntax evolved with the introduction of BuildKit as
default builder.

Given that the classic builder is deprecated, and only used for
Windows images, which are not verified by content trust;

    # docker pull --disable-content-trust=false mcr.microsoft.com/windows/servercore:ltsc2025
    Error: remote trust data does not exist for mcr.microsoft.com/windows/servercore: mcr.microsoft.com does not have trust data for mcr.microsoft.com/windows/servercore

With content trust not implemented in BuildKit, and not implemented
in docker compose, this resulted in an inconsistent behavior.

This patch removes content-trust support for "docker build". As this
is a client-side feature, users who require this feature can still
use an older CLI to to start the build.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-21 19:05:38 +02:00
Sebastiaan van Stijn 71bc8ab3ea
Merge pull request #6186 from thaJeztah/remove_more_aliases
opts: minor cleanup in tests, and remove some import aliases
2025-07-17 17:18:15 +02:00
Sebastiaan van Stijn 6cf2c023f8
Merge pull request #6187 from thaJeztah/container_unexport
cli/command/container: deprecate NewDiffFormat, DiffFormatWrite
2025-07-17 17:09:50 +02:00
Sebastiaan van Stijn 73604b8c36
Merge pull request #6192 from thaJeztah/trust_no_api_const
cli/command/image: remove use of api.NoBaseImageSpecifier
2025-07-17 15:59:06 +02:00
Sebastiaan van Stijn e2cab2c64c
cli/command/image: remove use of api.NoBaseImageSpecifier
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-17 14:28:13 +02:00
Sebastiaan van Stijn 74042f5ffa
Merge pull request #6191 from robmry/info_firewall_backend
Include FirewallBackend in docker info output
2025-07-17 11:52:35 +02:00
Sebastiaan van Stijn 8c317ad3fd
Merge pull request #6190 from thaJeztah/fork_remotecontext
add local fork of github.com/docker/docker/builder/remotecontext
2025-07-17 01:34:55 +02:00
Sebastiaan van Stijn 64f33cd463
TestCloneArgsSmartHttp: fix unhandled error
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-16 22:21:46 +02:00
Rob Murray a3bea24086 Include FirewallBackend in docker info output
Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-07-16 17:17:27 +00:00
Sebastiaan van Stijn b05aa464a6
Dockerfile: install git-daemon for use in tests
gitutils_test.go:210: git-http-backend: git: 'http-backend' is not a git command. See 'git --help'.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-16 16:48:40 +02:00
Sebastiaan van Stijn e34616574f
fix linting issues
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-16 16:27:27 +02:00
Sebastiaan van Stijn 8d2ccc128a
add local fork of github.com/docker/docker/builder/remotecontext
Adds a local fork of this package for use in the classic builder.

Code was taken at commit [d33d46d01656e1d9ee26743f0c0d7779f685dd4e][1].

Migration was done using the following steps:

    # install filter-repo (https://github.com/newren/git-filter-repo/blob/main/INSTALL.md)
    brew install git-filter-repo

    # create a temporary clone of docker
    cd ~/Projects
    git clone https://github.com/docker/docker.git build_context_temp
    cd build_context_temp

    # commit taken from
    git rev-parse --verify HEAD
    d33d46d01656e1d9ee26743f0c0d7779f685dd4e

    git filter-repo --analyze

    # remove all code, except for the remotecontext packages, and move to build/internal docs and previous locations of it
    git filter-repo \
      --path 'builder/remotecontext/git' \
      --path 'builder/remotecontext/urlutil' \
      --path-rename builder/remotecontext:cli/command/image/build/internal

    # go to the target repository
    cd ~/go/src/github.com/docker/cli

    # create a branch to work with
    git checkout -b fork_remotecontext

    # add the temporary repository as an upstream and make sure it's up-to-date
    git remote add build_context_temp ~/Projects/build_context_temp
    git fetch build_context_temp

    # merge the upstream code
    git merge --allow-unrelated-histories --signoff -S build_context_temp/master

[1]: https://github.com/docker/docker/d33d46d01656e1d9ee26743f0c0d7779f685dd4e

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-16 16:18:51 +02:00
Sebastiaan van Stijn b5a939268b
Merge pull request #6189 from thaJeztah/cleanup_build_context
cli/command/image: move build-context detection to build
2025-07-16 15:57:58 +02:00
Sebastiaan van Stijn 260f1dbebb
cli/command/image: move build-context detection to build
Removes direct imports of github.com/docker/docker/builder in
the image package, to be moved later.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-16 15:50:32 +02:00
Sebastiaan van Stijn e95d133612
remove some redundant import aliases
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-16 13:56:49 +02:00
Sebastiaan van Stijn 3dec3879c8
opts: minor cleanup in tests
- use consistent name for MountOpt vars
- cleanup some comments and make them a GoDoc
- remove import alias
- use subtests for tests that were prepared for it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-16 13:56:49 +02:00
Sebastiaan van Stijn fdc90caeee
cli/command/container: deprecate DiffFormatWrite
It's part of the presentation logic of the cli, and only used internally.
We can consider providing utilities for these, but better as part of
separate packages.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-16 13:52:04 +02:00
Sebastiaan van Stijn 0db7b9f774
cli/command/container: newDiffContext: use struct-literal
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-16 13:50:31 +02:00
Sebastiaan van Stijn 239b727834
cli/command/container: DiffFormatWrite: remove intermediate var
Also rename "ctx" argument; we shouldn't use this as name for things
that are not a context.Context.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-16 13:45:09 +02:00
Sebastiaan van Stijn 907507e22a
cli/command/container: deprecate NewDiffFormat
It's part of the presentation logic of the cli, and only used internally.
We can consider providing utilities for these, but better as part of
separate packages.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-16 13:45:05 +02:00
Sebastiaan van Stijn d8089e7d1b
Merge pull request #6184 from Benehiko/deprecate-prompt-privilege-func
cli/command: deprecate RegistryAuthenticationPrivilegedFunc
2025-07-16 13:26:12 +02:00
Alano Terblanche 29263e865b
cli/command: remove usages of RegistryAuthenticationPrivilegedFunc
This patch deprecates the unused `RegistryAuthenticationPrivilegedFunc`.
The function would prompt the user when the registry returns a 403 after trying
the initial auth value set in `RegistryAuth`.

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-07-16 12:49:19 +02:00
Sebastiaan van Stijn 6bcc9ce730
Merge pull request #6174 from Benehiko/remove-prompt-privilege-func
cli/command: remove interactive login prompt from docker push/pull
2025-07-16 12:48:25 +02:00
Sebastiaan van Stijn 46b8679315
Merge pull request #6155 from thaJeztah/bump_alpine
Dockerfile: update to alpine 3.22
2025-07-16 12:47:48 +02:00
Sebastiaan van Stijn ea4c161067
Dockerfile: update to alpine 3.22
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-16 12:20:03 +02:00
Alano Terblanche 2b56b66b10
cli/command: remove interactive login prompt from docker push/pull
This patch removes the interactive prompts from `docker push/pull`.
The prompt would only execute on a response status code 403 from the registry
after trying the value set in `RegistryAuth`. Docker Hub could return 404
instead or 429, which would never execute the prompt.

The UX regarding the prompt is also questionable since the user might
not actually want to authenticate with a registry and the CLI could fail fast
instead. The user can always run `docker login` or set the `DOCKER_AUTH_CONFIG`
environment variable to get authenticated.

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2025-07-16 08:43:35 +02:00
Cesar Talledo 0ba4362d69 Update markdown docs to indicate multi-platform support in image load/save.
Signed-off-by: Cesar Talledo <cesar.talledo@docker.com>
2025-06-10 16:42:39 -07:00
Cesar Talledo 8993f54fc3 Add support for multiple platforms in docker image save
Signed-off-by: Cesar Talledo <cesar.talledo@docker.com>
2025-06-10 16:34:07 -07:00
Cesar Talledo 38b99adc10 Add support for multiple platforms in docker image load.
Signed-off-by: Cesar Talledo <cesar.talledo@docker.com>
2025-06-10 16:34:02 -07:00
Sebastiaan van Stijn 3b25977f82 Merge pull request #50110 from thaJeztah/remove_import_comments
all: remove // import comments
2025-05-30 20:35:54 +02:00
Sebastiaan van Stijn 342f8bca25 builder: remove // import comments
These comments were added to enforce using the correct import path for
our packages ("github.com/docker/docker", not "github.com/moby/moby").
However, when working in go module mode (not GOPATH / vendor), they have
no effect, so their impact is limited.

Remove these imports in preparation of migrating our code to become an
actual go module.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-05-30 15:59:11 +02:00
Sebastiaan van Stijn 7422403164 Merge pull request #49885 from mmorel-35/fix-staticcheck
fix staticcheck linting issues for golangci-lint v2
2025-05-01 17:08:40 +02:00
Matthieu MOREL 09a3c93f96 fix(QF1001): Apply De Morgan’s law
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-05-01 14:16:44 +02:00
Sebastiaan van Stijn a10a1e619b builder/remotecontext: remove unused named and "naked" returns
Also renamed some vars for clarity, renamed a error-returns to prevent
shadowing, and fixed some linter warnings about unhandled errors.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-26 15:47:11 +02:00
Sebastiaan van Stijn 75f791d904 builder: use lazyregexp to compile regexes on first use
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-02 21:37:32 +01:00
Aleksa Sarai 8d3c0fb6dc tests: migrate to assert.ErrorContains when possible
If we have an error type that we're checking a substring against, we
should really be checking using ErrorContains to indicate the right
semantics to assert.

Mostly done using these transforms:

  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r 'assert.Assert(t, is.ErrorContains(e, s)) -> assert.ErrorContains(t, e, s)'
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r 'assert.Assert(t, is.Contains(err.Error(), s)) -> assert.ErrorContains(t, err, s)'
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r 'assert.Check(t, is.Contains(err.Error(), s)) -> assert.Check(t, is.ErrorContains(err, s))'

As well as some small fixups to helpers that were doing
strings.Contains explicitly.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2024-11-22 23:59:21 +11:00
Sebastiaan van Stijn 45f09a1504 builder/remotecontext/git: remove redundant capturing of loop vars (copyloopvar)
builder/remotecontext/git/gitutils_test.go:116:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
            tc := tc
            ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-12 14:02:11 +01:00
Tianon Gravi ce639151e0 Merge pull request #47109 from whalelines/git-url-regex
Fix isGitURL regular expression
2024-01-18 14:02:57 -08:00
David Dooling 52c62bd13b Fix isGitURL regular expression
Escape period (.) so regular expression does not match any character before "git".

Signed-off-by: David Dooling <david.dooling@docker.com>
2024-01-18 14:14:08 -06:00
Sebastiaan van Stijn 8f865184a6 builder/remotecontext: format code with gofumpt
Formatting the code with https://github.com/mvdan/gofumpt

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-06-29 00:25:21 +02:00
Tianon Gravi ee957e144b Merge pull request #44381 from thaJeztah/strings_cut
Replace uses of `strings.Split(N)` with `strings.Cut()`
2022-12-21 09:16:05 -08:00
Sebastiaan van Stijn 6291744fa4 builder/remotecontext/git: use strings.Cut()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-12-21 11:09:00 +01:00
Sebastiaan van Stijn 60b326f814 builder/remotecontext/gitutils: switch back to os/exec
This is a partial revert of 389ada7188, which
switched from os/exec to the golang.org/x/sys/execabs package to mitigate
security issues (mainly on Windows) with lookups resolving to binaries in the
current directory.

from the go1.19 release notes https://go.dev/doc/go1.19#os-exec-path

> ## PATH lookups
>
> Command and LookPath no longer allow results from a PATH search to be found
> relative to the current directory. This removes a common source of security
> problems but may also break existing programs that depend on using, say,
> exec.Command("prog") to run a binary named prog (or, on Windows, prog.exe) in
> the current directory. See the os/exec package documentation for information
> about how best to update such programs.
>
> On Windows, Command and LookPath now respect the NoDefaultCurrentDirectoryInExePath
> environment variable, making it possible to disable the default implicit search
> of “.” in PATH lookups on Windows systems.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-09 12:28:17 +01:00
Sebastiaan van Stijn aa6ad06304 Merge pull request #44344 from thaJeztah/go1.18_compat
builder/remotecontext/git: allow building on go1.18
2022-10-21 19:38:54 +02:00
Sebastiaan van Stijn 66713384c3 builder/remotecontext/git: allow building on go1.18
cmd.Environ() is new in go1.19, and not needed for this specific case.
Without this, trying to use this package in code that uses go1.18 will fail;

    builder/remotecontext/git/gitutils.go:216:23: cmd.Environ undefined (type *exec.Cmd has no field or method Environ)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-10-21 17:41:41 +02:00
Cory Snider 5c21ec520e builder: add missing doc comment
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-10-20 16:47:18 -04:00
Cory Snider 212213e81e builder: fix running git commands on Windows
Setting cmd.Env overrides the default of passing through the parent
process' environment, which works out fine most of the time, except when
it doesn't. For whatever reason, leaving out all the environment causes
git-for-windows sh.exe subprocesses to enter an infinite loop of
access violations during Cygwin initialization in certain environments
(specifically, our very own dev container image).

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-10-20 16:47:18 -04:00
Cory Snider bcd6c45731 builder: make git config isolation opt-in
While it is undesirable for the system or user git config to be used
when the daemon clones a Git repo, it could break workflows if it was
unconditionally applied to docker/cli as well.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-10-20 16:47:18 -04:00
Cory Snider 876fc1dac4 builder: isolate git from local system
Prevent git commands we run from reading the user or system
configuration, or cloning submodules from the local filesystem.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-10-20 16:47:18 -04:00
Cory Snider 3bfb30acd7 builder: explicitly set CWD for all git commands
Keep It Simple! Set the working directory for git commands by...setting
the git process's working directory. Git commands can be run in the
parent process's working directory by passing the empty string.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-10-20 16:47:18 -04:00
Cory Snider 3f4cc89f64 builder: modernize TestCheckoutGit
Make the test more debuggable by logging all git command output and
running each table-driven test case as a subtest.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-10-20 16:47:18 -04:00
Sebastiaan van Stijn a12090d787 gofmt GoDoc comments with go1.19
Older versions of Go don't format comments, so committing this as
a separate commit, so that we can already make these changes before
we upgrade to Go 1.19.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-07-08 19:56:23 +02:00
Sebastiaan van Stijn f1b0ef127d Merge pull request #43477 from thaJeztah/deprecate_urlutil
pkg/urlutil: deprecate, and move to builder/remotecontext/urlutil
2022-04-13 17:16:15 +02:00
Sebastiaan van Stijn 26a11366a7 builder/remotecontext/urlutil: simplify and improve documentation
Simplify some of the logic, and add documentation about the package,
as well as warnings that this package should not be used as a general-
purpose utility.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-04-12 19:58:09 +02:00
Sebastiaan van Stijn 9e39630a05 pkg/urlutil: deprecate, and move to builder/remotecontext/urlutil
pkg/urlutil (despite its poorly chosen name) is not really intended as a generic
utility to handle URLs, and should only be used by the builder to handle (remote)
build contexts.

- IsURL() only does a very rudimentary check for http(s):// prefixes, without any
  other validation, but due to its name may give incorrect expectations.
- IsGitURL() is written specifically with docker build remote git contexts in
  mind, and has handling for backward-compatibility, where strings that are
  not URLs, but start with "github.com/" are accepted.

Because of the above, this patch:

- moves the package inside builder/remotecontext, close to where it's intended
  to be used (ideally this would be part of build/remotecontext itself, but this
  package imports many other dependencies, which would introduce those as extra
  dependencies in the CLI).
- deprecates pkg/urlutil, but adds aliases as there are some external consumers.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-04-12 19:58:05 +02:00
Eng Zer Jun 6d2a901118 refactor: move from io/ioutil to io and os package
The io/ioutil package has been deprecated in Go 1.16. This commit
replaces the existing io/ioutil functions with their new definitions in
io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2021-08-27 14:56:57 +08:00
Tibor Vass 389ada7188 Use golang.org/x/sys/execabs
Signed-off-by: Tibor Vass <tibor@docker.com>
2021-01-25 19:13:12 +00:00
Tibor Vass 613477b489 Merge pull request #41606 from thaJeztah/moby_sys_symlink
replace pkg/symlink with github.com/moby/sys/symlink
2020-11-03 09:58:08 -08:00
Sebastiaan van Stijn a4c8c72411 replace pkg/symlink with github.com/moby/sys/symlink
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-11-03 11:17:12 +01:00
Sebastiaan van Stijn 5896d383ca bump gotest.tools v3.0.1 for compatibility with Go 1.14
full diff: https://github.com/gotestyourself/gotest.tools/compare/v2.3.0...v3.0.1

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-02-11 00:06:42 +01:00
Sebastiaan van Stijn ea850377cd builder/remotecontext: allow ssh:// urls for remote context
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-12-05 21:22:49 +01:00
Sebastiaan van Stijn 2d0d4ce4af builder/remotecontext: use net/url instead of urlutil
urlutil.IsUrl() was merely checking if the url had a http(s)://
prefix, which is just as well handled through using url.Parse()

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-11-05 18:04:01 -08:00
Sebastiaan van Stijn a0d9b0cf0d TestParseRemoteURL: use subtests
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-11-05 14:00:18 -08:00
Yong Tang b3d0327781 Merge pull request #39668 from thaJeztah/replace_gometalinter
Replace gometalinter with golangci-lint
2019-09-18 07:30:18 -07:00
Sebastiaan van Stijn 70aef9f502 gosec: add ignore comments for reported issues that can be ignored
```
builder/remotecontext/remote.go:48:        G107: Potential HTTP request made with variable url (gosec)
builder/remotecontext/git/gitutils.go:145: G107: Potential HTTP request made with variable url (gosec)
builder/remotecontext/git/gitutils.go:147: G107: Potential HTTP request made with variable url (gosec)
pkg/fileutils/fileutils_test.go:185:       G303: File creation in shared tmp directory without using ioutil.Tempfile (gosec)
pkg/tarsum/tarsum_test.go:7:               G501: Blacklisted import `crypto/md5`: weak cryptographic primitive (gosec)
pkg/tarsum/tarsum_test.go:9:               G505: Blacklisted import `crypto/sha1`: weak cryptographic primitive (gosec)
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-18 12:57:43 +02:00
Sebastiaan van Stijn 80dd489f21 Merge pull request #38944 from andrewhsu/gitutils
gitutils: add validation for ref
2019-03-27 02:03:47 +01:00
Tonis Tiigi 04e2a24a9e gitutils: add validation for ref
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit 723b107ca4fba14580a6cd971e63d8af2e7d2bbe)
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
2019-03-26 22:05:46 +00:00
Vincent Demeester 84c375f430 Merge pull request #37243 from vdemeester/gotestyourself-with-tools
Update gotestyourself to gotest.tools
2018-06-13 16:23:26 +02:00
Vincent Demeester 71672ece9c Update tests to use gotest.tools 👼
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-06-13 09:04:30 +02:00
Daniel Nephin db857b5d9c Post migration assertion fixes
Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-03-16 11:03:46 -04:00
Daniel Nephin 242f176825 Automated migration using
gty-migrate-from-testify --ignore-build-tags

Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-03-16 11:03:43 -04:00
Daniel Nephin 6ea4877cff Add canonical import comment
Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-02-05 16:51:57 -05:00
Tonis Tiigi 7bc503344a gitutils: remove checkout directory on error
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2017-12-08 11:58:13 -08:00
Tonis Tiigi e2cc22d076 gitutils: fix checking out submodules
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2017-12-07 14:25:19 -08:00
Andrew He e9831d75e2 Fix shallow git clone in docker-build
If the HEAD request fails, use a GET request to properly test if git
server is smart-http.

Signed-off-by: Andrew He <he.andrew.mail@gmail.com>
2017-07-25 13:20:59 -07:00
Sebastiaan van Stijn 9450481b7e Move IsGitTransport() to gitutils
This function was only used inside gitutils,
and is written specifically for the requirements
there.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-06-26 10:07:04 -07:00
Sebastiaan van Stijn a6cc6cd878 Fix handling of remote "git@" notation
`docker build` accepts remote repositories
using either the `git://` notation, or `git@`.

Docker attempted to parse both as an URL, however,
`git@` is not an URL, but an argument to `git clone`.

Go 1.7 silently ignored this, and managed to
extract the needed information from these
remotes, however, Go 1.8 does a more strict
validation, and invalidated these.

This patch adds a different path for `git@` remotes,
to prevent them from being handled as URL (and
invalidated).

A test is also added, because there were no
tests for handling of `git@` remotes.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-06-26 10:02:12 -07:00
Daniel Nephin e907d54fe6 Move pkg/gitutils to remotecontext/git
Signed-off-by: Daniel Nephin <dnephin@docker.com>
2017-06-02 16:54:50 -04:00
859 changed files with 10519 additions and 27147 deletions

View File

@ -35,7 +35,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
-
name: Create matrix
id: platforms
@ -143,7 +143,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
-
name: Create matrix
id: platforms

View File

@ -46,7 +46,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 2
# CodeQL 2.16.4's auto-build added support for multi-module repositories,
@ -63,7 +63,7 @@ jobs:
name: Update Go
uses: actions/setup-go@v5
with:
go-version: "1.24.5"
go-version: "1.24.7"
-
name: Initialize CodeQL
uses: github/codeql-action/init@v3

View File

@ -44,7 +44,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
-
name: Update daemon.json
run: |

View File

@ -59,14 +59,14 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
path: ${{ env.GOPATH }}/src/github.com/docker/cli
-
name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.24.5"
go-version: "1.24.7"
-
name: Test
run: |

View File

@ -11,18 +11,23 @@ permissions:
on:
pull_request:
types: [opened, edited, labeled, unlabeled]
types: [opened, edited, labeled, unlabeled, synchronize]
jobs:
check-area-label:
check-labels:
runs-on: ubuntu-24.04
timeout-minutes: 120 # guardrails timeout for the whole job
steps:
- name: Missing `area/` label
if: contains(join(github.event.pull_request.labels.*.name, ','), 'impact/') && !contains(join(github.event.pull_request.labels.*.name, ','), 'area/')
if: always() && contains(join(github.event.pull_request.labels.*.name, ','), 'impact/') && !contains(join(github.event.pull_request.labels.*.name, ','), 'area/')
run: |
echo "::error::Every PR with an 'impact/*' label should also have an 'area/*' label"
exit 1
- name: Missing `kind/` label
if: always() && contains(join(github.event.pull_request.labels.*.name, ','), 'impact/') && !contains(join(github.event.pull_request.labels.*.name, ','), 'kind/')
run: |
echo "::error::Every PR with an 'impact/*' label should also have a 'kind/*' label"
exit 1
- name: OK
run: exit 0

View File

@ -48,7 +48,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
-
name: Generate
shell: 'script --return --quiet --command "bash {0}"'
@ -74,7 +74,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
-
name: Run
shell: 'script --return --quiet --command "bash {0}"'

View File

@ -5,7 +5,7 @@ run:
# which causes it to fallback to go1.17 semantics.
#
# TODO(thaJeztah): update "usetesting" settings to enable go1.24 features once our minimum version is go1.24
go: "1.24.5"
go: "1.24.7"
timeout: 5m
@ -86,6 +86,8 @@ linters:
desc: Use github.com/moby/sys/userns instead.
- pkg: "github.com/containerd/containerd/platforms"
desc: The containerd platforms package was migrated to a separate module. Use github.com/containerd/platforms instead.
- pkg: "github.com/docker/docker/errdefs"
desc: Use github.com/containerd/errdefs instead.
- pkg: "github.com/docker/docker/pkg/system"
desc: This package should not be used unless strictly necessary.
- pkg: "github.com/docker/distribution/uuid"
@ -124,10 +126,9 @@ linters:
no-unaliased: true
alias:
# Enforce alias to prevent it accidentally being used instead of our
# own errdefs package (or vice-versa).
- pkg: github.com/containerd/errdefs
alias: cerrdefs
# Should no longer be aliased, because we no longer allow moby/docker errdefs.
- pkg: "github.com/docker/docker/errdefs"
alias: ""
- pkg: github.com/opencontainers/image-spec/specs-go/v1
alias: ocispec
# Enforce that gotest.tools/v3/assert/cmp is always aliased as "is"
@ -221,6 +222,14 @@ linters:
linters:
- staticcheck
# Ignore deprecation linting for cli/command/stack/*.
#
# FIXME(thaJeztah): remove exception once these functions are un-exported or internal; see https://github.com/docker/cli/pull/6389
- text: '^(SA1019): '
path: "cli/command/stack"
linters:
- staticcheck
# Log a warning if an exclusion rule is unused.
# Default: false
warn-unused: true

View File

@ -5,10 +5,10 @@ ARG BASE_VARIANT=alpine
# ALPINE_VERSION sets the version of the alpine base image to use, including for the golang image.
# It must be a supported tag in the docker.io/library/alpine image repository
# that's also available as alpine image variant for the Golang version used.
ARG ALPINE_VERSION=3.21
ARG ALPINE_VERSION=3.22
ARG BASE_DEBIAN_DISTRO=bookworm
ARG GO_VERSION=1.24.5
ARG GO_VERSION=1.24.7
ARG XX_VERSION=1.6.1
ARG GOVERSIONINFO_VERSION=v1.4.1
@ -31,7 +31,7 @@ FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS build-base-alpine
ENV GOTOOLCHAIN=local
COPY --link --from=xx / /
RUN apk add --no-cache bash clang lld llvm file git
RUN apk add --no-cache bash clang lld llvm file git git-daemon
WORKDIR /go/src/github.com/docker/cli
FROM build-base-alpine AS build-alpine

View File

@ -1 +1 @@
28.3.0-dev
29.0.0-dev

View File

@ -1,30 +0,0 @@
package manager
import "github.com/docker/cli/cli-plugins/metadata"
const (
// CommandAnnotationPlugin is added to every stub command added by
// AddPluginCommandStubs with the value "true" and so can be
// used to distinguish plugin stubs from regular commands.
CommandAnnotationPlugin = metadata.CommandAnnotationPlugin
// CommandAnnotationPluginVendor is added to every stub command
// added by AddPluginCommandStubs and contains the vendor of
// that plugin.
CommandAnnotationPluginVendor = metadata.CommandAnnotationPluginVendor
// CommandAnnotationPluginVersion is added to every stub command
// added by AddPluginCommandStubs and contains the version of
// that plugin.
CommandAnnotationPluginVersion = metadata.CommandAnnotationPluginVersion
// CommandAnnotationPluginInvalid is added to any stub command
// added by AddPluginCommandStubs for an invalid command (that
// is, one which failed it's candidate test) and contains the
// reason for the failure.
CommandAnnotationPluginInvalid = metadata.CommandAnnotationPluginInvalid
// CommandAnnotationPluginCommandPath is added to overwrite the
// command path for a plugin invocation.
CommandAnnotationPluginCommandPath = metadata.CommandAnnotationPluginCommandPath
)

View File

@ -6,12 +6,6 @@ import (
"github.com/docker/cli/cli-plugins/metadata"
)
// Candidate represents a possible plugin candidate, for mocking purposes
type Candidate interface {
Path() string
Metadata() ([]byte, error)
}
type candidate struct {
path string
}

View File

@ -32,14 +32,12 @@ func (c *fakeCandidate) Metadata() ([]byte, error) {
func TestValidateCandidate(t *testing.T) {
const (
goodPluginName = metadata.NamePrefix + "goodplugin"
builtinName = metadata.NamePrefix + "builtin"
builtinAlias = metadata.NamePrefix + "alias"
builtinName = metadata.NamePrefix + "builtin"
builtinAlias = metadata.NamePrefix + "alias"
badPrefixPath = "/usr/local/libexec/cli-plugins/wobble"
badNamePath = "/usr/local/libexec/cli-plugins/docker-123456"
goodPluginPath = "/usr/local/libexec/cli-plugins/" + goodPluginName
metaExperimental = `{"SchemaVersion": "0.1.0", "Vendor": "e2e-testing", "Experimental": true}`
badPrefixPath = "/usr/local/libexec/cli-plugins/wobble"
badNamePath = "/usr/local/libexec/cli-plugins/docker-123456"
goodPluginPath = "/usr/local/libexec/cli-plugins/" + goodPluginName
)
fakeroot := &cobra.Command{Use: "docker"}
@ -51,31 +49,83 @@ func TestValidateCandidate(t *testing.T) {
})
for _, tc := range []struct {
name string
c *fakeCandidate
name string
plugin *fakeCandidate
// Either err or invalid may be non-empty, but not both (both can be empty for a good plugin).
err string
invalid string
}{
/* Each failing one of the tests */
{name: "empty path", c: &fakeCandidate{path: ""}, err: "plugin candidate path cannot be empty"},
{name: "bad prefix", c: &fakeCandidate{path: badPrefixPath}, err: fmt.Sprintf("does not have %q prefix", metadata.NamePrefix)},
{name: "bad path", c: &fakeCandidate{path: badNamePath}, invalid: "did not match"},
{name: "builtin command", c: &fakeCandidate{path: builtinName}, invalid: `plugin "builtin" duplicates builtin command`},
{name: "builtin alias", c: &fakeCandidate{path: builtinAlias}, invalid: `plugin "alias" duplicates an alias of builtin command "builtin"`},
{name: "fetch failure", c: &fakeCandidate{path: goodPluginPath, exec: false}, invalid: fmt.Sprintf("failed to fetch metadata: faked a failure to exec %q", goodPluginPath)},
{name: "metadata not json", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `xyzzy`}, invalid: "invalid character"},
{name: "empty schemaversion", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{}`}, invalid: `plugin SchemaVersion "" is not valid`},
{name: "invalid schemaversion", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "xyzzy"}`}, invalid: `plugin SchemaVersion "xyzzy" is not valid`},
{name: "no vendor", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0"}`}, invalid: "plugin metadata does not define a vendor"},
{name: "empty vendor", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0", "Vendor": ""}`}, invalid: "plugin metadata does not define a vendor"},
// This one should work
{name: "valid", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0", "Vendor": "e2e-testing"}`}},
{name: "experimental + allowing experimental", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: metaExperimental}},
// Invalid cases.
{
name: "empty path",
plugin: &fakeCandidate{path: ""},
err: "plugin candidate path cannot be empty",
},
{
name: "bad prefix",
plugin: &fakeCandidate{path: badPrefixPath},
err: fmt.Sprintf("does not have %q prefix", metadata.NamePrefix),
},
{
name: "bad path",
plugin: &fakeCandidate{path: badNamePath},
invalid: "did not match",
},
{
name: "builtin command",
plugin: &fakeCandidate{path: builtinName},
invalid: `plugin "builtin" duplicates builtin command`,
},
{
name: "builtin alias",
plugin: &fakeCandidate{path: builtinAlias},
invalid: `plugin "alias" duplicates an alias of builtin command "builtin"`,
},
{
name: "fetch failure",
plugin: &fakeCandidate{path: goodPluginPath, exec: false},
invalid: fmt.Sprintf("failed to fetch metadata: faked a failure to exec %q", goodPluginPath),
},
{
name: "metadata not json",
plugin: &fakeCandidate{path: goodPluginPath, exec: true, meta: `xyzzy`},
invalid: "invalid character",
},
{
name: "empty schemaversion",
plugin: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{}`},
invalid: `plugin SchemaVersion "" is not valid`,
},
{
name: "invalid schemaversion",
plugin: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "xyzzy"}`},
invalid: `plugin SchemaVersion "xyzzy" is not valid`,
},
{
name: "no vendor",
plugin: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0"}`},
invalid: "plugin metadata does not define a vendor",
},
{
name: "empty vendor",
plugin: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0", "Vendor": ""}`},
invalid: "plugin metadata does not define a vendor",
},
// Valid cases.
{
name: "valid",
plugin: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0", "Vendor": "e2e-testing"}`},
},
{
// Including the deprecated "experimental" field should not break processing.
name: "with legacy experimental",
plugin: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0", "Vendor": "e2e-testing", "Experimental": true}`},
},
} {
t.Run(tc.name, func(t *testing.T) {
p, err := newPlugin(tc.c, fakeroot.Commands())
p, err := newPlugin(tc.plugin, fakeroot.Commands())
switch {
case tc.err != "":
assert.ErrorContains(t, err, tc.err)

View File

@ -23,11 +23,6 @@ func (e *pluginError) Error() string {
return e.cause.Error()
}
// Cause satisfies the errors.causer interface for pluginError.
func (e *pluginError) Cause() error {
return e.cause
}
// Unwrap provides compatibility for Go 1.13 error chains.
func (e *pluginError) Unwrap() error {
return e.cause
@ -41,14 +36,11 @@ func (e *pluginError) MarshalText() (text []byte, err error) {
// wrapAsPluginError wraps an error in a pluginError with an
// additional message.
func wrapAsPluginError(err error, msg string) error {
if err == nil {
return nil
}
return &pluginError{cause: fmt.Errorf("%s: %w", msg, err)}
}
// NewPluginError creates a new pluginError, analogous to
// newPluginError creates a new pluginError, analogous to
// errors.Errorf.
func NewPluginError(msg string, args ...any) error {
func newPluginError(msg string, args ...any) error {
return &pluginError{cause: fmt.Errorf(msg, args...)}
}

View File

@ -10,7 +10,7 @@ import (
)
func TestPluginError(t *testing.T) {
err := NewPluginError("new error")
err := newPluginError("new error")
assert.Check(t, is.Error(err, "new error"))
inner := errors.New("testing")
@ -21,4 +21,7 @@ func TestPluginError(t *testing.T) {
actual, err := json.Marshal(err)
assert.Check(t, err)
assert.Check(t, is.Equal(`"wrapping: testing"`, string(actual)))
err = wrapAsPluginError(nil, "wrapping")
assert.Check(t, is.Error(err, "wrapping: %!w(<nil>)"))
}

View File

@ -9,6 +9,7 @@ import (
"strings"
"sync"
"github.com/containerd/errdefs"
"github.com/docker/cli/cli-plugins/metadata"
"github.com/docker/cli/cli/config"
"github.com/docker/cli/cli/config/configfile"
@ -17,20 +18,6 @@ import (
"golang.org/x/sync/errgroup"
)
const (
// ReexecEnvvar is the name of an ennvar which is set to the command
// used to originally invoke the docker CLI when executing a
// plugin. Assuming $PATH and $CWD remain unchanged this should allow
// the plugin to re-execute the original CLI.
ReexecEnvvar = metadata.ReexecEnvvar
// ResourceAttributesEnvvar is the name of the envvar that includes additional
// resource attributes for OTEL.
//
// Deprecated: The "OTEL_RESOURCE_ATTRIBUTES" env-var is part of the OpenTelemetry specification; users should define their own const for this. This const will be removed in the next release.
ResourceAttributesEnvvar = "OTEL_RESOURCE_ATTRIBUTES"
)
// errPluginNotFound is the error returned when a plugin could not be found.
type errPluginNotFound string
@ -40,17 +27,6 @@ func (e errPluginNotFound) Error() string {
return "Error: No such CLI plugin: " + string(e)
}
type notFound interface{ NotFound() }
// IsNotFound is true if the given error is due to a plugin not being found.
func IsNotFound(err error) bool {
if e, ok := err.(*pluginError); ok {
err = e.Cause()
}
_, ok := err.(notFound)
return ok
}
// getPluginDirs returns the platform-specific locations to search for plugins
// in order of preference.
//
@ -127,7 +103,7 @@ func getPlugin(name string, pluginDirs []string, rootcmd *cobra.Command) (*Plugi
if err != nil {
return nil, err
}
if !IsNotFound(p.Err) {
if !errdefs.IsNotFound(p.Err) {
p.ShadowedPaths = paths[1:]
}
return &p, nil
@ -164,7 +140,7 @@ func ListPlugins(dockerCli config.Provider, rootcmd *cobra.Command) ([]Plugin, e
if err != nil {
return err
}
if !IsNotFound(p.Err) {
if !errdefs.IsNotFound(p.Err) {
p.ShadowedPaths = paths[1:]
mu.Lock()
defer mu.Unlock()
@ -185,15 +161,15 @@ func ListPlugins(dockerCli config.Provider, rootcmd *cobra.Command) ([]Plugin, e
return plugins, nil
}
// PluginRunCommand returns an "os/exec".Cmd which when .Run() will execute the named plugin.
// PluginRunCommand returns an [os/exec.Cmd] which when [os/exec.Cmd.Run] will execute the named plugin.
// The rootcmd argument is referenced to determine the set of builtin commands in order to detect conficts.
// The error returned satisfies the IsNotFound() predicate if no plugin was found or if the first candidate plugin was invalid somehow.
// The error returned satisfies the [errdefs.IsNotFound] predicate if no plugin was found or if the first candidate plugin was invalid somehow.
func PluginRunCommand(dockerCli config.Provider, name string, rootcmd *cobra.Command) (*exec.Cmd, error) {
// This uses the full original args, not the args which may
// have been provided by cobra to our caller. This is because
// they lack e.g. global options which we must propagate here.
args := os.Args[1:]
if !pluginNameRe.MatchString(name) {
if !isValidPluginName(name) {
// We treat this as "not found" so that callers will
// fallback to their "invalid" command path.
return nil, errPluginNotFound(name)

View File

@ -5,6 +5,7 @@ import (
"strings"
"testing"
"github.com/containerd/errdefs"
"github.com/docker/cli/cli/config"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/internal/test"
@ -131,7 +132,7 @@ echo '{"SchemaVersion":"0.1.0"}'`, fs.WithMode(0o777)),
_, err = GetPlugin("ccc", cli, &cobra.Command{})
assert.Error(t, err, "Error: No such CLI plugin: ccc")
assert.Assert(t, IsNotFound(err))
assert.Assert(t, errdefs.IsNotFound(err))
}
func TestListPluginsIsSorted(t *testing.T) {
@ -166,8 +167,8 @@ func TestErrPluginNotFound(t *testing.T) {
var err error = errPluginNotFound("test")
err.(errPluginNotFound).NotFound()
assert.Error(t, err, "Error: No such CLI plugin: test")
assert.Assert(t, IsNotFound(err))
assert.Assert(t, !IsNotFound(nil))
assert.Assert(t, errdefs.IsNotFound(err))
assert.Assert(t, !errdefs.IsNotFound(nil))
}
func TestGetPluginDirs(t *testing.T) {

View File

@ -1,23 +0,0 @@
package manager
import (
"github.com/docker/cli/cli-plugins/metadata"
)
const (
// NamePrefix is the prefix required on all plugin binary names
NamePrefix = metadata.NamePrefix
// MetadataSubcommandName is the name of the plugin subcommand
// which must be supported by every plugin and returns the
// plugin metadata.
MetadataSubcommandName = metadata.MetadataSubcommandName
// HookSubcommandName is the name of the plugin subcommand
// which must be implemented by plugins declaring support
// for hooks in their metadata.
HookSubcommandName = metadata.HookSubcommandName
)
// Metadata provided by the plugin.
type Metadata = metadata.Metadata

View File

@ -2,6 +2,7 @@ package manager
import (
"context"
"encoding"
"encoding/json"
"errors"
"fmt"
@ -11,12 +12,9 @@ import (
"strings"
"github.com/docker/cli/cli-plugins/metadata"
"github.com/docker/cli/internal/lazyregexp"
"github.com/spf13/cobra"
)
var pluginNameRe = lazyregexp.New("^[a-z][a-z0-9]*$")
// Plugin represents a potential plugin with all it's metadata.
type Plugin struct {
metadata.Metadata
@ -31,12 +29,34 @@ type Plugin struct {
ShadowedPaths []string `json:",omitempty"`
}
// MarshalJSON implements [json.Marshaler] to handle marshaling the
// [Plugin.Err] field (Go doesn't marshal errors by default).
func (p *Plugin) MarshalJSON() ([]byte, error) {
type Alias Plugin // avoid recursion
cp := *p // shallow copy to avoid mutating original
if cp.Err != nil {
if _, ok := cp.Err.(encoding.TextMarshaler); !ok {
cp.Err = &pluginError{cp.Err}
}
}
return json.Marshal((*Alias)(&cp))
}
// pluginCandidate represents a possible plugin candidate, for mocking purposes.
type pluginCandidate interface {
Path() string
Metadata() ([]byte, error)
}
// newPlugin determines if the given candidate is valid and returns a
// Plugin. If the candidate fails one of the tests then `Plugin.Err`
// is set, and is always a `pluginError`, but the `Plugin` is still
// returned with no error. An error is only returned due to a
// non-recoverable error.
func newPlugin(c Candidate, cmds []*cobra.Command) (Plugin, error) {
func newPlugin(c pluginCandidate, cmds []*cobra.Command) (Plugin, error) {
path := c.Path()
if path == "" {
return Plugin{}, errors.New("plugin candidate path cannot be empty")
@ -62,8 +82,8 @@ func newPlugin(c Candidate, cmds []*cobra.Command) (Plugin, error) {
}
// Now apply the candidate tests, so these update p.Err.
if !pluginNameRe.MatchString(p.Name) {
p.Err = NewPluginError("plugin candidate %q did not match %q", p.Name, pluginNameRe.String())
if !isValidPluginName(p.Name) {
p.Err = newPluginError("plugin candidate %q did not match %q", p.Name, pluginNameFormat)
return p, nil
}
@ -75,11 +95,11 @@ func newPlugin(c Candidate, cmds []*cobra.Command) (Plugin, error) {
continue
}
if cmd.Name() == p.Name {
p.Err = NewPluginError("plugin %q duplicates builtin command", p.Name)
p.Err = newPluginError("plugin %q duplicates builtin command", p.Name)
return p, nil
}
if cmd.HasAlias(p.Name) {
p.Err = NewPluginError("plugin %q duplicates an alias of builtin command %q", p.Name, cmd.Name())
p.Err = newPluginError("plugin %q duplicates an alias of builtin command %q", p.Name, cmd.Name())
return p, nil
}
}
@ -96,11 +116,11 @@ func newPlugin(c Candidate, cmds []*cobra.Command) (Plugin, error) {
return p, nil
}
if p.Metadata.SchemaVersion != "0.1.0" {
p.Err = NewPluginError("plugin SchemaVersion %q is not valid, must be 0.1.0", p.Metadata.SchemaVersion)
p.Err = newPluginError("plugin SchemaVersion %q is not valid, must be 0.1.0", p.Metadata.SchemaVersion)
return p, nil
}
if p.Metadata.Vendor == "" {
p.Err = NewPluginError("plugin metadata does not define a vendor")
p.Err = newPluginError("plugin metadata does not define a vendor")
return p, nil
}
return p, nil
@ -124,3 +144,26 @@ func (p *Plugin) RunHook(ctx context.Context, hookData HookPluginData) ([]byte,
return hookCmdOutput, nil
}
// pluginNameFormat is used as part of errors for invalid plugin-names.
// We should consider making this less technical ("must start with "a-z",
// and only consist of lowercase alphanumeric characters").
const pluginNameFormat = `^[a-z][a-z0-9]*$`
func isValidPluginName(s string) bool {
if len(s) == 0 {
return false
}
// first character must be a-z
if c := s[0]; c < 'a' || c > 'z' {
return false
}
// followed by a-z or 0-9
for i := 1; i < len(s); i++ {
c := s[i]
if (c < 'a' || c > 'z') && (c < '0' || c > '9') {
return false
}
}
return true
}

View File

@ -0,0 +1,43 @@
package manager
import (
"encoding/json"
"errors"
"testing"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
func TestPluginMarshal(t *testing.T) {
const jsonWithError = `{"Name":"some-plugin","Err":"something went wrong"}`
const jsonNoError = `{"Name":"some-plugin"}`
tests := []struct {
doc string
error error
expected string
}{
{
doc: "no error",
expected: jsonNoError,
},
{
doc: "regular error",
error: errors.New("something went wrong"),
expected: jsonWithError,
},
{
doc: "custom error",
error: newPluginError("something went wrong"),
expected: jsonWithError,
},
}
for _, tc := range tests {
t.Run(tc.doc, func(t *testing.T) {
actual, err := json.Marshal(&Plugin{Name: "some-plugin", Err: tc.error})
assert.NilError(t, err)
assert.Check(t, is.Equal(string(actual), tc.expected))
})
}
}

View File

@ -14,7 +14,7 @@ import (
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/connhelper"
"github.com/docker/cli/cli/debug"
"github.com/docker/docker/client"
"github.com/moby/moby/client"
"github.com/spf13/cobra"
"go.opentelemetry.io/otel"
)
@ -175,11 +175,24 @@ func newPluginCommand(dockerCli *command.DockerCli, plugin *cobra.Command, meta
newMetadataSubcommand(plugin, meta),
)
cli.DisableFlagsInUseLine(cmd)
visitAll(cmd,
// prevent adding "[flags]" to the end of the usage line.
func(c *cobra.Command) { c.DisableFlagsInUseLine = true },
)
return cli.NewTopLevelCommand(cmd, dockerCli, opts, cmd.Flags())
}
// visitAll traverses all commands from the root.
func visitAll(root *cobra.Command, fns ...func(*cobra.Command)) {
for _, cmd := range root.Commands() {
visitAll(cmd, fns...)
}
for _, fn := range fns {
fn(root)
}
}
func newMetadataSubcommand(plugin *cobra.Command, meta metadata.Metadata) *cobra.Command {
if meta.ShortDescription == "" {
meta.ShortDescription = plugin.Short

View File

@ -0,0 +1,28 @@
package plugin
import (
"slices"
"testing"
"github.com/spf13/cobra"
)
func TestVisitAll(t *testing.T) {
root := &cobra.Command{Use: "root"}
sub1 := &cobra.Command{Use: "sub1"}
sub1sub1 := &cobra.Command{Use: "sub1sub1"}
sub1sub2 := &cobra.Command{Use: "sub1sub2"}
sub2 := &cobra.Command{Use: "sub2"}
root.AddCommand(sub1, sub2)
sub1.AddCommand(sub1sub1, sub1sub2)
var visited []string
visitAll(root, func(ccmd *cobra.Command) {
visited = append(visited, ccmd.Name())
})
expected := []string{"sub1sub1", "sub1sub2", "sub1", "sub2", "root"}
if !slices.Equal(expected, visited) {
t.Errorf("expected %#v, got %#v", expected, visited)
}
}

View File

@ -12,7 +12,6 @@ import (
"github.com/fvbommel/sortorder"
"github.com/moby/term"
"github.com/morikuni/aec"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
@ -167,35 +166,6 @@ func (tcmd *TopLevelCommand) Initialize(ops ...command.CLIOption) error {
return tcmd.dockerCli.Initialize(tcmd.opts, ops...)
}
// VisitAll will traverse all commands from the root.
// This is different from the VisitAll of cobra.Command where only parents
// are checked.
func VisitAll(root *cobra.Command, fn func(*cobra.Command)) {
for _, cmd := range root.Commands() {
VisitAll(cmd, fn)
}
fn(root)
}
// DisableFlagsInUseLine sets the DisableFlagsInUseLine flag on all
// commands within the tree rooted at cmd.
func DisableFlagsInUseLine(cmd *cobra.Command) {
VisitAll(cmd, func(ccmd *cobra.Command) {
// do not add a `[flags]` to the end of the usage line.
ccmd.DisableFlagsInUseLine = true
})
}
// HasCompletionArg returns true if a cobra completion arg request is found.
func HasCompletionArg(args []string) bool {
for _, arg := range args {
if arg == cobra.ShellCompRequestCmd || arg == cobra.ShellCompNoDescRequestCmd {
return true
}
}
return false
}
var helpCommand = &cobra.Command{
Use: "help [command]",
Short: "Help about the command",
@ -204,7 +174,7 @@ var helpCommand = &cobra.Command{
RunE: func(c *cobra.Command, args []string) error {
cmd, args, e := c.Root().Find(args)
if cmd == nil || e != nil || len(args) > 0 {
return errors.Errorf("unknown help topic: %v", strings.Join(args, " "))
return fmt.Errorf("unknown help topic: %v", strings.Join(args, " "))
}
helpFunc := cmd.HelpFunc()
helpFunc(cmd, args)

View File

@ -10,28 +10,6 @@ import (
is "gotest.tools/v3/assert/cmp"
)
func TestVisitAll(t *testing.T) {
root := &cobra.Command{Use: "root"}
sub1 := &cobra.Command{Use: "sub1"}
sub1sub1 := &cobra.Command{Use: "sub1sub1"}
sub1sub2 := &cobra.Command{Use: "sub1sub2"}
sub2 := &cobra.Command{Use: "sub2"}
root.AddCommand(sub1, sub2)
sub1.AddCommand(sub1sub1, sub1sub2)
// Take the opportunity to test DisableFlagsInUseLine too
DisableFlagsInUseLine(root)
var visited []string
VisitAll(root, func(ccmd *cobra.Command) {
visited = append(visited, ccmd.Name())
assert.Assert(t, ccmd.DisableFlagsInUseLine, "DisableFlagsInUseLine not set on %q", ccmd.Name())
})
expected := []string{"sub1sub1", "sub1sub2", "sub1", "sub2", "root"}
assert.DeepEqual(t, expected, visited)
}
func TestVendorAndVersion(t *testing.T) {
// Non plugin.
assert.Equal(t, vendorAndVersion(&cobra.Command{Use: "test"}), "")

View File

@ -3,8 +3,8 @@ package builder
import (
"context"
"github.com/docker/docker/api/types/build"
"github.com/docker/docker/client"
"github.com/moby/moby/api/types/build"
"github.com/moby/moby/client"
)
type fakeClient struct {

View File

@ -6,29 +6,41 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/image"
"github.com/docker/cli/internal/commands"
)
// NewBuilderCommand returns a cobra command for `builder` subcommands
func NewBuilderCommand(dockerCli command.Cli) *cobra.Command {
func init() {
commands.Register(newBuilderCommand)
commands.Register(func(c command.Cli) *cobra.Command {
return newBakeStubCommand(c)
})
}
// newBuilderCommand returns a cobra command for `builder` subcommands
func newBuilderCommand(dockerCLI command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "builder",
Short: "Manage builds",
Args: cli.NoArgs,
RunE: command.ShowHelp(dockerCli.Err()),
RunE: command.ShowHelp(dockerCLI.Err()),
Annotations: map[string]string{"version": "1.31"},
DisableFlagsInUseLine: true,
}
cmd.AddCommand(
NewPruneCommand(dockerCli),
image.NewBuildCommand(dockerCli),
newPruneCommand(dockerCLI),
// we should have a mechanism for registering sub-commands in the cli/internal/commands.Register function.
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
image.NewBuildCommand(dockerCLI),
)
return cmd
}
// NewBakeStubCommand returns a cobra command "stub" for the "bake" subcommand.
// newBakeStubCommand returns a cobra command "stub" for the "bake" subcommand.
// This command is a placeholder / stub that is dynamically replaced by an
// alias for "docker buildx bake" if BuildKit is enabled (and the buildx plugin
// installed).
func NewBakeStubCommand(dockerCLI command.Streams) *cobra.Command {
func newBakeStubCommand(dockerCLI command.Streams) *cobra.Command {
return &cobra.Command{
Use: "bake [OPTIONS] [TARGET...]",
Short: "Build from a file",
@ -40,5 +52,6 @@ func NewBakeStubCommand(dockerCLI command.Streams) *cobra.Command {
"aliases": "docker buildx bake",
"version": "1.31",
},
DisableFlagsInUseLine: true,
}
}

View File

@ -8,14 +8,22 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/cli/cli/command/system/pruner"
"github.com/docker/cli/internal/prompt"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/build"
"github.com/docker/go-units"
"github.com/moby/moby/api/types/build"
"github.com/moby/moby/api/types/versions"
"github.com/spf13/cobra"
)
func init() {
// Register the prune command to run as part of "docker system prune"
if err := pruner.Register(pruner.TypeBuildCache, pruneFn); err != nil {
panic(err)
}
}
type pruneOptions struct {
force bool
all bool
@ -23,8 +31,8 @@ type pruneOptions struct {
keepStorage opts.MemBytes
}
// NewPruneCommand returns a new cobra prune command for images
func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
// newPruneCommand returns a new cobra prune command for images
func newPruneCommand(dockerCLI command.Cli) *cobra.Command {
options := pruneOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{
@ -32,18 +40,19 @@ func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
Short: "Remove build cache",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
spaceReclaimed, output, err := runPrune(cmd.Context(), dockerCli, options)
spaceReclaimed, output, err := runPrune(cmd.Context(), dockerCLI, options)
if err != nil {
return err
}
if output != "" {
fmt.Fprintln(dockerCli.Out(), output)
_, _ = fmt.Fprintln(dockerCLI.Out(), output)
}
fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
_, _ = fmt.Fprintln(dockerCLI.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
return nil
},
Annotations: map[string]string{"version": "1.39"},
ValidArgsFunction: completion.NoComplete,
Annotations: map[string]string{"version": "1.39"},
ValidArgsFunction: cobra.NoFileCompletions,
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()
@ -104,7 +113,30 @@ type cancelledErr struct{ error }
func (cancelledErr) Cancelled() {}
// CachePrune executes a prune command for build cache
func CachePrune(ctx context.Context, dockerCli command.Cli, all bool, filter opts.FilterOpt) (uint64, string, error) {
return runPrune(ctx, dockerCli, pruneOptions{force: true, all: all, filter: filter})
type errNotImplemented struct{ error }
func (errNotImplemented) NotImplemented() {}
// pruneFn prunes the build cache for use in "docker system prune" and
// returns the amount of space reclaimed and a detailed output string.
func pruneFn(ctx context.Context, dockerCLI command.Cli, options pruner.PruneOptions) (uint64, string, error) {
if ver := dockerCLI.Client().ClientVersion(); ver != "" && versions.LessThan(ver, "1.31") {
// Not supported on older daemons.
return 0, "", errNotImplemented{errors.New("builder prune requires API version 1.31 or greater")}
}
if !options.Confirmed {
// Dry-run: perform validation and produce confirmation before pruning.
var confirmMsg string
if options.All {
confirmMsg = "all build cache"
} else {
confirmMsg = "unused build cache"
}
return 0, confirmMsg, cancelledErr{errors.New("builder prune has been cancelled")}
}
return runPrune(ctx, dockerCLI, pruneOptions{
force: true,
all: options.All,
filter: options.Filter,
})
}

View File

@ -7,7 +7,7 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/build"
"github.com/moby/moby/api/types/build"
)
func TestBuilderPromptTermination(t *testing.T) {
@ -19,7 +19,7 @@ func TestBuilderPromptTermination(t *testing.T) {
return nil, errors.New("fakeClient builderPruneFunc should not be called")
},
})
cmd := NewPruneCommand(cli)
cmd := newPruneCommand(cli)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
test.TerminatePrompt(ctx, t, cmd, cli)

View File

@ -3,8 +3,8 @@ package checkpoint
import (
"context"
"github.com/docker/docker/api/types/checkpoint"
"github.com/docker/docker/client"
"github.com/moby/moby/api/types/checkpoint"
"github.com/moby/moby/client"
)
type fakeClient struct {

View File

@ -3,26 +3,32 @@ package checkpoint
import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/internal/commands"
"github.com/spf13/cobra"
)
// NewCheckpointCommand returns the `checkpoint` subcommand (only in experimental)
func NewCheckpointCommand(dockerCli command.Cli) *cobra.Command {
func init() {
commands.Register(newCheckpointCommand)
}
// newCheckpointCommand returns the `checkpoint` subcommand (only in experimental)
func newCheckpointCommand(dockerCLI command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "checkpoint",
Short: "Manage checkpoints",
Args: cli.NoArgs,
RunE: command.ShowHelp(dockerCli.Err()),
RunE: command.ShowHelp(dockerCLI.Err()),
Annotations: map[string]string{
"experimental": "",
"ostype": "linux",
"version": "1.25",
},
DisableFlagsInUseLine: true,
}
cmd.AddCommand(
newCreateCommand(dockerCli),
newListCommand(dockerCli),
newRemoveCommand(dockerCli),
newCreateCommand(dockerCLI),
newListCommand(dockerCLI),
newRemoveCommand(dockerCLI),
)
return cmd
}

View File

@ -6,8 +6,7 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/docker/api/types/checkpoint"
"github.com/moby/moby/api/types/checkpoint"
"github.com/spf13/cobra"
)
@ -18,7 +17,7 @@ type createOptions struct {
leaveRunning bool
}
func newCreateCommand(dockerCli command.Cli) *cobra.Command {
func newCreateCommand(dockerCLI command.Cli) *cobra.Command {
var opts createOptions
cmd := &cobra.Command{
@ -28,9 +27,10 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
opts.container = args[0]
opts.checkpoint = args[1]
return runCreate(cmd.Context(), dockerCli, opts)
return runCreate(cmd.Context(), dockerCLI, opts)
},
ValidArgsFunction: completion.NoComplete,
ValidArgsFunction: cobra.NoFileCompletions,
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()

View File

@ -8,7 +8,7 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/checkpoint"
"github.com/moby/moby/api/types/checkpoint"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)

View File

@ -2,7 +2,7 @@ package checkpoint
import (
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/docker/api/types/checkpoint"
"github.com/moby/moby/api/types/checkpoint"
)
const (
@ -10,25 +10,31 @@ const (
checkpointNameHeader = "CHECKPOINT NAME"
)
// NewFormat returns a format for use with a checkpoint Context
func NewFormat(source string) formatter.Format {
// newFormat returns a format for use with a checkpointContext.
func newFormat(source string) formatter.Format {
if source == formatter.TableFormatKey {
return defaultCheckpointFormat
}
return formatter.Format(source)
}
// FormatWrite writes formatted checkpoints using the Context
func FormatWrite(ctx formatter.Context, checkpoints []checkpoint.Summary) error {
render := func(format func(subContext formatter.SubContext) error) error {
// formatWrite writes formatted checkpoints using the Context
func formatWrite(fmtCtx formatter.Context, checkpoints []checkpoint.Summary) error {
cpContext := &checkpointContext{
HeaderContext: formatter.HeaderContext{
Header: formatter.SubHeaderContext{
"Name": checkpointNameHeader,
},
},
}
return fmtCtx.Write(cpContext, func(format func(subContext formatter.SubContext) error) error {
for _, cp := range checkpoints {
if err := format(&checkpointContext{c: cp}); err != nil {
return err
}
}
return nil
}
return ctx.Write(newCheckpointContext(), render)
})
}
type checkpointContext struct {
@ -36,14 +42,6 @@ type checkpointContext struct {
c checkpoint.Summary
}
func newCheckpointContext() *checkpointContext {
cpCtx := checkpointContext{}
cpCtx.Header = formatter.SubHeaderContext{
"Name": checkpointNameHeader,
}
return &cpCtx
}
func (c *checkpointContext) MarshalJSON() ([]byte, error) {
return formatter.MarshalJSON(c)
}

View File

@ -5,7 +5,7 @@ import (
"testing"
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/docker/api/types/checkpoint"
"github.com/moby/moby/api/types/checkpoint"
"gotest.tools/v3/assert"
)
@ -15,7 +15,7 @@ func TestCheckpointContextFormatWrite(t *testing.T) {
expected string
}{
{
formatter.Context{Format: NewFormat(defaultCheckpointFormat)},
formatter.Context{Format: newFormat(defaultCheckpointFormat)},
`CHECKPOINT NAME
checkpoint-1
checkpoint-2
@ -23,14 +23,14 @@ checkpoint-3
`,
},
{
formatter.Context{Format: NewFormat("{{.Name}}")},
formatter.Context{Format: newFormat("{{.Name}}")},
`checkpoint-1
checkpoint-2
checkpoint-3
`,
},
{
formatter.Context{Format: NewFormat("{{.Name}}:")},
formatter.Context{Format: newFormat("{{.Name}}:")},
`checkpoint-1:
checkpoint-2:
checkpoint-3:
@ -41,7 +41,7 @@ checkpoint-3:
for _, testcase := range cases {
out := bytes.NewBufferString("")
testcase.context.Output = out
err := FormatWrite(testcase.context, []checkpoint.Summary{
err := formatWrite(testcase.context, []checkpoint.Summary{
{Name: "checkpoint-1"},
{Name: "checkpoint-2"},
{Name: "checkpoint-3"},

View File

@ -7,7 +7,7 @@ import (
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/docker/api/types/checkpoint"
"github.com/moby/moby/api/types/checkpoint"
"github.com/spf13/cobra"
)
@ -15,7 +15,7 @@ type listOptions struct {
checkpointDir string
}
func newListCommand(dockerCli command.Cli) *cobra.Command {
func newListCommand(dockerCLI command.Cli) *cobra.Command {
var opts listOptions
cmd := &cobra.Command{
@ -24,9 +24,10 @@ func newListCommand(dockerCli command.Cli) *cobra.Command {
Short: "List checkpoints for a container",
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return runList(cmd.Context(), dockerCli, args[0], opts)
return runList(cmd.Context(), dockerCLI, args[0], opts)
},
ValidArgsFunction: completion.ContainerNames(dockerCli, false),
ValidArgsFunction: completion.ContainerNames(dockerCLI, false),
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()
@ -45,7 +46,7 @@ func runList(ctx context.Context, dockerCli command.Cli, container string, opts
cpCtx := formatter.Context{
Output: dockerCli.Out(),
Format: NewFormat(formatter.TableFormatKey),
Format: newFormat(formatter.TableFormatKey),
}
return FormatWrite(cpCtx, checkpoints)
return formatWrite(cpCtx, checkpoints)
}

View File

@ -6,7 +6,7 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/checkpoint"
"github.com/moby/moby/api/types/checkpoint"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/golden"

View File

@ -5,7 +5,7 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/docker/api/types/checkpoint"
"github.com/moby/moby/api/types/checkpoint"
"github.com/spf13/cobra"
)
@ -13,7 +13,7 @@ type removeOptions struct {
checkpointDir string
}
func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
func newRemoveCommand(dockerCLI command.Cli) *cobra.Command {
var opts removeOptions
cmd := &cobra.Command{
@ -22,8 +22,9 @@ func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
Short: "Remove a checkpoint",
Args: cli.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
return runRemove(cmd.Context(), dockerCli, args[0], args[1], opts)
return runRemove(cmd.Context(), dockerCLI, args[0], args[1], opts)
},
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()

View File

@ -6,7 +6,7 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/checkpoint"
"github.com/moby/moby/api/types/checkpoint"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)

View File

@ -5,6 +5,7 @@ package command
import (
"context"
"errors"
"fmt"
"io"
"os"
@ -23,11 +24,9 @@ import (
"github.com/docker/cli/cli/streams"
"github.com/docker/cli/cli/version"
dopts "github.com/docker/cli/opts"
"github.com/docker/docker/api"
"github.com/docker/docker/api/types/build"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/client"
"github.com/pkg/errors"
"github.com/moby/moby/api/types/build"
"github.com/moby/moby/api/types/swarm"
"github.com/moby/moby/client"
"github.com/spf13/cobra"
)
@ -88,9 +87,9 @@ type DockerCli struct {
enableGlobalMeter, enableGlobalTracer bool
}
// DefaultVersion returns [api.DefaultVersion].
// DefaultVersion returns [client.DefaultAPIVersion].
func (*DockerCli) DefaultVersion() string {
return api.DefaultVersion
return client.DefaultAPIVersion
}
// CurrentVersion returns the API version currently negotiated, or the default
@ -98,7 +97,7 @@ func (*DockerCli) DefaultVersion() string {
func (cli *DockerCli) CurrentVersion() string {
_ = cli.initialize()
if cli.client == nil {
return api.DefaultVersion
return client.DefaultAPIVersion
}
return cli.client.ClientVersion()
}
@ -169,7 +168,7 @@ func (cli *DockerCli) BuildKitEnabled() (bool, error) {
if v := os.Getenv("DOCKER_BUILDKIT"); v != "" {
enabled, err := strconv.ParseBool(v)
if err != nil {
return false, errors.Wrap(err, "DOCKER_BUILDKIT environment variable expects boolean value")
return false, fmt.Errorf("DOCKER_BUILDKIT environment variable expects boolean value: %w", err)
}
return enabled, nil
}
@ -282,6 +281,17 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...CLIOption)
}
filterResourceAttributesEnvvar()
// early return if GODEBUG is already set or the docker context is
// the default context, i.e. is a virtual context where we won't override
// any GODEBUG values.
if v := os.Getenv("GODEBUG"); cli.currentContext == DefaultContextName || v != "" {
return nil
}
meta, err := cli.contextStore.GetMetadata(cli.currentContext)
if err == nil {
setGoDebug(meta)
}
return nil
}
@ -300,7 +310,7 @@ func NewAPIClientFromFlags(opts *cliflags.ClientOptions, configFile *configfile.
}
endpoint, err := resolveDockerEndpoint(contextStore, resolveContextName(opts, configFile))
if err != nil {
return nil, errors.Wrap(err, "unable to resolve docker endpoint")
return nil, fmt.Errorf("unable to resolve docker endpoint: %w", err)
}
return newAPIClientFromEndpoint(endpoint, configFile)
}
@ -475,11 +485,62 @@ func (cli *DockerCli) getDockerEndPoint() (ep docker.Endpoint, err error) {
return resolveDockerEndpoint(cli.contextStore, cn)
}
// setGoDebug is an escape hatch that sets the GODEBUG environment
// variable value using docker context metadata.
//
// {
// "Name": "my-context",
// "Metadata": { "GODEBUG": "x509negativeserial=1" }
// }
//
// WARNING: Setting x509negativeserial=1 allows Go's x509 library to accept
// X.509 certificates with negative serial numbers.
// This behavior is deprecated and non-compliant with current security
// standards (RFC 5280). Accepting negative serial numbers can introduce
// serious security vulnerabilities, including the risk of certificate
// collision or bypass attacks.
// This option should only be used for legacy compatibility and never in
// production environments.
// Use at your own risk.
func setGoDebug(meta store.Metadata) {
fieldName := "GODEBUG"
godebugEnv := os.Getenv(fieldName)
// early return if GODEBUG is already set. We don't want to override what
// the user already sets.
if godebugEnv != "" {
return
}
var cfg any
var ok bool
switch m := meta.Metadata.(type) {
case DockerContext:
cfg, ok = m.AdditionalFields[fieldName]
if !ok {
return
}
case map[string]any:
cfg, ok = m[fieldName]
if !ok {
return
}
default:
return
}
v, ok := cfg.(string)
if !ok {
return
}
// set the GODEBUG environment variable with whatever was in the context
_ = os.Setenv(fieldName, v)
}
func (cli *DockerCli) initialize() error {
cli.init.Do(func() {
cli.dockerEndpoint, cli.initErr = cli.getDockerEndPoint()
if cli.initErr != nil {
cli.initErr = errors.Wrap(cli.initErr, "unable to resolve docker endpoint")
cli.initErr = fmt.Errorf("unable to resolve docker endpoint: %w", cli.initErr)
return
}
if cli.client == nil {
@ -547,7 +608,7 @@ func getServerHost(hosts []string, defaultToTLS bool) (string, error) {
case 1:
return dopts.ParseHost(defaultToTLS, hosts[0])
default:
return "", errors.New("Specify only one -H")
return "", errors.New("specify only one -H")
}
}

View File

@ -3,6 +3,7 @@ package command
import (
"context"
"encoding/csv"
"fmt"
"io"
"net/http"
"os"
@ -10,9 +11,8 @@ import (
"strings"
"github.com/docker/cli/cli/streams"
"github.com/docker/docker/client"
"github.com/moby/moby/client"
"github.com/moby/term"
"github.com/pkg/errors"
)
// CLIOption is a functional argument to apply options to a [DockerCli]. These
@ -189,7 +189,7 @@ func withCustomHeadersFromEnv() client.Opt {
csvReader := csv.NewReader(strings.NewReader(value))
fields, err := csvReader.Read()
if err != nil {
return invalidParameter(errors.Errorf(
return invalidParameter(fmt.Errorf(
"failed to parse custom headers from %s environment variable: value must be formatted as comma-separated key=value pairs",
envOverrideHTTPHeaders,
))
@ -206,7 +206,7 @@ func withCustomHeadersFromEnv() client.Opt {
k = strings.TrimSpace(k)
if k == "" {
return invalidParameter(errors.Errorf(
return invalidParameter(fmt.Errorf(
`failed to set custom headers from %s environment variable: value contains a key=value pair with an empty key: '%s'`,
envOverrideHTTPHeaders, kv,
))
@ -217,7 +217,7 @@ func withCustomHeadersFromEnv() client.Opt {
// from an environment variable with the same name). In the meantime,
// produce an error to prevent users from depending on this.
if !hasValue {
return invalidParameter(errors.Errorf(
return invalidParameter(fmt.Errorf(
`failed to set custom headers from %s environment variable: missing "=" in key=value pair: '%s'`,
envOverrideHTTPHeaders, kv,
))

View File

@ -18,10 +18,10 @@ import (
"github.com/docker/cli/cli/config"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/context/store"
"github.com/docker/cli/cli/flags"
"github.com/docker/docker/api"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/moby/moby/api/types"
"github.com/moby/moby/client"
"gotest.tools/v3/assert"
)
@ -34,7 +34,7 @@ func TestNewAPIClientFromFlags(t *testing.T) {
apiClient, err := NewAPIClientFromFlags(opts, &configfile.ConfigFile{})
assert.NilError(t, err)
assert.Equal(t, apiClient.DaemonHost(), host)
assert.Equal(t, apiClient.ClientVersion(), api.DefaultVersion)
assert.Equal(t, apiClient.ClientVersion(), client.DefaultAPIVersion)
}
func TestNewAPIClientFromFlagsForDefaultSchema(t *testing.T) {
@ -47,7 +47,7 @@ func TestNewAPIClientFromFlagsForDefaultSchema(t *testing.T) {
apiClient, err := NewAPIClientFromFlags(opts, &configfile.ConfigFile{})
assert.NilError(t, err)
assert.Equal(t, apiClient.DaemonHost(), slug+host)
assert.Equal(t, apiClient.ClientVersion(), api.DefaultVersion)
assert.Equal(t, apiClient.ClientVersion(), client.DefaultAPIVersion)
}
func TestNewAPIClientFromFlagsWithCustomHeaders(t *testing.T) {
@ -71,7 +71,7 @@ func TestNewAPIClientFromFlagsWithCustomHeaders(t *testing.T) {
apiClient, err := NewAPIClientFromFlags(opts, configFile)
assert.NilError(t, err)
assert.Equal(t, apiClient.DaemonHost(), host)
assert.Equal(t, apiClient.ClientVersion(), api.DefaultVersion)
assert.Equal(t, apiClient.ClientVersion(), client.DefaultAPIVersion)
// verify User-Agent is not appended to the configfile. see https://github.com/docker/cli/pull/2756
assert.DeepEqual(t, configFile.HTTPHeaders, map[string]string{"My-Header": "Custom-Value"})
@ -106,7 +106,7 @@ func TestNewAPIClientFromFlagsWithCustomHeadersFromEnv(t *testing.T) {
apiClient, err := NewAPIClientFromFlags(opts, configFile)
assert.NilError(t, err)
assert.Equal(t, apiClient.DaemonHost(), host)
assert.Equal(t, apiClient.ClientVersion(), api.DefaultVersion)
assert.Equal(t, apiClient.ClientVersion(), client.DefaultAPIVersion)
expectedHeaders := http.Header{
"One": []string{"one-value"},
@ -188,16 +188,16 @@ func TestInitializeFromClient(t *testing.T) {
for _, tc := range testcases {
t.Run(tc.doc, func(t *testing.T) {
apiclient := &fakeClient{
apiClient := &fakeClient{
pingFunc: tc.pingFunc,
version: defaultVersion,
}
cli := &DockerCli{client: apiclient}
cli := &DockerCli{client: apiClient}
err := cli.Initialize(flags.NewClientOptions())
assert.NilError(t, err)
assert.DeepEqual(t, cli.ServerInfo(), tc.expectedServer)
assert.Equal(t, apiclient.negotiated, tc.negotiated)
assert.Equal(t, apiClient.negotiated, tc.negotiated)
})
}
}
@ -353,3 +353,23 @@ func TestHooksEnabled(t *testing.T) {
assert.Check(t, !cli.HooksEnabled())
})
}
func TestSetGoDebug(t *testing.T) {
t.Run("GODEBUG already set", func(t *testing.T) {
t.Setenv("GODEBUG", "val1,val2")
meta := store.Metadata{}
setGoDebug(meta)
assert.Equal(t, "val1,val2", os.Getenv("GODEBUG"))
})
t.Run("GODEBUG in context metadata can set env", func(t *testing.T) {
meta := store.Metadata{
Metadata: DockerContext{
AdditionalFields: map[string]any{
"GODEBUG": "val1,val2=1",
},
},
}
setGoDebug(meta)
assert.Equal(t, "val1,val2=1", os.Getenv("GODEBUG"))
})
}

View File

@ -1,110 +1,31 @@
package commands
import (
"os"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/builder"
"github.com/docker/cli/cli/command/checkpoint"
"github.com/docker/cli/cli/command/config"
"github.com/docker/cli/cli/command/container"
"github.com/docker/cli/cli/command/context"
"github.com/docker/cli/cli/command/image"
"github.com/docker/cli/cli/command/manifest"
"github.com/docker/cli/cli/command/network"
"github.com/docker/cli/cli/command/node"
"github.com/docker/cli/cli/command/plugin"
"github.com/docker/cli/cli/command/registry"
"github.com/docker/cli/cli/command/secret"
"github.com/docker/cli/cli/command/service"
"github.com/docker/cli/cli/command/stack"
"github.com/docker/cli/cli/command/swarm"
"github.com/docker/cli/cli/command/system"
"github.com/docker/cli/cli/command/trust"
"github.com/docker/cli/cli/command/volume"
_ "github.com/docker/cli/cli/command/builder"
_ "github.com/docker/cli/cli/command/checkpoint"
_ "github.com/docker/cli/cli/command/config"
_ "github.com/docker/cli/cli/command/container"
_ "github.com/docker/cli/cli/command/context"
_ "github.com/docker/cli/cli/command/image"
_ "github.com/docker/cli/cli/command/manifest"
_ "github.com/docker/cli/cli/command/network"
_ "github.com/docker/cli/cli/command/node"
_ "github.com/docker/cli/cli/command/plugin"
_ "github.com/docker/cli/cli/command/registry"
_ "github.com/docker/cli/cli/command/secret"
_ "github.com/docker/cli/cli/command/service"
_ "github.com/docker/cli/cli/command/stack"
_ "github.com/docker/cli/cli/command/swarm"
_ "github.com/docker/cli/cli/command/system"
_ "github.com/docker/cli/cli/command/trust"
_ "github.com/docker/cli/cli/command/volume"
"github.com/docker/cli/internal/commands"
"github.com/spf13/cobra"
)
// AddCommands adds all the commands from cli/command to the root command
func AddCommands(cmd *cobra.Command, dockerCli command.Cli) {
cmd.AddCommand(
// commonly used shorthands
container.NewRunCommand(dockerCli),
container.NewExecCommand(dockerCli),
container.NewPsCommand(dockerCli),
image.NewBuildCommand(dockerCli),
image.NewPullCommand(dockerCli),
image.NewPushCommand(dockerCli),
image.NewImagesCommand(dockerCli),
registry.NewLoginCommand(dockerCli),
registry.NewLogoutCommand(dockerCli),
registry.NewSearchCommand(dockerCli),
system.NewVersionCommand(dockerCli),
system.NewInfoCommand(dockerCli),
// management commands
builder.NewBakeStubCommand(dockerCli),
builder.NewBuilderCommand(dockerCli),
checkpoint.NewCheckpointCommand(dockerCli),
container.NewContainerCommand(dockerCli),
context.NewContextCommand(dockerCli),
image.NewImageCommand(dockerCli),
manifest.NewManifestCommand(dockerCli),
network.NewNetworkCommand(dockerCli),
plugin.NewPluginCommand(dockerCli),
system.NewSystemCommand(dockerCli),
trust.NewTrustCommand(dockerCli),
volume.NewVolumeCommand(dockerCli),
// orchestration (swarm) commands
config.NewConfigCommand(dockerCli),
node.NewNodeCommand(dockerCli),
secret.NewSecretCommand(dockerCli),
service.NewServiceCommand(dockerCli),
stack.NewStackCommand(dockerCli),
swarm.NewSwarmCommand(dockerCli),
// legacy commands may be hidden
hide(container.NewAttachCommand(dockerCli)),
hide(container.NewCommitCommand(dockerCli)),
hide(container.NewCopyCommand(dockerCli)),
hide(container.NewCreateCommand(dockerCli)),
hide(container.NewDiffCommand(dockerCli)),
hide(container.NewExportCommand(dockerCli)),
hide(container.NewKillCommand(dockerCli)),
hide(container.NewLogsCommand(dockerCli)),
hide(container.NewPauseCommand(dockerCli)),
hide(container.NewPortCommand(dockerCli)),
hide(container.NewRenameCommand(dockerCli)),
hide(container.NewRestartCommand(dockerCli)),
hide(container.NewRmCommand(dockerCli)),
hide(container.NewStartCommand(dockerCli)),
hide(container.NewStatsCommand(dockerCli)),
hide(container.NewStopCommand(dockerCli)),
hide(container.NewTopCommand(dockerCli)),
hide(container.NewUnpauseCommand(dockerCli)),
hide(container.NewUpdateCommand(dockerCli)),
hide(container.NewWaitCommand(dockerCli)),
hide(image.NewHistoryCommand(dockerCli)),
hide(image.NewImportCommand(dockerCli)),
hide(image.NewLoadCommand(dockerCli)),
hide(image.NewRemoveCommand(dockerCli)),
hide(image.NewSaveCommand(dockerCli)),
hide(image.NewTagCommand(dockerCli)),
hide(system.NewEventsCommand(dockerCli)),
hide(system.NewInspectCommand(dockerCli)),
)
}
func hide(cmd *cobra.Command) *cobra.Command {
// If the environment variable with name "DOCKER_HIDE_LEGACY_COMMANDS" is not empty,
// these legacy commands (such as `docker ps`, `docker exec`, etc)
// will not be shown in output console.
if os.Getenv("DOCKER_HIDE_LEGACY_COMMANDS") == "" {
return cmd
func AddCommands(cmd *cobra.Command, dockerCLI command.Cli) {
for _, c := range commands.Commands() {
cmd.AddCommand(c(dockerCLI))
}
cmdCopy := *cmd
cmdCopy.Hidden = true
cmdCopy.Aliases = []string{}
return &cmdCopy
}

View File

@ -5,20 +5,12 @@ import (
"strings"
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/volume"
"github.com/docker/docker/client"
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/client"
"github.com/spf13/cobra"
)
// ValidArgsFn a function to be used by cobra command as `ValidArgsFunction` to offer command line completion.
//
// Deprecated: use [cobra.CompletionFunc].
type ValidArgsFn = cobra.CompletionFunc
// APIClientProvider provides a method to get an [client.APIClient], initializing
// APIClientProvider provides a method to get a [client.APIClient], initializing
// it if needed.
//
// It's a smaller interface than [command.Cli], and used in situations where an
@ -34,7 +26,7 @@ func ImageNames(dockerCLI APIClientProvider, limit int) cobra.CompletionFunc {
if limit > 0 && len(args) >= limit {
return nil, cobra.ShellCompDirectiveNoFileComp
}
list, err := dockerCLI.Client().ImageList(cmd.Context(), image.ListOptions{})
list, err := dockerCLI.Client().ImageList(cmd.Context(), client.ImageListOptions{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
@ -84,7 +76,7 @@ func ContainerNames(dockerCLI APIClientProvider, all bool, filters ...func(conta
// VolumeNames offers completion for volumes
func VolumeNames(dockerCLI APIClientProvider) cobra.CompletionFunc {
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
list, err := dockerCLI.Client().VolumeList(cmd.Context(), volume.ListOptions{})
list, err := dockerCLI.Client().VolumeList(cmd.Context(), client.VolumeListOptions{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
@ -99,7 +91,7 @@ func VolumeNames(dockerCLI APIClientProvider) cobra.CompletionFunc {
// NetworkNames offers completion for networks
func NetworkNames(dockerCLI APIClientProvider) cobra.CompletionFunc {
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
list, err := dockerCLI.Client().NetworkList(cmd.Context(), network.ListOptions{})
list, err := dockerCLI.Client().NetworkList(cmd.Context(), client.NetworkListOptions{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
@ -146,11 +138,6 @@ func FileNames(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCom
return nil, cobra.ShellCompDirectiveDefault
}
// NoComplete is used for commands where there's no relevant completion
func NoComplete(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return nil, cobra.ShellCompDirectiveNoFileComp
}
var commonPlatforms = []string{
"linux/386",
"linux/amd64",

View File

@ -6,13 +6,13 @@ import (
"sort"
"testing"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/volume"
"github.com/docker/docker/client"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/api/types/filters"
"github.com/moby/moby/api/types/image"
"github.com/moby/moby/api/types/network"
"github.com/moby/moby/api/types/volume"
"github.com/moby/moby/client"
"github.com/spf13/cobra"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
@ -31,8 +31,8 @@ func (c fakeCLI) Client() client.APIClient {
type fakeClient struct {
client.Client
containerListFunc func(options container.ListOptions) ([]container.Summary, error)
imageListFunc func(options image.ListOptions) ([]image.Summary, error)
networkListFunc func(ctx context.Context, options network.ListOptions) ([]network.Summary, error)
imageListFunc func(options client.ImageListOptions) ([]image.Summary, error)
networkListFunc func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error)
volumeListFunc func(filter filters.Args) (volume.ListResponse, error)
}
@ -43,21 +43,21 @@ func (c *fakeClient) ContainerList(_ context.Context, options container.ListOpti
return []container.Summary{}, nil
}
func (c *fakeClient) ImageList(_ context.Context, options image.ListOptions) ([]image.Summary, error) {
func (c *fakeClient) ImageList(_ context.Context, options client.ImageListOptions) ([]image.Summary, error) {
if c.imageListFunc != nil {
return c.imageListFunc(options)
}
return []image.Summary{}, nil
}
func (c *fakeClient) NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error) {
func (c *fakeClient) NetworkList(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error) {
if c.networkListFunc != nil {
return c.networkListFunc(ctx, options)
}
return []network.Inspect{}, nil
}
func (c *fakeClient) VolumeList(_ context.Context, options volume.ListOptions) (volume.ListResponse, error) {
func (c *fakeClient) VolumeList(_ context.Context, options client.VolumeListOptions) (volume.ListResponse, error) {
if c.volumeListFunc != nil {
return c.volumeListFunc(options.Filters)
}
@ -228,7 +228,7 @@ func TestCompleteImageNames(t *testing.T) {
for _, tc := range tests {
t.Run(tc.doc, func(t *testing.T) {
comp := ImageNames(fakeCLI{&fakeClient{
imageListFunc: func(options image.ListOptions) ([]image.Summary, error) {
imageListFunc: func(options client.ImageListOptions) ([]image.Summary, error) {
if tc.expDirective == cobra.ShellCompDirectiveError {
return nil, errors.New("some error occurred")
}
@ -273,7 +273,7 @@ func TestCompleteNetworkNames(t *testing.T) {
for _, tc := range tests {
t.Run(tc.doc, func(t *testing.T) {
comp := NetworkNames(fakeCLI{&fakeClient{
networkListFunc: func(ctx context.Context, options network.ListOptions) ([]network.Summary, error) {
networkListFunc: func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error) {
if tc.expDirective == cobra.ShellCompDirectiveError {
return nil, errors.New("some error occurred")
}
@ -288,12 +288,6 @@ func TestCompleteNetworkNames(t *testing.T) {
}
}
func TestCompleteNoComplete(t *testing.T) {
values, directives := NoComplete(nil, nil, "")
assert.Check(t, is.Equal(directives, cobra.ShellCompDirectiveNoFileComp))
assert.Check(t, is.Len(values, 0))
}
func TestCompletePlatforms(t *testing.T) {
values, directives := Platforms(nil, nil, "")
assert.Check(t, is.Equal(directives&cobra.ShellCompDirectiveNoFileComp, cobra.ShellCompDirectiveNoFileComp), "Should not perform file completion")

View File

@ -3,15 +3,15 @@ package config
import (
"context"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/client"
"github.com/moby/moby/api/types/swarm"
"github.com/moby/moby/client"
)
type fakeClient struct {
client.Client
configCreateFunc func(context.Context, swarm.ConfigSpec) (swarm.ConfigCreateResponse, error)
configInspectFunc func(context.Context, string) (swarm.Config, []byte, error)
configListFunc func(context.Context, swarm.ConfigListOptions) ([]swarm.Config, error)
configListFunc func(context.Context, client.ConfigListOptions) ([]swarm.Config, error)
configRemoveFunc func(string) error
}
@ -29,7 +29,7 @@ func (c *fakeClient) ConfigInspectWithRaw(ctx context.Context, id string) (swarm
return swarm.Config{}, nil, nil
}
func (c *fakeClient) ConfigList(ctx context.Context, options swarm.ConfigListOptions) ([]swarm.Config, error) {
func (c *fakeClient) ConfigList(ctx context.Context, options client.ConfigListOptions) ([]swarm.Config, error) {
if c.configListFunc != nil {
return c.configListFunc(ctx, options)
}

View File

@ -4,27 +4,33 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/cli/internal/commands"
"github.com/moby/moby/client"
"github.com/spf13/cobra"
)
// NewConfigCommand returns a cobra command for `config` subcommands
func NewConfigCommand(dockerCli command.Cli) *cobra.Command {
func init() {
commands.Register(newConfigCommand)
}
// newConfigCommand returns a cobra command for `config` subcommands
func newConfigCommand(dockerCLI command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "config",
Short: "Manage Swarm configs",
Args: cli.NoArgs,
RunE: command.ShowHelp(dockerCli.Err()),
RunE: command.ShowHelp(dockerCLI.Err()),
Annotations: map[string]string{
"version": "1.30",
"swarm": "manager",
},
DisableFlagsInUseLine: true,
}
cmd.AddCommand(
newConfigListCommand(dockerCli),
newConfigCreateCommand(dockerCli),
newConfigInspectCommand(dockerCli),
newConfigRemoveCommand(dockerCli),
newConfigListCommand(dockerCLI),
newConfigCreateCommand(dockerCLI),
newConfigInspectCommand(dockerCLI),
newConfigRemoveCommand(dockerCLI),
)
return cmd
}
@ -32,7 +38,7 @@ func NewConfigCommand(dockerCli command.Cli) *cobra.Command {
// completeNames offers completion for swarm configs
func completeNames(dockerCLI completion.APIClientProvider) cobra.CompletionFunc {
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
list, err := dockerCLI.Client().ConfigList(cmd.Context(), swarm.ConfigListOptions{})
list, err := dockerCLI.Client().ConfigList(cmd.Context(), client.ConfigListOptions{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}

View File

@ -2,30 +2,29 @@ package config
import (
"context"
"errors"
"fmt"
"io"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/swarm"
"github.com/moby/moby/api/types/swarm"
"github.com/moby/sys/sequential"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
// CreateOptions specifies some options that are used when creating a config.
type CreateOptions struct {
Name string
TemplateDriver string
File string
Labels opts.ListOpts
// createOptions specifies some options that are used when creating a config.
type createOptions struct {
name string
templateDriver string
file string
labels opts.ListOpts
}
func newConfigCreateCommand(dockerCli command.Cli) *cobra.Command {
createOpts := CreateOptions{
Labels: opts.NewListOpts(opts.ValidateLabel),
func newConfigCreateCommand(dockerCLI command.Cli) *cobra.Command {
createOpts := createOptions{
labels: opts.NewListOpts(opts.ValidateLabel),
}
cmd := &cobra.Command{
@ -33,39 +32,40 @@ func newConfigCreateCommand(dockerCli command.Cli) *cobra.Command {
Short: "Create a config from a file or STDIN",
Args: cli.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
createOpts.Name = args[0]
createOpts.File = args[1]
return RunConfigCreate(cmd.Context(), dockerCli, createOpts)
createOpts.name = args[0]
createOpts.file = args[1]
return runCreate(cmd.Context(), dockerCLI, createOpts)
},
ValidArgsFunction: completion.NoComplete,
ValidArgsFunction: cobra.NoFileCompletions,
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()
flags.VarP(&createOpts.Labels, "label", "l", "Config labels")
flags.StringVar(&createOpts.TemplateDriver, "template-driver", "", "Template driver")
flags.SetAnnotation("template-driver", "version", []string{"1.37"})
flags.VarP(&createOpts.labels, "label", "l", "Config labels")
flags.StringVar(&createOpts.templateDriver, "template-driver", "", "Template driver")
_ = flags.SetAnnotation("template-driver", "version", []string{"1.37"})
return cmd
}
// RunConfigCreate creates a config with the given options.
func RunConfigCreate(ctx context.Context, dockerCLI command.Cli, options CreateOptions) error {
// runCreate creates a config with the given options.
func runCreate(ctx context.Context, dockerCLI command.Cli, options createOptions) error {
apiClient := dockerCLI.Client()
configData, err := readConfigData(dockerCLI.In(), options.File)
configData, err := readConfigData(dockerCLI.In(), options.file)
if err != nil {
return errors.Errorf("Error reading content from %q: %v", options.File, err)
return fmt.Errorf("error reading content from %q: %v", options.file, err)
}
spec := swarm.ConfigSpec{
Annotations: swarm.Annotations{
Name: options.Name,
Labels: opts.ConvertKVStringsToMap(options.Labels.GetSlice()),
Name: options.name,
Labels: opts.ConvertKVStringsToMap(options.labels.GetSlice()),
},
Data: configData,
}
if options.TemplateDriver != "" {
if options.templateDriver != "" {
spec.Templating = &swarm.Driver{
Name: options.TemplateDriver,
Name: options.templateDriver,
}
}
r, err := apiClient.ConfigCreate(ctx, spec)

View File

@ -12,7 +12,7 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/swarm"
"github.com/moby/moby/api/types/swarm"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/golden"

View File

@ -7,8 +7,8 @@ import (
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/cli/command/inspect"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/go-units"
"github.com/moby/moby/api/types/swarm"
)
const (
@ -29,8 +29,8 @@ Data:
{{.Data}}`
)
// NewFormat returns a Format for rendering using a config Context
func NewFormat(source string, quiet bool) formatter.Format {
// newFormat returns a Format for rendering using a configContext.
func newFormat(source string, quiet bool) formatter.Format {
switch source {
case formatter.PrettyFormatKey:
return configInspectPrettyTemplate
@ -43,9 +43,20 @@ func NewFormat(source string, quiet bool) formatter.Format {
return formatter.Format(source)
}
// FormatWrite writes the context
func FormatWrite(ctx formatter.Context, configs []swarm.Config) error {
render := func(format func(subContext formatter.SubContext) error) error {
// formatWrite writes the context
func formatWrite(fmtCtx formatter.Context, configs []swarm.Config) error {
cCtx := &configContext{
HeaderContext: formatter.HeaderContext{
Header: formatter.SubHeaderContext{
"ID": configIDHeader,
"Name": formatter.NameHeader,
"CreatedAt": configCreatedHeader,
"UpdatedAt": configUpdatedHeader,
"Labels": formatter.LabelsHeader,
},
},
}
return fmtCtx.Write(cCtx, func(format func(subContext formatter.SubContext) error) error {
for _, config := range configs {
configCtx := &configContext{c: config}
if err := format(configCtx); err != nil {
@ -53,21 +64,7 @@ func FormatWrite(ctx formatter.Context, configs []swarm.Config) error {
}
}
return nil
}
return ctx.Write(newConfigContext(), render)
}
func newConfigContext() *configContext {
cCtx := &configContext{}
cCtx.Header = formatter.SubHeaderContext{
"ID": configIDHeader,
"Name": formatter.NameHeader,
"CreatedAt": configCreatedHeader,
"UpdatedAt": configUpdatedHeader,
"Labels": formatter.LabelsHeader,
}
return cCtx
})
}
type configContext struct {
@ -114,12 +111,12 @@ func (c *configContext) Label(name string) string {
return c.c.Spec.Annotations.Labels[name]
}
// InspectFormatWrite renders the context for a list of configs
func InspectFormatWrite(ctx formatter.Context, refs []string, getRef inspect.GetRefFunc) error {
if ctx.Format != configInspectPrettyTemplate {
return inspect.Inspect(ctx.Output, refs, string(ctx.Format), getRef)
// inspectFormatWrite renders the context for a list of configs
func inspectFormatWrite(fmtCtx formatter.Context, refs []string, getRef inspect.GetRefFunc) error {
if fmtCtx.Format != configInspectPrettyTemplate {
return inspect.Inspect(fmtCtx.Output, refs, string(fmtCtx.Format), getRef)
}
render := func(format func(subContext formatter.SubContext) error) error {
return fmtCtx.Write(&configInspectContext{}, func(format func(subContext formatter.SubContext) error) error {
for _, ref := range refs {
configI, _, err := getRef(ref)
if err != nil {
@ -134,8 +131,7 @@ func InspectFormatWrite(ctx formatter.Context, refs []string, getRef inspect.Get
}
}
return nil
}
return ctx.Write(&configInspectContext{}, render)
})
}
type configInspectContext struct {

View File

@ -6,7 +6,7 @@ import (
"time"
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/docker/api/types/swarm"
"github.com/moby/moby/api/types/swarm"
"gotest.tools/v3/assert"
)
@ -27,21 +27,21 @@ func TestConfigContextFormatWrite(t *testing.T) {
},
// Table format
{
formatter.Context{Format: NewFormat("table", false)},
formatter.Context{Format: newFormat("table", false)},
`ID NAME CREATED UPDATED
1 passwords Less than a second ago Less than a second ago
2 id_rsa Less than a second ago Less than a second ago
`,
},
{
formatter.Context{Format: NewFormat("table {{.Name}}", true)},
formatter.Context{Format: newFormat("table {{.Name}}", true)},
`NAME
passwords
id_rsa
`,
},
{
formatter.Context{Format: NewFormat("{{.ID}}-{{.Name}}", false)},
formatter.Context{Format: newFormat("{{.ID}}-{{.Name}}", false)},
`1-passwords
2-id_rsa
`,
@ -64,7 +64,7 @@ id_rsa
t.Run(string(tc.context.Format), func(t *testing.T) {
var out bytes.Buffer
tc.context.Output = &out
if err := FormatWrite(tc.context, configs); err != nil {
if err := formatWrite(tc.context, configs); err != nil {
assert.ErrorContains(t, err, tc.expected)
} else {
assert.Equal(t, out.String(), tc.expected)

View File

@ -15,58 +15,58 @@ import (
"github.com/spf13/cobra"
)
// InspectOptions contains options for the docker config inspect command.
type InspectOptions struct {
Names []string
Format string
Pretty bool
// inspectOptions contains options for the docker config inspect command.
type inspectOptions struct {
names []string
format string
pretty bool
}
func newConfigInspectCommand(dockerCli command.Cli) *cobra.Command {
opts := InspectOptions{}
func newConfigInspectCommand(dockerCLI command.Cli) *cobra.Command {
opts := inspectOptions{}
cmd := &cobra.Command{
Use: "inspect [OPTIONS] CONFIG [CONFIG...]",
Short: "Display detailed information on one or more configs",
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.Names = args
return RunConfigInspect(cmd.Context(), dockerCli, opts)
opts.names = args
return runInspect(cmd.Context(), dockerCLI, opts)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completeNames(dockerCli)(cmd, args, toComplete)
return completeNames(dockerCLI)(cmd, args, toComplete)
},
DisableFlagsInUseLine: true,
}
cmd.Flags().StringVarP(&opts.Format, "format", "f", "", flagsHelper.InspectFormatHelp)
cmd.Flags().BoolVar(&opts.Pretty, "pretty", false, "Print the information in a human friendly format")
cmd.Flags().StringVarP(&opts.format, "format", "f", "", flagsHelper.InspectFormatHelp)
cmd.Flags().BoolVar(&opts.pretty, "pretty", false, "Print the information in a human friendly format")
return cmd
}
// RunConfigInspect inspects the given Swarm config.
func RunConfigInspect(ctx context.Context, dockerCLI command.Cli, opts InspectOptions) error {
// runInspect inspects the given Swarm config.
func runInspect(ctx context.Context, dockerCLI command.Cli, opts inspectOptions) error {
apiClient := dockerCLI.Client()
if opts.Pretty {
opts.Format = "pretty"
if opts.pretty {
opts.format = "pretty"
}
getRef := func(id string) (any, []byte, error) {
return apiClient.ConfigInspectWithRaw(ctx, id)
}
f := opts.Format
// check if the user is trying to apply a template to the pretty format, which
// is not supported
if strings.HasPrefix(f, "pretty") && f != "pretty" {
if strings.HasPrefix(opts.format, "pretty") && opts.format != "pretty" {
return errors.New("cannot supply extra formatting options to the pretty template")
}
configCtx := formatter.Context{
Output: dockerCLI.Out(),
Format: NewFormat(f, false),
Format: newFormat(opts.format, false),
}
if err := InspectFormatWrite(configCtx, opts.Names, getRef); err != nil {
if err := inspectFormatWrite(configCtx, opts.names, getRef); err != nil {
return cli.StatusError{StatusCode: 1, Status: err.Error()}
}
return nil

View File

@ -10,7 +10,7 @@ import (
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/api/types/swarm"
"github.com/moby/moby/api/types/swarm"
"gotest.tools/v3/assert"
"gotest.tools/v3/golden"
)

View File

@ -6,24 +6,23 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/cli/cli/command/formatter"
flagsHelper "github.com/docker/cli/cli/flags"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/swarm"
"github.com/fvbommel/sortorder"
"github.com/moby/moby/client"
"github.com/spf13/cobra"
)
// ListOptions contains options for the docker config ls command.
type ListOptions struct {
Quiet bool
Format string
Filter opts.FilterOpt
// listOptions contains options for the docker config ls command.
type listOptions struct {
quiet bool
format string
filter opts.FilterOpt
}
func newConfigListCommand(dockerCli command.Cli) *cobra.Command {
listOpts := ListOptions{Filter: opts.NewFilterOpt()}
func newConfigListCommand(dockerCLI command.Cli) *cobra.Command {
listOpts := listOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{
Use: "ls [OPTIONS]",
@ -31,31 +30,32 @@ func newConfigListCommand(dockerCli command.Cli) *cobra.Command {
Short: "List configs",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return RunConfigList(cmd.Context(), dockerCli, listOpts)
return runList(cmd.Context(), dockerCLI, listOpts)
},
ValidArgsFunction: completion.NoComplete,
ValidArgsFunction: cobra.NoFileCompletions,
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()
flags.BoolVarP(&listOpts.Quiet, "quiet", "q", false, "Only display IDs")
flags.StringVar(&listOpts.Format, "format", "", flagsHelper.FormatHelp)
flags.VarP(&listOpts.Filter, "filter", "f", "Filter output based on conditions provided")
flags.BoolVarP(&listOpts.quiet, "quiet", "q", false, "Only display IDs")
flags.StringVar(&listOpts.format, "format", "", flagsHelper.FormatHelp)
flags.VarP(&listOpts.filter, "filter", "f", "Filter output based on conditions provided")
return cmd
}
// RunConfigList lists Swarm configs.
func RunConfigList(ctx context.Context, dockerCLI command.Cli, options ListOptions) error {
// runList lists Swarm configs.
func runList(ctx context.Context, dockerCLI command.Cli, options listOptions) error {
apiClient := dockerCLI.Client()
configs, err := apiClient.ConfigList(ctx, swarm.ConfigListOptions{Filters: options.Filter.Value()})
configs, err := apiClient.ConfigList(ctx, client.ConfigListOptions{Filters: options.filter.Value()})
if err != nil {
return err
}
format := options.Format
format := options.format
if len(format) == 0 {
if len(dockerCLI.ConfigFile().ConfigFormat) > 0 && !options.Quiet {
if len(dockerCLI.ConfigFile().ConfigFormat) > 0 && !options.quiet {
format = dockerCLI.ConfigFile().ConfigFormat
} else {
format = formatter.TableFormatKey
@ -68,7 +68,7 @@ func RunConfigList(ctx context.Context, dockerCLI command.Cli, options ListOptio
configCtx := formatter.Context{
Output: dockerCLI.Out(),
Format: NewFormat(format, options.Quiet),
Format: newFormat(format, options.quiet),
}
return FormatWrite(configCtx, configs)
return formatWrite(configCtx, configs)
}

View File

@ -10,7 +10,8 @@ import (
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/api/types/swarm"
"github.com/moby/moby/api/types/swarm"
"github.com/moby/moby/client"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/golden"
@ -19,7 +20,7 @@ import (
func TestConfigListErrors(t *testing.T) {
testCases := []struct {
args []string
configListFunc func(context.Context, swarm.ConfigListOptions) ([]swarm.Config, error)
configListFunc func(context.Context, client.ConfigListOptions) ([]swarm.Config, error)
expectedError string
}{
{
@ -27,7 +28,7 @@ func TestConfigListErrors(t *testing.T) {
expectedError: "accepts no argument",
},
{
configListFunc: func(_ context.Context, options swarm.ConfigListOptions) ([]swarm.Config, error) {
configListFunc: func(_ context.Context, options client.ConfigListOptions) ([]swarm.Config, error) {
return []swarm.Config{}, errors.New("error listing configs")
},
expectedError: "error listing configs",
@ -48,7 +49,7 @@ func TestConfigListErrors(t *testing.T) {
func TestConfigList(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
configListFunc: func(_ context.Context, options swarm.ConfigListOptions) ([]swarm.Config, error) {
configListFunc: func(_ context.Context, options client.ConfigListOptions) ([]swarm.Config, error) {
return []swarm.Config{
*builders.Config(builders.ConfigID("ID-1-foo"),
builders.ConfigName("1-foo"),
@ -78,7 +79,7 @@ func TestConfigList(t *testing.T) {
func TestConfigListWithQuietOption(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
configListFunc: func(_ context.Context, options swarm.ConfigListOptions) ([]swarm.Config, error) {
configListFunc: func(_ context.Context, options client.ConfigListOptions) ([]swarm.Config, error) {
return []swarm.Config{
*builders.Config(builders.ConfigID("ID-foo"), builders.ConfigName("foo")),
*builders.Config(builders.ConfigID("ID-bar"), builders.ConfigName("bar"), builders.ConfigLabels(map[string]string{
@ -95,7 +96,7 @@ func TestConfigListWithQuietOption(t *testing.T) {
func TestConfigListWithConfigFormat(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
configListFunc: func(_ context.Context, options swarm.ConfigListOptions) ([]swarm.Config, error) {
configListFunc: func(_ context.Context, options client.ConfigListOptions) ([]swarm.Config, error) {
return []swarm.Config{
*builders.Config(builders.ConfigID("ID-foo"), builders.ConfigName("foo")),
*builders.Config(builders.ConfigID("ID-bar"), builders.ConfigName("bar"), builders.ConfigLabels(map[string]string{
@ -114,7 +115,7 @@ func TestConfigListWithConfigFormat(t *testing.T) {
func TestConfigListWithFormat(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
configListFunc: func(_ context.Context, options swarm.ConfigListOptions) ([]swarm.Config, error) {
configListFunc: func(_ context.Context, options client.ConfigListOptions) ([]swarm.Config, error) {
return []swarm.Config{
*builders.Config(builders.ConfigID("ID-foo"), builders.ConfigName("foo")),
*builders.Config(builders.ConfigID("ID-bar"), builders.ConfigName("bar"), builders.ConfigLabels(map[string]string{
@ -131,7 +132,7 @@ func TestConfigListWithFormat(t *testing.T) {
func TestConfigListWithFilter(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
configListFunc: func(_ context.Context, options swarm.ConfigListOptions) ([]swarm.Config, error) {
configListFunc: func(_ context.Context, options client.ConfigListOptions) ([]swarm.Config, error) {
assert.Check(t, is.Equal("foo", options.Filters.Get("name")[0]))
assert.Check(t, is.Equal("lbl1=Label-bar", options.Filters.Get("label")[0]))
return []swarm.Config{

View File

@ -10,35 +10,28 @@ import (
"github.com/spf13/cobra"
)
// RemoveOptions contains options for the docker config rm command.
type RemoveOptions struct {
Names []string
}
func newConfigRemoveCommand(dockerCli command.Cli) *cobra.Command {
func newConfigRemoveCommand(dockerCLI command.Cli) *cobra.Command {
return &cobra.Command{
Use: "rm CONFIG [CONFIG...]",
Aliases: []string{"remove"},
Short: "Remove one or more configs",
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts := RemoveOptions{
Names: args,
}
return RunConfigRemove(cmd.Context(), dockerCli, opts)
return runRemove(cmd.Context(), dockerCLI, args)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completeNames(dockerCli)(cmd, args, toComplete)
return completeNames(dockerCLI)(cmd, args, toComplete)
},
DisableFlagsInUseLine: true,
}
}
// RunConfigRemove removes the given Swarm configs.
func RunConfigRemove(ctx context.Context, dockerCLI command.Cli, opts RemoveOptions) error {
// runRemove removes the given Swarm configs.
func runRemove(ctx context.Context, dockerCLI command.Cli, names []string) error {
apiClient := dockerCLI.Client()
var errs []error
for _, name := range opts.Names {
for _, name := range names {
if err := apiClient.ConfigRemove(ctx, name); err != nil {
errs = append(errs, err)
continue

View File

@ -2,15 +2,15 @@ package container
import (
"context"
"errors"
"io"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/client"
"github.com/moby/sys/signal"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@ -28,20 +28,20 @@ func inspectContainerAndCheckState(ctx context.Context, apiClient client.APIClie
return nil, err
}
if !c.State.Running {
return nil, errors.New("You cannot attach to a stopped container, start it first")
return nil, errors.New("cannot attach to a stopped container, start it first")
}
if c.State.Paused {
return nil, errors.New("You cannot attach to a paused container, unpause it first")
return nil, errors.New("cannot attach to a paused container, unpause it first")
}
if c.State.Restarting {
return nil, errors.New("You cannot attach to a restarting container, wait until it is running")
return nil, errors.New("cannot attach to a restarting container, wait until it is running")
}
return &c, nil
}
// NewAttachCommand creates a new cobra.Command for `docker attach`
func NewAttachCommand(dockerCLI command.Cli) *cobra.Command {
// newAttachCommand creates a new cobra.Command for `docker attach`
func newAttachCommand(dockerCLI command.Cli) *cobra.Command {
var opts AttachOptions
cmd := &cobra.Command{
@ -58,6 +58,7 @@ func NewAttachCommand(dockerCLI command.Cli) *cobra.Command {
ValidArgsFunction: completion.ContainerNames(dockerCLI, false, func(ctr container.Summary) bool {
return ctr.State != container.StatePaused
}),
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()

View File

@ -7,7 +7,7 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/container"
"github.com/moby/moby/api/types/container"
"gotest.tools/v3/assert"
)
@ -29,13 +29,11 @@ func TestNewAttachCommandErrors(t *testing.T) {
{
name: "client-stopped",
args: []string{"5cb5bb5e4a3b"},
expectedError: "You cannot attach to a stopped container",
expectedError: "cannot attach to a stopped container",
containerInspectFunc: func(containerID string) (container.InspectResponse, error) {
return container.InspectResponse{
ContainerJSONBase: &container.ContainerJSONBase{
State: &container.State{
Running: false,
},
State: &container.State{
Running: false,
},
}, nil
},
@ -43,14 +41,12 @@ func TestNewAttachCommandErrors(t *testing.T) {
{
name: "client-paused",
args: []string{"5cb5bb5e4a3b"},
expectedError: "You cannot attach to a paused container",
expectedError: "cannot attach to a paused container",
containerInspectFunc: func(containerID string) (container.InspectResponse, error) {
return container.InspectResponse{
ContainerJSONBase: &container.ContainerJSONBase{
State: &container.State{
Running: true,
Paused: true,
},
State: &container.State{
Running: true,
Paused: true,
},
}, nil
},
@ -58,15 +54,13 @@ func TestNewAttachCommandErrors(t *testing.T) {
{
name: "client-restarting",
args: []string{"5cb5bb5e4a3b"},
expectedError: "You cannot attach to a restarting container",
expectedError: "cannot attach to a restarting container",
containerInspectFunc: func(containerID string) (container.InspectResponse, error) {
return container.InspectResponse{
ContainerJSONBase: &container.ContainerJSONBase{
State: &container.State{
Running: true,
Paused: false,
Restarting: true,
},
State: &container.State{
Running: true,
Paused: false,
Restarting: true,
},
}, nil
},
@ -74,7 +68,7 @@ func TestNewAttachCommandErrors(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cmd := NewAttachCommand(test.NewFakeCli(&fakeClient{inspectFunc: tc.containerInspectFunc}))
cmd := newAttachCommand(test.NewFakeCli(&fakeClient{inspectFunc: tc.containerInspectFunc}))
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
cmd.SetArgs(tc.args)

View File

@ -4,13 +4,11 @@ import (
"context"
"io"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/client"
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/api/types/filters"
"github.com/moby/moby/api/types/network"
"github.com/moby/moby/api/types/system"
"github.com/moby/moby/client"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
@ -25,7 +23,7 @@ type fakeClient struct {
platform *ocispec.Platform,
containerName string) (container.CreateResponse, error)
containerStartFunc func(containerID string, options container.StartOptions) error
imageCreateFunc func(ctx context.Context, parentReference string, options image.CreateOptions) (io.ReadCloser, error)
imageCreateFunc func(ctx context.Context, parentReference string, options client.ImageCreateOptions) (io.ReadCloser, error)
infoFunc func() (system.Info, error)
containerStatPathFunc func(containerID, path string) (container.PathStat, error)
containerCopyFromFunc func(containerID, srcPath string) (io.ReadCloser, container.PathStat, error)
@ -33,13 +31,13 @@ type fakeClient struct {
waitFunc func(string) (<-chan container.WaitResponse, <-chan error)
containerListFunc func(container.ListOptions) ([]container.Summary, error)
containerExportFunc func(string) (io.ReadCloser, error)
containerExecResizeFunc func(id string, options container.ResizeOptions) error
containerExecResizeFunc func(id string, options client.ContainerResizeOptions) error
containerRemoveFunc func(ctx context.Context, containerID string, options container.RemoveOptions) error
containerRestartFunc func(ctx context.Context, containerID string, options container.StopOptions) error
containerStopFunc func(ctx context.Context, containerID string, options container.StopOptions) error
containerKillFunc func(ctx context.Context, containerID, signal string) error
containerPruneFunc func(ctx context.Context, pruneFilters filters.Args) (container.PruneReport, error)
containerAttachFunc func(ctx context.Context, containerID string, options container.AttachOptions) (types.HijackedResponse, error)
containerAttachFunc func(ctx context.Context, containerID string, options container.AttachOptions) (client.HijackedResponse, error)
containerDiffFunc func(ctx context.Context, containerID string) ([]container.FilesystemChange, error)
containerRenameFunc func(ctx context.Context, oldName, newName string) error
containerCommitFunc func(ctx context.Context, container string, options container.CommitOptions) (container.CommitResponse, error)
@ -100,7 +98,7 @@ func (f *fakeClient) ContainerRemove(ctx context.Context, containerID string, op
return nil
}
func (f *fakeClient) ImageCreate(ctx context.Context, parentReference string, options image.CreateOptions) (io.ReadCloser, error) {
func (f *fakeClient) ImageCreate(ctx context.Context, parentReference string, options client.ImageCreateOptions) (io.ReadCloser, error) {
if f.imageCreateFunc != nil {
return f.imageCreateFunc(ctx, parentReference, options)
}
@ -160,7 +158,7 @@ func (f *fakeClient) ContainerExport(_ context.Context, containerID string) (io.
return nil, nil
}
func (f *fakeClient) ContainerExecResize(_ context.Context, id string, options container.ResizeOptions) error {
func (f *fakeClient) ContainerExecResize(_ context.Context, id string, options client.ContainerResizeOptions) error {
if f.containerExecResizeFunc != nil {
return f.containerExecResizeFunc(id, options)
}
@ -195,11 +193,11 @@ func (f *fakeClient) ContainerStop(ctx context.Context, containerID string, opti
return nil
}
func (f *fakeClient) ContainerAttach(ctx context.Context, containerID string, options container.AttachOptions) (types.HijackedResponse, error) {
func (f *fakeClient) ContainerAttach(ctx context.Context, containerID string, options container.AttachOptions) (client.HijackedResponse, error) {
if f.containerAttachFunc != nil {
return f.containerAttachFunc(ctx, containerID, options)
}
return types.HijackedResponse{}, nil
return client.HijackedResponse{}, nil
}
func (f *fakeClient) ContainerDiff(ctx context.Context, containerID string) ([]container.FilesystemChange, error) {

View File

@ -3,43 +3,73 @@ package container
import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/internal/commands"
"github.com/spf13/cobra"
)
// NewContainerCommand returns a cobra command for `container` subcommands
func NewContainerCommand(dockerCli command.Cli) *cobra.Command {
func init() {
commands.Register(newRunCommand)
commands.Register(newExecCommand)
commands.Register(newPsCommand)
commands.Register(newContainerCommand)
commands.RegisterLegacy(newAttachCommand)
commands.RegisterLegacy(newCommitCommand)
commands.RegisterLegacy(newCopyCommand)
commands.RegisterLegacy(newCreateCommand)
commands.RegisterLegacy(newDiffCommand)
commands.RegisterLegacy(newExportCommand)
commands.RegisterLegacy(newKillCommand)
commands.RegisterLegacy(newLogsCommand)
commands.RegisterLegacy(newPauseCommand)
commands.RegisterLegacy(newPortCommand)
commands.RegisterLegacy(newRenameCommand)
commands.RegisterLegacy(newRestartCommand)
commands.RegisterLegacy(newRmCommand)
commands.RegisterLegacy(newStartCommand)
commands.RegisterLegacy(newStatsCommand)
commands.RegisterLegacy(newStopCommand)
commands.RegisterLegacy(newTopCommand)
commands.RegisterLegacy(newUnpauseCommand)
commands.RegisterLegacy(newUpdateCommand)
commands.RegisterLegacy(newWaitCommand)
}
// newContainerCommand returns a cobra command for `container` subcommands
func newContainerCommand(dockerCLI command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "container",
Short: "Manage containers",
Args: cli.NoArgs,
RunE: command.ShowHelp(dockerCli.Err()),
RunE: command.ShowHelp(dockerCLI.Err()),
DisableFlagsInUseLine: true,
}
cmd.AddCommand(
NewAttachCommand(dockerCli),
NewCommitCommand(dockerCli),
NewCopyCommand(dockerCli),
NewCreateCommand(dockerCli),
NewDiffCommand(dockerCli),
NewExecCommand(dockerCli),
NewExportCommand(dockerCli),
NewKillCommand(dockerCli),
NewLogsCommand(dockerCli),
NewPauseCommand(dockerCli),
NewPortCommand(dockerCli),
NewRenameCommand(dockerCli),
NewRestartCommand(dockerCli),
newRemoveCommand(dockerCli),
NewRunCommand(dockerCli),
NewStartCommand(dockerCli),
NewStatsCommand(dockerCli),
NewStopCommand(dockerCli),
NewTopCommand(dockerCli),
NewUnpauseCommand(dockerCli),
NewUpdateCommand(dockerCli),
NewWaitCommand(dockerCli),
newListCommand(dockerCli),
newInspectCommand(dockerCli),
NewPruneCommand(dockerCli),
newAttachCommand(dockerCLI),
newCommitCommand(dockerCLI),
newCopyCommand(dockerCLI),
newCreateCommand(dockerCLI),
newDiffCommand(dockerCLI),
newExecCommand(dockerCLI),
newExportCommand(dockerCLI),
newKillCommand(dockerCLI),
newLogsCommand(dockerCLI),
newPauseCommand(dockerCLI),
newPortCommand(dockerCLI),
newRenameCommand(dockerCLI),
newRestartCommand(dockerCLI),
newRemoveCommand(dockerCLI),
newRunCommand(dockerCLI),
newStartCommand(dockerCLI),
newStatsCommand(dockerCLI),
newStopCommand(dockerCLI),
newTopCommand(dockerCLI),
newUnpauseCommand(dockerCLI),
newUpdateCommand(dockerCLI),
newWaitCommand(dockerCLI),
newListCommand(dockerCLI),
newInspectCommand(dockerCLI),
newPruneCommand(dockerCLI),
)
return cmd
}

View File

@ -8,7 +8,7 @@ import (
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/container"
"github.com/moby/moby/api/types/container"
"github.com/spf13/cobra"
)
@ -22,8 +22,8 @@ type commitOptions struct {
changes opts.ListOpts
}
// NewCommitCommand creates a new cobra.Command for `docker commit`
func NewCommitCommand(dockerCli command.Cli) *cobra.Command {
// newCommitCommand creates a new cobra.Command for `docker commit`
func newCommitCommand(dockerCLI command.Cli) *cobra.Command {
var options commitOptions
cmd := &cobra.Command{
@ -35,12 +35,13 @@ func NewCommitCommand(dockerCli command.Cli) *cobra.Command {
if len(args) > 1 {
options.reference = args[1]
}
return runCommit(cmd.Context(), dockerCli, &options)
return runCommit(cmd.Context(), dockerCLI, &options)
},
Annotations: map[string]string{
"aliases": "docker container commit, docker commit",
},
ValidArgsFunction: completion.ContainerNames(dockerCli, false),
ValidArgsFunction: completion.ContainerNames(dockerCLI, false),
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()

View File

@ -7,7 +7,7 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/container"
"github.com/moby/moby/api/types/container"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
@ -29,7 +29,7 @@ func TestRunCommit(t *testing.T) {
},
})
cmd := NewCommitCommand(cli)
cmd := newCommitCommand(cli)
cmd.SetOut(io.Discard)
cmd.SetArgs(
[]string{
@ -60,7 +60,7 @@ func TestRunCommitClientError(t *testing.T) {
},
})
cmd := NewCommitCommand(cli)
cmd := newCommitCommand(cli)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
cmd.SetArgs([]string{"container-id"})

View File

@ -8,7 +8,7 @@ import (
"sync"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/docker/api/types/container"
"github.com/moby/moby/api/types/container"
"github.com/moby/sys/capability"
"github.com/moby/sys/signal"
"github.com/spf13/cobra"

View File

@ -6,7 +6,7 @@ import (
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/api/types/container"
"github.com/moby/moby/api/types/container"
"github.com/moby/sys/signal"
"github.com/spf13/cobra"
"gotest.tools/v3/assert"
@ -59,7 +59,7 @@ func TestCompletePid(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
containerListFunc: tc.containerListFunc,
})
completions, directive := completePid(cli)(NewRunCommand(cli), nil, tc.toComplete)
completions, directive := completePid(cli)(newRunCommand(cli), nil, tc.toComplete)
assert.Check(t, is.DeepEqual(completions, tc.expectedCompletions))
assert.Check(t, is.Equal(directive, tc.expectedDirective))
})

View File

@ -3,6 +3,7 @@ package container
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"os"
@ -15,11 +16,10 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/streams"
"github.com/docker/docker/api/types/container"
"github.com/docker/go-units"
"github.com/moby/go-archive"
"github.com/moby/moby/api/types/container"
"github.com/morikuni/aec"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
@ -121,8 +121,8 @@ func copyProgress(ctx context.Context, dst io.Writer, header string, total *int6
return restore, done
}
// NewCopyCommand creates a new `docker cp` command
func NewCopyCommand(dockerCli command.Cli) *cobra.Command {
// newCopyCommand creates a new `docker cp` command
func newCopyCommand(dockerCLI command.Cli) *cobra.Command {
var opts copyOptions
cmd := &cobra.Command{
@ -147,13 +147,14 @@ container source to stdout.`,
opts.destination = args[1]
if !cmd.Flag("quiet").Changed {
// User did not specify "quiet" flag; suppress output if no terminal is attached
opts.quiet = !dockerCli.Out().IsTerminal()
opts.quiet = !dockerCLI.Out().IsTerminal()
}
return runCopy(cmd.Context(), dockerCli, opts)
return runCopy(cmd.Context(), dockerCLI, opts)
},
Annotations: map[string]string{
"aliases": "docker container cp, docker cp",
},
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()
@ -298,50 +299,50 @@ func copyFromContainer(ctx context.Context, dockerCLI command.Cli, copyConfig cp
// about both the source and destination. The API is a simple tar
// archive/extract API but we can use the stat info header about the
// destination to be more informed about exactly what the destination is.
func copyToContainer(ctx context.Context, dockerCLI command.Cli, copyConfig cpConfig) (err error) {
func copyToContainer(ctx context.Context, dockerCLI command.Cli, copyConfig cpConfig) error {
srcPath := copyConfig.sourcePath
dstPath := copyConfig.destPath
if srcPath != "-" {
// Get an absolute source path.
srcPath, err = resolveLocalPath(srcPath)
p, err := resolveLocalPath(srcPath)
if err != nil {
return err
}
srcPath = p
}
apiClient := dockerCLI.Client()
// Prepare destination copy info by stat-ing the container path.
dstInfo := archive.CopyInfo{Path: dstPath}
dstStat, err := apiClient.ContainerStatPath(ctx, copyConfig.container, dstPath)
if dstStat, err := apiClient.ContainerStatPath(ctx, copyConfig.container, dstPath); err == nil {
// If the destination is a symbolic link, we should evaluate it.
if dstStat.Mode&os.ModeSymlink != 0 {
linkTarget := dstStat.LinkTarget
if !isAbs(linkTarget) {
// Join with the parent directory.
dstParent, _ := archive.SplitPathDirEntry(dstPath)
linkTarget = filepath.Join(dstParent, linkTarget)
}
// If the destination is a symbolic link, we should evaluate it.
if err == nil && dstStat.Mode&os.ModeSymlink != 0 {
linkTarget := dstStat.LinkTarget
if !isAbs(linkTarget) {
// Join with the parent directory.
dstParent, _ := archive.SplitPathDirEntry(dstPath)
linkTarget = filepath.Join(dstParent, linkTarget)
dstInfo.Path = linkTarget
dstStat, err = apiClient.ContainerStatPath(ctx, copyConfig.container, linkTarget)
}
// Validate the destination path
if err == nil {
if err := command.ValidateOutputPathFileMode(dstStat.Mode); err != nil {
return fmt.Errorf(`destination "%s:%s" must be a directory or a regular file: %w`, copyConfig.container, dstPath, err)
}
dstInfo.Exists, dstInfo.IsDir = true, dstStat.Mode.IsDir()
}
dstInfo.Path = linkTarget
dstStat, err = apiClient.ContainerStatPath(ctx, copyConfig.container, linkTarget)
// FIXME(thaJeztah): unhandled error (should this return?)
}
// Validate the destination path
if err := command.ValidateOutputPathFileMode(dstStat.Mode); err != nil {
return errors.Wrapf(err, `destination "%s:%s" must be a directory or a regular file`, copyConfig.container, dstPath)
}
// Ignore any error and assume that the parent directory of the destination
// path exists, in which case the copy may still succeed. If there is any
// type of conflict (e.g., non-directory overwriting an existing directory
// or vice versa) the extraction will fail. If the destination simply did
// not exist, but the parent directory does, the extraction will still
// succeed.
if err == nil {
dstInfo.Exists, dstInfo.IsDir = true, dstStat.Mode.IsDir()
// Ignore any error and assume that the parent directory of the destination
// path exists, in which case the copy may still succeed. If there is any
// type of conflict (e.g., non-directory overwriting an existing directory
// or vice versa) the extraction will fail. If the destination simply did
// not exist, but the parent directory does, the extraction will still
// succeed.
_ = err // Intentionally ignore stat errors (see above)
}
var (
@ -354,7 +355,7 @@ func copyToContainer(ctx context.Context, dockerCLI command.Cli, copyConfig cpCo
content = os.Stdin
resolvedDstPath = dstInfo.Path
if !dstInfo.IsDir {
return errors.Errorf("destination \"%s:%s\" must be a directory", copyConfig.container, dstPath)
return fmt.Errorf(`destination "%s:%s" must be a directory`, copyConfig.container, dstPath)
}
} else {
// Prepare source copy info.
@ -411,7 +412,7 @@ func copyToContainer(ctx context.Context, dockerCLI command.Cli, copyConfig cpCo
cancel()
<-done
restore()
fmt.Fprintln(dockerCLI.Err(), "Successfully copied", progressHumanSize(copiedSize), "to", copyConfig.container+":"+dstInfo.Path)
_, _ = fmt.Fprintln(dockerCLI.Err(), "Successfully copied", progressHumanSize(copiedSize), "to", copyConfig.container+":"+dstInfo.Path)
return res
}

View File

@ -9,9 +9,9 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/container"
"github.com/moby/go-archive"
"github.com/moby/go-archive/compression"
"github.com/moby/moby/api/types/container"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/fs"

View File

@ -4,6 +4,7 @@ import (
"archive/tar"
"bytes"
"context"
"errors"
"fmt"
"io"
"net/netip"
@ -11,7 +12,7 @@ import (
"path"
"strings"
cerrdefs "github.com/containerd/errdefs"
"github.com/containerd/errdefs"
"github.com/containerd/platforms"
"github.com/distribution/reference"
"github.com/docker/cli/cli"
@ -24,13 +25,11 @@ import (
"github.com/docker/cli/cli/trust"
"github.com/docker/cli/internal/jsonstream"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/container"
imagetypes "github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client"
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/api/types/mount"
"github.com/moby/moby/api/types/versions"
"github.com/moby/moby/client"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
@ -51,8 +50,8 @@ type createOptions struct {
useAPISocket bool
}
// NewCreateCommand creates a new cobra.Command for `docker create`
func NewCreateCommand(dockerCli command.Cli) *cobra.Command {
// newCreateCommand creates a new cobra.Command for `docker create`
func newCreateCommand(dockerCLI command.Cli) *cobra.Command {
var options createOptions
var copts *containerOptions
@ -65,12 +64,13 @@ func NewCreateCommand(dockerCli command.Cli) *cobra.Command {
if len(args) > 1 {
copts.Args = args[1:]
}
return runCreate(cmd.Context(), dockerCli, cmd.Flags(), &options, copts)
return runCreate(cmd.Context(), dockerCLI, cmd.Flags(), &options, copts)
},
Annotations: map[string]string{
"aliases": "docker container create, docker create",
},
ValidArgsFunction: completion.ImageNames(dockerCli, -1),
ValidArgsFunction: completion.ImageNames(dockerCLI, -1),
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()
@ -80,23 +80,26 @@ func NewCreateCommand(dockerCli command.Cli) *cobra.Command {
flags.StringVar(&options.pull, "pull", PullImageMissing, `Pull image before creating ("`+PullImageAlways+`", "|`+PullImageMissing+`", "`+PullImageNever+`")`)
flags.BoolVarP(&options.quiet, "quiet", "q", false, "Suppress the pull output")
flags.BoolVarP(&options.useAPISocket, "use-api-socket", "", false, "Bind mount Docker API socket and required auth")
flags.SetAnnotation("use-api-socket", "experimentalCLI", nil) // Marks flag as experimental for now.
_ = flags.SetAnnotation("use-api-socket", "experimentalCLI", nil) // Mark flag as experimental for now.
// Add an explicit help that doesn't have a `-h` to prevent the conflict
// with hostname
flags.Bool("help", false, "Print usage")
command.AddPlatformFlag(flags, &options.platform)
command.AddTrustVerificationFlags(flags, &options.untrusted, dockerCli.ContentTrustEnabled())
// TODO(thaJeztah): consider adding platform as "image create option" on containerOptions
addPlatformFlag(flags, &options.platform)
_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms)
flags.BoolVar(&options.untrusted, "disable-content-trust", !dockerCLI.ContentTrustEnabled(), "Skip image verification")
copts = addFlags(flags)
addCompletions(cmd, dockerCli)
addCompletions(cmd, dockerCLI)
flags.VisitAll(func(flag *pflag.Flag) {
// Set a default completion function if none was set. We don't look
// up if it does already have one set, because Cobra does this for
// us, and returns an error (which we ignore for this reason).
_ = cmd.RegisterFlagCompletionFunc(flag.Name, completion.NoComplete)
_ = cmd.RegisterFlagCompletionFunc(flag.Name, cobra.NoFileCompletions)
})
return cmd
@ -110,7 +113,7 @@ func runCreate(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet,
}
}
proxyConfig := dockerCli.ConfigFile().ParseProxyConfig(dockerCli.Client().DaemonHost(), opts.ConvertKVStringsToMapWithNil(copts.env.GetSlice()))
newEnv := []string{}
newEnv := make([]string, 0, len(proxyConfig))
for k, v := range proxyConfig {
if v == nil {
newEnv = append(newEnv, k)
@ -141,14 +144,16 @@ func pullImage(ctx context.Context, dockerCli command.Cli, img string, options *
return err
}
responseBody, err := dockerCli.Client().ImageCreate(ctx, img, imagetypes.CreateOptions{
responseBody, err := dockerCli.Client().ImageCreate(ctx, img, client.ImageCreateOptions{
RegistryAuth: encodedAuth,
Platform: options.platform,
})
if err != nil {
return err
}
defer responseBody.Close()
defer func() {
_ = responseBody.Close()
}()
out := dockerCli.Err()
if options.quiet {
@ -167,13 +172,13 @@ func (cid *cidFile) Close() error {
if cid.file == nil {
return nil
}
cid.file.Close()
_ = cid.file.Close()
if cid.written {
return nil
}
if err := os.Remove(cid.path); err != nil {
return errors.Wrapf(err, "failed to remove the CID file '%s'", cid.path)
return fmt.Errorf("failed to remove the CID file '%s': %w", cid.path, err)
}
return nil
@ -184,7 +189,7 @@ func (cid *cidFile) Write(id string) error {
return nil
}
if _, err := cid.file.Write([]byte(id)); err != nil {
return errors.Wrap(err, "failed to write the container ID to the file")
return fmt.Errorf("failed to write the container ID to the file: %w", err)
}
cid.written = true
return nil
@ -195,12 +200,12 @@ func newCIDFile(cidPath string) (*cidFile, error) {
return &cidFile{}, nil
}
if _, err := os.Stat(cidPath); err == nil {
return nil, errors.Errorf("container ID file found, make sure the other container isn't running or delete %s", cidPath)
return nil, errors.New("container ID file found, make sure the other container isn't running or delete " + cidPath)
}
f, err := os.Create(cidPath)
if err != nil {
return nil, errors.Wrap(err, "failed to create the container ID file")
return nil, fmt.Errorf("failed to create the container ID file: %w", err)
}
return &cidFile{path: cidPath, file: f}, nil
@ -221,7 +226,9 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
if err != nil {
return "", err
}
defer containerIDFile.Close()
defer func() {
_ = containerIDFile.Close()
}()
ref, err := reference.ParseAnyReference(config.Image)
if err != nil {
@ -315,7 +322,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
if options.platform != "" && versions.GreaterThanOrEqualTo(dockerCli.Client().ClientVersion(), "1.41") {
p, err := platforms.Parse(options.platform)
if err != nil {
return "", errors.Wrap(invalidParameter(err), "error parsing specified platform")
return "", invalidParameter(fmt.Errorf("error parsing specified platform: %w", err))
}
platform = &p
}
@ -341,7 +348,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
response, err := dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, platform, options.name)
if err != nil {
// Pull image if it does not exist locally and we have the PullImageMissing option. Default behavior.
if cerrdefs.IsNotFound(err) && namedRef != nil && options.pull == PullImageMissing {
if errdefs.IsNotFound(err) && namedRef != nil && options.pull == PullImageMissing {
if !options.quiet {
// we don't want to write to stdout anything apart from container.ID
_, _ = fmt.Fprintf(dockerCli.Err(), "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef))
@ -428,7 +435,7 @@ func copyDockerConfigIntoContainer(ctx context.Context, dockerAPI client.APIClie
// We don't need to get super fancy with the tar creation.
var tarBuf bytes.Buffer
tarWriter := tar.NewWriter(&tarBuf)
tarWriter.WriteHeader(&tar.Header{
_ = tarWriter.WriteHeader(&tar.Header{
Name: configPath,
Size: int64(configBuf.Len()),
Mode: 0o600,

View File

@ -14,11 +14,11 @@ import (
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/notary"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/system"
"github.com/google/go-cmp/cmp"
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/api/types/network"
"github.com/moby/moby/api/types/system"
"github.com/moby/moby/client"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/pflag"
"gotest.tools/v3/assert"
@ -116,7 +116,7 @@ func TestCreateContainerImagePullPolicy(t *testing.T) {
t.Run(tc.PullPolicy, func(t *testing.T) {
pullCounter := 0
client := &fakeClient{
apiClient := &fakeClient{
createContainerFunc: func(
config *container.Config,
hostConfig *container.HostConfig,
@ -132,7 +132,7 @@ func TestCreateContainerImagePullPolicy(t *testing.T) {
return container.CreateResponse{ID: containerID}, nil
}
},
imageCreateFunc: func(ctx context.Context, parentReference string, options image.CreateOptions) (io.ReadCloser, error) {
imageCreateFunc: func(ctx context.Context, parentReference string, options client.ImageCreateOptions) (io.ReadCloser, error) {
defer func() { pullCounter++ }()
return io.NopCloser(strings.NewReader("")), nil
},
@ -140,7 +140,7 @@ func TestCreateContainerImagePullPolicy(t *testing.T) {
return system.Info{IndexServerAddress: "https://indexserver.example.com"}, nil
},
}
fakeCLI := test.NewFakeCli(client)
fakeCLI := test.NewFakeCli(apiClient)
id, err := createContainer(context.Background(), fakeCLI, config, &createOptions{
name: "name",
platform: runtime.GOOS,
@ -206,7 +206,7 @@ func TestCreateContainerValidateFlags(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
cmd := NewCreateCommand(test.NewFakeCli(&fakeClient{}))
cmd := newCreateCommand(test.NewFakeCli(&fakeClient{}))
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
cmd.SetArgs(tc.args)
@ -260,7 +260,7 @@ func TestNewCreateCommandWithContentTrustErrors(t *testing.T) {
},
}, test.EnableContentTrust)
fakeCLI.SetNotaryClient(tc.notaryFunc)
cmd := NewCreateCommand(fakeCLI)
cmd := newCreateCommand(fakeCLI)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
cmd.SetArgs(tc.args)
@ -314,7 +314,7 @@ func TestNewCreateCommandWithWarnings(t *testing.T) {
return container.CreateResponse{Warnings: tc.warnings}, nil
},
})
cmd := NewCreateCommand(fakeCLI)
cmd := newCreateCommand(fakeCLI)
cmd.SetOut(io.Discard)
cmd.SetArgs(tc.args)
err := cmd.Execute()
@ -366,7 +366,7 @@ func TestCreateContainerWithProxyConfig(t *testing.T) {
},
},
})
cmd := NewCreateCommand(fakeCLI)
cmd := newCreateCommand(fakeCLI)
cmd.SetOut(io.Discard)
cmd.SetArgs([]string{"image:tag"})
err := cmd.Execute()

View File

@ -10,19 +10,20 @@ import (
"github.com/spf13/cobra"
)
// NewDiffCommand creates a new cobra.Command for `docker diff`
func NewDiffCommand(dockerCli command.Cli) *cobra.Command {
// newDiffCommand creates a new cobra.Command for `docker diff`
func newDiffCommand(dockerCLI command.Cli) *cobra.Command {
return &cobra.Command{
Use: "diff CONTAINER",
Short: "Inspect changes to files or directories on a container's filesystem",
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return runDiff(cmd.Context(), dockerCli, args[0])
return runDiff(cmd.Context(), dockerCLI, args[0])
},
Annotations: map[string]string{
"aliases": "docker container diff, docker diff",
},
ValidArgsFunction: completion.ContainerNames(dockerCli, false),
ValidArgsFunction: completion.ContainerNames(dockerCLI, false),
DisableFlagsInUseLine: true,
}
}
@ -33,7 +34,7 @@ func runDiff(ctx context.Context, dockerCLI command.Cli, containerID string) err
}
diffCtx := formatter.Context{
Output: dockerCLI.Out(),
Format: NewDiffFormat("{{.Type}} {{.Path}}"),
Format: newDiffFormat("{{.Type}} {{.Path}}"),
}
return DiffFormatWrite(diffCtx, changes)
return diffFormatWrite(diffCtx, changes)
}

View File

@ -8,7 +8,7 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/container"
"github.com/moby/moby/api/types/container"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
@ -36,7 +36,7 @@ func TestRunDiff(t *testing.T) {
},
})
cmd := NewDiffCommand(cli)
cmd := newDiffCommand(cli)
cmd.SetOut(io.Discard)
cmd.SetArgs([]string{"container-id"})
@ -68,7 +68,7 @@ func TestRunDiffClientError(t *testing.T) {
},
})
cmd := NewDiffCommand(cli)
cmd := newDiffCommand(cli)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)

View File

@ -1,9 +1,9 @@
package container
import cerrdefs "github.com/containerd/errdefs"
import "github.com/containerd/errdefs"
func invalidParameter(err error) error {
if err == nil || cerrdefs.IsInvalidArgument(err) {
if err == nil || errdefs.IsInvalidArgument(err) {
return err
}
return invalidParameterErr{err}
@ -17,7 +17,7 @@ func (e invalidParameterErr) Unwrap() error {
}
func notFound(err error) error {
if err == nil || cerrdefs.IsNotFound(err) {
if err == nil || errdefs.IsNotFound(err) {
return err
}
return notFoundErr{err}

View File

@ -10,8 +10,8 @@ import (
"github.com/docker/cli/cli/command/completion"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/client"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@ -39,8 +39,8 @@ func NewExecOptions() ExecOptions {
}
}
// NewExecCommand creates a new cobra.Command for `docker exec`
func NewExecCommand(dockerCli command.Cli) *cobra.Command {
// newExecCommand creates a new cobra.Command for "docker exec".
func newExecCommand(dockerCLI command.Cli) *cobra.Command {
options := NewExecOptions()
cmd := &cobra.Command{
@ -50,15 +50,16 @@ func NewExecCommand(dockerCli command.Cli) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
containerIDorName := args[0]
options.Command = args[1:]
return RunExec(cmd.Context(), dockerCli, containerIDorName, options)
return RunExec(cmd.Context(), dockerCLI, containerIDorName, options)
},
ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr container.Summary) bool {
ValidArgsFunction: completion.ContainerNames(dockerCLI, false, func(ctr container.Summary) bool {
return ctr.State != container.StatePaused
}),
Annotations: map[string]string{
"category-top": "2",
"aliases": "docker container exec, docker exec",
},
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()

View File

@ -12,7 +12,7 @@ import (
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/container"
"github.com/moby/moby/api/types/container"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/fs"
@ -234,13 +234,13 @@ func TestGetExecExitStatus(t *testing.T) {
}
for _, testcase := range testcases {
client := &fakeClient{
apiClient := &fakeClient{
execInspectFunc: func(id string) (container.ExecInspect, error) {
assert.Check(t, is.Equal(execID, id))
return container.ExecInspect{ExitCode: testcase.exitCode}, testcase.inspectError
},
}
err := getExecExitStatus(context.Background(), client, execID)
err := getExecExitStatus(context.Background(), apiClient, execID)
assert.Check(t, is.Equal(testcase.expectedError, err))
}
}
@ -263,7 +263,7 @@ func TestNewExecCommandErrors(t *testing.T) {
}
for _, tc := range testCases {
fakeCLI := test.NewFakeCli(&fakeClient{inspectFunc: tc.containerInspectFunc})
cmd := NewExecCommand(fakeCLI)
cmd := newExecCommand(fakeCLI)
cmd.SetOut(io.Discard)
cmd.SetArgs(tc.args)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)

View File

@ -17,8 +17,8 @@ type exportOptions struct {
output string
}
// NewExportCommand creates a new `docker export` command
func NewExportCommand(dockerCli command.Cli) *cobra.Command {
// newExportCommand creates a new "docker container export" command.
func newExportCommand(dockerCLI command.Cli) *cobra.Command {
var opts exportOptions
cmd := &cobra.Command{
@ -27,12 +27,13 @@ func NewExportCommand(dockerCli command.Cli) *cobra.Command {
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.container = args[0]
return runExport(cmd.Context(), dockerCli, opts)
return runExport(cmd.Context(), dockerCLI, opts)
},
Annotations: map[string]string{
"aliases": "docker container export, docker export",
},
ValidArgsFunction: completion.ContainerNames(dockerCli, true),
ValidArgsFunction: completion.ContainerNames(dockerCLI, true),
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()

View File

@ -19,7 +19,7 @@ func TestContainerExportOutputToFile(t *testing.T) {
return io.NopCloser(strings.NewReader("bar")), nil
},
})
cmd := NewExportCommand(cli)
cmd := newExportCommand(cli)
cmd.SetOut(io.Discard)
cmd.SetArgs([]string{"-o", dir.Join("foo"), "container"})
assert.NilError(t, cmd.Execute())
@ -37,7 +37,7 @@ func TestContainerExportOutputToIrregularFile(t *testing.T) {
return io.NopCloser(strings.NewReader("foo")), nil
},
})
cmd := NewExportCommand(cli)
cmd := newExportCommand(cli)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
cmd.SetArgs([]string{"-o", "/dev/random", "container"})

View File

@ -2,7 +2,7 @@ package container
import (
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/docker/api/types/container"
"github.com/moby/moby/api/types/container"
)
const (
@ -12,25 +12,24 @@ const (
pathHeader = "PATH"
)
// NewDiffFormat returns a format for use with a diff Context
func NewDiffFormat(source string) formatter.Format {
// newDiffFormat returns a format for use with a diff [formatter.Context].
func newDiffFormat(source string) formatter.Format {
if source == formatter.TableFormatKey {
return defaultDiffTableFormat
}
return formatter.Format(source)
}
// DiffFormatWrite writes formatted diff using the Context
func DiffFormatWrite(ctx formatter.Context, changes []container.FilesystemChange) error {
render := func(format func(subContext formatter.SubContext) error) error {
// diffFormatWrite writes formatted diff using the [formatter.Context].
func diffFormatWrite(fmtCtx formatter.Context, changes []container.FilesystemChange) error {
return fmtCtx.Write(newDiffContext(), func(format func(subContext formatter.SubContext) error) error {
for _, change := range changes {
if err := format(&diffContext{c: change}); err != nil {
return err
}
}
return nil
}
return ctx.Write(newDiffContext(), render)
})
}
type diffContext struct {
@ -39,12 +38,14 @@ type diffContext struct {
}
func newDiffContext() *diffContext {
diffCtx := diffContext{}
diffCtx.Header = formatter.SubHeaderContext{
"Type": changeTypeHeader,
"Path": pathHeader,
return &diffContext{
HeaderContext: formatter.HeaderContext{
Header: formatter.SubHeaderContext{
"Type": changeTypeHeader,
"Path": pathHeader,
},
},
}
return &diffCtx
}
func (d *diffContext) MarshalJSON() ([]byte, error) {

View File

@ -5,7 +5,7 @@ import (
"testing"
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/docker/api/types/container"
"github.com/moby/moby/api/types/container"
"gotest.tools/v3/assert"
)
@ -16,7 +16,7 @@ func TestDiffContextFormatWrite(t *testing.T) {
expected string
}{
{
formatter.Context{Format: NewDiffFormat("table")},
formatter.Context{Format: newDiffFormat("table")},
`CHANGE TYPE PATH
C /var/log/app.log
A /usr/app/app.js
@ -24,7 +24,7 @@ D /usr/app/old_app.js
`,
},
{
formatter.Context{Format: NewDiffFormat("table {{.Path}}")},
formatter.Context{Format: newDiffFormat("table {{.Path}}")},
`PATH
/var/log/app.log
/usr/app/app.js
@ -32,7 +32,7 @@ D /usr/app/old_app.js
`,
},
{
formatter.Context{Format: NewDiffFormat("{{.Type}}: {{.Path}}")},
formatter.Context{Format: newDiffFormat("{{.Type}}: {{.Path}}")},
`C: /var/log/app.log
A: /usr/app/app.js
D: /usr/app/old_app.js
@ -50,7 +50,7 @@ D: /usr/app/old_app.js
t.Run(string(tc.context.Format), func(t *testing.T) {
out := bytes.NewBufferString("")
tc.context.Output = out
err := DiffFormatWrite(tc.context, diffs)
err := diffFormatWrite(tc.context, diffs)
if err != nil {
assert.Error(t, err, tc.expected)
} else {

View File

@ -8,8 +8,8 @@ import (
"sync"
"github.com/docker/cli/cli/command"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/stdcopy"
"github.com/moby/moby/api/pkg/stdcopy"
"github.com/moby/moby/client"
"github.com/moby/term"
"github.com/sirupsen/logrus"
)
@ -38,7 +38,7 @@ type hijackedIOStreamer struct {
outputStream io.Writer
errorStream io.Writer
resp types.HijackedResponse
resp client.HijackedResponse
tty bool
detachKeys string

View File

@ -21,7 +21,7 @@ type inspectOptions struct {
}
// newInspectCommand creates a new cobra.Command for `docker container inspect`
func newInspectCommand(dockerCli command.Cli) *cobra.Command {
func newInspectCommand(dockerCLI command.Cli) *cobra.Command {
var opts inspectOptions
cmd := &cobra.Command{
@ -30,9 +30,10 @@ func newInspectCommand(dockerCli command.Cli) *cobra.Command {
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.refs = args
return runInspect(cmd.Context(), dockerCli, opts)
return runInspect(cmd.Context(), dockerCLI, opts)
},
ValidArgsFunction: completion.ContainerNames(dockerCli, true),
ValidArgsFunction: completion.ContainerNames(dockerCLI, true),
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()

View File

@ -17,8 +17,8 @@ type killOptions struct {
containers []string
}
// NewKillCommand creates a new cobra.Command for `docker kill`
func NewKillCommand(dockerCli command.Cli) *cobra.Command {
// newKillCommand creates a new cobra.Command for "docker container kill"
func newKillCommand(dockerCLI command.Cli) *cobra.Command {
var opts killOptions
cmd := &cobra.Command{
@ -27,12 +27,13 @@ func NewKillCommand(dockerCli command.Cli) *cobra.Command {
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.containers = args
return runKill(cmd.Context(), dockerCli, &opts)
return runKill(cmd.Context(), dockerCLI, &opts)
},
Annotations: map[string]string{
"aliases": "docker container kill, docker kill",
},
ValidArgsFunction: completion.ContainerNames(dockerCli, false),
ValidArgsFunction: completion.ContainerNames(dockerCLI, false),
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()

View File

@ -24,7 +24,7 @@ func TestRunKill(t *testing.T) {
},
})
cmd := NewKillCommand(cli)
cmd := newKillCommand(cli)
cmd.SetOut(io.Discard)
cmd.SetArgs([]string{
@ -56,7 +56,7 @@ func TestRunKillClientError(t *testing.T) {
},
})
cmd := NewKillCommand(cli)
cmd := newKillCommand(cli)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)

View File

@ -6,12 +6,11 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/cli/cli/command/formatter"
flagsHelper "github.com/docker/cli/cli/flags"
"github.com/docker/cli/opts"
"github.com/docker/cli/templates"
"github.com/docker/docker/api/types/container"
"github.com/moby/moby/api/types/container"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
@ -28,8 +27,8 @@ type psOptions struct {
filter opts.FilterOpt
}
// NewPsCommand creates a new cobra.Command for `docker ps`
func NewPsCommand(dockerCLI command.Cli) *cobra.Command {
// newPsCommand creates a new cobra.Command for "docker container ps"
func newPsCommand(dockerCLI command.Cli) *cobra.Command {
options := psOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{
@ -44,7 +43,8 @@ func NewPsCommand(dockerCLI command.Cli) *cobra.Command {
"category-top": "3",
"aliases": "docker container ls, docker container list, docker container ps, docker ps",
},
ValidArgsFunction: completion.NoComplete,
ValidArgsFunction: cobra.NoFileCompletions,
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()
@ -62,7 +62,7 @@ func NewPsCommand(dockerCLI command.Cli) *cobra.Command {
}
func newListCommand(dockerCLI command.Cli) *cobra.Command {
cmd := *NewPsCommand(dockerCLI)
cmd := *newPsCommand(dockerCLI)
cmd.Aliases = []string{"ps", "list"}
cmd.Use = "ls [OPTIONS]"
return &cmd
@ -82,7 +82,7 @@ func buildContainerListOptions(options *psOptions) (*container.ListOptions, erro
// always validate template when `--format` is used, for consistency
if len(options.format) > 0 {
tmpl, err := templates.NewParse("", options.format)
tmpl, err := templates.Parse(options.format)
if err != nil {
return nil, errors.Wrap(err, "failed to parse template")
}

View File

@ -9,7 +9,7 @@ import (
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/builders"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/container"
"github.com/moby/moby/api/types/container"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/golden"

View File

@ -7,8 +7,8 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/pkg/stdcopy"
"github.com/moby/moby/api/pkg/stdcopy"
"github.com/moby/moby/api/types/container"
"github.com/spf13/cobra"
)
@ -23,8 +23,8 @@ type logsOptions struct {
container string
}
// NewLogsCommand creates a new cobra.Command for `docker logs`
func NewLogsCommand(dockerCli command.Cli) *cobra.Command {
// newLogsCommand creates a new cobra.Command for "docker container logs"
func newLogsCommand(dockerCLI command.Cli) *cobra.Command {
var opts logsOptions
cmd := &cobra.Command{
@ -33,12 +33,13 @@ func NewLogsCommand(dockerCli command.Cli) *cobra.Command {
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.container = args[0]
return runLogs(cmd.Context(), dockerCli, &opts)
return runLogs(cmd.Context(), dockerCLI, &opts)
},
Annotations: map[string]string{
"aliases": "docker container logs, docker logs",
},
ValidArgsFunction: completion.ContainerNames(dockerCli, true),
ValidArgsFunction: completion.ContainerNames(dockerCLI, true),
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()

View File

@ -7,7 +7,7 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/container"
"github.com/moby/moby/api/types/container"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
@ -21,8 +21,8 @@ var logFn = func(expectedOut string) func(string, container.LogsOptions) (io.Rea
func TestRunLogs(t *testing.T) {
inspectFn := func(containerID string) (container.InspectResponse, error) {
return container.InspectResponse{
Config: &container.Config{Tty: true},
ContainerJSONBase: &container.ContainerJSONBase{State: &container.State{Running: false}},
Config: &container.Config{Tty: true},
State: &container.State{Running: false},
}, nil
}

View File

@ -12,13 +12,13 @@ import (
"strings"
"time"
"github.com/docker/cli/cli/compose/loader"
"github.com/docker/cli/internal/lazyregexp"
"github.com/docker/cli/internal/volumespec"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/container"
mounttypes "github.com/docker/docker/api/types/mount"
networktypes "github.com/docker/docker/api/types/network"
"github.com/docker/go-connections/nat"
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/api/types/mount"
"github.com/moby/moby/api/types/network"
"github.com/pkg/errors"
"github.com/spf13/pflag"
cdi "tags.cncf.io/container-device-interface/pkg/parser"
@ -141,6 +141,16 @@ type containerOptions struct {
Args []string
}
// addPlatformFlag adds "--platform" to a set of flags for API version 1.32 and
// later, using the value of "DOCKER_DEFAULT_PLATFORM" (if set) as a default.
//
// It should not be used for new uses, which may have a different API version
// requirement.
func addPlatformFlag(flags *pflag.FlagSet, target *string) {
flags.StringVar(target, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
_ = flags.SetAnnotation("platform", "version", []string{"1.32"})
}
// addFlags adds all command line flags that will be used by parse to the FlagSet
func addFlags(flags *pflag.FlagSet) *containerOptions {
copts := &containerOptions{
@ -323,7 +333,7 @@ func addFlags(flags *pflag.FlagSet) *containerOptions {
type containerConfig struct {
Config *container.Config
HostConfig *container.HostConfig
NetworkingConfig *networktypes.NetworkingConfig
NetworkingConfig *network.NetworkingConfig
}
// parse parses the args for the specified command and generates a Config,
@ -364,7 +374,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
volumes := copts.volumes.GetMap()
// add any bind targets to the list of container volumes
for bind := range copts.volumes.GetMap() {
parsed, err := loader.ParseVolume(bind)
parsed, err := volumespec.Parse(bind)
if err != nil {
return nil, err
}
@ -372,7 +382,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
if parsed.Source != "" {
toBind := bind
if parsed.Type == string(mounttypes.TypeBind) {
if parsed.Type == string(mount.TypeBind) {
if hostPart, targetPath, ok := strings.Cut(bind, ":"); ok {
if !filepath.IsAbs(hostPart) && strings.HasPrefix(hostPart, ".") {
if absHostPart, err := filepath.Abs(hostPart); err == nil {
@ -414,8 +424,8 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
publishOpts := copts.publish.GetSlice()
var (
ports map[nat.Port]struct{}
portBindings map[nat.Port][]nat.PortBinding
ports map[container.PortRangeProto]struct{}
portBindings map[container.PortRangeProto][]container.PortBinding
convertedOpts []string
)
@ -706,8 +716,8 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
config.StdinOnce = true
}
networkingConfig := &networktypes.NetworkingConfig{
EndpointsConfig: make(map[string]*networktypes.EndpointSettings),
networkingConfig := &network.NetworkingConfig{
EndpointsConfig: make(map[string]*network.EndpointSettings),
}
networkingConfig.EndpointsConfig, err = parseNetworkOpts(copts)
@ -735,9 +745,9 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
// this function may return _multiple_ endpoints, which is not currently supported
// by the daemon, but may be in future; it's up to the daemon to produce an error
// in case that is not supported.
func parseNetworkOpts(copts *containerOptions) (map[string]*networktypes.EndpointSettings, error) {
func parseNetworkOpts(copts *containerOptions) (map[string]*network.EndpointSettings, error) {
var (
endpoints = make(map[string]*networktypes.EndpointSettings, len(copts.netMode.Value()))
endpoints = make(map[string]*network.EndpointSettings, len(copts.netMode.Value()))
hasUserDefined, hasNonUserDefined bool
)
@ -783,7 +793,7 @@ func parseNetworkOpts(copts *containerOptions) (map[string]*networktypes.Endpoin
// and only a single network is specified, omit the endpoint-configuration
// on the client (the daemon will still create it when creating the container)
if i == 0 && len(copts.netMode.Value()) == 1 {
if ep == nil || reflect.DeepEqual(*ep, networktypes.EndpointSettings{}) {
if ep == nil || reflect.DeepEqual(*ep, network.EndpointSettings{}) {
continue
}
}
@ -841,7 +851,7 @@ func applyContainerOptions(n *opts.NetworkAttachmentOpts, copts *containerOption
return nil
}
func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*networktypes.EndpointSettings, error) {
func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*network.EndpointSettings, error) {
if strings.TrimSpace(ep.Target) == "" {
return nil, errors.New("no name set for network")
}
@ -854,7 +864,7 @@ func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*networktypes.End
}
}
epConfig := &networktypes.EndpointSettings{
epConfig := &network.EndpointSettings{
GwPriority: ep.GwPriority,
}
epConfig.Aliases = append(epConfig.Aliases, ep.Aliases...)
@ -866,7 +876,7 @@ func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*networktypes.End
epConfig.Links = ep.Links
}
if ep.IPv4Address != "" || ep.IPv6Address != "" || len(ep.LinkLocalIPs) > 0 {
epConfig.IPAMConfig = &networktypes.EndpointIPAMConfig{
epConfig.IPAMConfig = &network.EndpointIPAMConfig{
IPv4Address: ep.IPv4Address,
IPv6Address: ep.IPv6Address,
LinkLocalIPs: ep.LinkLocalIPs,

View File

@ -10,9 +10,8 @@ import (
"testing"
"time"
"github.com/docker/docker/api/types/container"
networktypes "github.com/docker/docker/api/types/network"
"github.com/docker/go-connections/nat"
"github.com/moby/moby/api/types/container"
networktypes "github.com/moby/moby/api/types/network"
"github.com/spf13/pflag"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
@ -439,7 +438,7 @@ func TestParseWithExpose(t *testing.T) {
"8080-NaN/tcp": `invalid range format for --expose: 8080-NaN/tcp, error: strconv.ParseUint: parsing "NaN": invalid syntax`,
"1234567890-8080/tcp": `invalid range format for --expose: 1234567890-8080/tcp, error: strconv.ParseUint: parsing "1234567890": value out of range`,
}
valids := map[string][]nat.Port{
valids := map[string][]container.PortRangeProto{
"8080/tcp": {"8080/tcp"},
"8080/udp": {"8080/udp"},
"8080/ncp": {"8080/ncp"},
@ -473,7 +472,7 @@ func TestParseWithExpose(t *testing.T) {
if len(config.ExposedPorts) != 2 {
t.Fatalf("Expected 2 exposed ports, got %v", config.ExposedPorts)
}
ports := []nat.Port{"80/tcp", "81/tcp"}
ports := []container.PortRangeProto{"80/tcp", "81/tcp"}
for _, port := range ports {
if _, ok := config.ExposedPorts[port]; !ok {
t.Fatalf("Expected %v, got %v", ports, config.ExposedPorts)
@ -1017,7 +1016,7 @@ func TestParseLabelfileVariables(t *testing.T) {
func TestParseEntryPoint(t *testing.T) {
config, _, _, err := parseRun([]string{"--entrypoint=anything", "cmd", "img"})
assert.NilError(t, err)
assert.Check(t, is.DeepEqual([]string(config.Entrypoint), []string{"anything"}))
assert.Check(t, is.DeepEqual(config.Entrypoint, []string{"anything"}))
}
func TestValidateDevice(t *testing.T) {

View File

@ -8,7 +8,7 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/docker/api/types/container"
"github.com/moby/moby/api/types/container"
"github.com/spf13/cobra"
)
@ -16,8 +16,8 @@ type pauseOptions struct {
containers []string
}
// NewPauseCommand creates a new cobra.Command for `docker pause`
func NewPauseCommand(dockerCli command.Cli) *cobra.Command {
// newPauseCommand creates a new cobra.Command for "docker container pause"
func newPauseCommand(dockerCLI command.Cli) *cobra.Command {
var opts pauseOptions
return &cobra.Command{
@ -26,14 +26,15 @@ func NewPauseCommand(dockerCli command.Cli) *cobra.Command {
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.containers = args
return runPause(cmd.Context(), dockerCli, &opts)
return runPause(cmd.Context(), dockerCLI, &opts)
},
Annotations: map[string]string{
"aliases": "docker container pause, docker pause",
},
ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr container.Summary) bool {
ValidArgsFunction: completion.ContainerNames(dockerCLI, false, func(ctr container.Summary) bool {
return ctr.State != container.StatePaused
}),
DisableFlagsInUseLine: true,
}
}

View File

@ -21,7 +21,7 @@ func TestRunPause(t *testing.T) {
},
)
cmd := NewPauseCommand(cli)
cmd := newPauseCommand(cli)
cmd.SetOut(io.Discard)
cmd.SetArgs([]string{"container-id-1", "container-id-2"})
@ -47,7 +47,7 @@ func TestRunPauseClientError(t *testing.T) {
},
)
cmd := NewPauseCommand(cli)
cmd := newPauseCommand(cli)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
cmd.SetArgs([]string{"container-id-1", "container-id-2"})

View File

@ -11,8 +11,8 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/go-connections/nat"
"github.com/fvbommel/sortorder"
"github.com/moby/moby/api/types/container"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
@ -23,8 +23,8 @@ type portOptions struct {
port string
}
// NewPortCommand creates a new cobra.Command for `docker port`
func NewPortCommand(dockerCli command.Cli) *cobra.Command {
// newPortCommand creates a new cobra.Command for "docker container port".
func newPortCommand(dockerCLI command.Cli) *cobra.Command {
var opts portOptions
cmd := &cobra.Command{
@ -36,12 +36,13 @@ func NewPortCommand(dockerCli command.Cli) *cobra.Command {
if len(args) > 1 {
opts.port = args[1]
}
return runPort(cmd.Context(), dockerCli, &opts)
return runPort(cmd.Context(), dockerCLI, &opts)
},
Annotations: map[string]string{
"aliases": "docker container port, docker port",
},
ValidArgsFunction: completion.ContainerNames(dockerCli, false),
ValidArgsFunction: completion.ContainerNames(dockerCLI, false),
DisableFlagsInUseLine: true,
}
return cmd
}
@ -67,7 +68,7 @@ func runPort(ctx context.Context, dockerCli command.Cli, opts *portOptions) erro
if _, err = strconv.ParseUint(port, 10, 16); err != nil {
return errors.Wrapf(err, "Error: invalid port (%s)", port)
}
frontends, exists := c.NetworkSettings.Ports[nat.Port(port+"/"+proto)]
frontends, exists := c.NetworkSettings.Ports[container.PortRangeProto(port+"/"+proto)]
if !exists || len(frontends) == 0 {
return errors.Errorf("Error: No public port '%s' published for %s", opts.port, opts.container)
}

View File

@ -5,8 +5,7 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/container"
"github.com/docker/go-connections/nat"
"github.com/moby/moby/api/types/container"
"gotest.tools/v3/assert"
"gotest.tools/v3/golden"
)
@ -47,26 +46,26 @@ func TestNewPortCommandOutput(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
inspectFunc: func(string) (container.InspectResponse, error) {
ci := container.InspectResponse{NetworkSettings: &container.NetworkSettings{}}
ci.NetworkSettings.Ports = nat.PortMap{
"80/tcp": make([]nat.PortBinding, len(tc.ips)),
"443/tcp": make([]nat.PortBinding, len(tc.ips)),
"443/udp": make([]nat.PortBinding, len(tc.ips)),
ci.NetworkSettings.Ports = container.PortMap{
"80/tcp": make([]container.PortBinding, len(tc.ips)),
"443/tcp": make([]container.PortBinding, len(tc.ips)),
"443/udp": make([]container.PortBinding, len(tc.ips)),
}
for i, ip := range tc.ips {
ci.NetworkSettings.Ports["80/tcp"][i] = nat.PortBinding{
ci.NetworkSettings.Ports["80/tcp"][i] = container.PortBinding{
HostIP: ip, HostPort: "3456",
}
ci.NetworkSettings.Ports["443/tcp"][i] = nat.PortBinding{
ci.NetworkSettings.Ports["443/tcp"][i] = container.PortBinding{
HostIP: ip, HostPort: "4567",
}
ci.NetworkSettings.Ports["443/udp"][i] = nat.PortBinding{
ci.NetworkSettings.Ports["443/udp"][i] = container.PortBinding{
HostIP: ip, HostPort: "5678",
}
}
return ci, nil
},
})
cmd := NewPortCommand(cli)
cmd := newPortCommand(cli)
cmd.SetErr(io.Discard)
cmd.SetArgs([]string{"some_container", tc.port})
err := cmd.Execute()

View File

@ -6,7 +6,7 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/cli/cli/command/system/pruner"
"github.com/docker/cli/internal/prompt"
"github.com/docker/cli/opts"
"github.com/docker/go-units"
@ -14,13 +14,20 @@ import (
"github.com/spf13/cobra"
)
func init() {
// Register the prune command to run as part of "docker system prune"
if err := pruner.Register(pruner.TypeContainer, pruneFn); err != nil {
panic(err)
}
}
type pruneOptions struct {
force bool
filter opts.FilterOpt
}
// NewPruneCommand returns a new cobra prune command for containers
func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
// newPruneCommand returns a new cobra prune command for containers.
func newPruneCommand(dockerCLI command.Cli) *cobra.Command {
options := pruneOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{
@ -28,18 +35,19 @@ func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
Short: "Remove all stopped containers",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
spaceReclaimed, output, err := runPrune(cmd.Context(), dockerCli, options)
spaceReclaimed, output, err := runPrune(cmd.Context(), dockerCLI, options)
if err != nil {
return err
}
if output != "" {
fmt.Fprintln(dockerCli.Out(), output)
fmt.Fprintln(dockerCLI.Out(), output)
}
fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
fmt.Fprintln(dockerCLI.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
return nil
},
Annotations: map[string]string{"version": "1.25"},
ValidArgsFunction: completion.NoComplete,
Annotations: map[string]string{"version": "1.25"},
ValidArgsFunction: cobra.NoFileCompletions,
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()
@ -85,8 +93,16 @@ type cancelledErr struct{ error }
func (cancelledErr) Cancelled() {}
// RunPrune calls the Container Prune API
// This returns the amount of space reclaimed and a detailed output string
func RunPrune(ctx context.Context, dockerCli command.Cli, _ bool, filter opts.FilterOpt) (uint64, string, error) {
return runPrune(ctx, dockerCli, pruneOptions{force: true, filter: filter})
// pruneFn calls the Container Prune API for use in "docker system prune",
// and returns the amount of space reclaimed and a detailed output string.
func pruneFn(ctx context.Context, dockerCLI command.Cli, options pruner.PruneOptions) (uint64, string, error) {
if !options.Confirmed {
// Dry-run: perform validation and produce confirmation before pruning.
confirmMsg := "all stopped containers"
return 0, confirmMsg, cancelledErr{errors.New("containers prune has been cancelled")}
}
return runPrune(ctx, dockerCLI, pruneOptions{
force: true,
filter: options.Filter,
})
}

View File

@ -7,8 +7,8 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/api/types/filters"
)
func TestContainerPrunePromptTermination(t *testing.T) {
@ -20,7 +20,7 @@ func TestContainerPrunePromptTermination(t *testing.T) {
return container.PruneReport{}, errors.New("fakeClient containerPruneFunc should not be called")
},
})
cmd := NewPruneCommand(cli)
cmd := newPruneCommand(cli)
cmd.SetArgs([]string{})
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)

View File

@ -17,8 +17,8 @@ type renameOptions struct {
newName string
}
// NewRenameCommand creates a new cobra.Command for `docker rename`
func NewRenameCommand(dockerCli command.Cli) *cobra.Command {
// newRenameCommand creates a new cobra.Command for "docker container rename".
func newRenameCommand(dockerCLI command.Cli) *cobra.Command {
var opts renameOptions
cmd := &cobra.Command{
@ -28,12 +28,13 @@ func NewRenameCommand(dockerCli command.Cli) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
opts.oldName = args[0]
opts.newName = args[1]
return runRename(cmd.Context(), dockerCli, &opts)
return runRename(cmd.Context(), dockerCLI, &opts)
},
Annotations: map[string]string{
"aliases": "docker container rename, docker rename",
},
ValidArgsFunction: completion.ContainerNames(dockerCli, true),
ValidArgsFunction: completion.ContainerNames(dockerCLI, true),
DisableFlagsInUseLine: true,
}
return cmd
}

View File

@ -43,7 +43,7 @@ func TestRunRename(t *testing.T) {
},
})
cmd := NewRenameCommand(cli)
cmd := newRenameCommand(cli)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
cmd.SetArgs([]string{tc.oldName, tc.newName})
@ -66,7 +66,7 @@ func TestRunRenameClientError(t *testing.T) {
},
})
cmd := NewRenameCommand(cli)
cmd := newRenameCommand(cli)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
cmd.SetArgs([]string{"oldName", "newName"})

View File

@ -8,7 +8,7 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/docker/api/types/container"
"github.com/moby/moby/api/types/container"
"github.com/spf13/cobra"
)
@ -20,8 +20,8 @@ type restartOptions struct {
containers []string
}
// NewRestartCommand creates a new cobra.Command for `docker restart`
func NewRestartCommand(dockerCli command.Cli) *cobra.Command {
// newRestartCommand creates a new cobra.Command for "docker container restart".
func newRestartCommand(dockerCLI command.Cli) *cobra.Command {
var opts restartOptions
cmd := &cobra.Command{
@ -34,12 +34,13 @@ func NewRestartCommand(dockerCli command.Cli) *cobra.Command {
}
opts.containers = args
opts.timeoutChanged = cmd.Flags().Changed("timeout") || cmd.Flags().Changed("time")
return runRestart(cmd.Context(), dockerCli, &opts)
return runRestart(cmd.Context(), dockerCLI, &opts)
},
Annotations: map[string]string{
"aliases": "docker container restart, docker restart",
},
ValidArgsFunction: completion.ContainerNames(dockerCli, true),
ValidArgsFunction: completion.ContainerNames(dockerCLI, true),
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()

View File

@ -9,7 +9,7 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/container"
"github.com/moby/moby/api/types/container"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
@ -76,7 +76,7 @@ func TestRestart(t *testing.T) {
},
Version: "1.36",
})
cmd := NewRestartCommand(cli)
cmd := newRestartCommand(cli)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
cmd.SetArgs(tc.args)

View File

@ -6,11 +6,11 @@ import (
"fmt"
"strings"
cerrdefs "github.com/containerd/errdefs"
"github.com/containerd/errdefs"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/docker/api/types/container"
"github.com/moby/moby/api/types/container"
"github.com/spf13/cobra"
)
@ -22,8 +22,8 @@ type rmOptions struct {
containers []string
}
// NewRmCommand creates a new cobra.Command for `docker rm`
func NewRmCommand(dockerCli command.Cli) *cobra.Command {
// newRmCommand creates a new cobra.Command for "docker container rm".
func newRmCommand(dockerCLI command.Cli) *cobra.Command {
var opts rmOptions
cmd := &cobra.Command{
@ -32,14 +32,15 @@ func NewRmCommand(dockerCli command.Cli) *cobra.Command {
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.containers = args
return runRm(cmd.Context(), dockerCli, &opts)
return runRm(cmd.Context(), dockerCLI, &opts)
},
Annotations: map[string]string{
"aliases": "docker container rm, docker container remove, docker rm",
},
ValidArgsFunction: completion.ContainerNames(dockerCli, true, func(ctr container.Summary) bool {
ValidArgsFunction: completion.ContainerNames(dockerCLI, true, func(ctr container.Summary) bool {
return opts.force || ctr.State == container.StateExited || ctr.State == container.StateCreated
}),
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()
@ -53,7 +54,7 @@ func NewRmCommand(dockerCli command.Cli) *cobra.Command {
// top-level "docker rm", it also adds a "remove" alias to support
// "docker container remove" in addition to "docker container rm".
func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
cmd := *NewRmCommand(dockerCli)
cmd := *newRmCommand(dockerCli)
cmd.Aliases = []string{"rm", "remove"}
return &cmd
}
@ -75,7 +76,7 @@ func runRm(ctx context.Context, dockerCLI command.Cli, opts *rmOptions) error {
var errs []error
for _, name := range opts.containers {
if err := <-errChan; err != nil {
if opts.force && cerrdefs.IsNotFound(err) {
if opts.force && errdefs.IsNotFound(err) {
_, _ = fmt.Fprintln(dockerCLI.Err(), err)
continue
}

View File

@ -9,7 +9,7 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/container"
"github.com/moby/moby/api/types/container"
"gotest.tools/v3/assert"
)
@ -41,7 +41,7 @@ func TestRemoveForce(t *testing.T) {
},
Version: "1.36",
})
cmd := NewRmCommand(cli)
cmd := newRmCommand(cli)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
cmd.SetArgs(tc.args)

View File

@ -11,7 +11,7 @@ import (
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/container"
"github.com/moby/moby/api/types/container"
"github.com/moby/sys/signal"
"github.com/moby/term"
"github.com/pkg/errors"
@ -27,8 +27,8 @@ type runOptions struct {
detachKeys string
}
// NewRunCommand create a new `docker run` command
func NewRunCommand(dockerCli command.Cli) *cobra.Command {
// newRunCommand create a new "docker run" command.
func newRunCommand(dockerCLI command.Cli) *cobra.Command {
var options runOptions
var copts *containerOptions
@ -41,13 +41,14 @@ func NewRunCommand(dockerCli command.Cli) *cobra.Command {
if len(args) > 1 {
copts.Args = args[1:]
}
return runRun(cmd.Context(), dockerCli, cmd.Flags(), &options, copts)
return runRun(cmd.Context(), dockerCLI, cmd.Flags(), &options, copts)
},
ValidArgsFunction: completion.ImageNames(dockerCli, 1),
ValidArgsFunction: completion.ImageNames(dockerCLI, 1),
Annotations: map[string]string{
"category-top": "1",
"aliases": "docker container run, docker run",
},
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()
@ -66,18 +67,19 @@ func NewRunCommand(dockerCli command.Cli) *cobra.Command {
// with hostname
flags.Bool("help", false, "Print usage")
command.AddPlatformFlag(flags, &options.platform)
command.AddTrustVerificationFlags(flags, &options.untrusted, dockerCli.ContentTrustEnabled())
// TODO(thaJeztah): consider adding platform as "image create option" on containerOptions
addPlatformFlag(flags, &options.platform)
flags.BoolVar(&options.untrusted, "disable-content-trust", !dockerCLI.ContentTrustEnabled(), "Skip image verification")
copts = addFlags(flags)
_ = cmd.RegisterFlagCompletionFunc("detach-keys", completeDetachKeys)
addCompletions(cmd, dockerCli)
addCompletions(cmd, dockerCLI)
flags.VisitAll(func(flag *pflag.Flag) {
// Set a default completion function if none was set. We don't look
// up if it does already have one set, because Cobra does this for
// us, and returns an error (which we ignore for this reason).
_ = cmd.RegisterFlagCompletionFunc(flag.Name, completion.NoComplete)
_ = cmd.RegisterFlagCompletionFunc(flag.Name, cobra.NoFileCompletions)
})
return cmd

View File

@ -2,9 +2,7 @@ package container
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net"
"syscall"
@ -16,11 +14,12 @@ import (
"github.com/docker/cli/cli/streams"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/notary"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/moby/moby/api/pkg/progress"
"github.com/moby/moby/api/pkg/streamformatter"
"github.com/moby/moby/api/types"
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/api/types/network"
"github.com/moby/moby/client"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/pflag"
"gotest.tools/v3/assert"
@ -40,7 +39,7 @@ func TestRunValidateFlags(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
cmd := NewRunCommand(test.NewFakeCli(&fakeClient{}))
cmd := newRunCommand(test.NewFakeCli(&fakeClient{}))
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
cmd.SetArgs(tc.args)
@ -64,7 +63,7 @@ func TestRunLabel(t *testing.T) {
},
Version: "1.36",
})
cmd := NewRunCommand(fakeCLI)
cmd := newRunCommand(fakeCLI)
cmd.SetArgs([]string{"--detach=true", "--label", "foo", "busybox"})
assert.NilError(t, cmd.Execute())
}
@ -85,14 +84,14 @@ func TestRunAttach(t *testing.T) {
ID: "id",
}, nil
},
containerAttachFunc: func(ctx context.Context, containerID string, options container.AttachOptions) (types.HijackedResponse, error) {
server, client := net.Pipe()
containerAttachFunc: func(ctx context.Context, containerID string, options container.AttachOptions) (client.HijackedResponse, error) {
server, clientConn := net.Pipe()
conn = server
t.Cleanup(func() {
_ = server.Close()
})
attachCh <- struct{}{}
return types.NewHijackedResponse(client, types.MediaTypeRawStream), nil
return client.NewHijackedResponse(clientConn, types.MediaTypeRawStream), nil
},
waitFunc: func(_ string) (<-chan container.WaitResponse, <-chan error) {
responseChan := make(chan container.WaitResponse, 1)
@ -111,7 +110,7 @@ func TestRunAttach(t *testing.T) {
fc.SetIn(streams.NewIn(tty))
})
cmd := NewRunCommand(fakeCLI)
cmd := newRunCommand(fakeCLI)
cmd.SetArgs([]string{"-it", "busybox"})
cmd.SilenceUsage = true
cmdErrC := make(chan error, 1)
@ -162,14 +161,14 @@ func TestRunAttachTermination(t *testing.T) {
}
return nil
},
containerAttachFunc: func(ctx context.Context, containerID string, options container.AttachOptions) (types.HijackedResponse, error) {
server, client := net.Pipe()
containerAttachFunc: func(ctx context.Context, containerID string, options container.AttachOptions) (client.HijackedResponse, error) {
server, clientConn := net.Pipe()
conn = server
t.Cleanup(func() {
_ = server.Close()
})
attachCh <- struct{}{}
return types.NewHijackedResponse(client, types.MediaTypeRawStream), nil
return client.NewHijackedResponse(clientConn, types.MediaTypeRawStream), nil
},
waitFunc: func(_ string) (<-chan container.WaitResponse, <-chan error) {
responseChan := make(chan container.WaitResponse, 1)
@ -188,7 +187,7 @@ func TestRunAttachTermination(t *testing.T) {
fc.SetIn(streams.NewIn(tty))
})
cmd := NewRunCommand(fakeCLI)
cmd := newRunCommand(fakeCLI)
cmd.SetArgs([]string{"-it", "busybox"})
cmd.SilenceUsage = true
cmdErrC := make(chan error, 1)
@ -233,44 +232,40 @@ func TestRunPullTermination(t *testing.T) {
) (container.CreateResponse, error) {
return container.CreateResponse{}, errors.New("shouldn't try to create a container")
},
containerAttachFunc: func(ctx context.Context, containerID string, options container.AttachOptions) (types.HijackedResponse, error) {
return types.HijackedResponse{}, errors.New("shouldn't try to attach to a container")
containerAttachFunc: func(ctx context.Context, containerID string, options container.AttachOptions) (client.HijackedResponse, error) {
return client.HijackedResponse{}, errors.New("shouldn't try to attach to a container")
},
imageCreateFunc: func(ctx context.Context, parentReference string, options image.CreateOptions) (io.ReadCloser, error) {
server, client := net.Pipe()
imageCreateFunc: func(ctx context.Context, parentReference string, options client.ImageCreateOptions) (io.ReadCloser, error) {
server, respReader := net.Pipe()
t.Cleanup(func() {
_ = server.Close()
})
go func() {
enc := json.NewEncoder(server)
id := test.RandomID()[:12] // short-ID
progressOutput := streamformatter.NewJSONProgressOutput(server, true)
for i := 0; i < 100; i++ {
select {
case <-ctx.Done():
assert.NilError(t, server.Close(), "failed to close imageCreateFunc server")
return
default:
assert.NilError(t, enc.Encode(jsonmessage.JSONMessage{
Status: "Downloading",
ID: fmt.Sprintf("id-%d", i),
TimeNano: time.Now().UnixNano(),
Time: time.Now().Unix(),
Progress: &jsonmessage.JSONProgress{
Current: int64(i),
Total: 100,
Start: 0,
},
assert.NilError(t, progressOutput.WriteProgress(progress.Progress{
ID: id,
Message: "Downloading",
Current: int64(i),
Total: 100,
}))
time.Sleep(100 * time.Millisecond)
}
}
}()
attachCh <- struct{}{}
return client, nil
return respReader, nil
},
Version: "1.30",
})
cmd := NewRunCommand(fakeCLI)
cmd := newRunCommand(fakeCLI)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
cmd.SetArgs([]string{"--pull", "always", "foobar:latest"})
@ -339,7 +334,7 @@ func TestRunCommandWithContentTrustErrors(t *testing.T) {
},
}, test.EnableContentTrust)
fakeCLI.SetNotaryClient(tc.notaryFunc)
cmd := NewRunCommand(fakeCLI)
cmd := newRunCommand(fakeCLI)
cmd.SetArgs(tc.args)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)

View File

@ -5,7 +5,7 @@ import (
"os"
gosignal "os/signal"
"github.com/docker/docker/client"
"github.com/moby/moby/client"
"github.com/moby/sys/signal"
"github.com/sirupsen/logrus"
)

Some files were not shown because too many files have changed in this diff Show More