Compare commits

...

177 Commits

Author SHA1 Message Date
Paweł Gronowski aced30d906
Merge pull request #6399 from vvoland/6371-28.x
[28.x backport] Add escape hatch for GODEBUG=x509negativeserial
2025-08-29 16:34:50 +02:00
Alano Terblanche b9e15efde0
return early if GODEBUG set or context is default
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
(cherry picked from commit 72f79333e5)
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-08-29 16:00:23 +02:00
Alano Terblanche 4108febfae
rename function to fit what it is doing
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
(cherry picked from commit 6163c03b11)
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-08-29 16:00:21 +02:00
Alano Terblanche 8cfe1f712e
Test setAllowNegativex509
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
(cherry picked from commit 467305fcea)
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-08-29 16:00:19 +02:00
Alano Terblanche 7c34fd56d0
Cleanup setAllowNegativex509
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
(cherry picked from commit 65a6c35d90)
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-08-29 16:00:18 +02:00
Alano Terblanche 0a2eaa4d05
Add escape hatch for GODEBUG=x509negativeserial
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
(cherry picked from commit 7d7a7aac4d)
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-08-29 16:00:16 +02:00
Paweł Gronowski d26f1fd6d3 Merge pull request #6266 from thaJeztah/28.x_bump_engine
[28.x] vendor: github.com/docker/docker 02b4a1a3decc (v28.4.0-dev)
2025-08-28 16:38:19 +02:00
Paweł Gronowski 4f6182a50c
Merge pull request #6394 from thaJeztah/28.x_bump_version
[28.x] bump version to v28.4.0-dev
2025-08-28 16:37:58 +02:00
Sebastiaan van Stijn 4caa99468d
[28.x] bump version to v28.4.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-08-28 15:52:47 +02:00
Sebastiaan van Stijn c2117f956f
vendor: github.com/docker/docker 02b4a1a3decc (v28.4.0-dev)
full diff: https://github.com/moby/moby/compare/v28.3.3...02b4a1a3decc99de2965421cea5634c1e5297266

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-28 15:51:57 +02:00
Paweł Gronowski 19b86ef9e2
Merge pull request #6391 from thaJeztah/28.x_backport_deprecate_stack_commands
[28.x backport] cli/command/stack/*: deprecate exported functions and types
2025-08-28 13:55:57 +02:00
Sebastiaan van Stijn 88d6197d4c
Merge pull request #6392 from thaJeztah/28.x_backport_fix_email_deprecation
[28.x backport] cli/config/types: update deprecation comment for AuthConfig.Email
2025-08-28 13:52:44 +02:00
Sebastiaan van Stijn bda15c766a
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>
(cherry picked from commit aab947de8f)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-28 13:22:09 +02:00
Sebastiaan van Stijn e636ed2ae5
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>
(cherry picked from commit d16c560664)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-28 12:07:56 +02:00
Sebastiaan van Stijn 19b7dfa1cf
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>
(cherry picked from commit 036d3a6bab)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-28 12:07:52 +02:00
Sebastiaan van Stijn 91de2a6dae
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>
(cherry picked from commit f0e5a0d654)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-28 12:04:51 +02:00
Sebastiaan van Stijn 7c6f58affe
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>
(cherry picked from commit ad6ab189a6)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-28 12:04:51 +02:00
Sebastiaan van Stijn 8c6a7fcbc9
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>
(cherry picked from commit 30774ed1f2)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-28 12:04:48 +02:00
Sebastiaan van Stijn 3e87f59859
Merge pull request #6390 from thaJeztah/28.x_backport_avoid_shadowing
[28.x backport] cli/command: rename vars for consistency and prevent shadowing
2025-08-28 12:03:34 +02:00
Sebastiaan van Stijn a621313658
cli/command: rename vars for consistency and prevent shadowing
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 9fd71c8347)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-28 11:37:25 +02:00
Austin Vazquez 69dd67fc06
Merge pull request #6381 from thaJeztah/28.x_backport_internalize_ParseEnvFile
[28.x backport] opts: deprecate ParseEnvFile
2025-08-27 12:26:38 -07:00
Austin Vazquez b90c5a8fcb
Merge pull request #6379 from thaJeztah/28.x_backport_test_fixes
[28.x backport] cli/command/system: don't use deprecated fields in tests
2025-08-27 12:22:48 -07:00
Austin Vazquez 99676e6c9c
Merge pull request #6384 from thaJeztah/28.x_backport_mergo
[28.x backport] vendor: dario.cat/mergo v1.0.2
2025-08-27 11:18:09 -07:00
Austin Vazquez 524fd156f5
Merge pull request #6380 from thaJeztah/28.x_backport_docs_fixes
[28.x backport] docs fixes and fix flag annotation
2025-08-27 11:17:14 -07:00
Austin Vazquez 07bcb9cca2
Merge pull request #6386 from thaJeztah/28.x_backport_bump_go_events
[28.x backport] vendor: github.com/docker/go-events v0.0.0-20250114142523-c867878c5e32
2025-08-27 11:14:41 -07:00
Sebastiaan van Stijn 48ea3fa14f
vendor: github.com/docker/go-events v0.0.0-20250114142523-c867878c5e32
full diff: e31b211e4f...c867878c5e

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 05220c5f19)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-27 15:55:20 +02:00
Sebastiaan van Stijn a27a86289e
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>
(cherry picked from commit a93ed48d06)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-27 15:47:11 +02:00
Sebastiaan van Stijn e112eeea4d
opts: deprecate ParseEnvFile
It was a wrapper around kvfile.Load, which should be used instead.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit e650803f09)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-27 15:00:30 +02:00
Sebastiaan van Stijn 3b68cde77a
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>
(cherry picked from commit dcc3d25dc2)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-27 14:57:28 +02:00
Hossein Abbasi c712d97172
docs: add missing backticks in 'run.md'
Signed-off-by: Hossein Abbasi <16090309+hsnabszhdn@users.noreply.github.com>
(cherry picked from commit d9cafa759f)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-27 14:57:15 +02:00
Hossein Abbasi f385cb994f
docs: fix sentence structures in 'run.md'
Signed-off-by: Hossein Abbasi <16090309+hsnabszhdn@users.noreply.github.com>
(cherry picked from commit ba2c1c94ab)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-27 14:57:00 +02:00
Sebastiaan van Stijn 44c1d5775d
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>
(cherry picked from commit 3d87aa441f)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-27 14:51:55 +02:00
Sebastiaan van Stijn 1468bb1962
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>
(cherry picked from commit 823c6a75b3)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-27 14:49:21 +02:00
Austin Vazquez 44fb305591
Merge pull request #6348 from thaJeztah/28.x_backport_bump_x_sync
[28.x backport] vendor: golang.org/x/sync v0.16.0
2025-08-26 08:26:11 -07:00
Sebastiaan van Stijn b74574cd53
Merge pull request #6369 from thaJeztah/28.x_backport_deprecate_exported_config_funcs
[28.x backport] cli/command/config: deprecate exported types and functions
2025-08-26 13:19:00 +02:00
Sebastiaan van Stijn e60b20f08e
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>
(cherry picked from commit a5f4ba08d9)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-25 18:55:48 +02:00
Sebastiaan van Stijn 6f7865f89a
Merge pull request #6358 from thaJeztah/28.x_backport_rm_image_pull
[28.x backport] cli/command/image: remove exported RunPull, PullOptions
2025-08-25 16:20:31 +02:00
Sebastiaan van Stijn 23518a47dd
Merge pull request #6357 from thaJeztah/28.x_backport_unexport_authresolver_util
[28.x backport] cli/command/image: deprecate AuthResolver and un-export
2025-08-25 16:20:09 +02:00
Sebastiaan van Stijn eb120d2c28
Merge pull request #6354 from thaJeztah/28.x_backport_rm_json_deprecated
[28.x backport] internal/jsonstream: remove uses of deprecated fields
2025-08-25 15:52:28 +02:00
Sebastiaan van Stijn 146f6492c7
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>
(cherry picked from commit 9216f04eb6)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-23 03:51:47 +02:00
Sebastiaan van Stijn 8def226e53
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>
(cherry picked from commit 7ad113ccc2)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-23 03:48:35 +02:00
Sebastiaan van Stijn 82c5138c8e
internal/jsonstream: remove uses of deprecated fields
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 045ac0b159)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-23 02:18:45 +02:00
Sebastiaan van Stijn bd3e420cc7
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>
(cherry picked from commit c7cbac58b3)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 21:12:55 +02:00
Sebastiaan van Stijn bb2ed910bb
Merge pull request #6343 from thaJeztah/28.x_backport_deprecate_builder_NewPruneCommand
[28.x backport] cli/command/builder: deprecate NewPruneCommand
2025-08-22 12:35:24 +02:00
Sebastiaan van Stijn 1415080cfa
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>
(cherry picked from commit 7032f5922e)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 12:22:11 +02:00
Sebastiaan van Stijn 0bbdda88e6
Merge pull request #6341 from thaJeztah/28.x_backport_internalize_formatters
[28.x backport] cli/command/*: deprecate formatting-related functions and types
2025-08-22 12:10:03 +02:00
Sebastiaan van Stijn 4133271530
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>
(cherry picked from commit 95c9b1b13b)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 11:47:54 +02:00
Sebastiaan van Stijn 0e17907266
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>
(cherry picked from commit c3ee82fdc3)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 11:47:54 +02:00
Sebastiaan van Stijn b0b7dcfe86
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>
(cherry picked from commit 9f453d3fea)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 11:47:54 +02:00
Sebastiaan van Stijn 531ea22e7d
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>
(cherry picked from commit f3088e37a0)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 11:47:53 +02:00
Sebastiaan van Stijn e8cf8e65f7
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>
(cherry picked from commit 83371c2014)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 11:47:53 +02:00
Sebastiaan van Stijn 22c68c5366
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>
(cherry picked from commit bf47419852)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 11:47:53 +02:00
Sebastiaan van Stijn e424c50373
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>
(cherry picked from commit 123ef81f7d)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 11:47:53 +02:00
Sebastiaan van Stijn 399861e7d2
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>
(cherry picked from commit e626f778ec)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 11:47:52 +02:00
Sebastiaan van Stijn 694e92aa10
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>
(cherry picked from commit d861b78a8a)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 11:47:52 +02:00
Sebastiaan van Stijn 09a36f2ef1
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>
(cherry picked from commit 15cf4fa912)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 11:47:52 +02:00
Sebastiaan van Stijn 73fbe6a020
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>
(cherry picked from commit e3903a1ac8)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 11:47:52 +02:00
Sebastiaan van Stijn 4480024a80
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>
(cherry picked from commit fdc90caeee)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 11:47:52 +02:00
Sebastiaan van Stijn b4f2c0ca3d
cli/command/container: newDiffContext: use struct-literal
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 0db7b9f774)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 11:47:51 +02:00
Sebastiaan van Stijn 85a5e3da36
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>
(cherry picked from commit 239b727834)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 11:47:51 +02:00
Sebastiaan van Stijn 34a75fb6f4
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>
(cherry picked from commit 907507e22a)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 11:47:48 +02:00
Sebastiaan van Stijn b52ab17a14
Merge pull request #6340 from thaJeztah/28.x_backport_cleanup_plugins
[28.x backport] cli/command/plugin: fix linting issues, and assorted cleanups
2025-08-22 11:31:06 +02:00
Sebastiaan van Stijn ec89d0ba67
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>
(cherry picked from commit c6f935eba5)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:54:50 +02:00
Austin Vazquez aa44c436d7
Merge pull request #6333 from thaJeztah/28.x_fix_plugin_tests
[28.x] e2e/testutils: fix incorrect use of PluginConfigInterface
2025-08-20 15:29:46 -07:00
Sebastiaan van Stijn 39e1213615
e2e/testutils: fix incorrect use of PluginConfigInterface
This code was using the type incorrectly; current versions of the
API MarshalText ignore this mistake, but the moby/moby/api module
produces an error:

    === Failed
    === FAIL: e2e/global TestPromptExitCode/plugin_install (0.28s)
        cli_test.go:203: assertion failed: error is not nil: json: error calling MarshalText for type plugin.CapabilityID: capability "docker.dummy/1.0" cannot contain a dot

    === FAIL: e2e/global TestPromptExitCode/plugin_upgrade (0.26s)
        cli_test.go:203: assertion failed: error is not nil: json: error calling MarshalText for type plugin.CapabilityID: capability "docker.dummy/1.0" cannot contain a dot

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 22:00:06 +02:00
Austin Vazquez 5184f2ed65
Merge pull request #6332 from thaJeztah/28.x_deprecate_prompt_utils
[28.x] cli/command: deprecate prompt utilities that were for internal use
2025-08-20 11:55:06 -07:00
Sebastiaan van Stijn cb42a72704
cli/command: deprecate 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 deprecates 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-20 18:04:22 +02:00
Sebastiaan van Stijn 5ef48d620d
Merge pull request #6331 from thaJeztah/28.x_backport_issue_6188
[28.x backport] refactor(cli/compose/loader): extract ParseVolume() to its own package
2025-08-20 17:27:05 +02:00
Michael Tews 9e08776681
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>
(cherry picked from commit ef7fd8bb67)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 16:52:12 +02:00
Sebastiaan van Stijn 85512e35cd
Merge pull request #6312 from thaJeztah/28.x_backport_deprecate_cobra_commands
[28.x backport] un-export and deprecate cobra commands
2025-08-20 15:55:43 +02:00
Alano Terblanche ce242b0ee8
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>
(cherry picked from commit bd8e3e4440)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 14:20:43 +02:00
Alano Terblanche ae3ee9b47b
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>
(cherry picked from commit c6b7268932)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 14:20:32 +02:00
Alano Terblanche 733762af0a
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>
(cherry picked from commit bf39340294)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 14:20:16 +02:00
Alano Terblanche 46862878f7
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>
(cherry picked from commit d4588c711c)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 13:45:11 +02:00
Alano Terblanche 4a2b024c57
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>
(cherry picked from commit 630fe430ff)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 13:41:28 +02:00
Alano Terblanche 82de0590b6
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>
(cherry picked from commit 3b0edc794c)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 13:41:25 +02:00
Alano Terblanche 3e36fa624a
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>
(cherry picked from commit 9961e39d40)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 13:19:17 +02:00
Alano Terblanche 01ea3a7da7
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>
(cherry picked from commit 88178eda32)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 12:58:33 +02:00
Alano Terblanche 0f2721ee4f
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>
(cherry picked from commit e00762ed7d)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 12:55:01 +02:00
Alano Terblanche 6fc62cf5b6
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>
(cherry picked from commit 02fda07211)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 12:54:49 +02:00
Alano Terblanche c580c9741e
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>
(cherry picked from commit ab3fcf9f9b)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 12:54:38 +02:00
Alano Terblanche ba8b22e783
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>
(cherry picked from commit 78a8856c14)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 12:54:20 +02:00
Alano Terblanche def5bfc11c
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>
(cherry picked from commit cfb8cb91f2)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 12:37:17 +02:00
Alano Terblanche 9d258edf27
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>
(cherry picked from commit e66a1456d3)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 12:37:17 +02:00
Alano Terblanche f68a9a06fe
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>
(cherry picked from commit 38595fecb6)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 12:37:17 +02:00
Alano Terblanche 60caaa39e0
Unexport config command
This patch unexports the `config` command.

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
(cherry picked from commit cce29da061)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 12:37:17 +02:00
Alano Terblanche c94245da66
Unexport checkpoint command
This patch unexports the `checkpoint` command.

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
(cherry picked from commit 3265cead1d)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 12:37:16 +02:00
Alano Terblanche 79c03dcaaf
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>
(cherry picked from commit 1b9d0762a5)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 12:37:16 +02:00
Sebastiaan van Stijn acb019a344
Merge pull request #6311 from thaJeztah/28.x_backport_deprecate_platform_flags
[28.x backport] cli/command: remove `AddTrustSigningFlags`, `AddTrustVerificationFlags`, `AddPlatformFlag` utilities
2025-08-20 12:04:45 +02:00
Sebastiaan van Stijn 5a80c3e98d
Merge pull request #6315 from thaJeztah/28.x_backport_auth_cleanups
[28.x backport] cli/command: fix godoc links and inline resolveAuthConfigFromImage
2025-08-20 11:58:27 +02:00
Sebastiaan van Stijn e250694a35
Merge pull request #6313 from thaJeztah/28.x_backport_internalize_registryclient
[28.x backport] cli/registry/client: deprecate and move internal
2025-08-20 11:58:05 +02:00
Sebastiaan van Stijn 942eade165
cli/command: inline resolveAuthConfigFromImage
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 4286883b95)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-19 23:42:44 +02:00
Sebastiaan van Stijn a746a99d97
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>
(cherry picked from commit 2d3b0b33b4)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-19 23:42:44 +02:00
Sebastiaan van Stijn 66c3dbdfed
cli/registry/client: deprecate and move internal
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 13010ba673)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-19 22:37:33 +02:00
Austin Vazquez cf44e3164b
Merge pull request #6310 from thaJeztah/28.x_backport_rm_decodeauthconfig
[28.x backport] cli/command: TestRetrieveAuthTokenFromImage: don't decode authconfig
2025-08-19 11:30:51 -07:00
Austin Vazquez ce3196c726
Merge pull request #6309 from thaJeztah/28.x_backport_docs
[28.x backport] docs/deprecated: legacy links env vars
2025-08-19 11:19:41 -07:00
Sebastiaan van Stijn 80884714de
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>
(cherry picked from commit 7026e68a71)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-19 18:35:03 +02:00
Sebastiaan van Stijn 4e00c31c71
cli/command: remove AddTrustVerificationFlags
It was only used internally; inline it where used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit c0fbbe05ca)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-19 18:35:03 +02:00
Sebastiaan van Stijn 7126bf7d22
[28.x] remove some uses of AddTrustVerificationFlags
These were already removed in master, so adding an extra commit
in the 28.x branch to remove their use.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-19 18:34:56 +02:00
Sebastiaan van Stijn 53ed958805
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>
(cherry picked from commit 8c22927978)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-19 18:17:52 +02:00
Sebastiaan van Stijn be307b2925
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>
(cherry picked from commit ae1727c41e)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-19 18:12:39 +02:00
Sebastiaan van Stijn 8f8d39c35e
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>
(cherry picked from commit 1d571d178d)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-19 18:09:18 +02:00
Albin Kerouanton c61c0cdb3c
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>
(cherry picked from commit 5c76f7f2d8)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-19 18:05:08 +02:00
Austin Vazquez 830b5f1d2f
Merge pull request #6308 from thaJeztah/28.x_backport_mountrecursive
[28.x] docs: add deprecated `bind-nonrecursive` option for `--mount`
2025-08-19 08:06:35 -07:00
Austin Vazquez abfc1f4c76
Merge pull request #6307 from thaJeztah/28.x_bump_gha
[28.x backport] build(deps): bump actions/checkout from 4 to 5
2025-08-19 08:03:23 -07:00
Sebastiaan van Stijn 31fa40cb25
docs: add deprecated `bind-nonrecursive` option for `--mount`
The `bind-nonrecursive` option was replaced with the [`bind-recursive`]
option (see [cli-4316], [cli-4671]), but the deprecated docs was not
updated to mention.

Based on abfe4d4629 in master

[`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>
(cherry picked from commit abfe4d4629)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-19 16:49:51 +02:00
dependabot[bot] 4881921784
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>
(cherry picked from commit f2af519f2e)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-19 16:32:19 +02:00
Sebastiaan van Stijn 4313a2bbb7
Merge pull request #6294 from thaJeztah/28.x_backport_progress_test
[28.x] cli/command/container: TestRunPullTermination: rewrite with streamformatter
2025-08-19 13:04:32 +02:00
Sebastiaan van Stijn 20c34ef13b
Merge pull request #6292 from thaJeztah/28.x_backport_deprecate_opts
[28.x backport] opts: deprecate NewNamedListOptsRef, NewNamedMapOpts
2025-08-19 12:50:57 +02:00
Sebastiaan van Stijn 34a90bdd81
Merge pull request #6298 from thaJeztah/28.x_backport_plugin_manager_more_deprecations
[28.x backport] cli-plugins/manager: deprecate annotation metadata aliases
2025-08-19 12:50:08 +02:00
Sebastiaan van Stijn 98b82d5156
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>
(cherry picked from commit 72f76f2720)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-18 21:54:05 +02:00
Sebastiaan van Stijn 0e474e38f1
[28.x] 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)

This is a modified version of 69854c4e08
with some changes specific to the 28.x branch (the variant on master
had some patches for the moby/api and moby/client transition).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 69854c4e08)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-18 19:17:14 +02:00
Sebastiaan van Stijn 6adde56036
Merge pull request #6291 from thaJeztah/28.x_backport_deprecate_quoted_values
[28.x backport] Deprecate special handling for quoted values for TLS flags
2025-08-18 18:35:07 +02:00
Sebastiaan van Stijn 7ccd6d29c6
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>
(cherry picked from commit 6f0c66c152)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-18 18:28:48 +02:00
Sebastiaan van Stijn 14f297204f
Merge pull request #6289 from thaJeztah/28.x_backport_hosts_regular_stringarray
[28.x backport] cli/flags: add "hostVar" to handle --host / -H as a single string
2025-08-18 18:28:25 +02:00
Sebastiaan van Stijn d1617cb0c0
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>
(cherry picked from commit ee05a71513)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-18 18:18:04 +02:00
Sebastiaan van Stijn 7091e8bea4
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>
(cherry picked from commit f14eeeb361)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-18 17:12:54 +02:00
Sebastiaan van Stijn ff42ff9f06
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>
(cherry picked from commit 5ee2906e78)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-18 17:11:54 +02:00
Sebastiaan van Stijn bcc479b4c3
Merge pull request #6276 from thaJeztah/28.x_backport_cli_internalize_utils
[28.x backport] cli: deprecate VisitAll, DisableFlagsInUseLine utilities, remove HasCompletionArg
2025-08-18 11:41:10 +02:00
Sebastiaan van Stijn 6a596c007c
Merge pull request #6269 from thaJeztah/28.x_backport_plugin_manager_unexport
[28.x backport] cli-plugins/manager: various fixes and deprecations
2025-08-18 11:24:41 +02:00
Sebastiaan van Stijn 79e0b1d7d9
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>
(cherry picked from commit 513ceeec0a)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-17 19:44:54 +02:00
Sebastiaan van Stijn 099820d8ca
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>
(cherry picked from commit 5876b2941c)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-17 19:44:53 +02:00
Sebastiaan van Stijn ac88b74462
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>
(cherry picked from commit 50963accec)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-17 19:44:53 +02:00
Sebastiaan van Stijn 7f699066bd
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>
(cherry picked from commit d789bac04a)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-17 19:44:53 +02:00
Sebastiaan van Stijn fe1d790d8e
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>
(cherry picked from commit 71460215d3)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-17 19:44:53 +02:00
Sebastiaan van Stijn 5e29918a44
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>
(cherry picked from commit 1cc698c68f)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-17 19:44:53 +02:00
Sebastiaan van Stijn 09efe3f408
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>
(cherry picked from commit 549d39a89f)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-17 19:44:52 +02:00
Sebastiaan van Stijn 79dd3a3c79
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>
(cherry picked from commit 54367b3283)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-17 19:44:49 +02:00
Austin Vazquez a8fe4aaa7f
Merge pull request #6272 from thaJeztah/28.x_backport_errdefs_unalias
[28.x backport] remove aliases for containerd/errdefs, disallow docker/errdefs
2025-08-16 15:34:43 -07:00
Sebastiaan van Stijn 034dc932d7
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>
(cherry picked from commit 89d8c8a2a7)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-16 18:29:23 +02:00
Austin Vazquez 0718529a7e
Merge pull request #6221 from thaJeztah/28.x_fork_registry
[28.x] add internal fork of docker/docker/registry
2025-08-16 08:04:59 -07:00
Austin Vazquez c754ac3c5b
Merge pull request #6280 from thaJeztah/28.x_backport_deprecate_ValidateHost
[28.x backport] opts: deprecate ValidateHost utility
2025-08-16 07:21:56 -07:00
Austin Vazquez 5d327e8032
Merge pull request #6277 from thaJeztah/28.x_backport_fix_prune_example
[28.x backport] docs: fix output example for docker system prune
2025-08-16 07:20:24 -07:00
Austin Vazquez bce66f6126
Merge pull request #6275 from thaJeztah/28.x_backport_deprecate_quotedstring
[28.x backport] opts: deprecate QuotedString
2025-08-15 13:20:06 -07:00
Sebastiaan van Stijn 511821052a
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>
(cherry picked from commit d0ac0acff0)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 22:18:29 +02:00
Austin Vazquez 9fc26d43ed
Merge pull request #6278 from thaJeztah/28.x_backport_update-golang-1.24.6
[28.x backport] update to go1.24.6
2025-08-15 13:06:03 -07:00
Austin Vazquez 2b4e0a0f45
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>
(cherry picked from commit 6769f62746)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 19:16:22 +02:00
Sebastiaan van Stijn 5d6e64c4a6
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>
(cherry picked from commit bf13010df8)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 19:13:57 +02:00
Sebastiaan van Stijn ed52ada4a3
cmd/docker: fix some minor linting issues
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 5a38118956)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 19:11:17 +02:00
Sebastiaan van Stijn 60d16e20ac
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>
(cherry picked from commit 6bd8a4b2b5)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 19:11:17 +02:00
Sebastiaan van Stijn 713ed839fe
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>
(cherry picked from commit 5a99022556)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 19:11:17 +02:00
Sebastiaan van Stijn 6bfee62d6d
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>
(cherry picked from commit 187a942a88)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 19:07:52 +02:00
Sebastiaan van Stijn efdf008933
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>
(cherry picked from commit 21e8bbc8a2)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 15:45:49 +02:00
Sebastiaan van Stijn 28ffe2416d
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>
(cherry picked from commit 86b5b528a6)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 15:45:49 +02:00
Sebastiaan van Stijn b0bb4acc11
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>
(cherry picked from commit f907c7a4b0)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 15:45:49 +02:00
Sebastiaan van Stijn 2e5a36728b
cli/command/system: remove use of Mirrors field in test
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit cd277a5815)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 15:45:49 +02:00
Sebastiaan van Stijn a5a17eb2c7
internal/registry: remove pkg/errors
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit c297770d2d)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 15:45:48 +02:00
Sebastiaan van Stijn e1f79927f3
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>
(cherry picked from commit 219cfc8b7d)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 15:45:48 +02:00
Sebastiaan van Stijn cab6012db9
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>
(cherry picked from commit 2607ba8062)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 15:45:48 +02:00
Sebastiaan van Stijn 75a4cbbf8e
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>
(cherry picked from commit 5322affc9f)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 15:45:48 +02:00
Sebastiaan van Stijn 9071d3868c
internal/registry: remove NewStaticCredentialStore
It was only used in a single place; inline it there.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit dc41365b56)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 15:45:48 +02:00
Sebastiaan van Stijn e7f4f04156
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>
(cherry picked from commit dad2e67860)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 15:45:48 +02:00
Sebastiaan van Stijn 7e01a3a8a9
internal/registry: Service.Auth remove unused statusmessage return
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 7cf245d2f7)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 15:45:47 +02:00
Sebastiaan van Stijn 72f85ccd16
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>
(cherry picked from commit e0b351b3d9)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 15:45:47 +02:00
Sebastiaan van Stijn ecd54bc6dd
internal/registry: remove dead code
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 7716219e17)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 15:45:47 +02:00
Sebastiaan van Stijn 8b9baffdf7
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>
(cherry picked from commit f6b90bc253)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 15:45:47 +02:00
Sebastiaan van Stijn 93a51c39f4
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>
(cherry picked from commit e504faf6da)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-15 15:45:45 +02:00
Austin Vazquez 2dc9daae32
Merge pull request #6265 from thaJeztah/28.x_backport_fork_remotecontext
[28.x backport] add local fork of github.com/docker/docker/builder/remotecontext
2025-08-15 05:51:05 -07:00
Sebastiaan van Stijn a4f8f22a33
Merge pull request #6190 from thaJeztah/fork_remotecontext
add local fork of github.com/docker/docker/builder/remotecontext

(cherry picked from commit 8c317ad3fd)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-14 21:50:07 +02:00
Sebastiaan van Stijn 7d3bde083c
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>
(cherry picked from commit 260f1dbebb)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-14 21:50:07 +02:00
Sebastiaan van Stijn 32207833d0
Merge pull request #6262 from thaJeztah/28.x_backport_no_pkg_process
[28.x backport] cli/connhelper: remove dependency on pkg/process
2025-08-14 21:49:42 +02:00
Sebastiaan van Stijn 7399781944
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>
(cherry picked from commit 2abcbf842f)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-14 18:45:43 +02:00
Sebastiaan van Stijn efee5879a1
Merge pull request #6264 from thaJeztah/28.x_merge_28.3.3
[28.x] merge v28.3.3 tag into v28.x
2025-08-14 18:42:32 +02:00
Sebastiaan van Stijn b82e19efe0
[28.x] merge v28.3.3 tag into v28.x
The v28.3.3 tag was created from master, but the v28.x branch
wasn't fast-forwarded, and PR's merged after that. This should
bring the v28.3.3 tag's changes into the v28.x branch.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-14 17:45:14 +02:00
Sebastiaan van Stijn eceff3dbc5
Merge pull request #6256 from thaJeztah/28.x_backport_remove_prompt_privilege_func
[28.x backport] cli/command: remove interactive login prompt from docker push/pull, deprecate RegistryAuthenticationPrivilegedFunc
2025-08-14 14:43:15 +02:00
Paweł Gronowski 3598fc3745
Merge pull request #6259 from thaJeztah/28.x_backport_rm_completion
[28.x backport] cli/command/completion: remove deprecated ValidArgsFn
2025-08-14 10:51:34 +02:00
Paweł Gronowski 2df466710b
Merge pull request #6258 from thaJeztah/28.x_backport_remove_RepoNameForReference
[28.x backport] cli/registry/client: remove deprecated RepoNameForReference
2025-08-14 10:22:59 +02:00
Paweł Gronowski 29f2ce760a
Merge pull request #6257 from thaJeztah/28.x_backport_remove_deprecated
[28.x backport] cli/command: remove deprecated CopyToFile, ConfigureAuth utilities
2025-08-14 10:22:07 +02:00
Sebastiaan van Stijn 363f4c0031
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>
(cherry picked from commit 5052a39915)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-13 18:06:23 +02:00
Sebastiaan van Stijn 6d4ffec3fb
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>
(cherry picked from commit a87bde0068)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-13 18:02:48 +02:00
Sebastiaan van Stijn 5c1cee4630
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>
(cherry picked from commit 22cc0e90ae)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-13 17:54:06 +02:00
Sebastiaan van Stijn 88274f4805
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>
(cherry picked from commit de54347518)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-13 17:53:58 +02:00
Alano Terblanche 5566c3a9b8
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>
(cherry picked from commit 29263e865b)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-13 17:38:45 +02:00
Alano Terblanche 5edc6748f4
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>
(cherry picked from commit 2b56b66b10)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-13 17:38:29 +02:00
Sebastiaan van Stijn 6007e83a75
Merge pull request #6218 from thaJeztah/28.x_bump_deps
[28.x] vendor: github.com/docker/docker v28.3.3, github.com/opencontainers/image-spec v1.1.1
2025-07-29 20:17:56 +02:00
Sebastiaan van Stijn ce2a0a4ecb
vendor: github.com/opencontainers/image-spec v1.1.1
full diff: https://github.com/opencontainers/image-spec/compare/v1.1.0...v1.1.1

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-29 18:10:03 +02:00
Sebastiaan van Stijn 3cd108fcd0
vendor: github.com/docker/docker v28.3.3
full diff: https://github.com/docker/docker/compare/v28.3.1...v28.3.3

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-29 18:09:24 +02:00
350 changed files with 4720 additions and 4704 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.6"
-
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.6"
-
name: Test
run: |

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.6"
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

@ -8,7 +8,7 @@ ARG BASE_VARIANT=alpine
ARG ALPINE_VERSION=3.21
ARG BASE_DEBIAN_DISTRO=bookworm
ARG GO_VERSION=1.24.5
ARG GO_VERSION=1.24.6
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
28.4.0-dev

View File

@ -6,25 +6,35 @@ 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.
//
// Deprecated: use [metadata.CommandAnnotationPlugin]. This alias will be removed in the next release.
CommandAnnotationPlugin = metadata.CommandAnnotationPlugin
// CommandAnnotationPluginVendor is added to every stub command
// added by AddPluginCommandStubs and contains the vendor of
// that plugin.
//
// Deprecated: use [metadata.CommandAnnotationPluginVendor]. This alias will be removed in the next release.
CommandAnnotationPluginVendor = metadata.CommandAnnotationPluginVendor
// CommandAnnotationPluginVersion is added to every stub command
// added by AddPluginCommandStubs and contains the version of
// that plugin.
//
// Deprecated: use [metadata.CommandAnnotationPluginVersion]. This alias will be removed in the next release.
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.
//
// Deprecated: use [metadata.CommandAnnotationPluginInvalid]. This alias will be removed in the next release.
CommandAnnotationPluginInvalid = metadata.CommandAnnotationPluginInvalid
// CommandAnnotationPluginCommandPath is added to overwrite the
// command path for a plugin invocation.
//
// Deprecated: use [metadata.CommandAnnotationPluginCommandPath]. This alias will be removed in the next release.
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

@ -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"
@ -23,12 +24,6 @@ const (
// 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.
@ -40,15 +35,11 @@ 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.
//
// Deprecated: use [errdefs.IsNotFound].
func IsNotFound(err error) bool {
if e, ok := err.(*pluginError); ok {
err = e.Cause()
}
_, ok := err.(notFound)
return ok
return errdefs.IsNotFound(err)
}
// getPluginDirs returns the platform-specific locations to search for plugins
@ -127,7 +118,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 +155,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,9 +176,9 @@ 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

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

@ -6,18 +6,26 @@ import (
const (
// NamePrefix is the prefix required on all plugin binary names
//
// Deprecated: use [metadata.NamePrefix]. This alias will be removed in a future release.
NamePrefix = metadata.NamePrefix
// MetadataSubcommandName is the name of the plugin subcommand
// which must be supported by every plugin and returns the
// plugin metadata.
//
// Deprecated: use [metadata.MetadataSubcommandName]. This alias will be removed in a future release.
MetadataSubcommandName = metadata.MetadataSubcommandName
// HookSubcommandName is the name of the plugin subcommand
// which must be implemented by plugins declaring support
// for hooks in their metadata.
//
// Deprecated: use [metadata.HookSubcommandName]. This alias will be removed in a future release.
HookSubcommandName = metadata.HookSubcommandName
)
// Metadata provided by the plugin.
//
// Deprecated: use [metadata.Metadata]. This alias will be removed in a future release.
type Metadata = metadata.Metadata

View File

@ -2,6 +2,7 @@ package manager
import (
"context"
"encoding"
"encoding/json"
"errors"
"fmt"
@ -31,12 +32,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")
@ -63,7 +86,7 @@ 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())
p.Err = newPluginError("plugin candidate %q did not match %q", p.Name, pluginNameRe.String())
return p, nil
}
@ -75,11 +98,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 +119,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

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

@ -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

@ -168,34 +168,30 @@ func (tcmd *TopLevelCommand) Initialize(ops ...command.CLIOption) error {
}
// VisitAll will traverse all commands from the root.
// This is different from the VisitAll of cobra.Command where only parents
// are checked.
//
// Deprecated: this utility was only used internally and will be removed in the next release.
func VisitAll(root *cobra.Command, fn func(*cobra.Command)) {
visitAll(root, fn)
}
func visitAll(root *cobra.Command, fn func(*cobra.Command)) {
for _, cmd := range root.Commands() {
VisitAll(cmd, fn)
visitAll(cmd, fn)
}
fn(root)
}
// DisableFlagsInUseLine sets the DisableFlagsInUseLine flag on all
// commands within the tree rooted at cmd.
//
// Deprecated: this utility was only used internally and will be removed in the next release.
func DisableFlagsInUseLine(cmd *cobra.Command) {
VisitAll(cmd, func(ccmd *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",

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

@ -9,17 +9,25 @@ import (
)
// NewBuilderCommand returns a cobra command for `builder` subcommands
func NewBuilderCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewBuilderCommand(dockerCLI command.Cli) *cobra.Command {
return newBuilderCommand(dockerCLI)
}
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"},
}
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
}
@ -28,7 +36,13 @@ func NewBuilderCommand(dockerCli command.Cli) *cobra.Command {
// 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).
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewBakeStubCommand(dockerCLI command.Streams) *cobra.Command {
return newBakeStubCommand(dockerCLI)
}
func newBakeStubCommand(dockerCLI command.Streams) *cobra.Command {
return &cobra.Command{
Use: "bake [OPTIONS] [TARGET...]",
Short: "Build from a file",

View File

@ -24,7 +24,14 @@ type pruneOptions struct {
}
// NewPruneCommand returns a new cobra prune command for images
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
return newPruneCommand(dockerCli)
}
// 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,14 +39,14 @@ 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"},

View File

@ -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

@ -7,12 +7,18 @@ import (
)
// NewCheckpointCommand returns the `checkpoint` subcommand (only in experimental)
func NewCheckpointCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewCheckpointCommand(dockerCLI command.Cli) *cobra.Command {
return newCheckpointCommand(dockerCLI)
}
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",
@ -20,9 +26,9 @@ func NewCheckpointCommand(dockerCli command.Cli) *cobra.Command {
},
}
cmd.AddCommand(
newCreateCommand(dockerCli),
newListCommand(dockerCli),
newRemoveCommand(dockerCli),
newCreateCommand(dockerCLI),
newListCommand(dockerCLI),
newRemoveCommand(dockerCLI),
)
return cmd
}

View File

@ -11,7 +11,14 @@ const (
)
// NewFormat returns a format for use with a checkpoint Context
//
// Deprecated: this function was only used internally and will be removed in the next release.
func NewFormat(source string) formatter.Format {
return newFormat(source)
}
// newFormat returns a format for use with a checkpointContext.
func newFormat(source string) formatter.Format {
if source == formatter.TableFormatKey {
return defaultCheckpointFormat
}
@ -19,7 +26,14 @@ func NewFormat(source string) formatter.Format {
}
// FormatWrite writes formatted checkpoints using the Context
func FormatWrite(ctx formatter.Context, checkpoints []checkpoint.Summary) error {
//
// Deprecated: this function was only used internally and will be removed in the next release.
func FormatWrite(fmtCtx formatter.Context, checkpoints []checkpoint.Summary) error {
return formatWrite(fmtCtx, checkpoints)
}
// formatWrite writes formatted checkpoints using the Context
func formatWrite(fmtCtx formatter.Context, checkpoints []checkpoint.Summary) error {
render := func(format func(subContext formatter.SubContext) error) error {
for _, cp := range checkpoints {
if err := format(&checkpointContext{c: cp}); err != nil {
@ -28,7 +42,7 @@ func FormatWrite(ctx formatter.Context, checkpoints []checkpoint.Summary) error
}
return nil
}
return ctx.Write(newCheckpointContext(), render)
return fmtCtx.Write(newCheckpointContext(), render)
}
type checkpointContext struct {

View File

@ -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

@ -45,7 +45,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

@ -282,6 +282,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
}
@ -475,6 +486,57 @@ 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()

View File

@ -18,6 +18,7 @@ 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"
@ -188,16 +189,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 +354,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

@ -29,69 +29,127 @@ import (
func AddCommands(cmd *cobra.Command, dockerCli command.Cli) {
cmd.AddCommand(
// commonly used shorthands
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
container.NewRunCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
container.NewExecCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
container.NewPsCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
image.NewBuildCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
image.NewPullCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
image.NewPushCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
image.NewImagesCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
registry.NewLoginCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
registry.NewLogoutCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
registry.NewSearchCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
system.NewVersionCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
system.NewInfoCommand(dockerCli),
// management commands
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
builder.NewBakeStubCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
builder.NewBuilderCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
checkpoint.NewCheckpointCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
container.NewContainerCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
context.NewContextCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
image.NewImageCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
manifest.NewManifestCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
network.NewNetworkCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
plugin.NewPluginCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
system.NewSystemCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
trust.NewTrustCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
volume.NewVolumeCommand(dockerCli),
// orchestration (swarm) commands
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
config.NewConfigCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
node.NewNodeCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
secret.NewSecretCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
service.NewServiceCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
stack.NewStackCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
swarm.NewSwarmCommand(dockerCli),
// legacy commands may be hidden
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(container.NewAttachCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(container.NewCommitCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(container.NewCopyCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(container.NewCreateCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(container.NewDiffCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(container.NewExportCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(container.NewKillCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(container.NewLogsCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(container.NewPauseCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(container.NewPortCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(container.NewRenameCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(container.NewRestartCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(container.NewRmCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(container.NewStartCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(container.NewStatsCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(container.NewStopCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(container.NewTopCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(container.NewUnpauseCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(container.NewUpdateCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(container.NewWaitCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(image.NewHistoryCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(image.NewImportCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(image.NewLoadCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(image.NewRemoveCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(image.NewSaveCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(image.NewTagCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(system.NewEventsCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(system.NewInspectCommand(dockerCli)),
)
}

View File

@ -13,11 +13,6 @@ import (
"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
// it if needed.
//

View File

@ -9,22 +9,28 @@ import (
)
// NewConfigCommand returns a cobra command for `config` subcommands
func NewConfigCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewConfigCommand(dockerCLI command.Cli) *cobra.Command {
return newConfigCommand(dockerCLI)
}
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",
},
}
cmd.AddCommand(
newConfigListCommand(dockerCli),
newConfigCreateCommand(dockerCli),
newConfigInspectCommand(dockerCli),
newConfigRemoveCommand(dockerCli),
newConfigListCommand(dockerCLI),
newConfigCreateCommand(dockerCLI),
newConfigInspectCommand(dockerCLI),
newConfigRemoveCommand(dockerCLI),
)
return cmd
}

View File

@ -16,6 +16,8 @@ import (
)
// CreateOptions specifies some options that are used when creating a config.
//
// Deprecated: this type was for internal use and will be removed in the next release.
type CreateOptions struct {
Name string
TemplateDriver string
@ -23,9 +25,17 @@ type CreateOptions struct {
Labels opts.ListOpts
}
func newConfigCreateCommand(dockerCli command.Cli) *cobra.Command {
createOpts := CreateOptions{
Labels: opts.NewListOpts(opts.ValidateLabel),
// 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),
}
cmd := &cobra.Command{
@ -33,39 +43,51 @@ 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,
}
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.
//
// Deprecated: this function was for internal use and will be removed in the next release.
func RunConfigCreate(ctx context.Context, dockerCLI command.Cli, options CreateOptions) error {
return runCreate(ctx, dockerCLI, createOptions{
name: options.Name,
templateDriver: options.TemplateDriver,
file: options.File,
labels: options.Labels,
})
}
// 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 errors.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

@ -30,7 +30,14 @@ Data:
)
// NewFormat returns a Format for rendering using a config Context
//
// Deprecated: this function was only used internally and will be removed in the next release.
func NewFormat(source string, quiet bool) formatter.Format {
return newFormat(source, quiet)
}
// newFormat returns a Format for rendering using a configContext.
func newFormat(source string, quiet bool) formatter.Format {
switch source {
case formatter.PrettyFormatKey:
return configInspectPrettyTemplate
@ -44,7 +51,14 @@ func NewFormat(source string, quiet bool) formatter.Format {
}
// FormatWrite writes the context
func FormatWrite(ctx formatter.Context, configs []swarm.Config) error {
//
// Deprecated: this function was only used internally and will be removed in the next release.
func FormatWrite(fmtCtx formatter.Context, configs []swarm.Config) error {
return formatWrite(fmtCtx, configs)
}
// formatWrite writes the context
func formatWrite(fmtCtx formatter.Context, configs []swarm.Config) error {
render := func(format func(subContext formatter.SubContext) error) error {
for _, config := range configs {
configCtx := &configContext{c: config}
@ -54,7 +68,7 @@ func FormatWrite(ctx formatter.Context, configs []swarm.Config) error {
}
return nil
}
return ctx.Write(newConfigContext(), render)
return fmtCtx.Write(newConfigContext(), render)
}
func newConfigContext() *configContext {
@ -115,9 +129,16 @@ func (c *configContext) Label(name string) string {
}
// 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)
//
// Deprecated: this function was only used internally and will be removed in the next release.
func InspectFormatWrite(fmtCtx formatter.Context, refs []string, getRef inspect.GetRefFunc) error {
return inspectFormatWrite(fmtCtx, refs, 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 {
for _, ref := range refs {
@ -135,7 +156,7 @@ func InspectFormatWrite(ctx formatter.Context, refs []string, getRef inspect.Get
}
return nil
}
return ctx.Write(&configInspectContext{}, render)
return fmtCtx.Write(&configInspectContext{}, render)
}
type configInspectContext struct {

View File

@ -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

@ -16,57 +16,76 @@ import (
)
// InspectOptions contains options for the docker config inspect command.
//
// Deprecated: this type was for internal use and will be removed in the next release.
type InspectOptions struct {
Names []string
Format string
Pretty bool
}
func newConfigInspectCommand(dockerCli command.Cli) *cobra.Command {
opts := InspectOptions{}
// 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{}
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)
},
}
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.
//
// Deprecated: this function was for internal use and will be removed in the next release.
func RunConfigInspect(ctx context.Context, dockerCLI command.Cli, opts InspectOptions) error {
return runInspect(ctx, dockerCLI, inspectOptions{
names: opts.Names,
format: opts.Format,
pretty: opts.Pretty,
})
}
// 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

@ -16,14 +16,23 @@ import (
)
// ListOptions contains options for the docker config ls command.
//
// Deprecated: this type was for internal use and will be removed in the next release.
type ListOptions struct {
Quiet bool
Format string
Filter opts.FilterOpt
}
func newConfigListCommand(dockerCli command.Cli) *cobra.Command {
listOpts := ListOptions{Filter: opts.NewFilterOpt()}
// 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()}
cmd := &cobra.Command{
Use: "ls [OPTIONS]",
@ -31,31 +40,42 @@ 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,
}
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.
//
// Deprecated: this function was for internal use and will be removed in the next release.
func RunConfigList(ctx context.Context, dockerCLI command.Cli, options ListOptions) error {
return runList(ctx, dockerCLI, listOptions{
quiet: options.Quiet,
format: options.Format,
filter: options.Filter,
})
}
// 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, swarm.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 +88,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

@ -11,34 +11,40 @@ import (
)
// RemoveOptions contains options for the docker config rm command.
//
// Deprecated: this type was for internal use and will be removed in the next release.
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)
},
}
}
// RunConfigRemove removes the given Swarm configs.
//
// Deprecated: this function was for internal use and will be removed in the next release.
func RunConfigRemove(ctx context.Context, dockerCLI command.Cli, opts RemoveOptions) error {
return runRemove(ctx, dockerCLI, opts.Names)
}
// 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

@ -41,7 +41,13 @@ func inspectContainerAndCheckState(ctx context.Context, apiClient client.APIClie
}
// NewAttachCommand creates a new cobra.Command for `docker attach`
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewAttachCommand(dockerCLI command.Cli) *cobra.Command {
return newAttachCommand(dockerCLI)
}
func newAttachCommand(dockerCLI command.Cli) *cobra.Command {
var opts AttachOptions
cmd := &cobra.Command{

View File

@ -74,7 +74,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

@ -7,39 +7,45 @@ import (
)
// NewContainerCommand returns a cobra command for `container` subcommands
func NewContainerCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewContainerCommand(dockerCLI command.Cli) *cobra.Command {
return newContainerCommand(dockerCLI)
}
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()),
}
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

@ -23,7 +23,13 @@ type commitOptions struct {
}
// NewCommitCommand creates a new cobra.Command for `docker commit`
func NewCommitCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewCommitCommand(dockerCLI command.Cli) *cobra.Command {
return newCommitCommand(dockerCLI)
}
func newCommitCommand(dockerCLI command.Cli) *cobra.Command {
var options commitOptions
cmd := &cobra.Command{
@ -35,12 +41,12 @@ 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),
}
flags := cmd.Flags()

View File

@ -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

@ -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

@ -122,7 +122,13 @@ func copyProgress(ctx context.Context, dst io.Writer, header string, total *int6
}
// NewCopyCommand creates a new `docker cp` command
func NewCopyCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewCopyCommand(dockerCLI command.Cli) *cobra.Command {
return newCopyCommand(dockerCLI)
}
func newCopyCommand(dockerCLI command.Cli) *cobra.Command {
var opts copyOptions
cmd := &cobra.Command{
@ -147,9 +153,9 @@ 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",

View File

@ -11,7 +11,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"
@ -52,7 +52,13 @@ type createOptions struct {
}
// NewCreateCommand creates a new cobra.Command for `docker create`
func NewCreateCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewCreateCommand(dockerCLI command.Cli) *cobra.Command {
return newCreateCommand(dockerCLI)
}
func newCreateCommand(dockerCLI command.Cli) *cobra.Command {
var options createOptions
var copts *containerOptions
@ -65,12 +71,12 @@ 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),
}
flags := cmd.Flags()
@ -86,11 +92,14 @@ func NewCreateCommand(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)
_ = 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
@ -341,7 +350,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))

View File

@ -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,
@ -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

@ -11,18 +11,24 @@ import (
)
// NewDiffCommand creates a new cobra.Command for `docker diff`
func NewDiffCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewDiffCommand(dockerCLI command.Cli) *cobra.Command {
return newDiffCommand(dockerCLI)
}
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),
}
}
@ -33,7 +39,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

@ -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

@ -40,7 +40,13 @@ func NewExecOptions() ExecOptions {
}
// NewExecCommand creates a new cobra.Command for `docker exec`
func NewExecCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewExecCommand(dockerCLI command.Cli) *cobra.Command {
return newExecCommand(dockerCLI)
}
func newExecCommand(dockerCLI command.Cli) *cobra.Command {
options := NewExecOptions()
cmd := &cobra.Command{
@ -50,9 +56,9 @@ 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{

View File

@ -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

@ -18,7 +18,13 @@ type exportOptions struct {
}
// NewExportCommand creates a new `docker export` command
func NewExportCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewExportCommand(dockerCLI command.Cli) *cobra.Command {
return newExportCommand(dockerCLI)
}
func newExportCommand(dockerCLI command.Cli) *cobra.Command {
var opts exportOptions
cmd := &cobra.Command{
@ -27,12 +33,12 @@ 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),
}
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

@ -13,7 +13,14 @@ const (
)
// NewDiffFormat returns a format for use with a diff Context
//
// Deprecated: this function was only used internally and will be removed in the next release.
func NewDiffFormat(source string) formatter.Format {
return newDiffFormat(source)
}
// newDiffFormat returns a format for use with a diff [formatter.Context].
func newDiffFormat(source string) formatter.Format {
if source == formatter.TableFormatKey {
return defaultDiffTableFormat
}
@ -21,16 +28,22 @@ func NewDiffFormat(source string) formatter.Format {
}
// 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 {
//
// Deprecated: this function was only used internally and will be removed in the next release.
func DiffFormatWrite(fmtCtx formatter.Context, changes []container.FilesystemChange) error {
return diffFormatWrite(fmtCtx, changes)
}
// 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 +52,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

@ -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

@ -18,7 +18,13 @@ type killOptions struct {
}
// NewKillCommand creates a new cobra.Command for `docker kill`
func NewKillCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewKillCommand(dockerCLI command.Cli) *cobra.Command {
return newKillCommand(dockerCLI)
}
func newKillCommand(dockerCLI command.Cli) *cobra.Command {
var opts killOptions
cmd := &cobra.Command{
@ -27,12 +33,12 @@ 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),
}
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

@ -29,7 +29,13 @@ type psOptions struct {
}
// NewPsCommand creates a new cobra.Command for `docker ps`
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewPsCommand(dockerCLI command.Cli) *cobra.Command {
return newPsCommand(dockerCLI)
}
func newPsCommand(dockerCLI command.Cli) *cobra.Command {
options := psOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{
@ -62,7 +68,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

View File

@ -24,7 +24,13 @@ type logsOptions struct {
}
// NewLogsCommand creates a new cobra.Command for `docker logs`
func NewLogsCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewLogsCommand(dockerCLI command.Cli) *cobra.Command {
return newLogsCommand(dockerCLI)
}
func newLogsCommand(dockerCLI command.Cli) *cobra.Command {
var opts logsOptions
cmd := &cobra.Command{
@ -33,12 +39,12 @@ 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),
}
flags := cmd.Flags()

View File

@ -12,8 +12,8 @@ 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"
@ -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{
@ -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
}

View File

@ -17,7 +17,13 @@ type pauseOptions struct {
}
// NewPauseCommand creates a new cobra.Command for `docker pause`
func NewPauseCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewPauseCommand(dockerCLI command.Cli) *cobra.Command {
return newPauseCommand(dockerCLI)
}
func newPauseCommand(dockerCLI command.Cli) *cobra.Command {
var opts pauseOptions
return &cobra.Command{
@ -26,12 +32,12 @@ 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
}),
}

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

@ -24,7 +24,13 @@ type portOptions struct {
}
// NewPortCommand creates a new cobra.Command for `docker port`
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewPortCommand(dockerCli command.Cli) *cobra.Command {
return newPortCommand(dockerCli)
}
func newPortCommand(dockerCli command.Cli) *cobra.Command {
var opts portOptions
cmd := &cobra.Command{

View File

@ -66,7 +66,7 @@ func TestNewPortCommandOutput(t *testing.T) {
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

@ -20,7 +20,13 @@ type pruneOptions struct {
}
// NewPruneCommand returns a new cobra prune command for containers
func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewPruneCommand(dockerCLI command.Cli) *cobra.Command {
return newPruneCommand(dockerCLI)
}
func newPruneCommand(dockerCLI command.Cli) *cobra.Command {
options := pruneOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{
@ -28,14 +34,14 @@ 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"},

View File

@ -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

@ -18,7 +18,13 @@ type renameOptions struct {
}
// NewRenameCommand creates a new cobra.Command for `docker rename`
func NewRenameCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewRenameCommand(dockerCLI command.Cli) *cobra.Command {
return newRenameCommand(dockerCLI)
}
func newRenameCommand(dockerCLI command.Cli) *cobra.Command {
var opts renameOptions
cmd := &cobra.Command{
@ -28,12 +34,12 @@ 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),
}
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

@ -21,7 +21,13 @@ type restartOptions struct {
}
// NewRestartCommand creates a new cobra.Command for `docker restart`
func NewRestartCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewRestartCommand(dockerCLI command.Cli) *cobra.Command {
return newRestartCommand(dockerCLI)
}
func newRestartCommand(dockerCLI command.Cli) *cobra.Command {
var opts restartOptions
cmd := &cobra.Command{
@ -34,12 +40,12 @@ 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),
}
flags := cmd.Flags()

View File

@ -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,7 +6,7 @@ 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"
@ -23,7 +23,13 @@ type rmOptions struct {
}
// NewRmCommand creates a new cobra.Command for `docker rm`
func NewRmCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewRmCommand(dockerCLI command.Cli) *cobra.Command {
return newRmCommand(dockerCLI)
}
func newRmCommand(dockerCLI command.Cli) *cobra.Command {
var opts rmOptions
cmd := &cobra.Command{
@ -32,12 +38,12 @@ 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
}),
}
@ -53,7 +59,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 +81,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

@ -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

@ -28,7 +28,13 @@ type runOptions struct {
}
// NewRunCommand create a new `docker run` command
func NewRunCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewRunCommand(dockerCLI command.Cli) *cobra.Command {
return newRunCommand(dockerCLI)
}
func newRunCommand(dockerCLI command.Cli) *cobra.Command {
var options runOptions
var copts *containerOptions
@ -41,9 +47,9 @@ 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",
@ -66,12 +72,13 @@ 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

View File

@ -2,9 +2,7 @@ package container
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net"
"syscall"
@ -20,7 +18,8 @@ import (
"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/docker/docker/pkg/progress"
"github.com/docker/docker/pkg/streamformatter"
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())
}
@ -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)
@ -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)
@ -242,23 +241,19 @@ func TestRunPullTermination(t *testing.T) {
_ = 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)
}
@ -270,7 +265,7 @@ func TestRunPullTermination(t *testing.T) {
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

@ -28,7 +28,13 @@ type StartOptions struct {
}
// NewStartCommand creates a new cobra.Command for `docker start`
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewStartCommand(dockerCli command.Cli) *cobra.Command {
return newStartCommand(dockerCli)
}
func newStartCommand(dockerCli command.Cli) *cobra.Command {
var opts StartOptions
cmd := &cobra.Command{

View File

@ -64,7 +64,13 @@ type StatsOptions struct {
}
// NewStatsCommand creates a new [cobra.Command] for "docker stats".
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewStatsCommand(dockerCLI command.Cli) *cobra.Command {
return newStatsCommand(dockerCLI)
}
func newStatsCommand(dockerCLI command.Cli) *cobra.Command {
options := StatsOptions{}
cmd := &cobra.Command{

View File

@ -21,7 +21,13 @@ type stopOptions struct {
}
// NewStopCommand creates a new cobra.Command for `docker stop`
func NewStopCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewStopCommand(dockerCLI command.Cli) *cobra.Command {
return newStopCommand(dockerCLI)
}
func newStopCommand(dockerCLI command.Cli) *cobra.Command {
var opts stopOptions
cmd := &cobra.Command{
@ -34,12 +40,12 @@ func NewStopCommand(dockerCli command.Cli) *cobra.Command {
}
opts.containers = args
opts.timeoutChanged = cmd.Flags().Changed("timeout") || cmd.Flags().Changed("time")
return runStop(cmd.Context(), dockerCli, &opts)
return runStop(cmd.Context(), dockerCLI, &opts)
},
Annotations: map[string]string{
"aliases": "docker container stop, docker stop",
},
ValidArgsFunction: completion.ContainerNames(dockerCli, false),
ValidArgsFunction: completion.ContainerNames(dockerCLI, false),
}
flags := cmd.Flags()

View File

@ -77,7 +77,7 @@ func TestStop(t *testing.T) {
},
Version: "1.36",
})
cmd := NewStopCommand(cli)
cmd := newStopCommand(cli)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
cmd.SetArgs(tc.args)

View File

@ -19,7 +19,13 @@ type topOptions struct {
}
// NewTopCommand creates a new cobra.Command for `docker top`
func NewTopCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewTopCommand(dockerCLI command.Cli) *cobra.Command {
return newTopCommand(dockerCLI)
}
func newTopCommand(dockerCLI command.Cli) *cobra.Command {
var opts topOptions
cmd := &cobra.Command{
@ -29,12 +35,12 @@ func NewTopCommand(dockerCli command.Cli) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
opts.container = args[0]
opts.args = args[1:]
return runTop(cmd.Context(), dockerCli, &opts)
return runTop(cmd.Context(), dockerCLI, &opts)
},
Annotations: map[string]string{
"aliases": "docker container top, docker top",
},
ValidArgsFunction: completion.ContainerNames(dockerCli, false),
ValidArgsFunction: completion.ContainerNames(dockerCLI, false),
}
flags := cmd.Flags()

View File

@ -17,7 +17,13 @@ type unpauseOptions struct {
}
// NewUnpauseCommand creates a new cobra.Command for `docker unpause`
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewUnpauseCommand(dockerCli command.Cli) *cobra.Command {
return newUnpauseCommand(dockerCli)
}
func newUnpauseCommand(dockerCli command.Cli) *cobra.Command {
var opts unpauseOptions
cmd := &cobra.Command{

View File

@ -37,7 +37,13 @@ type updateOptions struct {
}
// NewUpdateCommand creates a new cobra.Command for `docker update`
func NewUpdateCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewUpdateCommand(dockerCLI command.Cli) *cobra.Command {
return newUpdateCommand(dockerCLI)
}
func newUpdateCommand(dockerCLI command.Cli) *cobra.Command {
var options updateOptions
cmd := &cobra.Command{
@ -47,12 +53,12 @@ func NewUpdateCommand(dockerCli command.Cli) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
options.containers = args
options.nFlag = cmd.Flags().NFlag()
return runUpdate(cmd.Context(), dockerCli, &options)
return runUpdate(cmd.Context(), dockerCLI, &options)
},
Annotations: map[string]string{
"aliases": "docker container update, docker update",
},
ValidArgsFunction: completion.ContainerNames(dockerCli, true),
ValidArgsFunction: completion.ContainerNames(dockerCLI, true),
}
flags := cmd.Flags()

View File

@ -16,7 +16,13 @@ type waitOptions struct {
}
// NewWaitCommand creates a new cobra.Command for `docker wait`
func NewWaitCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewWaitCommand(dockerCLI command.Cli) *cobra.Command {
return newWaitCommand(dockerCLI)
}
func newWaitCommand(dockerCLI command.Cli) *cobra.Command {
var opts waitOptions
cmd := &cobra.Command{
@ -25,12 +31,12 @@ func NewWaitCommand(dockerCli command.Cli) *cobra.Command {
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.containers = args
return runWait(cmd.Context(), dockerCli, &opts)
return runWait(cmd.Context(), dockerCLI, &opts)
},
Annotations: map[string]string{
"aliases": "docker container wait, docker wait",
},
ValidArgsFunction: completion.ContainerNames(dockerCli, false),
ValidArgsFunction: completion.ContainerNames(dockerCLI, false),
}
return cmd

View File

@ -7,23 +7,30 @@ import (
)
// NewContextCommand returns the context cli subcommand
func NewContextCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewContextCommand(dockerCLI command.Cli) *cobra.Command {
return newContextCommand(dockerCLI)
}
// newContextCommand returns the context cli subcommand
func newContextCommand(dockerCLI command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "context",
Short: "Manage contexts",
Args: cli.NoArgs,
RunE: command.ShowHelp(dockerCli.Err()),
RunE: command.ShowHelp(dockerCLI.Err()),
}
cmd.AddCommand(
newCreateCommand(dockerCli),
newListCommand(dockerCli),
newUseCommand(dockerCli),
newExportCommand(dockerCli),
newImportCommand(dockerCli),
newRemoveCommand(dockerCli),
newUpdateCommand(dockerCli),
newInspectCommand(dockerCli),
newShowCommand(dockerCli),
newCreateCommand(dockerCLI),
newListCommand(dockerCLI),
newUseCommand(dockerCLI),
newExportCommand(dockerCLI),
newImportCommand(dockerCLI),
newRemoveCommand(dockerCLI),
newUpdateCommand(dockerCLI),
newInspectCommand(dockerCLI),
newShowCommand(dockerCLI),
)
return cmd
}

View File

@ -8,7 +8,7 @@ import (
"errors"
"fmt"
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"
@ -122,7 +122,7 @@ func checkContextNameForCreation(s store.Reader, name string) error {
if err := store.ValidateContextName(name); err != nil {
return err
}
if _, err := s.GetMetadata(name); !cerrdefs.IsNotFound(err) {
if _, err := s.GetMetadata(name); !errdefs.IsNotFound(err) {
if err != nil {
return fmt.Errorf("error while getting existing contexts: %w", err)
}

View File

@ -4,7 +4,7 @@ import (
"path/filepath"
"testing"
cerrdefs "github.com/containerd/errdefs"
"github.com/containerd/errdefs"
"github.com/docker/cli/cli/config"
"github.com/docker/cli/cli/config/configfile"
"gotest.tools/v3/assert"
@ -18,7 +18,7 @@ func TestRemove(t *testing.T) {
_, err := cli.ContextStore().GetMetadata("current")
assert.NilError(t, err)
_, err = cli.ContextStore().GetMetadata("other")
assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
}
func TestRemoveNotAContext(t *testing.T) {

View File

@ -9,7 +9,7 @@ import (
"runtime"
"testing"
cerrdefs "github.com/containerd/errdefs"
"github.com/containerd/errdefs"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/config"
"github.com/docker/cli/cli/config/configfile"
@ -47,7 +47,7 @@ func TestUse(t *testing.T) {
func TestUseNoExist(t *testing.T) {
cli := makeFakeCli(t)
err := newUseCommand(cli).RunE(nil, []string{"test"})
assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
}
// TestUseDefaultWithoutConfigFile verifies that the CLI does not create

View File

@ -7,7 +7,7 @@ import (
"crypto/rand"
"testing"
cerrdefs "github.com/containerd/errdefs"
"github.com/containerd/errdefs"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/context/docker"
"github.com/docker/cli/cli/context/store"
@ -158,7 +158,7 @@ func TestErrCreateDefault(t *testing.T) {
Metadata: testContext{Bar: "baz"},
Name: "default",
})
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument))
assert.Check(t, is.ErrorType(err, errdefs.IsInvalidArgument))
assert.Error(t, err, "default context cannot be created nor updated")
}
@ -166,7 +166,7 @@ func TestErrRemoveDefault(t *testing.T) {
meta := testDefaultMetadata()
s := testStore(t, meta, store.ContextTLSData{})
err := s.Remove("default")
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument))
assert.Check(t, is.ErrorType(err, errdefs.IsInvalidArgument))
assert.Error(t, err, "default context cannot be removed")
}
@ -174,5 +174,5 @@ func TestErrTLSDataError(t *testing.T) {
meta := testDefaultMetadata()
s := testStore(t, meta, store.ContextTLSData{})
_, err := s.GetTLSData("default", "noop", "noop")
assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
}

View File

@ -12,13 +12,13 @@ import (
)
func TestResolveError(t *testing.T) {
cli := &fakeClient{
apiClient := &fakeClient{
nodeInspectFunc: func(nodeID string) (swarm.Node, []byte, error) {
return swarm.Node{}, []byte{}, errors.New("error inspecting node")
},
}
idResolver := New(cli, false)
idResolver := New(apiClient, false)
_, err := idResolver.Resolve(context.Background(), struct{}{}, "nodeID")
assert.Error(t, err, "unsupported type")
@ -26,7 +26,7 @@ func TestResolveError(t *testing.T) {
func TestResolveWithNoResolveOption(t *testing.T) {
resolved := false
cli := &fakeClient{
apiClient := &fakeClient{
nodeInspectFunc: func(nodeID string) (swarm.Node, []byte, error) {
resolved = true
return swarm.Node{}, []byte{}, nil
@ -37,7 +37,7 @@ func TestResolveWithNoResolveOption(t *testing.T) {
},
}
idResolver := New(cli, true)
idResolver := New(apiClient, true)
id, err := idResolver.Resolve(context.Background(), swarm.Node{}, "nodeID")
assert.NilError(t, err)
@ -47,14 +47,14 @@ func TestResolveWithNoResolveOption(t *testing.T) {
func TestResolveWithCache(t *testing.T) {
inspectCounter := 0
cli := &fakeClient{
apiClient := &fakeClient{
nodeInspectFunc: func(nodeID string) (swarm.Node, []byte, error) {
inspectCounter++
return *builders.Node(builders.NodeName("node-foo")), []byte{}, nil
},
}
idResolver := New(cli, false)
idResolver := New(apiClient, false)
ctx := context.Background()
for i := 0; i < 2; i++ {
@ -97,10 +97,10 @@ func TestResolveNode(t *testing.T) {
ctx := context.Background()
for _, tc := range testCases {
cli := &fakeClient{
apiClient := &fakeClient{
nodeInspectFunc: tc.nodeInspectFunc,
}
idResolver := New(cli, false)
idResolver := New(apiClient, false)
id, err := idResolver.Resolve(ctx, swarm.Node{}, tc.nodeID)
assert.NilError(t, err)
@ -132,10 +132,10 @@ func TestResolveService(t *testing.T) {
ctx := context.Background()
for _, tc := range testCases {
cli := &fakeClient{
apiClient := &fakeClient{
serviceInspectFunc: tc.serviceInspectFunc,
}
idResolver := New(cli, false)
idResolver := New(apiClient, false)
id, err := idResolver.Resolve(ctx, swarm.Service{}, tc.serviceID)
assert.NilError(t, err)

View File

@ -28,7 +28,6 @@ import (
buildtypes "github.com/docker/docker/api/types/build"
"github.com/docker/docker/api/types/container"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/builder/remotecontext/urlutil"
"github.com/docker/docker/pkg/progress"
"github.com/docker/docker/pkg/streamformatter"
"github.com/moby/go-archive"
@ -76,12 +75,6 @@ func (o buildOptions) dockerfileFromStdin() bool {
return o.dockerfileName == "-"
}
// contextFromStdin returns true when the user specified that the build context
// should be read from stdin
func (o buildOptions) contextFromStdin() bool {
return o.context == "-"
}
func newBuildOptions() buildOptions {
ulimits := make(map[string]*container.Ulimit)
return buildOptions{
@ -94,7 +87,14 @@ func newBuildOptions() buildOptions {
}
// NewBuildCommand creates a new `docker build` command
func NewBuildCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewBuildCommand(dockerCLI command.Cli) *cobra.Command {
return newBuildCommand(dockerCLI)
}
// newBuildCommand creates a new `docker build` command
func newBuildCommand(dockerCli command.Cli) *cobra.Command {
options := newBuildOptions()
cmd := &cobra.Command{
@ -152,7 +152,7 @@ func NewBuildCommand(dockerCli command.Cli) *cobra.Command {
flags.SetAnnotation("target", annotation.ExternalURL, []string{"https://docs.docker.com/reference/cli/docker/buildx/build/#target"})
flags.StringVar(&options.imageIDFile, "iidfile", "", "Write the image ID to the file")
command.AddTrustVerificationFlags(flags, &options.untrusted, dockerCli.ContentTrustEnabled())
flags.BoolVar(&options.untrusted, "disable-content-trust", !dockerCli.ContentTrustEnabled(), "Skip image verification")
flags.StringVar(&options.platform, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
flags.SetAnnotation("platform", "version", []string{"1.38"})
@ -189,21 +189,24 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
buildCtx io.ReadCloser
dockerfileCtx io.ReadCloser
contextDir string
tempDir string
relDockerfile string
progBuff io.Writer
buildBuff io.Writer
remote string
)
contextType, err := build.DetectContextType(options.context)
if err != nil {
return err
}
if options.dockerfileFromStdin() {
if options.contextFromStdin() {
if contextType == build.ContextTypeStdin {
return errors.New("invalid argument: can't use stdin for both build context and dockerfile")
}
dockerfileCtx = dockerCli.In()
}
specifiedContext := options.context
progBuff = dockerCli.Out()
buildBuff = dockerCli.Out()
if options.quiet {
@ -217,13 +220,19 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
}
}
switch {
case options.contextFromStdin():
switch contextType {
case build.ContextTypeStdin:
// buildCtx is tar archive. if stdin was dockerfile then it is wrapped
buildCtx, relDockerfile, err = build.GetContextFromReader(dockerCli.In(), options.dockerfileName)
case isLocalDir(specifiedContext):
contextDir, relDockerfile, err = build.GetContextFromLocalDir(specifiedContext, options.dockerfileName)
if err == nil && strings.HasPrefix(relDockerfile, ".."+string(filepath.Separator)) {
if err != nil {
return fmt.Errorf("unable to prepare context from STDIN: %w", err)
}
case build.ContextTypeLocal:
contextDir, relDockerfile, err = build.GetContextFromLocalDir(options.context, options.dockerfileName)
if err != nil {
return errors.Errorf("unable to prepare context: %s", err)
}
if strings.HasPrefix(relDockerfile, ".."+string(filepath.Separator)) {
// Dockerfile is outside of build-context; read the Dockerfile and pass it as dockerfileCtx
dockerfileCtx, err = os.Open(options.dockerfileName)
if err != nil {
@ -231,24 +240,23 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
}
defer dockerfileCtx.Close()
}
case urlutil.IsGitURL(specifiedContext):
tempDir, relDockerfile, err = build.GetContextFromGitURL(specifiedContext, options.dockerfileName)
case urlutil.IsURL(specifiedContext):
buildCtx, relDockerfile, err = build.GetContextFromURL(progBuff, specifiedContext, options.dockerfileName)
default:
return errors.Errorf("unable to prepare context: path %q not found", specifiedContext)
}
if err != nil {
if options.quiet && urlutil.IsURL(specifiedContext) {
case build.ContextTypeGit:
var tempDir string
tempDir, relDockerfile, err = build.GetContextFromGitURL(options.context, options.dockerfileName)
if err != nil {
return errors.Errorf("unable to prepare context: %s", err)
}
defer func() {
_ = os.RemoveAll(tempDir)
}()
contextDir = tempDir
case build.ContextTypeRemote:
buildCtx, relDockerfile, err = build.GetContextFromURL(progBuff, options.context, options.dockerfileName)
if err != nil && options.quiet {
_, _ = fmt.Fprintln(dockerCli.Err(), progBuff)
}
return errors.Errorf("unable to prepare context: %s", err)
}
if tempDir != "" {
defer os.RemoveAll(tempDir)
contextDir = tempDir
default:
return errors.Errorf("unable to prepare context: path %q not found", options.context)
}
// read from a directory into tar archive
@ -415,11 +423,6 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
return nil
}
func isLocalDir(c string) bool {
_, err := os.Stat(c)
return err == nil
}
type translatorFunc func(context.Context, reference.NamedTagged) (reference.Canonical, error)
// validateTag checks if the given image name can be resolved.

View File

@ -16,7 +16,7 @@ import (
"strings"
"time"
"github.com/docker/docker/builder/remotecontext/git"
"github.com/docker/cli/cli/command/image/build/internal/git"
"github.com/docker/docker/pkg/progress"
"github.com/docker/docker/pkg/streamformatter"
"github.com/moby/go-archive"

View File

@ -0,0 +1,39 @@
package build
import (
"fmt"
"os"
"github.com/docker/cli/cli/command/image/build/internal/urlutil"
)
// ContextType describes the type (source) of build-context specified.
type ContextType string
const (
ContextTypeStdin ContextType = "stdin" // ContextTypeStdin indicates that the build-context is a TAR archive passed through STDIN.
ContextTypeLocal ContextType = "local" // ContextTypeLocal indicates that the build-context is a local directory.
ContextTypeRemote ContextType = "remote" // ContextTypeRemote indicates that the build-context is a remote URL.
ContextTypeGit ContextType = "git" // ContextTypeGit indicates that the build-context is a GIT URL.
)
// DetectContextType detects the type (source) of the build-context.
func DetectContextType(specifiedContext string) (ContextType, error) {
switch {
case specifiedContext == "-":
return ContextTypeStdin, nil
case isLocalDir(specifiedContext):
return ContextTypeLocal, nil
case urlutil.IsGitURL(specifiedContext):
return ContextTypeGit, nil
case urlutil.IsURL(specifiedContext):
return ContextTypeRemote, nil
default:
return "", fmt.Errorf("unable to prepare context: path %q not found", specifiedContext)
}
}
func isLocalDir(c string) bool {
_, err := os.Stat(c)
return err == nil
}

View File

@ -148,6 +148,9 @@ func supportsShallowClone(remoteURL string) bool {
// Try a HEAD request and fallback to a Get request on error
res, err := http.Head(serviceURL) // #nosec G107
if err == nil {
_ = res.Body.Close()
}
if err != nil || res.StatusCode != http.StatusOK {
res, err = http.Get(serviceURL) // #nosec G107
if err == nil {

View File

@ -0,0 +1,382 @@
package git
import (
"bytes"
"fmt"
"net/http"
"net/http/cgi"
"net/http/httptest"
"net/url"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
func TestParseRemoteURL(t *testing.T) {
tests := []struct {
doc string
url string
expected gitRepo
}{
{
doc: "git scheme uppercase, no url-fragment",
url: "GIT://github.com/user/repo.git",
expected: gitRepo{
remote: "git://github.com/user/repo.git",
ref: "master",
},
},
{
doc: "git scheme, no url-fragment",
url: "git://github.com/user/repo.git",
expected: gitRepo{
remote: "git://github.com/user/repo.git",
ref: "master",
},
},
{
doc: "git scheme, with url-fragment",
url: "git://github.com/user/repo.git#mybranch:mydir/mysubdir/",
expected: gitRepo{
remote: "git://github.com/user/repo.git",
ref: "mybranch",
subdir: "mydir/mysubdir/",
},
},
{
doc: "https scheme, no url-fragment",
url: "https://github.com/user/repo.git",
expected: gitRepo{
remote: "https://github.com/user/repo.git",
ref: "master",
},
},
{
doc: "https scheme, with url-fragment",
url: "https://github.com/user/repo.git#mybranch:mydir/mysubdir/",
expected: gitRepo{
remote: "https://github.com/user/repo.git",
ref: "mybranch",
subdir: "mydir/mysubdir/",
},
},
{
doc: "git@, no url-fragment",
url: "git@github.com:user/repo.git",
expected: gitRepo{
remote: "git@github.com:user/repo.git",
ref: "master",
},
},
{
doc: "git@, with url-fragment",
url: "git@github.com:user/repo.git#mybranch:mydir/mysubdir/",
expected: gitRepo{
remote: "git@github.com:user/repo.git",
ref: "mybranch",
subdir: "mydir/mysubdir/",
},
},
{
doc: "ssh, no url-fragment",
url: "ssh://github.com/user/repo.git",
expected: gitRepo{
remote: "ssh://github.com/user/repo.git",
ref: "master",
},
},
{
doc: "ssh, with url-fragment",
url: "ssh://github.com/user/repo.git#mybranch:mydir/mysubdir/",
expected: gitRepo{
remote: "ssh://github.com/user/repo.git",
ref: "mybranch",
subdir: "mydir/mysubdir/",
},
},
{
doc: "ssh, with url-fragment and user",
url: "ssh://foo%40barcorp.com@github.com/user/repo.git#mybranch:mydir/mysubdir/",
expected: gitRepo{
remote: "ssh://foo%40barcorp.com@github.com/user/repo.git",
ref: "mybranch",
subdir: "mydir/mysubdir/",
},
},
}
for _, tc := range tests {
t.Run(tc.doc, func(t *testing.T) {
repo, err := parseRemoteURL(tc.url)
assert.NilError(t, err)
assert.Check(t, is.DeepEqual(tc.expected, repo, cmp.AllowUnexported(gitRepo{})))
})
}
}
func TestCloneArgsSmartHttp(t *testing.T) {
mux := http.NewServeMux()
server := httptest.NewServer(mux)
serverURL, err := url.Parse(server.URL)
assert.NilError(t, err)
serverURL.Path = "/repo.git"
mux.HandleFunc("/repo.git/info/refs", func(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query().Get("service")
w.Header().Set("Content-Type", fmt.Sprintf("application/x-%s-advertisement", q))
})
args := fetchArgs(serverURL.String(), "master")
exp := []string{"fetch", "--depth", "1", "origin", "--", "master"}
assert.Check(t, is.DeepEqual(exp, args))
}
func TestCloneArgsDumbHttp(t *testing.T) {
mux := http.NewServeMux()
server := httptest.NewServer(mux)
serverURL, _ := url.Parse(server.URL)
serverURL.Path = "/repo.git"
mux.HandleFunc("/repo.git/info/refs", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
})
args := fetchArgs(serverURL.String(), "master")
exp := []string{"fetch", "origin", "--", "master"}
assert.Check(t, is.DeepEqual(exp, args))
}
func TestCloneArgsGit(t *testing.T) {
args := fetchArgs("git://github.com/docker/docker", "master")
exp := []string{"fetch", "--depth", "1", "origin", "--", "master"}
assert.Check(t, is.DeepEqual(exp, args))
}
func gitGetConfig(name string) string {
b, err := gitRepo{}.gitWithinDir("", "config", "--get", name)
if err != nil {
// since we are interested in empty or non empty string,
// we can safely ignore the err here.
return ""
}
return strings.TrimSpace(string(b))
}
func TestCheckoutGit(t *testing.T) {
root := t.TempDir()
gitpath, err := exec.LookPath("git")
assert.NilError(t, err)
gitversion, _ := exec.Command(gitpath, "version").CombinedOutput()
t.Logf("%s", gitversion) // E.g. "git version 2.30.2"
// Serve all repositories under root using the Smart HTTP protocol so
// they can be cloned. The Dumb HTTP protocol is incompatible with
// shallow cloning but we unconditionally shallow-clone submodules, and
// we explicitly disable the file protocol.
// (Another option would be to use `git daemon` and the Git protocol,
// but that listens on a fixed port number which is a recipe for
// disaster in CI. Funnily enough, `git daemon --port=0` works but there
// is no easy way to discover which port got picked!)
// Associate git-http-backend logs with the current (sub)test.
// Incompatible with parallel subtests.
currentSubtest := t
githttp := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var logs bytes.Buffer
(&cgi.Handler{
Path: gitpath,
Args: []string{"http-backend"},
Dir: root,
Env: []string{
"GIT_PROJECT_ROOT=" + root,
"GIT_HTTP_EXPORT_ALL=1",
},
Stderr: &logs,
}).ServeHTTP(w, r)
if logs.Len() == 0 {
return
}
for {
line, err := logs.ReadString('\n')
currentSubtest.Log("git-http-backend: " + line)
if err != nil {
break
}
}
})
server := httptest.NewServer(&githttp)
defer server.Close()
eol := "\n"
autocrlf := gitGetConfig("core.autocrlf")
switch autocrlf {
case "true":
eol = "\r\n"
case "false", "input", "":
// accepted values
default:
t.Logf(`unknown core.autocrlf value: "%s"`, autocrlf)
}
must := func(out []byte, err error) {
t.Helper()
if len(out) > 0 {
t.Logf("%s", out)
}
assert.NilError(t, err)
}
gitDir := filepath.Join(root, "repo")
must(gitRepo{}.gitWithinDir(root, "-c", "init.defaultBranch=master", "init", gitDir))
must(gitRepo{}.gitWithinDir(gitDir, "config", "user.email", "test@docker.com"))
must(gitRepo{}.gitWithinDir(gitDir, "config", "user.name", "Docker test"))
assert.NilError(t, os.WriteFile(filepath.Join(gitDir, "Dockerfile"), []byte("FROM scratch"), 0o644))
subDir := filepath.Join(gitDir, "subdir")
assert.NilError(t, os.Mkdir(subDir, 0o755))
assert.NilError(t, os.WriteFile(filepath.Join(subDir, "Dockerfile"), []byte("FROM scratch\nEXPOSE 5000"), 0o644))
if runtime.GOOS != "windows" {
assert.NilError(t, os.Symlink("../subdir", filepath.Join(gitDir, "parentlink")))
assert.NilError(t, os.Symlink("/subdir", filepath.Join(gitDir, "absolutelink")))
}
must(gitRepo{}.gitWithinDir(gitDir, "add", "-A"))
must(gitRepo{}.gitWithinDir(gitDir, "commit", "-am", "First commit"))
must(gitRepo{}.gitWithinDir(gitDir, "checkout", "-b", "test"))
assert.NilError(t, os.WriteFile(filepath.Join(gitDir, "Dockerfile"), []byte("FROM scratch\nEXPOSE 3000"), 0o644))
assert.NilError(t, os.WriteFile(filepath.Join(subDir, "Dockerfile"), []byte("FROM busybox\nEXPOSE 5000"), 0o644))
must(gitRepo{}.gitWithinDir(gitDir, "add", "-A"))
must(gitRepo{}.gitWithinDir(gitDir, "commit", "-am", "Branch commit"))
must(gitRepo{}.gitWithinDir(gitDir, "checkout", "master"))
// set up submodule
subrepoDir := filepath.Join(root, "subrepo")
must(gitRepo{}.gitWithinDir(root, "-c", "init.defaultBranch=master", "init", subrepoDir))
must(gitRepo{}.gitWithinDir(subrepoDir, "config", "user.email", "test@docker.com"))
must(gitRepo{}.gitWithinDir(subrepoDir, "config", "user.name", "Docker test"))
assert.NilError(t, os.WriteFile(filepath.Join(subrepoDir, "subfile"), []byte("subcontents"), 0o644))
must(gitRepo{}.gitWithinDir(subrepoDir, "add", "-A"))
must(gitRepo{}.gitWithinDir(subrepoDir, "commit", "-am", "Subrepo initial"))
must(gitRepo{}.gitWithinDir(gitDir, "submodule", "add", server.URL+"/subrepo", "sub"))
must(gitRepo{}.gitWithinDir(gitDir, "add", "-A"))
must(gitRepo{}.gitWithinDir(gitDir, "commit", "-am", "With submodule"))
type singleCase struct {
frag string
exp string
fail bool
submodule bool
}
cases := []singleCase{
{"", "FROM scratch", false, true},
{"master", "FROM scratch", false, true},
{":subdir", "FROM scratch" + eol + "EXPOSE 5000", false, false},
{":nosubdir", "", true, false}, // missing directory error
{":Dockerfile", "", true, false}, // not a directory error
{"master:nosubdir", "", true, false},
{"master:subdir", "FROM scratch" + eol + "EXPOSE 5000", false, false},
{"master:../subdir", "", true, false},
{"test", "FROM scratch" + eol + "EXPOSE 3000", false, false},
{"test:", "FROM scratch" + eol + "EXPOSE 3000", false, false},
{"test:subdir", "FROM busybox" + eol + "EXPOSE 5000", false, false},
}
if runtime.GOOS != "windows" {
// Windows GIT (2.7.1 x64) does not support parentlink/absolutelink. Sample output below
// git --work-tree .\repo --git-dir .\repo\.git add -A
// error: readlink("absolutelink"): Function not implemented
// error: unable to index file absolutelink
// fatal: adding files failed
cases = append(cases, singleCase{frag: "master:absolutelink", exp: "FROM scratch" + eol + "EXPOSE 5000", fail: false})
cases = append(cases, singleCase{frag: "master:parentlink", exp: "FROM scratch" + eol + "EXPOSE 5000", fail: false})
}
for _, c := range cases {
t.Run(c.frag, func(t *testing.T) {
currentSubtest = t
ref, subdir := getRefAndSubdir(c.frag)
r, err := gitRepo{remote: server.URL + "/repo", ref: ref, subdir: subdir}.clone()
if c.fail {
assert.Check(t, is.ErrorContains(err, ""))
return
}
assert.NilError(t, err)
defer os.RemoveAll(r)
if c.submodule {
b, err := os.ReadFile(filepath.Join(r, "sub/subfile"))
assert.NilError(t, err)
assert.Check(t, is.Equal("subcontents", string(b)))
} else {
_, err := os.Stat(filepath.Join(r, "sub/subfile"))
assert.ErrorContains(t, err, "")
assert.Assert(t, os.IsNotExist(err))
}
b, err := os.ReadFile(filepath.Join(r, "Dockerfile"))
assert.NilError(t, err)
assert.Check(t, is.Equal(c.exp, string(b)))
})
}
}
func TestValidGitTransport(t *testing.T) {
gitUrls := []string{
"git://github.com/docker/docker",
"git@github.com:docker/docker.git",
"git@bitbucket.org:atlassianlabs/atlassian-docker.git",
"https://github.com/docker/docker.git",
"http://github.com/docker/docker.git",
"http://github.com/docker/docker.git#branch",
"http://github.com/docker/docker.git#:dir",
}
incompleteGitUrls := []string{
"github.com/docker/docker",
}
for _, u := range gitUrls {
if !isGitTransport(u) {
t.Fatalf("%q should be detected as valid Git prefix", u)
}
}
for _, u := range incompleteGitUrls {
if isGitTransport(u) {
t.Fatalf("%q should not be detected as valid Git prefix", u)
}
}
}
func TestGitInvalidRef(t *testing.T) {
gitUrls := []string{
"git://github.com/moby/moby#--foo bar",
"git@github.com/moby/moby#--upload-pack=sleep;:",
"git@g.com:a/b.git#-B",
"git@g.com:a/b.git#with space",
}
for _, u := range gitUrls {
_, err := Clone(u)
assert.Assert(t, err != nil)
// On Windows, git has different case for the "invalid refspec" error,
// so we can't use ErrorContains.
assert.Check(t, is.Contains(strings.ToLower(err.Error()), "invalid refspec"))
}
}

View File

@ -8,7 +8,7 @@ package urlutil
import (
"strings"
"github.com/docker/docker/internal/lazyregexp"
"github.com/docker/cli/internal/lazyregexp"
)
// urlPathWithFragmentSuffix matches fragments to use as Git reference and build

View File

@ -0,0 +1,42 @@
package urlutil
import "testing"
var (
gitUrls = []string{
"git://github.com/docker/docker",
"git@github.com:docker/docker.git",
"git@bitbucket.org:atlassianlabs/atlassian-docker.git",
"https://github.com/docker/docker.git",
"http://github.com/docker/docker.git",
"http://github.com/docker/docker.git#branch",
"http://github.com/docker/docker.git#:dir",
}
incompleteGitUrls = []string{
"github.com/docker/docker",
}
invalidGitUrls = []string{
"http://github.com/docker/docker.git:#branch",
"https://github.com/docker/dgit",
}
)
func TestIsGIT(t *testing.T) {
for _, url := range gitUrls {
if !IsGitURL(url) {
t.Fatalf("%q should be detected as valid Git url", url)
}
}
for _, url := range incompleteGitUrls {
if !IsGitURL(url) {
t.Fatalf("%q should be detected as valid Git url", url)
}
}
for _, url := range invalidGitUrls {
if IsGitURL(url) {
t.Fatalf("%q should not be detected as valid Git prefix", url)
}
}
}

View File

@ -123,7 +123,7 @@ COPY data /data
// to support testing (ex: docker/cli#294)
func TestRunBuildFromGitHubSpecialCase(t *testing.T) {
t.Setenv("DOCKER_BUILDKIT", "0")
cmd := NewBuildCommand(test.NewFakeCli(&fakeClient{}))
cmd := newBuildCommand(test.NewFakeCli(&fakeClient{}))
// Clone a small repo that exists so git doesn't prompt for credentials
cmd.SetArgs([]string{"github.com/docker/for-win"})
cmd.SetOut(io.Discard)
@ -146,7 +146,7 @@ func TestRunBuildFromLocalGitHubDir(t *testing.T) {
assert.NilError(t, err)
client := test.NewFakeCli(&fakeClient{})
cmd := NewBuildCommand(client)
cmd := newBuildCommand(client)
cmd.SetArgs([]string{buildDir})
cmd.SetOut(io.Discard)
err = cmd.Execute()

View File

@ -7,7 +7,14 @@ import (
)
// NewImageCommand returns a cobra command for `image` subcommands
func NewImageCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewImageCommand(dockerCLI command.Cli) *cobra.Command {
return newImageCommand(dockerCLI)
}
// newImageCommand returns a cobra command for `image` subcommands
func newImageCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "image",
Short: "Manage images",
@ -15,18 +22,18 @@ func NewImageCommand(dockerCli command.Cli) *cobra.Command {
RunE: command.ShowHelp(dockerCli.Err()),
}
cmd.AddCommand(
NewBuildCommand(dockerCli),
NewHistoryCommand(dockerCli),
NewImportCommand(dockerCli),
NewLoadCommand(dockerCli),
NewPullCommand(dockerCli),
NewPushCommand(dockerCli),
NewSaveCommand(dockerCli),
NewTagCommand(dockerCli),
newBuildCommand(dockerCli),
newHistoryCommand(dockerCli),
newImportCommand(dockerCli),
newLoadCommand(dockerCli),
newPullCommand(dockerCli),
newPushCommand(dockerCli),
newSaveCommand(dockerCli),
newTagCommand(dockerCli),
newListCommand(dockerCli),
newRemoveCommand(dockerCli),
newImageRemoveCommand(dockerCli),
newInspectCommand(dockerCli),
NewPruneCommand(dockerCli),
newPruneCommand(dockerCli),
)
return cmd
}

View File

@ -20,7 +20,14 @@ const (
)
// NewHistoryFormat returns a format for rendering an HistoryContext
//
// Deprecated: this function was only used internally and will be removed in the next release.
func NewHistoryFormat(source string, quiet bool, human bool) formatter.Format {
return newHistoryFormat(source, quiet, human)
}
// newHistoryFormat returns a format for rendering a historyContext.
func newHistoryFormat(source string, quiet bool, human bool) formatter.Format {
if source == formatter.TableFormatKey {
switch {
case quiet:
@ -36,10 +43,17 @@ func NewHistoryFormat(source string, quiet bool, human bool) formatter.Format {
}
// HistoryWrite writes the context
func HistoryWrite(ctx formatter.Context, human bool, histories []image.HistoryResponseItem) error {
//
// Deprecated: this function was only used internally and will be removed in the next release.
func HistoryWrite(fmtCtx formatter.Context, human bool, histories []image.HistoryResponseItem) error {
return historyWrite(fmtCtx, human, histories)
}
// historyWrite writes the context
func historyWrite(fmtCtx formatter.Context, human bool, histories []image.HistoryResponseItem) error {
render := func(format func(subContext formatter.SubContext) error) error {
for _, history := range histories {
historyCtx := &historyContext{trunc: ctx.Trunc, h: history, human: human}
historyCtx := &historyContext{trunc: fmtCtx.Trunc, h: history, human: human}
if err := format(historyCtx); err != nil {
return err
}
@ -55,7 +69,7 @@ func HistoryWrite(ctx formatter.Context, human bool, histories []image.HistoryRe
"Size": formatter.SizeHeader,
"Comment": commentHeader,
}
return ctx.Write(historyCtx, render)
return fmtCtx.Write(historyCtx, render)
}
type historyContext struct {

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