Compare commits

..

94 Commits

Author SHA1 Message Date
f480fb1e37 Merge pull request #4202 from thaJeztah/23.0_backport_docs_daemon_proxy_config
Some checks failed
build / prepare (push) Has been cancelled
build / build (push) Has been cancelled
build / prepare-plugins (push) Has been cancelled
build / plugins (push) Has been cancelled
e2e / e2e (19.03-dind, non-experimental) (push) Has been cancelled
e2e / e2e (alpine, stable-dind, connhelper-ssh) (push) Has been cancelled
e2e / e2e (alpine, stable-dind, experimental) (push) Has been cancelled
e2e / e2e (alpine, stable-dind, non-experimental) (push) Has been cancelled
e2e / e2e (bullseye, stable-dind, connhelper-ssh) (push) Has been cancelled
e2e / e2e (bullseye, stable-dind, experimental) (push) Has been cancelled
e2e / e2e (bullseye, stable-dind, non-experimental) (push) Has been cancelled
test / ctn (push) Has been cancelled
test / host (macos-11) (push) Has been cancelled
validate / validate (lint) (push) Has been cancelled
validate / validate (shellcheck) (push) Has been cancelled
validate / validate (update-authors) (push) Has been cancelled
validate / validate (validate-vendor) (push) Has been cancelled
validate / validate-make (manpages) (push) Has been cancelled
validate / validate-make (yamldocs) (push) Has been cancelled
[23.0 backport] docs/reference: update dockerd docs for changes in 23.0
2023-04-13 21:58:12 +02:00
ad7ae5a894 Merge pull request #4196 from thaJeztah/23.0_backport_registry_fix_ResolveAuthConfig_docs
[23.0 backport] cli/command: fix documentation for ResolveAuthConfig
2023-04-13 14:20:31 +02:00
b6cd3c85b5 docs: update dockerd usage output for new proxy-options
Adds documentation for the options that were added in
427c7cc5f8

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit c846428cb6)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-13 13:59:39 +02:00
aa85421ff8 docs/reference: dockerd: remove default oom-score-adjust
The daemon no longer adjusts its oom-score by default; see

- 2b8e68ef06
- cf7a5be0f2

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit c730a8eb95)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-13 13:59:39 +02:00
6bc4bf4f05 docs/reference: dockerd: update seccomp flag description
Update the description for the changes made in;
68e96f88ee

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit c209743612)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-13 13:59:38 +02:00
8a35f92fff docs/reference: dockerd: use table for env-vars
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 32bc912008)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-13 13:59:38 +02:00
2cb152c41d docs/reference: use table for proxy env-vars
Adding a description based on the Go documentation.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 3701748000)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-13 13:59:38 +02:00
623da1997e docs/reference: reformat env-vars table, and simplify
No need to mention that the env-var may be removed at that point to keep
the description more to-the-point.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 879e0804a4)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-13 13:59:38 +02:00
e76242fff2 docs/reference: remove mention of DOCKER_NOWARN_KERNEL_VERSION
Support for this environment variable was removed in docker 23.0 in
1240f8b41d

From that patch:

> All regular, non-EOL Linux distros now come with more recent kernels
> out of the box. There may still be users trying to run on kernel 3.10
> or older (some embedded systems, e.g.), but those should be a rare
> exception, which we don't have to take into account.
>
> This patch removes the kernel version check on Linux, and the corresponding
> DOCKER_NOWARN_KERNEL_VERSION environment that was there to skip this
> check.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 4a863df57a)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-13 13:59:38 +02:00
0b3f54066c Merge pull request #4195 from thaJeztah/23.0_backport_fix_deprecation_version
[23.0 backport] docs: deprecated: fix version (23.1.0 -> 24.0.0)
2023-04-12 12:42:21 +02:00
4b4d7e2b48 cli/command: fix documentation for ResolveAuthConfig
This function no longer uses the /info endpoint to resolve the registry
to use. The documentation for this function was still referring to
the (once used) special registry for Windows images, which is no longer
in use, so update the docs to reflect reality :)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 5bd359132b)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-12 12:39:06 +02:00
e67e5559d5 docs: deprecated: fix version (23.1.0 -> 24.0.0)
The next release will be "v24.0.0", not "v23.1.0"

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 04df700257)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-12 12:12:46 +02:00
8b783cc22a Merge pull request #4172 from thaJeztah/23.0_backport_fix_mddocs
[23.0 backport] scripts/docs/generate-md.sh: fix location of generate code
2023-04-11 18:11:30 +02:00
9d4a21cd79 Merge pull request #4175 from thaJeztah/23.0_backport_ci_split_build
[23.0 backport] ci: enhanced build workflow
2023-04-11 18:11:13 +02:00
d45284a65d Merge pull request #4176 from thaJeztah/23.0_backport_fix_docs_grammar
[23.0 backport] Fix grammar in docs by adding omitted word
2023-04-11 18:10:53 +02:00
fe7eb06263 Merge pull request #4182 from thaJeztah/23.0_backport_no_2206
[23.0 backport] docs: update engine versions in some examples
2023-04-11 18:10:15 +02:00
7192601845 Merge pull request #4178 from thaJeztah/23.0_engine_23.0.3
[23.0] vendor: github.com/docker/docker v23.0.3
2023-04-11 18:09:56 +02:00
726dfe92ec Merge pull request #4177 from thaJeztah/23.0_backport_fix_bash_file_completion
[23.0 backport] Fix plugin completion parsing for plugins using `ShellCompDirectiveFilterFileExt`
2023-04-11 09:29:11 +02:00
a8e3b4b852 docs: update engine versions in some examples
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 5d33b72769)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-10 16:51:44 +02:00
f88c159c7a [23.0] vendor: github.com/docker/docker v23.0.3
full diff: https://github.com/docker/docker/compare/v23.0.2...v23.0.3

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-10 00:15:57 +02:00
6c052fcda3 vendor: github.com/docker/docker v23.0.2
- migrate away from things deprecated in Go 1.20 (removes use of archive/tar.TypeRegA)

full diff: https://github.com/docker/docker/compare/v23.0.1...v23.0.2

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit a39958846d)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-10 00:13:48 +02:00
079e80889d vendor: golang.org/x/net v0.7.0
full diff: https://github.com/golang/net/compare/v0.5.0...v0.7.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit d213548bd0)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-10 00:11:54 +02:00
ff448ff455 vendor: golang.org/x/term v0.5.0
full diff: https://github.com/golang/term/compare/v0.4.0...v0.5.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 3a0d492d1c)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-10 00:11:44 +02:00
476933b68b vendor: golang.org/x/time v0.3.0
full diff: https://github.com/golang/time/compare/v0.1.0...v0.3.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit f40bbf4f7f)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-10 00:11:32 +02:00
6131fe9e45 vendor: golang.org/x/text v0.7.0
full diff: https://github.com/golang/text/compare/v0.6.0...v0.7.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit a85537d346)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-10 00:10:13 +02:00
bbc791ed7d vendor: golang.org/x/sys v0.5.0
full diff: https://github.com/golang/sys/compare/v0.4.0...v0.5.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 3e9c6e84ce)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-10 00:09:44 +02:00
dd6f77bbaa vendor: github.com/moby/swarmkit/v2 v2.0.0-20230309194213-a745a8755ce3
full diff: 904c221ac2...a745a8755c

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit ca8783ef43)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-10 00:05:28 +02:00
cb338ec972 vendor: github.com/containerd/containerd v1.6.19
full diff: https://github.com/containerd/containerd/compare/v1.6.16...v1.6.19

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 33806760a4)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-10 00:04:54 +02:00
ffafb38e30 vendor: github.com/docker/docker v23.0.1
full diff: https://github.com/docker/docker/compare/v23.0.0...v23.0.1

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 71e495aa54)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-10 00:04:45 +02:00
a763e51147 Fix plugin completion parsing for plugins using ShellCompDirectiveFilterFileExt
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
(cherry picked from commit 683e4bf0c4)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-09 23:56:30 +02:00
3c7de64541 Fix grammar in docs by adding omitted word
Edited second paragraph under ### Daemon configuration file to change "regardless their value" to "regardless of their value"

Signed-off-by: Jake Stokes <contactjake@developerjake.com>
(cherry picked from commit 9335690a66)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-09 23:54:00 +02:00
3d0d576af7 ci: enhanced build workflow
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
(cherry picked from commit bebdb6fa2a)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-09 23:51:34 +02:00
2609bd23ff docs: regenerate markdown docs
This adds the new aliases that were added in 9b54d860cd

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 08a794dc0c)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-09 23:00:16 +02:00
5fd2c08502 scripts/docs/generate-md.sh: fix location of generate code
Commit 1e3622c50c moved the generator code
to a subdirectory, but forgot to update the markdown version of this script.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 37f234fbe7)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-09 23:00:14 +02:00
24d608d5f1 Merge pull request #4164 from thaJeztah/23.0_bump_go1.19.8
[23.0] update go to go1.19.8
2023-04-06 12:55:03 +02:00
06ab5992dc Merge pull request #4154 from thaJeztah/23.0_backport_fix_deprecation_message
[23.0 backport] cli/command: fix deprecation comments for Stream types
2023-04-05 17:01:59 +02:00
5cd7710a04 update go to go1.19.8
go1.19.8 (released 2023-04-04) includes security fixes to the go/parser,
html/template, mime/multipart, net/http, and net/textproto packages, as well as
bug fixes to the linker, the runtime, and the time package. See the Go 1.19.8
milestone on our issue tracker for details:

https://github.com/golang/go/issues?q=milestone%3AGo1.19.8+label%3ACherryPickApproved

full diff: https://github.com/golang/go/compare/go1.19.7...go1.19.8

Further details from the announcement on the mailing list:

We have just released Go versions 1.20.3 and 1.19.8, minor point releases.
These minor releases include 4 security fixes following the security policy:

- go/parser: infinite loop in parsing

  Calling any of the Parse functions on Go source code which contains `//line`
  directives with very large line numbers can cause an infinite loop due to
  integer overflow.
  Thanks to Philippe Antoine (Catena cyber) for reporting this issue.
  This is CVE-2023-24537 and Go issue https://go.dev/issue/59180.

- html/template: backticks not treated as string delimiters

  Templates did not properly consider backticks (`) as Javascript string
  delimiters, and as such did not escape them as expected. Backticks are
  used, since ES6, for JS template literals. If a template contained a Go
  template action within a Javascript template literal, the contents of the
  action could be used to terminate the literal, injecting arbitrary Javascript
  code into the Go template.

  As ES6 template literals are rather complex, and themselves can do string
  interpolation, we've decided to simply disallow Go template actions from being
  used inside of them (e.g. "var a = {{.}}"), since there is no obviously safe
  way to allow this behavior. This takes the same approach as
  github.com/google/safehtml. Template.Parse will now return an Error when it
  encounters templates like this, with a currently unexported ErrorCode with a
  value of 12. This ErrorCode will be exported in the next major release.

  Users who rely on this behavior can re-enable it using the GODEBUG flag
  jstmpllitinterp=1, with the caveat that backticks will now be escaped. This
  should be used with caution.

  Thanks to Sohom Datta, Manipal Institute of Technology, for reporting this issue.

  This is CVE-2023-24538 and Go issue https://go.dev/issue/59234.

- net/http, net/textproto: denial of service from excessive memory allocation

  HTTP and MIME header parsing could allocate large amounts of memory, even when
  parsing small inputs.

  Certain unusual patterns of input data could cause the common function used to
  parse HTTP and MIME headers to allocate substantially more memory than
  required to hold the parsed headers. An attacker can exploit this behavior to
  cause an HTTP server to allocate large amounts of memory from a small request,
  potentially leading to memory exhaustion and a denial of service.
  Header parsing now correctly allocates only the memory required to hold parsed
  headers.

  Thanks to Jakob Ackermann (@das7pad) for discovering this issue.

  This is CVE-2023-24534 and Go issue https://go.dev/issue/58975.

- net/http, net/textproto, mime/multipart: denial of service from excessive resource consumption

  Multipart form parsing can consume large amounts of CPU and memory when
  processing form inputs containing very large numbers of parts. This stems from
  several causes:

  mime/multipart.Reader.ReadForm limits the total memory a parsed multipart form
  can consume. ReadForm could undercount the amount of memory consumed, leading
  it to accept larger inputs than intended. Limiting total memory does not
  account for increased pressure on the garbage collector from large numbers of
  small allocations in forms with many parts. ReadForm could allocate a large
  number of short-lived buffers, further increasing pressure on the garbage
  collector. The combination of these factors can permit an attacker to cause an
  program that parses multipart forms to consume large amounts of CPU and
  memory, potentially resulting in a denial of service. This affects programs
  that use mime/multipart.Reader.ReadForm, as well as form parsing in the
  net/http package with the Request methods FormFile, FormValue,
  ParseMultipartForm, and PostFormValue.

  ReadForm now does a better job of estimating the memory consumption of parsed
  forms, and performs many fewer short-lived allocations.

  In addition, mime/multipart.Reader now imposes the following limits on the
  size of parsed forms:

  Forms parsed with ReadForm may contain no more than 1000 parts. This limit may
  be adjusted with the environment variable GODEBUG=multipartmaxparts=. Form
  parts parsed with NextPart and NextRawPart may contain no more than 10,000
  header fields. In addition, forms parsed with ReadForm may contain no more
  than 10,000 header fields across all parts. This limit may be adjusted with
  the environment variable GODEBUG=multipartmaxheaders=.

  Thanks to Jakob Ackermann for discovering this issue.

  This is CVE-2023-24536 and Go issue https://go.dev/issue/59153.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-05 15:49:47 +02:00
683b099613 Merge pull request #4157 from cpuguy83/23.0_improve_cp_progress
[23.0 backport] improve cp progress
2023-04-05 02:33:53 +02:00
391b2f0fab Merge pull request #4141 from crazy-max/23.0_backport_fix-perf-reg
[23.0 backport] improve and load plugin command stubs when required
2023-04-05 02:33:19 +02:00
209e9c0c13 cp: Do not block transfer on writing to terminal
This moves all the terminal writing to a goroutine that updates the
terminal periodically.
In our MITM copier we just use an atomic to add to the total number of
bytes read/written, the goroutine reads the total and updates the
terminal as needed.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit eb392ff4ce)
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2023-04-03 22:31:41 +00:00
ce68ce7ae8 cp: Make gocyclo happy
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit b9a1b0928a)
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2023-04-03 22:31:34 +00:00
c28cb35c42 cp: Reduce number of progress updates
Only show progress updates after a time threshold has elapsed in order
to reduce the number of writes to the terminal.
This improves readability of the progress.

Also moves cursor show/hide into the progress printer to reduce chances
if messing up the user's terminal in case of cancellation.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit 90b7bc36d4)
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2023-04-03 22:31:23 +00:00
948dfa91c9 cp: reduce branching in progress printer
This just makes it easier to reason about what is happening.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit efd011b793)
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2023-04-03 22:31:13 +00:00
f813c9639f cp: Improve tty flashing on progress updates
- Instead of rewriting the entire line every time only clear and write
the parts that changed.
- Hide the cursor while writing progress

Both these things make the progress updates significantly easier to
read.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit ccae6e9299)
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2023-04-03 22:31:06 +00:00
97d91f13aa cp: do not emit progress if stderr is not a term
This fixes a case where a non-tty will have control characters + the log
line for every single read operation.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit f27927d934)
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2023-04-03 22:30:56 +00:00
6efc4eaccb cli/command: fix deprecation comments for Stream types
These were deprecated in 6c400a9c2009bba9376ad61ab59c04c1ad675871 (docker 19.03),
but the "Deprecated:" comments were missing a newline before them.

While most IDEs will detect such comments as "deprecated", pkg.go.dev and linters
will ignore them, which may result in users not being aware of them being deprecated.

This patch;

- Fixes the "Deprecated:" comments.
- Changes the var aliases to functions, which is slightly more boilerplating,
  but makes sure the functions are documented as "function", instead of shown
  in the "variables" section on pkg.go.dev.
- Adds some punctuation and adds "doc links", which allows readers to navigate
  to related content on pkg.go.dev.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 817897f891)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-04-01 20:38:27 +02:00
c7cdab58d2 improve plugins listing performance
We can slightly improve plugins listing by spawning a
goroutine for each iteration.

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
(cherry picked from commit 89583b92b7)

# Conflicts:
#	vendor.mod
#	vendor/modules.txt
2023-04-01 16:34:51 +02:00
d93d78588d load plugin command stubs when required
We are currently loading plugin command stubs for every
invocation which still has a significant performance hit.
With this change we are doing this operation only if cobra
completion arg request is found.

- 20.10.23: `docker --version` takes ~15ms
- 23.0.1: `docker --version` takes ~93ms

With this change `docker --version` takes ~9ms

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
(cherry picked from commit c39c711a18)
2023-03-31 16:38:01 +02:00
3e7cbfdee1 Merge pull request #4139 from thaJeztah/23.0_backport_fix_go_version
Some checks failed
build / build (cross, ) (push) Has been cancelled
build / build (cross, glibc) (push) Has been cancelled
build / build (dynbinary-cross, ) (push) Has been cancelled
build / build (dynbinary-cross, glibc) (push) Has been cancelled
build / plugins (push) Has been cancelled
e2e / e2e (19.03-dind, non-experimental) (push) Has been cancelled
e2e / e2e (alpine, stable-dind, connhelper-ssh) (push) Has been cancelled
e2e / e2e (alpine, stable-dind, experimental) (push) Has been cancelled
e2e / e2e (alpine, stable-dind, non-experimental) (push) Has been cancelled
e2e / e2e (bullseye, stable-dind, connhelper-ssh) (push) Has been cancelled
e2e / e2e (bullseye, stable-dind, experimental) (push) Has been cancelled
e2e / e2e (bullseye, stable-dind, non-experimental) (push) Has been cancelled
test / ctn (push) Has been cancelled
test / host (macos-11) (push) Has been cancelled
validate / validate (lint) (push) Has been cancelled
validate / validate (shellcheck) (push) Has been cancelled
validate / validate (update-authors) (push) Has been cancelled
validate / validate (validate-vendor) (push) Has been cancelled
validate / validate-make (manpages) (push) Has been cancelled
validate / validate-make (yamldocs) (push) Has been cancelled
[23.0 backport] gha: align stray go 1.19.4 version
2023-03-31 16:06:26 +02:00
8e38271f23 gha: align stray go 1.19.4 version
looks like this one was forgotten to be updated :)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit e4436853e8)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-30 16:56:58 +02:00
569dd73db1 Merge pull request #4126 from thaJeztah/23.0_backport_align_go_ver
Some checks failed
build / build (cross, ) (push) Has been cancelled
build / build (cross, glibc) (push) Has been cancelled
build / build (dynbinary-cross, ) (push) Has been cancelled
build / build (dynbinary-cross, glibc) (push) Has been cancelled
build / plugins (push) Has been cancelled
e2e / e2e (19.03-dind, non-experimental) (push) Has been cancelled
e2e / e2e (alpine, stable-dind, connhelper-ssh) (push) Has been cancelled
e2e / e2e (alpine, stable-dind, experimental) (push) Has been cancelled
e2e / e2e (alpine, stable-dind, non-experimental) (push) Has been cancelled
e2e / e2e (bullseye, stable-dind, connhelper-ssh) (push) Has been cancelled
e2e / e2e (bullseye, stable-dind, experimental) (push) Has been cancelled
e2e / e2e (bullseye, stable-dind, non-experimental) (push) Has been cancelled
test / ctn (push) Has been cancelled
test / host (macos-11) (push) Has been cancelled
validate / validate (lint) (push) Has been cancelled
validate / validate (shellcheck) (push) Has been cancelled
validate / validate (update-authors) (push) Has been cancelled
validate / validate (validate-vendor) (push) Has been cancelled
validate / validate-make (manpages) (push) Has been cancelled
validate / validate-make (yamldocs) (push) Has been cancelled
[23.0 backport] Dockerfile: align go version
2023-03-27 17:44:26 +02:00
f6643207a2 don't use null values in the bake definition
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
(cherry picked from commit bec5d37e91)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-27 17:18:38 +02:00
f381e08425 Dockerfile: align go version
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
(cherry picked from commit b854eff300)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-27 17:18:35 +02:00
18f20a5537 Merge pull request #4124 from thaJeztah/23.0_e2e_fix_certs
[23.0 backport] e2e: update notary certificates
2023-03-27 17:18:13 +02:00
d3a36fc38c e2e: update notary certificates
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
(cherry picked from commit b201ce5efd)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-27 15:26:23 +02:00
59bb07f2e4 e2e: increase tests certificates duration (10 years)
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
(cherry picked from commit c6c33380da)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-27 15:26:22 +02:00
80f27987f4 bake target to generate certs for e2e tets
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
(cherry picked from commit d234a81de7)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-27 15:26:20 +02:00
6a8406e602 Merge pull request #4092 from crazy-max/23.0_backport_buildx-completion
[23.0 backport] Add bash completion for available plugins
2023-03-22 20:05:09 +01:00
c2c122fb65 Merge pull request #4107 from thaJeztah/23.0_backport_size_flag_ps
[23.0 backport] Don't automatically request size if `--size` was explicitly set to `false`
2023-03-21 17:54:09 +01:00
40a48e4154 Merge pull request #4106 from thaJeztah/23.0_backport_fix_comments
[23.0 backport] cli/command: ElectAuthServer: fix deprecation comment
2023-03-21 17:52:39 +01:00
a43c9f3440 Don't automatically request size if --size was explicitly set to false
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
(cherry picked from commit 9733334487)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-21 17:02:35 +01:00
114e17ac4b cli/command: fix imports formatting
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 742881fc58)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-21 16:58:47 +01:00
e2c402118c cli/command: ElectAuthServer: fix deprecation comment
The comment was not formatted correctly, and because of that not picked up as
being deprecated.

updates b4ca1c7368

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit e3fa7280ad)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-21 16:58:47 +01:00
d07453890c Add bash completion for available plugins
Signed-off-by: CrazyMax <github@crazymax.dev>
(cherry picked from commit aa0aa4a6dc)
2023-03-17 15:06:45 +01:00
288b6c79fe Merge pull request #4083 from thaJeztah/23.0_backport_windows_drive_cwd_env
[23.0 backport] stack/loader: Ignore cmd.exe special env variables
2023-03-10 13:04:29 +01:00
fbab8cd2be Merge pull request #4086 from thaJeztah/23.0_backport_bump_go1.19.7
[23.0 backport] update to go1.19.7
2023-03-10 13:04:03 +01:00
b898a46135 Merge pull request #4088 from thaJeztah/23.0_backport_update_buildx
[23.0 backport] Dockerfile: update buildx to v0.10.4
2023-03-10 12:54:16 +01:00
90a72a5894 Dockerfile: update buildx to v0.10.4
release notes: https://github.com/docker/buildx/releases/tag/v0.10.4

full diff: https://github.com/docker/buildx/compare/v0.10.3...v0.10.4

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 74c4ed4171)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-10 12:33:03 +01:00
4c63110a92 update to go1.19.7
Includes a security fix for crypto/elliptic (CVE-2023-24532).

> go1.19.7 (released 2023-03-07) includes a security fix to the crypto/elliptic
> package, as well as bug fixes to the linker, the runtime, and the crypto/x509
> and syscall packages. See the Go 1.19.7 milestone on our issue tracker for
> details.

https://go.dev/doc/devel/release#go1.19.minor

From the announcement:

> We have just released Go versions 1.20.2 and 1.19.7, minor point releases.
>
> These minor releases include 1 security fixes following the security policy:
>
> - crypto/elliptic: incorrect P-256 ScalarMult and ScalarBaseMult results
    >
    >   The ScalarMult and ScalarBaseMult methods of the P256 Curve may return an
    >   incorrect result if called with some specific unreduced scalars (a scalar larger
    >   than the order of the curve).
    >
    >   This does not impact usages of crypto/ecdsa or crypto/ecdh.
>
> This is CVE-2023-24532 and Go issue https://go.dev/issue/58647.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 23da1cec6c)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-10 10:24:22 +01:00
b61b5a9878 stack: Change unexpected environment variable error
Make the error more specific by stating that it's caused by a specific
environment variable and not an environment as a whole.
Also don't escape the variable to make it more readable.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
(cherry picked from commit 012b77952e)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-09 22:13:20 +01:00
84fe451ec7 stack/loader: Ignore cmd.exe special env variables
On Windows, ignore all variables that start with "=" when building an
environment variables map for stack.
For MS-DOS compatibility cmd.exe can set some special environment
variables that start with a "=" characters, which breaks the general
assumption that the first encountered "=" separates a variable name from
variable value and causes trouble when parsing.

These variables don't seem to be documented anywhere, but they are
described by some third-party sources and confirmed empirically on my
Windows installation.

Useful sources:
https://devblogs.microsoft.com/oldnewthing/20100506-00/?p=14133
https://ss64.com/nt/syntax-variables.html

Known variables:

- `=ExitCode` stores the exit code returned by external command (in hex
  format)
- `=ExitCodeAscii` - same as above, except the value is the ASCII
  representation of the code (so exit code 65 (0x41) becomes 'A').
- `=::=::\` and friends - store drive specific working directory.
  There is one env variable for each separate drive letter that was
  accessed in the shell session and stores the working directory for that
  specific drive.
  The general format for these is:
    `=<DRIVE_LETTER>:=<CWD>`  (key=`=<DRIVE_LETTER>:`, value=`<CWD>`)
  where <CWD> is a working directory for the drive that is assigned to
  the letter <DRIVE_LETTER>

  A couple of examples:
    `=C:=C:\some\dir`  (key: `=C:`, value: `C:\some\dir`)
    `=D:=D:\some\other\dir`  (key: `=C:`, value: `C:\some\dir`)
    `=Z:=Z:\`  (key: `=Z:`, value: `Z:\`)

  `=::=::\` is the one that seems to be always set and I'm not exactly
  sure what this one is for (what's drive `::`?). Others are set as
  soon as you CD to a path on some drive. Considering that you start a
  cmd.exe also has some working directory, there are 2 of these on start.

All these variables can be safely ignored because they can't be
deliberately set by the user, their meaning is only relevant to the
cmd.exe session and they're all are related to the MS-DOS/Batch feature
that are irrelevant for us.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
(cherry picked from commit a47058bbd5)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-09 22:13:18 +01:00
71615c2df1 Merge pull request #4077 from thaJeztah/23.0_update_buildx
[23.0 backport] Dockerfile: update buildx to v0.10.3
2023-03-09 12:08:43 +01:00
a1acc9af91 Merge pull request #4076 from thaJeztah/23.0_backport_deprecate_buildinfo
[23.0 backport] docs: Deprecate buildkit's build information
2023-03-06 20:06:22 +01:00
95066ff3a2 Dockerfile: update buildx to v0.10.3
release notes: https://github.com/docker/buildx/releases/tag/v0.10.3

Signed-off-by: Jacopo Rigoli <rigoli.jacopo@gmail.com>
(cherry picked from commit dac79b19a7)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-06 18:28:30 +01:00
0dbf70fad2 docs: Deprecate buildkit's build information
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
(cherry picked from commit 8bc1aaceae)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-06 18:25:03 +01:00
e0b8e19687 Merge pull request #4035 from thaJeztah/23.0_backport_carry_4027
[23.0 backport] changed the container name in docker stats page
2023-03-03 16:47:47 +01:00
98e874dac7 Merge pull request #4039 from thaJeztah/23.0_backport_bump_go_1.19.6
[23.0 backport] update to go1.19.6
2023-03-02 14:34:36 +01:00
92164b0306 Merge pull request #4065 from vvoland/dangling-images-none-23
[23.0 backport] formatter: Consider empty RepoTags and RepoDigests as dangling
2023-03-02 14:31:31 +01:00
5af8077eeb formatter: Consider empty RepoTags and RepoDigests as dangling
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
(cherry picked from commit 89687d5b3f)
2023-03-02 09:48:45 +01:00
d352c504a8 Merge pull request #4061 from vvoland/test-fakecli-images-mock-23
[23.0 backport] test/cli: Use empty array as empty output of images/json
2023-03-01 21:03:06 +01:00
28c74b759b Merge pull request #4063 from thaJeztah/23.0_backport_write_file
[23.0 backport] context: avoid corrupt file writes
2023-03-01 21:02:40 +01:00
57a502772b context: avoid corrupt file writes
Write to a tempfile then move, so that if the
process dies mid-write it doesn't corrupt the store.

Also improve error messaging so that if a file does
get corrupted, the user has some hope of figuring
out which file is broken.

For background, see:
https://github.com/docker/for-win/issues/13180
https://github.com/docker/for-win/issues/12561

For a repro case, see:
https://github.com/nicks/contextstore-sandbox

Signed-off-by: Nick Santos <nick.santos@docker.com>
(cherry picked from commit c2487c2997)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-01 16:14:03 +01:00
14ac8db968 test/cli: Use empty array as empty output of images/json
Tests mocking the output of GET images/json with fakeClient used an
array with one empty element as an empty response.
Change it to just an empty array.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
(cherry picked from commit a1953e19b2)
2023-03-01 15:59:31 +01:00
1ab7665be8 Merge pull request #4047 from neersighted/backport/4019/23.0
[23.0 backport] docs: drop dated comments about graphdrivers
2023-02-23 18:41:54 +01:00
1810e922ac docs: drop dated comments about graphdrivers
Signed-off-by: Bjorn Neergaard <bneergaard@mirantis.com>
(cherry picked from commit e636747a14)
Signed-off-by: Bjorn Neergaard <bneergaard@mirantis.com>
2023-02-23 09:28:27 -07:00
5051d82a17 update to go1.19.6
go1.19.6 (released 2023-02-14) includes security fixes to the crypto/tls,
mime/multipart, net/http, and path/filepath packages, as well as bug fixes to
the go command, the linker, the runtime, and the crypto/x509, net/http, and
time packages. See the Go 1.19.6 milestone on our issue tracker for details:

https://github.com/golang/go/issues?q=milestone%3AGo1.19.6+label%3ACherryPickApproved

From the announcement on the security mailing:

We have just released Go versions 1.20.1 and 1.19.6, minor point releases.

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

- path/filepath: path traversal in filepath.Clean on Windows

  On Windows, the filepath.Clean function could transform an invalid path such
  as a/../c:/b into the valid path c:\b. This transformation of a relative (if
  invalid) path into an absolute path could enable a directory traversal attack.
  The filepath.Clean function will now transform this path into the relative
  (but still invalid) path .\c:\b.

  This is CVE-2022-41722 and Go issue https://go.dev/issue/57274.

- net/http, mime/multipart: denial of service from excessive resource
  consumption

  Multipart form parsing with mime/multipart.Reader.ReadForm can consume largely
  unlimited amounts of memory and disk files. This also affects form parsing in
  the net/http package with the Request methods FormFile, FormValue,
  ParseMultipartForm, and PostFormValue.

  ReadForm takes a maxMemory parameter, and is documented as storing "up to
  maxMemory bytes +10MB (reserved for non-file parts) in memory". File parts
  which cannot be stored in memory are stored on disk in temporary files. The
  unconfigurable 10MB reserved for non-file parts is excessively large and can
  potentially open a denial of service vector on its own. However, ReadForm did
  not properly account for all memory consumed by a parsed form, such as map
  ntry overhead, part names, and MIME headers, permitting a maliciously crafted
  form to consume well over 10MB. In addition, ReadForm contained no limit on
  the number of disk files created, permitting a relatively small request body
  to create a large number of disk temporary files.

  ReadForm now properly accounts for various forms of memory overhead, and
  should now stay within its documented limit of 10MB + maxMemory bytes of
  memory consumption. Users should still be aware that this limit is high and
  may still be hazardous.

  ReadForm now creates at most one on-disk temporary file, combining multiple
  form parts into a single temporary file. The mime/multipart.File interface
  type's documentation states, "If stored on disk, the File's underlying
  concrete type will be an *os.File.". This is no longer the case when a form
  contains more than one file part, due to this coalescing of parts into a
  single file. The previous behavior of using distinct files for each form part
  may be reenabled with the environment variable
  GODEBUG=multipartfiles=distinct.

  Users should be aware that multipart.ReadForm and the http.Request methods
  that call it do not limit the amount of disk consumed by temporary files.
  Callers can limit the size of form data with http.MaxBytesReader.

  This is CVE-2022-41725 and Go issue https://go.dev/issue/58006.

- crypto/tls: large handshake records may cause panics

  Both clients and servers may send large TLS handshake records which cause
  servers and clients, respectively, to panic when attempting to construct
  responses.

  This affects all TLS 1.3 clients, TLS 1.2 clients which explicitly enable
  session resumption (by setting Config.ClientSessionCache to a non-nil value),
  and TLS 1.3 servers which request client certificates (by setting
  Config.ClientAuth
  > = RequestClientCert).

  This is CVE-2022-41724 and Go issue https://go.dev/issue/58001.

- net/http: avoid quadratic complexity in HPACK decoding

  A maliciously crafted HTTP/2 stream could cause excessive CPU consumption
  in the HPACK decoder, sufficient to cause a denial of service from a small
  number of small requests.

  This issue is also fixed in golang.org/x/net/http2 v0.7.0, for users manually
  configuring HTTP/2.

  This is CVE-2022-41723 and Go issue https://go.dev/issue/57855.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit e921e103a4)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-02-17 01:11:03 +01:00
7f4e3ead75 changed the container name in docker stats page
Signed-off-by: Aslam Ahemad <aslamahemad@gmail.com>
(cherry picked from commit d2f726d5ad)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-02-15 11:53:36 +01:00
a5ee5b1dfc Merge pull request #4018 from thaJeztah/23.0_backport_fix_ci_events
Some checks failed
build / build (cross, ) (push) Has been cancelled
build / build (cross, glibc) (push) Has been cancelled
build / build (dynbinary-cross, ) (push) Has been cancelled
build / build (dynbinary-cross, glibc) (push) Has been cancelled
build / plugins (push) Has been cancelled
e2e / e2e (19.03-dind, non-experimental) (push) Has been cancelled
e2e / e2e (alpine, stable-dind, connhelper-ssh) (push) Has been cancelled
e2e / e2e (alpine, stable-dind, experimental) (push) Has been cancelled
e2e / e2e (alpine, stable-dind, non-experimental) (push) Has been cancelled
e2e / e2e (bullseye, stable-dind, connhelper-ssh) (push) Has been cancelled
e2e / e2e (bullseye, stable-dind, experimental) (push) Has been cancelled
e2e / e2e (bullseye, stable-dind, non-experimental) (push) Has been cancelled
test / ctn (push) Has been cancelled
test / host (macos-11) (push) Has been cancelled
validate / validate (lint) (push) Has been cancelled
validate / validate (shellcheck) (push) Has been cancelled
validate / validate (update-authors) (push) Has been cancelled
validate / validate (validate-vendor) (push) Has been cancelled
validate / validate-make (manpages) (push) Has been cancelled
validate / validate-make (yamldocs) (push) Has been cancelled
[23.0 backport] ci: fix branch filter pattern
2023-02-09 20:15:59 +01:00
27b19a6acf ci: fix branch filter pattern
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
(cherry picked from commit 0f39598687)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-02-09 19:55:03 +01:00
ab4ef4aed4 Merge pull request #4004 from thaJeztah/23.0_backports
[23.0 backports] assorted backports
2023-02-06 11:38:55 -08:00
14aac2c232 vendor: github.com/docker/docker v23.0.0
- client: improve error messaging on crash

full diff: https://github.com/docker/docker/compare/v23.0.0-rc.3...v23.0.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit bbebebaedf)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-02-06 14:47:36 +01:00
0cd15abfde vendor: github.com/containerd/containerd v1.6.16
no changes in vendored code

full diff: https://github.com/containerd/containerd/compare/v1.6.15...v1.6.16

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 5195db1ff5)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-02-06 14:47:36 +01:00
168f1b55e2 cli/command/container: exit 126 on EISDIR error
The error returned from "os/exec".Command when attempting to execute a
directory has been changed from syscall.EACCESS to syscall.EISDIR on
Go 1.20. 2b8f214094
Consequently, any runc runtime built against Go 1.20 will return an
error containing 'is a directory' and not 'permission denied'. Update
the string matching so the CLI exits with status code 126 on 'is a
directory' errors (EISDIR) in addition to 'permission denied' (EACCESS).

Signed-off-by: Cory Snider <csnider@mirantis.com>
(cherry picked from commit 9b5ceb52b0)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-02-06 14:47:36 +01:00
53ed25d9b6 Fix bad ThrottleDevice path
Fixes moby/moby#44904.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
(cherry picked from commit 56051b84b0)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-02-06 14:47:33 +01:00
526 changed files with 5051 additions and 8081 deletions

View File

@ -58,7 +58,7 @@ jobs:
uses: docker/setup-buildx-action@v2
-
name: Build
uses: docker/bake-action@v3
uses: docker/bake-action@v2
with:
targets: ${{ matrix.target }}
set: |
@ -121,7 +121,7 @@ jobs:
uses: docker/setup-buildx-action@v2
-
name: Build
uses: docker/bake-action@v3
uses: docker/bake-action@v2
with:
targets: plugins-cross
set: |

View File

@ -26,7 +26,7 @@ jobs:
uses: docker/setup-buildx-action@v2
-
name: Test
uses: docker/bake-action@v3
uses: docker/bake-action@v2
with:
targets: test-coverage
-
@ -61,9 +61,9 @@ jobs:
path: ${{ env.GOPATH }}/src/github.com/docker/cli
-
name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v3
with:
go-version: 1.20.5
go-version: 1.19.8
-
name: Test
run: |

View File

@ -29,33 +29,14 @@ jobs:
-
name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
-
name: Run
uses: docker/bake-action@v3
uses: docker/bake-action@v2
with:
targets: ${{ matrix.target }}
# check that the generated Markdown and the checked-in files match
validate-md:
runs-on: ubuntu-20.04
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Generate
shell: 'script --return --quiet --command "bash {0}"'
run: |
make -f docker.Makefile mddocs
-
name: Validate
run: |
if [[ $(git diff --stat) != '' ]]; then
echo 'fail: generated files do not match checked-in files'
git --no-pager diff
exit 1
fi
validate-make:
runs-on: ubuntu-20.04
strategy:
@ -68,6 +49,8 @@ jobs:
-
name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
-
name: Run
shell: 'script --return --quiet --command "bash {0}"'

View File

@ -1,12 +1,12 @@
# syntax=docker/dockerfile:1
ARG BASE_VARIANT=alpine
ARG GO_VERSION=1.20.5
ARG ALPINE_VERSION=3.17
ARG GO_VERSION=1.19.8
ARG ALPINE_VERSION=3.16
ARG XX_VERSION=1.1.1
ARG GOVERSIONINFO_VERSION=v1.3.0
ARG GOTESTSUM_VERSION=v1.10.0
ARG BUILDX_VERSION=0.11.0
ARG GOTESTSUM_VERSION=v1.8.2
ARG BUILDX_VERSION=0.10.4
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
@ -125,8 +125,8 @@ CMD ./scripts/test/e2e/entry
FROM build-base-${BASE_VARIANT} AS dev
COPY . .
FROM scratch AS plugins
COPY --from=build-plugins /out .
FROM scratch AS binary
COPY --from=build /out .
FROM scratch AS plugins
COPY --from=build-plugins /out .

View File

@ -49,9 +49,9 @@
people = [
"bsousaa",
"neersighted",
"programmerq",
"sam-thibault",
"thajeztah",
"vvoland"
]
@ -103,11 +103,6 @@
Email = "nicolas.deloof@gmail.com"
GitHub = "ndeloof"
[people.neersighted]
Name = "Bjorn Neergaard"
Email = "bneergaard@mirantis.com"
GitHub = "neersighted"
[people.programmerq]
Name = "Jeff Anderson"
Email = "jeff@docker.com"

View File

@ -1 +1 @@
24.0.0-dev
23.0.0-dev

View File

@ -23,7 +23,6 @@ type Metadata struct {
// URL is a pointer to the plugin's homepage.
URL string `json:",omitempty"`
// Experimental specifies whether the plugin is experimental.
//
// Deprecated: experimental features are now always enabled in the CLI
Experimental bool `json:",omitempty"`
}

View File

@ -426,7 +426,7 @@ func invalidPluginReason(cmd *cobra.Command) string {
return cmd.Annotations[pluginmanager.CommandAnnotationPluginInvalid]
}
const usageTemplate = `Usage:
var usageTemplate = `Usage:
{{- if not .HasSubCommands}} {{.UseLine}}{{end}}
{{- if .HasSubCommands}} {{ .CommandPath}}{{- if .HasAvailableFlags}} [OPTIONS]{{end}} COMMAND{{end}}
@ -525,5 +525,5 @@ Run '{{.CommandPath}} COMMAND --help' for more information on a command.
{{- end}}
`
const helpTemplate = `
var helpTemplate = `
{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`

View File

@ -14,21 +14,21 @@ type fakeClient struct {
checkpointListFunc func(container string, options types.CheckpointListOptions) ([]types.Checkpoint, error)
}
func (cli *fakeClient) CheckpointCreate(_ context.Context, container string, options types.CheckpointCreateOptions) error {
func (cli *fakeClient) CheckpointCreate(ctx context.Context, container string, options types.CheckpointCreateOptions) error {
if cli.checkpointCreateFunc != nil {
return cli.checkpointCreateFunc(container, options)
}
return nil
}
func (cli *fakeClient) CheckpointDelete(_ context.Context, container string, options types.CheckpointDeleteOptions) error {
func (cli *fakeClient) CheckpointDelete(ctx context.Context, container string, options types.CheckpointDeleteOptions) error {
if cli.checkpointDeleteFunc != nil {
return cli.checkpointDeleteFunc(container, options)
}
return nil
}
func (cli *fakeClient) CheckpointList(_ context.Context, container string, options types.CheckpointListOptions) ([]types.Checkpoint, error) {
func (cli *fakeClient) CheckpointList(ctx context.Context, container string, options types.CheckpointListOptions) ([]types.Checkpoint, error) {
if cli.checkpointListFunc != nil {
return cli.checkpointListFunc(container, options)
}

View File

@ -8,6 +8,7 @@ import (
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
"time"
@ -47,7 +48,9 @@ type Streams interface {
// Cli represents the docker command line client.
type Cli interface {
Client() client.APIClient
Streams
Out() *streams.Out
Err() io.Writer
In() *streams.In
SetIn(in *streams.In)
Apply(ops ...DockerCliOption) error
ConfigFile() *configfile.ConfigFile
@ -161,8 +164,8 @@ func (cli *DockerCli) ContentTrustEnabled() bool {
// BuildKitEnabled returns buildkit is enabled or not.
func (cli *DockerCli) BuildKitEnabled() (bool, error) {
// use DOCKER_BUILDKIT env var value if set and not empty
if v := os.Getenv("DOCKER_BUILDKIT"); v != "" {
// use DOCKER_BUILDKIT env var value if set
if v, ok := os.LookupEnv("DOCKER_BUILDKIT"); ok {
enabled, err := strconv.ParseBool(v)
if err != nil {
return false, errors.Wrap(err, "DOCKER_BUILDKIT environment variable expects boolean value")
@ -188,7 +191,7 @@ func (cli *DockerCli) ManifestStore() manifeststore.Store {
// RegistryClient returns a client for communicating with a Docker distribution
// registry
func (cli *DockerCli) RegistryClient(allowInsecure bool) registryclient.RegistryClient {
resolver := func(ctx context.Context, index *registry.IndexInfo) registry.AuthConfig {
resolver := func(ctx context.Context, index *registry.IndexInfo) types.AuthConfig {
return ResolveAuthConfig(ctx, cli, index)
}
return registryclient.NewRegistryClient(resolver, UserAgent(), allowInsecure)
@ -326,8 +329,13 @@ func (cli *DockerCli) getInitTimeout() time.Duration {
func (cli *DockerCli) initializeFromClient() {
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, cli.getInitTimeout())
defer cancel()
if !strings.HasPrefix(cli.dockerEndpoint.Host, "ssh://") {
// @FIXME context.WithTimeout doesn't work with connhelper / ssh connections
// time="2020-04-10T10:16:26Z" level=warning msg="commandConn.CloseWrite: commandconn: failed to wait: signal: killed"
var cancel func()
ctx, cancel = context.WithTimeout(ctx, cli.getInitTimeout())
defer cancel()
}
ping, err := cli.client.Ping(ctx)
if err != nil {
@ -375,7 +383,7 @@ func (cli *DockerCli) ContextStore() store.Store {
// the "default" context is used if:
//
// - The "--host" option is set
// - The "DOCKER_HOST" ([client.EnvOverrideHost]) environment variable is set
// - The "DOCKER_HOST" ([DefaultContextName]) environment variable is set
// to a non-empty value.
//
// In these cases, the default context is used, which uses the host as

View File

@ -6,7 +6,7 @@ import (
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/volume"
"github.com/docker/docker/api/types/filters"
"github.com/spf13/cobra"
)
@ -66,13 +66,13 @@ func ContainerNames(dockerCli command.Cli, all bool, filters ...func(types.Conta
// VolumeNames offers completion for volumes
func VolumeNames(dockerCli command.Cli) ValidArgsFn {
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
list, err := dockerCli.Client().VolumeList(cmd.Context(), volume.ListOptions{})
list, err := dockerCli.Client().VolumeList(cmd.Context(), filters.Args{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
for _, vol := range list.Volumes {
names = append(names, vol.Name)
for _, volume := range list.Volumes {
names = append(names, volume.Name)
}
return names, cobra.ShellCompDirectiveNoFileComp
}
@ -94,6 +94,6 @@ func NetworkNames(dockerCli command.Cli) ValidArgsFn {
}
// NoComplete is used for commands where there's no relevant completion
func NoComplete(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
func NoComplete(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return nil, cobra.ShellCompDirectiveNoFileComp
}

View File

@ -10,34 +10,34 @@ import (
type fakeClient struct {
client.Client
configCreateFunc func(context.Context, swarm.ConfigSpec) (types.ConfigCreateResponse, error)
configInspectFunc func(context.Context, string) (swarm.Config, []byte, error)
configListFunc func(context.Context, types.ConfigListOptions) ([]swarm.Config, error)
configCreateFunc func(swarm.ConfigSpec) (types.ConfigCreateResponse, error)
configInspectFunc func(string) (swarm.Config, []byte, error)
configListFunc func(types.ConfigListOptions) ([]swarm.Config, error)
configRemoveFunc func(string) error
}
func (c *fakeClient) ConfigCreate(ctx context.Context, spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) {
if c.configCreateFunc != nil {
return c.configCreateFunc(ctx, spec)
return c.configCreateFunc(spec)
}
return types.ConfigCreateResponse{}, nil
}
func (c *fakeClient) ConfigInspectWithRaw(ctx context.Context, id string) (swarm.Config, []byte, error) {
if c.configInspectFunc != nil {
return c.configInspectFunc(ctx, id)
return c.configInspectFunc(id)
}
return swarm.Config{}, nil, nil
}
func (c *fakeClient) ConfigList(ctx context.Context, options types.ConfigListOptions) ([]swarm.Config, error) {
if c.configListFunc != nil {
return c.configListFunc(ctx, options)
return c.configListFunc(options)
}
return []swarm.Config{}, nil
}
func (c *fakeClient) ConfigRemove(_ context.Context, name string) error {
func (c *fakeClient) ConfigRemove(ctx context.Context, name string) error {
if c.configRemoveFunc != nil {
return c.configRemoveFunc(name)
}

View File

@ -1,7 +1,6 @@
package config
import (
"context"
"io"
"os"
"path/filepath"
@ -23,7 +22,7 @@ const configDataFile = "config-create-with-name.golden"
func TestConfigCreateErrors(t *testing.T) {
testCases := []struct {
args []string
configCreateFunc func(context.Context, swarm.ConfigSpec) (types.ConfigCreateResponse, error)
configCreateFunc func(swarm.ConfigSpec) (types.ConfigCreateResponse, error)
expectedError string
}{
{
@ -36,7 +35,7 @@ func TestConfigCreateErrors(t *testing.T) {
},
{
args: []string{"name", filepath.Join("testdata", configDataFile)},
configCreateFunc: func(_ context.Context, configSpec swarm.ConfigSpec) (types.ConfigCreateResponse, error) {
configCreateFunc: func(configSpec swarm.ConfigSpec) (types.ConfigCreateResponse, error) {
return types.ConfigCreateResponse{}, errors.Errorf("error creating config")
},
expectedError: "error creating config",
@ -58,7 +57,7 @@ func TestConfigCreateWithName(t *testing.T) {
name := "foo"
var actual []byte
cli := test.NewFakeCli(&fakeClient{
configCreateFunc: func(_ context.Context, spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) {
configCreateFunc: func(spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) {
if spec.Name != name {
return types.ConfigCreateResponse{}, errors.Errorf("expected name %q, got %q", name, spec.Name)
}
@ -97,7 +96,7 @@ func TestConfigCreateWithLabels(t *testing.T) {
}
cli := test.NewFakeCli(&fakeClient{
configCreateFunc: func(_ context.Context, spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) {
configCreateFunc: func(spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) {
if !reflect.DeepEqual(spec, expected) {
return types.ConfigCreateResponse{}, errors.Errorf("expected %+v, got %+v", expected, spec)
}
@ -123,7 +122,7 @@ func TestConfigCreateWithTemplatingDriver(t *testing.T) {
name := "foo"
cli := test.NewFakeCli(&fakeClient{
configCreateFunc: func(_ context.Context, spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) {
configCreateFunc: func(spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) {
if spec.Name != name {
return types.ConfigCreateResponse{}, errors.Errorf("expected name %q, got %q", name, spec.Name)
}

View File

@ -1,7 +1,6 @@
package config
import (
"context"
"fmt"
"io"
"testing"
@ -19,7 +18,7 @@ func TestConfigInspectErrors(t *testing.T) {
testCases := []struct {
args []string
flags map[string]string
configInspectFunc func(_ context.Context, configID string) (swarm.Config, []byte, error)
configInspectFunc func(configID string) (swarm.Config, []byte, error)
expectedError string
}{
{
@ -27,7 +26,7 @@ func TestConfigInspectErrors(t *testing.T) {
},
{
args: []string{"foo"},
configInspectFunc: func(_ context.Context, configID string) (swarm.Config, []byte, error) {
configInspectFunc: func(configID string) (swarm.Config, []byte, error) {
return swarm.Config{}, nil, errors.Errorf("error while inspecting the config")
},
expectedError: "error while inspecting the config",
@ -41,7 +40,7 @@ func TestConfigInspectErrors(t *testing.T) {
},
{
args: []string{"foo", "bar"},
configInspectFunc: func(_ context.Context, configID string) (swarm.Config, []byte, error) {
configInspectFunc: func(configID string) (swarm.Config, []byte, error) {
if configID == "foo" {
return *Config(ConfigName("foo")), nil, nil
}
@ -69,12 +68,12 @@ func TestConfigInspectWithoutFormat(t *testing.T) {
testCases := []struct {
name string
args []string
configInspectFunc func(_ context.Context, configID string) (swarm.Config, []byte, error)
configInspectFunc func(configID string) (swarm.Config, []byte, error)
}{
{
name: "single-config",
args: []string{"foo"},
configInspectFunc: func(_ context.Context, name string) (swarm.Config, []byte, error) {
configInspectFunc: func(name string) (swarm.Config, []byte, error) {
if name != "foo" {
return swarm.Config{}, nil, errors.Errorf("Invalid name, expected %s, got %s", "foo", name)
}
@ -84,7 +83,7 @@ func TestConfigInspectWithoutFormat(t *testing.T) {
{
name: "multiple-configs-with-labels",
args: []string{"foo", "bar"},
configInspectFunc: func(_ context.Context, name string) (swarm.Config, []byte, error) {
configInspectFunc: func(name string) (swarm.Config, []byte, error) {
return *Config(ConfigID("ID-"+name), ConfigName(name), ConfigLabels(map[string]string{
"label1": "label-foo",
})), nil, nil
@ -101,7 +100,7 @@ func TestConfigInspectWithoutFormat(t *testing.T) {
}
func TestConfigInspectWithFormat(t *testing.T) {
configInspectFunc := func(_ context.Context, name string) (swarm.Config, []byte, error) {
configInspectFunc := func(name string) (swarm.Config, []byte, error) {
return *Config(ConfigName("foo"), ConfigLabels(map[string]string{
"label1": "label-foo",
})), nil, nil
@ -110,7 +109,7 @@ func TestConfigInspectWithFormat(t *testing.T) {
name string
format string
args []string
configInspectFunc func(_ context.Context, name string) (swarm.Config, []byte, error)
configInspectFunc func(name string) (swarm.Config, []byte, error)
}{
{
name: "simple-template",
@ -140,11 +139,11 @@ func TestConfigInspectWithFormat(t *testing.T) {
func TestConfigInspectPretty(t *testing.T) {
testCases := []struct {
name string
configInspectFunc func(context.Context, string) (swarm.Config, []byte, error)
configInspectFunc func(string) (swarm.Config, []byte, error)
}{
{
name: "simple",
configInspectFunc: func(_ context.Context, id string) (swarm.Config, []byte, error) {
configInspectFunc: func(id string) (swarm.Config, []byte, error) {
return *Config(
ConfigLabels(map[string]string{
"lbl1": "value1",

View File

@ -1,7 +1,6 @@
package config
import (
"context"
"io"
"testing"
"time"
@ -20,7 +19,7 @@ import (
func TestConfigListErrors(t *testing.T) {
testCases := []struct {
args []string
configListFunc func(context.Context, types.ConfigListOptions) ([]swarm.Config, error)
configListFunc func(types.ConfigListOptions) ([]swarm.Config, error)
expectedError string
}{
{
@ -28,7 +27,7 @@ func TestConfigListErrors(t *testing.T) {
expectedError: "accepts no argument",
},
{
configListFunc: func(_ context.Context, options types.ConfigListOptions) ([]swarm.Config, error) {
configListFunc: func(options types.ConfigListOptions) ([]swarm.Config, error) {
return []swarm.Config{}, errors.Errorf("error listing configs")
},
expectedError: "error listing configs",
@ -48,7 +47,7 @@ func TestConfigListErrors(t *testing.T) {
func TestConfigList(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
configListFunc: func(_ context.Context, options types.ConfigListOptions) ([]swarm.Config, error) {
configListFunc: func(options types.ConfigListOptions) ([]swarm.Config, error) {
return []swarm.Config{
*Config(ConfigID("ID-1-foo"),
ConfigName("1-foo"),
@ -78,7 +77,7 @@ func TestConfigList(t *testing.T) {
func TestConfigListWithQuietOption(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
configListFunc: func(_ context.Context, options types.ConfigListOptions) ([]swarm.Config, error) {
configListFunc: func(options types.ConfigListOptions) ([]swarm.Config, error) {
return []swarm.Config{
*Config(ConfigID("ID-foo"), ConfigName("foo")),
*Config(ConfigID("ID-bar"), ConfigName("bar"), ConfigLabels(map[string]string{
@ -95,7 +94,7 @@ func TestConfigListWithQuietOption(t *testing.T) {
func TestConfigListWithConfigFormat(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
configListFunc: func(_ context.Context, options types.ConfigListOptions) ([]swarm.Config, error) {
configListFunc: func(options types.ConfigListOptions) ([]swarm.Config, error) {
return []swarm.Config{
*Config(ConfigID("ID-foo"), ConfigName("foo")),
*Config(ConfigID("ID-bar"), ConfigName("bar"), ConfigLabels(map[string]string{
@ -114,7 +113,7 @@ func TestConfigListWithConfigFormat(t *testing.T) {
func TestConfigListWithFormat(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
configListFunc: func(_ context.Context, options types.ConfigListOptions) ([]swarm.Config, error) {
configListFunc: func(options types.ConfigListOptions) ([]swarm.Config, error) {
return []swarm.Config{
*Config(ConfigID("ID-foo"), ConfigName("foo")),
*Config(ConfigID("ID-bar"), ConfigName("bar"), ConfigLabels(map[string]string{
@ -131,7 +130,7 @@ func TestConfigListWithFormat(t *testing.T) {
func TestConfigListWithFilter(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
configListFunc: func(_ context.Context, options types.ConfigListOptions) ([]swarm.Config, error) {
configListFunc: func(options types.ConfigListOptions) ([]swarm.Config, error) {
assert.Check(t, is.Equal("foo", options.Filters.Get("name")[0]))
assert.Check(t, is.Equal("lbl1=Label-bar", options.Filters.Get("label")[0]))
return []swarm.Config{

View File

@ -64,7 +64,7 @@ func (f *fakeClient) ContainerExecInspect(_ context.Context, execID string) (typ
return types.ContainerExecInspect{}, nil
}
func (f *fakeClient) ContainerExecStart(context.Context, string, types.ExecStartCheck) error {
func (f *fakeClient) ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) error {
return nil
}
@ -89,7 +89,7 @@ func (f *fakeClient) ContainerRemove(ctx context.Context, container string, opti
return nil
}
func (f *fakeClient) ImageCreate(_ context.Context, parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error) {
func (f *fakeClient) ImageCreate(ctx context.Context, parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error) {
if f.imageCreateFunc != nil {
return f.imageCreateFunc(parentReference, options)
}

View File

@ -209,7 +209,7 @@ func resolveLocalPath(localPath string) (absPath string, err error) {
if absPath, err = filepath.Abs(localPath); err != nil {
return
}
return archive.PreserveTrailingDotOrSeparator(absPath, localPath), nil
return archive.PreserveTrailingDotOrSeparator(absPath, localPath, filepath.Separator), nil
}
func copyFromContainer(ctx context.Context, dockerCli command.Cli, copyConfig cpConfig) (err error) {

View File

@ -12,7 +12,6 @@ import (
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/cli/cli/command/image"
"github.com/docker/cli/cli/streams"
"github.com/docker/cli/opts"
"github.com/docker/distribution/reference"
"github.com/docker/docker/api/types"
@ -20,6 +19,7 @@ import (
"github.com/docker/docker/api/types/versions"
apiclient "github.com/docker/docker/client"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/registry"
specs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@ -95,16 +95,16 @@ func runCreate(dockerCli command.Cli, flags *pflag.FlagSet, options *createOptio
}
}
copts.env = *opts.NewListOptsRef(&newEnv, nil)
containerCfg, err := parse(flags, copts, dockerCli.ServerInfo().OSType)
containerConfig, err := parse(flags, copts, dockerCli.ServerInfo().OSType)
if err != nil {
reportError(dockerCli.Err(), "create", err.Error(), true)
return cli.StatusError{StatusCode: 125}
}
if err = validateAPIVersion(containerCfg, dockerCli.Client().ClientVersion()); err != nil {
if err = validateAPIVersion(containerConfig, dockerCli.Client().ClientVersion()); err != nil {
reportError(dockerCli.Err(), "create", err.Error(), true)
return cli.StatusError{StatusCode: 125}
}
response, err := createContainer(context.Background(), dockerCli, containerCfg, options)
response, err := createContainer(context.Background(), dockerCli, containerConfig, options)
if err != nil {
return err
}
@ -112,27 +112,41 @@ func runCreate(dockerCli command.Cli, flags *pflag.FlagSet, options *createOptio
return nil
}
// FIXME(thaJeztah): this is the only code-path that uses APIClient.ImageCreate. Rewrite this to use the regular "pull" code (or vice-versa).
func pullImage(ctx context.Context, dockerCli command.Cli, image string, opts *createOptions) error {
encodedAuth, err := command.RetrieveAuthTokenFromImage(ctx, dockerCli, image)
func pullImage(ctx context.Context, dockerCli command.Cli, image string, platform string, out io.Writer) error {
ref, err := reference.ParseNormalizedNamed(image)
if err != nil {
return err
}
responseBody, err := dockerCli.Client().ImageCreate(ctx, image, types.ImageCreateOptions{
// Resolve the Repository name from fqn to RepositoryInfo
repoInfo, err := registry.ParseRepositoryInfo(ref)
if err != nil {
return err
}
authConfig := command.ResolveAuthConfig(ctx, dockerCli, repoInfo.Index)
encodedAuth, err := command.EncodeAuthToBase64(authConfig)
if err != nil {
return err
}
options := types.ImageCreateOptions{
RegistryAuth: encodedAuth,
Platform: opts.platform,
})
Platform: platform,
}
responseBody, err := dockerCli.Client().ImageCreate(ctx, image, options)
if err != nil {
return err
}
defer responseBody.Close()
out := dockerCli.Err()
if opts.quiet {
out = io.Discard
}
return jsonmessage.DisplayJSONMessagesToStream(responseBody, streams.NewOut(out), nil)
return jsonmessage.DisplayJSONMessagesStream(
responseBody,
out,
dockerCli.Out().FD(),
dockerCli.Out().IsTerminal(),
nil)
}
type cidFile struct {
@ -185,10 +199,10 @@ func newCIDFile(path string) (*cidFile, error) {
}
//nolint:gocyclo
func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *containerConfig, opts *createOptions) (*container.CreateResponse, error) {
config := containerCfg.Config
hostConfig := containerCfg.HostConfig
networkingConfig := containerCfg.NetworkingConfig
func createContainer(ctx context.Context, dockerCli command.Cli, containerConfig *containerConfig, opts *createOptions) (*container.CreateResponse, error) {
config := containerConfig.Config
hostConfig := containerConfig.HostConfig
networkingConfig := containerConfig.NetworkingConfig
warnOnOomKillDisable(*hostConfig, dockerCli.Err())
warnOnLocalhostDNS(*hostConfig, dockerCli.Err())
@ -213,7 +227,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
if taggedRef, ok := namedRef.(reference.NamedTagged); ok && !opts.untrusted {
var err error
trustedRef, err = image.TrustedReference(ctx, dockerCli, taggedRef)
trustedRef, err = image.TrustedReference(ctx, dockerCli, taggedRef, nil)
if err != nil {
return nil, err
}
@ -222,7 +236,11 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
}
pullAndTagImage := func() error {
if err := pullImage(ctx, dockerCli, config.Image, opts); err != nil {
pullOut := dockerCli.Err()
if opts.quiet {
pullOut = io.Discard
}
if err := pullImage(ctx, dockerCli, config.Image, opts.platform, pullOut); err != nil {
return err
}
if taggedRef, ok := namedRef.(reference.NamedTagged); ok && trustedRef != nil {
@ -275,8 +293,8 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
}
}
for _, w := range response.Warnings {
fmt.Fprintf(dockerCli.Err(), "WARNING: %s\n", w)
for _, warning := range response.Warnings {
fmt.Fprintf(dockerCli.Err(), "WARNING: %s\n", warning)
}
err = containerIDFile.Write(response.ID)
return &response, err

View File

@ -3,6 +3,7 @@ package container
import (
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/pkg/archive"
)
const (
@ -22,7 +23,7 @@ func NewDiffFormat(source string) formatter.Format {
}
// DiffFormatWrite writes formatted diff using the Context
func DiffFormatWrite(ctx formatter.Context, changes []container.FilesystemChange) error {
func DiffFormatWrite(ctx formatter.Context, changes []container.ContainerChangeResponseItem) error {
render := func(format func(subContext formatter.SubContext) error) error {
for _, change := range changes {
if err := format(&diffContext{c: change}); err != nil {
@ -36,7 +37,7 @@ func DiffFormatWrite(ctx formatter.Context, changes []container.FilesystemChange
type diffContext struct {
formatter.HeaderContext
c container.FilesystemChange
c container.ContainerChangeResponseItem
}
func newDiffContext() *diffContext {
@ -53,7 +54,16 @@ func (d *diffContext) MarshalJSON() ([]byte, error) {
}
func (d *diffContext) Type() string {
return d.c.Kind.String()
var kind string
switch d.c.Kind {
case archive.ChangeModify:
kind = "C"
case archive.ChangeAdd:
kind = "A"
case archive.ChangeDelete:
kind = "D"
}
return kind
}
func (d *diffContext) Path() string {

View File

@ -6,6 +6,7 @@ import (
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/pkg/archive"
"gotest.tools/v3/assert"
)
@ -40,10 +41,10 @@ D: /usr/app/old_app.js
},
}
diffs := []container.FilesystemChange{
{Kind: container.ChangeModify, Path: "/var/log/app.log"},
{Kind: container.ChangeAdd, Path: "/usr/app/app.js"},
{Kind: container.ChangeDelete, Path: "/usr/app/old_app.js"},
diffs := []container.ContainerChangeResponseItem{
{Kind: archive.ChangeModify, Path: "/var/log/app.log"},
{Kind: archive.ChangeAdd, Path: "/usr/app/app.js"},
{Kind: archive.ChangeDelete, Path: "/usr/app/old_app.js"},
}
for _, tc := range cases {

View File

@ -120,8 +120,6 @@ func runPs(dockerCli command.Cli, options *psOptions) error {
if len(options.format) == 0 {
// load custom psFormat from CLI config (if any)
options.format = dockerCli.ConfigFile().PsFormat
} else if options.quiet {
_, _ = dockerCli.Err().Write([]byte("WARNING: Ignoring custom format, because both --format and --quiet are set.\n"))
}
listOptions, err := buildContainerListOptions(options)

View File

@ -309,22 +309,8 @@ func TestContainerListWithFormat(t *testing.T) {
}, nil
},
})
t.Run("with format", func(t *testing.T) {
cli.OutBuffer().Reset()
cmd := newListCommand(cli)
assert.Check(t, cmd.Flags().Set("format", "{{ .Names }} {{ .Image }} {{ .Labels }}"))
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "container-list-with-format.golden")
})
t.Run("with format and quiet", func(t *testing.T) {
cli.OutBuffer().Reset()
cmd := newListCommand(cli)
assert.Check(t, cmd.Flags().Set("format", "{{ .Names }} {{ .Image }} {{ .Labels }}"))
assert.Check(t, cmd.Flags().Set("quiet", "true"))
assert.NilError(t, cmd.Execute())
assert.Equal(t, cli.ErrBuffer().String(), "WARNING: Ignoring custom format, because both --format and --quiet are set.\n")
golden.Assert(t, cli.OutBuffer().String(), "container-list-quiet.golden")
})
cmd := newListCommand(cli)
cmd.Flags().Set("format", "{{ .Names }} {{ .Image }} {{ .Labels }}")
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "container-list-with-format.golden")
}

View File

@ -123,7 +123,6 @@ type containerOptions struct {
runtime string
autoRemove bool
init bool
annotations *opts.MapOpts
Image string
Args []string
@ -164,7 +163,6 @@ func addFlags(flags *pflag.FlagSet) *containerOptions {
ulimits: opts.NewUlimitOpt(nil),
volumes: opts.NewListOpts(nil),
volumesFrom: opts.NewListOpts(nil),
annotations: opts.NewMapOpts(nil, nil),
}
// General purpose flags
@ -299,10 +297,6 @@ func addFlags(flags *pflag.FlagSet) *containerOptions {
flags.BoolVar(&copts.init, "init", false, "Run an init inside the container that forwards signals and reaps processes")
flags.SetAnnotation("init", "version", []string{"1.25"})
flags.Var(copts.annotations, "annotation", "Add an annotation to the container (passed through to the OCI runtime)")
flags.SetAnnotation("annotation", "version", []string{"1.43"})
return copts
}
@ -660,7 +654,6 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
Mounts: mounts,
MaskedPaths: maskedPaths,
ReadonlyPaths: readonlyPaths,
Annotations: copts.annotations.GetAll(),
}
if copts.autoRemove && !hostConfig.RestartPolicy.IsNone() {

View File

@ -49,11 +49,11 @@ func parseRun(args []string) (*container.Config, *container.HostConfig, *network
return nil, nil, nil, err
}
// TODO: fix tests to accept ContainerConfig
containerCfg, err := parse(flags, copts, runtime.GOOS)
containerConfig, err := parse(flags, copts, runtime.GOOS)
if err != nil {
return nil, nil, nil, err
}
return containerCfg.Config, containerCfg.HostConfig, containerCfg.NetworkingConfig, err
return containerConfig.Config, containerConfig.HostConfig, containerConfig.NetworkingConfig, err
}
func setupRunFlags() (*pflag.FlagSet, *containerOptions) {

View File

@ -75,6 +75,6 @@ func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint6
// RunPrune calls the Container Prune API
// This returns the amount of space reclaimed and a detailed output string
func RunPrune(dockerCli command.Cli, _ bool, filter opts.FilterOpt) (uint64, string, error) {
func RunPrune(dockerCli command.Cli, all bool, filter opts.FilterOpt) (uint64, string, error) {
return runPrune(dockerCli, pruneOptions{force: true, filter: filter})
}

View File

@ -105,22 +105,22 @@ func runRun(dockerCli command.Cli, flags *pflag.FlagSet, ropts *runOptions, copt
}
}
copts.env = *opts.NewListOptsRef(&newEnv, nil)
containerCfg, err := parse(flags, copts, dockerCli.ServerInfo().OSType)
containerConfig, err := parse(flags, copts, dockerCli.ServerInfo().OSType)
// just in case the parse does not exit
if err != nil {
reportError(dockerCli.Err(), "run", err.Error(), true)
return cli.StatusError{StatusCode: 125}
}
if err = validateAPIVersion(containerCfg, dockerCli.CurrentVersion()); err != nil {
if err = validateAPIVersion(containerConfig, dockerCli.CurrentVersion()); err != nil {
reportError(dockerCli.Err(), "run", err.Error(), true)
return cli.StatusError{StatusCode: 125}
}
return runContainer(dockerCli, ropts, copts, containerCfg)
return runContainer(dockerCli, ropts, copts, containerConfig)
}
//nolint:gocyclo
func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptions, containerCfg *containerConfig) error {
config := containerCfg.Config
func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptions, containerConfig *containerConfig) error {
config := containerConfig.Config
stdout, stderr := dockerCli.Out(), dockerCli.Err()
client := dockerCli.Client()
@ -144,7 +144,7 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio
ctx, cancelFun := context.WithCancel(context.Background())
defer cancelFun()
createResponse, err := createContainer(ctx, dockerCli, containerCfg, &opts.createOptions)
createResponse, err := createContainer(ctx, dockerCli, containerConfig, &opts.createOptions)
if err != nil {
reportError(stderr, "run", err.Error(), true)
return runStartContainerErr(err)
@ -173,11 +173,11 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio
dockerCli.ConfigFile().DetachKeys = opts.detachKeys
}
closeFn, err := attachContainer(ctx, dockerCli, &errCh, config, createResponse.ID)
close, err := attachContainer(ctx, dockerCli, &errCh, config, createResponse.ID)
if err != nil {
return err
}
defer closeFn()
defer close()
}
statusChan := waitExitOrRemoved(ctx, dockerCli, createResponse.ID, copts.autoRemove)

View File

@ -1,2 +0,0 @@
container_id
container_id

View File

@ -118,7 +118,10 @@ func createNewContext(o *CreateOptions, cli command.Cli, s store.Writer) error {
if err := s.CreateOrUpdate(contextMetadata); err != nil {
return err
}
return s.ResetTLSMaterial(o.Name, &contextTLSData)
if err := s.ResetTLSMaterial(o.Name, &contextTLSData); err != nil {
return err
}
return nil
}
func checkContextNameForCreation(s store.Reader, name string) error {

View File

@ -6,7 +6,6 @@ import (
"io"
"os"
"path/filepath"
"runtime"
"testing"
"github.com/docker/cli/cli/command"
@ -14,6 +13,7 @@ import (
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/flags"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/pkg/homedir"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
@ -57,11 +57,7 @@ func TestUseDefaultWithoutConfigFile(t *testing.T) {
// the _default_ configuration file. If we specify a custom configuration
// file, the CLI produces an error if the file doesn't exist.
tmpHomeDir := t.TempDir()
if runtime.GOOS == "windows" {
t.Setenv("USERPROFILE", tmpHomeDir)
} else {
t.Setenv("HOME", tmpHomeDir)
}
t.Setenv(homedir.Key(), tmpHomeDir)
configDir := filepath.Join(tmpHomeDir, ".docker")
configFilePath := filepath.Join(configDir, "config.json")

View File

@ -55,9 +55,6 @@ ports: {{- pad .Ports 1 0}}
}
return Format(format)
default: // custom format
if quiet {
return DefaultQuietFormat
}
return Format(source)
}
}

View File

@ -163,7 +163,7 @@ containerID2 ubuntu "" 24 hours ago foobar_bar
},
{
Context{Format: NewContainerFormat("table {{.Image}}", true, false)},
"containerID1\ncontainerID2\n",
"IMAGE\nubuntu\nubuntu\n",
},
{
Context{Format: NewContainerFormat("table", true, false)},

View File

@ -84,3 +84,10 @@ func (c *clientContextContext) Error() string {
// TODO(thaJeztah) add "--no-trunc" option to context ls and set default to 30 cols to match "docker service ps"
return Ellipsis(c.c.Error, maxErrLength)
}
// KubernetesEndpoint returns the kubernetes endpoint.
//
// Deprecated: support for kubernetes endpoints in contexts has been removed, and this formatting option will always be empty.
func (c *clientContextContext) KubernetesEndpoint() string {
return ""
}

View File

@ -14,7 +14,7 @@ import (
)
const (
defaultDiskUsageImageTableFormat = "table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.CreatedSince}}\t{{.Size}}\t{{.SharedSize}}\t{{.UniqueSize}}\t{{.Containers}}"
defaultDiskUsageImageTableFormat = "table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.CreatedSince}}\t{{.VirtualSize}}\t{{.SharedSize}}\t{{.UniqueSize}}\t{{.Containers}}"
defaultDiskUsageContainerTableFormat = "table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.LocalVolumes}}\t{{.Size}}\t{{.RunningFor}}\t{{.Status}}\t{{.Names}}"
defaultDiskUsageVolumeTableFormat = "table {{.Name}}\t{{.Links}}\t{{.Size}}"
defaultDiskUsageBuildCacheTableFormat = "table {{.ID}}\t{{.CacheType}}\t{{.Size}}\t{{.CreatedSince}}\t{{.LastUsedSince}}\t{{.UsageCount}}\t{{.Shared}}"
@ -296,10 +296,10 @@ func (c *diskUsageImagesContext) Reclaimable() string {
for _, i := range c.images {
if i.Containers != 0 {
if i.Size == -1 || i.SharedSize == -1 {
if i.VirtualSize == -1 || i.SharedSize == -1 {
continue
}
used += i.Size - i.SharedSize
used += i.VirtualSize - i.SharedSize
}
}

View File

@ -19,7 +19,7 @@ const (
JSONFormatKey = "json"
DefaultQuietFormat = "{{.ID}}"
JSONFormat = "{{json .}}"
jsonFormat = "{{json .}}"
)
// Format is the format string rendered using the Context
@ -62,7 +62,7 @@ func (c *Context) preFormat() {
case c.Format.IsTable():
c.finalFormat = c.finalFormat[len(TableFormatKey):]
case c.Format.IsJSON():
c.finalFormat = JSONFormat
c.finalFormat = jsonFormat
}
c.finalFormat = strings.Trim(c.finalFormat, " ")

View File

@ -205,7 +205,7 @@ func newImageContext() *imageContext {
"CreatedAt": CreatedAtHeader,
"Size": SizeHeader,
"Containers": containersHeader,
"VirtualSize": SizeHeader, // Deprecated: VirtualSize is deprecated, and equivalent to Size.
"VirtualSize": SizeHeader,
"SharedSize": sharedSizeHeader,
"UniqueSize": uniqueSizeHeader,
}
@ -260,13 +260,8 @@ func (c *imageContext) Containers() string {
return fmt.Sprintf("%d", c.i.Containers)
}
// VirtualSize shows the virtual size of the image and all of its parent
// images. Starting with docker 1.10, images are self-contained, and
// the VirtualSize is identical to Size.
//
// Deprecated: VirtualSize is deprecated, and equivalent to [imageContext.Size].
func (c *imageContext) VirtualSize() string {
return units.HumanSize(float64(c.i.Size))
return units.HumanSize(float64(c.i.VirtualSize))
}
func (c *imageContext) SharedSize() string {
@ -277,8 +272,8 @@ func (c *imageContext) SharedSize() string {
}
func (c *imageContext) UniqueSize() string {
if c.i.Size == -1 || c.i.SharedSize == -1 {
if c.i.VirtualSize == -1 || c.i.SharedSize == -1 {
return "N/A"
}
return units.HumanSize(float64(c.i.Size - c.i.SharedSize))
return units.HumanSize(float64(c.i.VirtualSize - c.i.SharedSize))
}

View File

@ -36,7 +36,7 @@ func TestImageContext(t *testing.T) {
call: ctx.ID,
},
{
imageCtx: imageContext{i: types.ImageSummary{Size: 10}, trunc: true},
imageCtx: imageContext{i: types.ImageSummary{Size: 10, VirtualSize: 10}, trunc: true},
expValue: "10B",
call: ctx.Size,
},
@ -70,9 +70,9 @@ func TestImageContext(t *testing.T) {
call: ctx.Containers,
},
{
imageCtx: imageContext{i: types.ImageSummary{Size: 10000}},
imageCtx: imageContext{i: types.ImageSummary{VirtualSize: 10000}},
expValue: "10kB",
call: ctx.VirtualSize, //nolint:staticcheck // ignore SA1019: field is deprecated, but still set on API < v1.44.
call: ctx.VirtualSize,
},
{
imageCtx: imageContext{i: types.ImageSummary{SharedSize: 10000}},
@ -80,7 +80,7 @@ func TestImageContext(t *testing.T) {
call: ctx.SharedSize,
},
{
imageCtx: imageContext{i: types.ImageSummary{SharedSize: 5000, Size: 20000}},
imageCtx: imageContext{i: types.ImageSummary{SharedSize: 5000, VirtualSize: 20000}},
expValue: "15kB",
call: ctx.UniqueSize,
},

View File

@ -14,14 +14,14 @@ type fakeClient struct {
serviceInspectFunc func(string) (swarm.Service, []byte, error)
}
func (cli *fakeClient) NodeInspectWithRaw(_ context.Context, nodeID string) (swarm.Node, []byte, error) {
func (cli *fakeClient) NodeInspectWithRaw(ctx context.Context, nodeID string) (swarm.Node, []byte, error) {
if cli.nodeInspectFunc != nil {
return cli.nodeInspectFunc(nodeID)
}
return swarm.Node{}, []byte{}, nil
}
func (cli *fakeClient) ServiceInspectWithRaw(_ context.Context, serviceID string, _ types.ServiceInspectOptions) (swarm.Service, []byte, error) {
func (cli *fakeClient) ServiceInspectWithRaw(ctx context.Context, serviceID string, options types.ServiceInspectOptions) (swarm.Service, []byte, error) {
if cli.serviceInspectFunc != nil {
return cli.serviceInspectFunc(serviceID)
}

View File

@ -22,7 +22,6 @@ import (
"github.com/docker/docker/api"
"github.com/docker/docker/api/types"
"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/archive"
"github.com/docker/docker/pkg/idtools"
@ -280,7 +279,7 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
var resolvedTags []*resolvedTag
if !options.untrusted {
translator := func(ctx context.Context, ref reference.NamedTagged) (reference.Canonical, error) {
return TrustedReference(ctx, dockerCli, ref)
return TrustedReference(ctx, dockerCli, ref, nil)
}
// if there is a tar wrapper, the dockerfile needs to be replaced inside it
if buildCtx != nil {
@ -323,9 +322,9 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
configFile := dockerCli.ConfigFile()
creds, _ := configFile.GetAllCredentials()
authConfigs := make(map[string]registrytypes.AuthConfig, len(creds))
authConfigs := make(map[string]types.AuthConfig, len(creds))
for k, auth := range creds {
authConfigs[k] = registrytypes.AuthConfig(auth)
authConfigs[k] = types.AuthConfig(auth)
}
buildOptions := imageBuildOptions(dockerCli, options)
buildOptions.Version = types.BuilderV1

View File

@ -18,7 +18,7 @@ import (
const dockerfileContents = "FROM busybox"
func prepareEmpty(_ *testing.T) string {
func prepareEmpty(t *testing.T) string {
return ""
}

View File

@ -34,7 +34,7 @@ func TestRunBuildDockerfileFromStdinWithCompress(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{imageBuildFunc: fakeImageBuild})
dockerfile := bytes.NewBufferString(`
FROM alpine:frozen
FROM alpine:3.6
COPY foo /
`)
cli.SetIn(streams.NewIn(io.NopCloser(dockerfile)))
@ -66,7 +66,7 @@ func TestRunBuildResetsUidAndGidInContext(t *testing.T) {
dir := fs.NewDir(t, "test-build-context",
fs.WithFile("foo", "some content", fs.AsUser(65534, 65534)),
fs.WithFile("Dockerfile", `
FROM alpine:frozen
FROM alpine:3.6
COPY foo bar /
`),
)
@ -155,7 +155,7 @@ func TestRunBuildFromLocalGitHubDir(t *testing.T) {
func TestRunBuildWithSymlinkedContext(t *testing.T) {
t.Setenv("DOCKER_BUILDKIT", "0")
dockerfile := `
FROM alpine:frozen
FROM alpine:3.6
RUN echo hello world
`

View File

@ -87,7 +87,7 @@ func (cli *fakeClient) ImageLoad(_ context.Context, input io.Reader, quiet bool)
return types.ImageLoadResponse{}, nil
}
func (cli *fakeClient) ImageList(_ context.Context, options types.ImageListOptions) ([]types.ImageSummary, error) {
func (cli *fakeClient) ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error) {
if cli.imageListFunc != nil {
return cli.imageListFunc(options)
}

View File

@ -69,7 +69,7 @@ func RunPull(cli command.Cli, opts PullOptions) error {
}
ctx := context.Background()
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, AuthResolver(cli), distributionRef.String())
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, nil, AuthResolver(cli), distributionRef.String())
if err != nil {
return err
}

View File

@ -11,7 +11,6 @@ import (
"github.com/docker/cli/cli/streams"
"github.com/docker/distribution/reference"
"github.com/docker/docker/api/types"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/registry"
"github.com/pkg/errors"
@ -77,7 +76,7 @@ func RunPush(dockerCli command.Cli, opts pushOptions) error {
// Resolve the Auth config relevant for this server
authConfig := command.ResolveAuthConfig(ctx, dockerCli, repoInfo.Index)
encodedAuth, err := registrytypes.EncodeAuthConfig(authConfig)
encodedAuth, err := command.EncodeAuthToBase64(authConfig)
if err != nil {
return err
}

View File

@ -14,6 +14,7 @@
"Architecture": "",
"Os": "",
"Size": 0,
"VirtualSize": 0,
"GraphDriver": {
"Data": null,
"Name": ""
@ -38,6 +39,7 @@
"Architecture": "",
"Os": "",
"Size": 0,
"VirtualSize": 0,
"GraphDriver": {
"Data": null,
"Name": ""

View File

@ -14,6 +14,7 @@
"Architecture": "",
"Os": "",
"Size": 0,
"VirtualSize": 0,
"GraphDriver": {
"Data": null,
"Name": ""

View File

@ -30,7 +30,7 @@ type target struct {
}
// TrustedPush handles content trust pushing of an image
func TrustedPush(ctx context.Context, cli command.Cli, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig registrytypes.AuthConfig, options types.ImagePushOptions) error {
func TrustedPush(ctx context.Context, cli command.Cli, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig types.AuthConfig, options types.ImagePushOptions) error {
responseBody, err := cli.Client().ImagePush(ctx, reference.FamiliarString(ref), options)
if err != nil {
return err
@ -44,7 +44,7 @@ func TrustedPush(ctx context.Context, cli command.Cli, repoInfo *registry.Reposi
// PushTrustedReference pushes a canonical reference to the trust server.
//
//nolint:gocyclo
func PushTrustedReference(streams command.Streams, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig registrytypes.AuthConfig, in io.Reader) error {
func PushTrustedReference(streams command.Streams, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig types.AuthConfig, in io.Reader) error {
// If it is a trusted push we would like to find the target entry which match the
// tag provided in the function and then do an AddTarget later.
target := &client.Target{}
@ -186,7 +186,7 @@ func trustedPull(ctx context.Context, cli command.Cli, imgRefAndAuth trust.Image
if err != nil {
return err
}
updatedImgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, AuthResolver(cli), trustedRef.String())
updatedImgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, nil, AuthResolver(cli), trustedRef.String())
if err != nil {
return err
}
@ -262,17 +262,20 @@ func getTrustedPullTargets(cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth)
// imagePullPrivileged pulls the image and displays it to the output
func imagePullPrivileged(ctx context.Context, cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth, opts PullOptions) error {
encodedAuth, err := registrytypes.EncodeAuthConfig(*imgRefAndAuth.AuthConfig())
ref := reference.FamiliarString(imgRefAndAuth.Reference())
encodedAuth, err := command.EncodeAuthToBase64(*imgRefAndAuth.AuthConfig())
if err != nil {
return err
}
requestPrivilege := command.RegistryAuthenticationPrivilegedFunc(cli, imgRefAndAuth.RepoInfo().Index, "pull")
responseBody, err := cli.Client().ImagePull(ctx, reference.FamiliarString(imgRefAndAuth.Reference()), types.ImagePullOptions{
options := types.ImagePullOptions{
RegistryAuth: encodedAuth,
PrivilegeFunc: requestPrivilege,
All: opts.all,
Platform: opts.platform,
})
}
responseBody, err := cli.Client().ImagePull(ctx, ref, options)
if err != nil {
return err
}
@ -286,8 +289,8 @@ func imagePullPrivileged(ctx context.Context, cli command.Cli, imgRefAndAuth tru
}
// TrustedReference returns the canonical trusted reference for an image reference
func TrustedReference(ctx context.Context, cli command.Cli, ref reference.NamedTagged) (reference.Canonical, error) {
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, AuthResolver(cli), ref.String())
func TrustedReference(ctx context.Context, cli command.Cli, ref reference.NamedTagged, rs registry.Service) (reference.Canonical, error) {
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, rs, AuthResolver(cli), ref.String())
if err != nil {
return nil, err
}
@ -337,8 +340,8 @@ func TagTrusted(ctx context.Context, cli command.Cli, trustedRef reference.Canon
}
// AuthResolver returns an auth resolver function from a command.Cli
func AuthResolver(cli command.Cli) func(ctx context.Context, index *registrytypes.IndexInfo) registrytypes.AuthConfig {
return func(ctx context.Context, index *registrytypes.IndexInfo) registrytypes.AuthConfig {
func AuthResolver(cli command.Cli) func(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig {
return func(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig {
return command.ResolveAuthConfig(ctx, cli, index)
}
}

View File

@ -52,6 +52,6 @@ func (c *fakeClient) NetworkRemove(ctx context.Context, networkID string) error
return nil
}
func (c *fakeClient) NetworkInspectWithRaw(context.Context, string, types.NetworkInspectOptions) (types.NetworkResource, []byte, error) {
func (c *fakeClient) NetworkInspectWithRaw(ctx context.Context, network string, options types.NetworkInspectOptions) (types.NetworkResource, []byte, error) {
return types.NetworkResource{}, nil, nil
}

View File

@ -70,7 +70,7 @@ func runPrune(dockerCli command.Cli, options pruneOptions) (output string, err e
// RunPrune calls the Network Prune API
// This returns the amount of space reclaimed and a detailed output string
func RunPrune(dockerCli command.Cli, _ bool, filter opts.FilterOpt) (uint64, string, error) {
func RunPrune(dockerCli command.Cli, all bool, filter opts.FilterOpt) (uint64, string, error) {
output, err := runPrune(dockerCli, pruneOptions{force: true, filter: filter})
return 0, output, err
}

View File

@ -20,49 +20,49 @@ type fakeClient struct {
serviceInspectFunc func(ctx context.Context, serviceID string, opts types.ServiceInspectOptions) (swarm.Service, []byte, error)
}
func (cli *fakeClient) NodeInspectWithRaw(context.Context, string) (swarm.Node, []byte, error) {
func (cli *fakeClient) NodeInspectWithRaw(ctx context.Context, ref string) (swarm.Node, []byte, error) {
if cli.nodeInspectFunc != nil {
return cli.nodeInspectFunc()
}
return swarm.Node{}, []byte{}, nil
}
func (cli *fakeClient) NodeList(context.Context, types.NodeListOptions) ([]swarm.Node, error) {
func (cli *fakeClient) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error) {
if cli.nodeListFunc != nil {
return cli.nodeListFunc()
}
return []swarm.Node{}, nil
}
func (cli *fakeClient) NodeRemove(context.Context, string, types.NodeRemoveOptions) error {
func (cli *fakeClient) NodeRemove(ctx context.Context, nodeID string, options types.NodeRemoveOptions) error {
if cli.nodeRemoveFunc != nil {
return cli.nodeRemoveFunc()
}
return nil
}
func (cli *fakeClient) NodeUpdate(_ context.Context, nodeID string, version swarm.Version, node swarm.NodeSpec) error {
func (cli *fakeClient) NodeUpdate(ctx context.Context, nodeID string, version swarm.Version, node swarm.NodeSpec) error {
if cli.nodeUpdateFunc != nil {
return cli.nodeUpdateFunc(nodeID, version, node)
}
return nil
}
func (cli *fakeClient) Info(context.Context) (types.Info, error) {
func (cli *fakeClient) Info(ctx context.Context) (types.Info, error) {
if cli.infoFunc != nil {
return cli.infoFunc()
}
return types.Info{}, nil
}
func (cli *fakeClient) TaskInspectWithRaw(_ context.Context, taskID string) (swarm.Task, []byte, error) {
func (cli *fakeClient) TaskInspectWithRaw(ctx context.Context, taskID string) (swarm.Task, []byte, error) {
if cli.taskInspectFunc != nil {
return cli.taskInspectFunc(taskID)
}
return swarm.Task{}, []byte{}, nil
}
func (cli *fakeClient) TaskList(_ context.Context, options types.TaskListOptions) ([]swarm.Task, error) {
func (cli *fakeClient) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) {
if cli.taskListFunc != nil {
return cli.taskListFunc(options)
}

View File

@ -20,42 +20,42 @@ type fakeClient struct {
pluginInspectFunc func(name string) (*types.Plugin, []byte, error)
}
func (c *fakeClient) PluginCreate(_ context.Context, createContext io.Reader, createOptions types.PluginCreateOptions) error {
func (c *fakeClient) PluginCreate(ctx context.Context, createContext io.Reader, createOptions types.PluginCreateOptions) error {
if c.pluginCreateFunc != nil {
return c.pluginCreateFunc(createContext, createOptions)
}
return nil
}
func (c *fakeClient) PluginEnable(_ context.Context, name string, enableOptions types.PluginEnableOptions) error {
func (c *fakeClient) PluginEnable(ctx context.Context, name string, enableOptions types.PluginEnableOptions) error {
if c.pluginEnableFunc != nil {
return c.pluginEnableFunc(name, enableOptions)
}
return nil
}
func (c *fakeClient) PluginDisable(_ context.Context, name string, disableOptions types.PluginDisableOptions) error {
func (c *fakeClient) PluginDisable(context context.Context, name string, disableOptions types.PluginDisableOptions) error {
if c.pluginDisableFunc != nil {
return c.pluginDisableFunc(name, disableOptions)
}
return nil
}
func (c *fakeClient) PluginRemove(_ context.Context, name string, removeOptions types.PluginRemoveOptions) error {
func (c *fakeClient) PluginRemove(context context.Context, name string, removeOptions types.PluginRemoveOptions) error {
if c.pluginRemoveFunc != nil {
return c.pluginRemoveFunc(name, removeOptions)
}
return nil
}
func (c *fakeClient) PluginInstall(_ context.Context, name string, installOptions types.PluginInstallOptions) (io.ReadCloser, error) {
func (c *fakeClient) PluginInstall(context context.Context, name string, installOptions types.PluginInstallOptions) (io.ReadCloser, error) {
if c.pluginInstallFunc != nil {
return c.pluginInstallFunc(name, installOptions)
}
return nil, nil
}
func (c *fakeClient) PluginList(_ context.Context, filter filters.Args) (types.PluginsListResponse, error) {
func (c *fakeClient) PluginList(context context.Context, filter filters.Args) (types.PluginsListResponse, error) {
if c.pluginListFunc != nil {
return c.pluginListFunc(filter)
}
@ -63,7 +63,7 @@ func (c *fakeClient) PluginList(_ context.Context, filter filters.Args) (types.P
return types.PluginsListResponse{}, nil
}
func (c *fakeClient) PluginInspectWithRaw(_ context.Context, name string) (*types.Plugin, []byte, error) {
func (c *fakeClient) PluginInspectWithRaw(ctx context.Context, name string) (*types.Plugin, []byte, error) {
if c.pluginInspectFunc != nil {
return c.pluginInspectFunc(name)
}
@ -71,6 +71,6 @@ func (c *fakeClient) PluginInspectWithRaw(_ context.Context, name string) (*type
return nil, nil, nil
}
func (c *fakeClient) Info(context.Context) (types.Info, error) {
func (c *fakeClient) Info(ctx context.Context) (types.Info, error) {
return types.Info{}, nil
}

View File

@ -10,7 +10,6 @@ import (
"github.com/docker/cli/cli/command/image"
"github.com/docker/distribution/reference"
"github.com/docker/docker/api/types"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/registry"
"github.com/pkg/errors"
@ -55,6 +54,26 @@ func newInstallCommand(dockerCli command.Cli) *cobra.Command {
return cmd
}
type pluginRegistryService struct {
registry.Service
}
func (s pluginRegistryService) ResolveRepository(name reference.Named) (*registry.RepositoryInfo, error) {
repoInfo, err := s.Service.ResolveRepository(name)
if repoInfo != nil {
repoInfo.Class = "plugin"
}
return repoInfo, err
}
func newRegistryService() (registry.Service, error) {
svc, err := registry.NewService(registry.ServiceOptions{})
if err != nil {
return nil, err
}
return pluginRegistryService{Service: svc}, nil
}
func buildPullConfig(ctx context.Context, dockerCli command.Cli, opts pluginOptions, cmdName string) (types.PluginInstallOptions, error) {
// Names with both tag and digest will be treated by the daemon
// as a pull by digest with a local name for the tag
@ -79,7 +98,12 @@ func buildPullConfig(ctx context.Context, dockerCli command.Cli, opts pluginOpti
return types.PluginInstallOptions{}, errors.Errorf("invalid name: %s", ref.String())
}
trusted, err := image.TrustedReference(context.Background(), dockerCli, nt)
ctx := context.Background()
svc, err := newRegistryService()
if err != nil {
return types.PluginInstallOptions{}, err
}
trusted, err := image.TrustedReference(ctx, dockerCli, nt, svc)
if err != nil {
return types.PluginInstallOptions{}, err
}
@ -87,7 +111,8 @@ func buildPullConfig(ctx context.Context, dockerCli command.Cli, opts pluginOpti
}
authConfig := command.ResolveAuthConfig(ctx, dockerCli, repoInfo.Index)
encodedAuth, err := registrytypes.EncodeAuthConfig(authConfig)
encodedAuth, err := command.EncodeAuthToBase64(authConfig)
if err != nil {
return types.PluginInstallOptions{}, err
}

View File

@ -7,7 +7,6 @@ import (
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/image"
"github.com/docker/distribution/reference"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/registry"
"github.com/pkg/errors"
@ -56,7 +55,8 @@ func runPush(dockerCli command.Cli, opts pushOptions) error {
return err
}
authConfig := command.ResolveAuthConfig(ctx, dockerCli, repoInfo.Index)
encodedAuth, err := registrytypes.EncodeAuthConfig(authConfig)
encodedAuth, err := command.EncodeAuthToBase64(authConfig)
if err != nil {
return err
}
@ -68,6 +68,7 @@ func runPush(dockerCli command.Cli, opts pushOptions) error {
defer responseBody.Close()
if !opts.untrusted {
repoInfo.Class = "plugin"
return image.PushTrustedReference(dockerCli, repoInfo, named, authConfig, responseBody)
}

View File

@ -3,6 +3,8 @@ package command
import (
"bufio"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"os"
@ -19,11 +21,20 @@ import (
"github.com/pkg/errors"
)
// EncodeAuthToBase64 serializes the auth configuration as JSON base64 payload.
// ElectAuthServer returns the default registry to use.
//
// Deprecated: use [registrytypes.EncodeAuthConfig] instead.
func EncodeAuthToBase64(authConfig registrytypes.AuthConfig) (string, error) {
return registrytypes.EncodeAuthConfig(authConfig)
// Deprecated: use [registry.IndexServer] instead.
func ElectAuthServer(_ context.Context, _ Cli) string {
return registry.IndexServer
}
// EncodeAuthToBase64 serializes the auth configuration as JSON base64 payload
func EncodeAuthToBase64(authConfig types.AuthConfig) (string, error) {
buf, err := json.Marshal(authConfig)
if err != nil {
return "", err
}
return base64.URLEncoding.EncodeToString(buf), nil
}
// RegistryAuthenticationPrivilegedFunc returns a RequestPrivilegeFunc from the specified registry index info
@ -41,7 +52,7 @@ func RegistryAuthenticationPrivilegedFunc(cli Cli, index *registrytypes.IndexInf
if err != nil {
return "", err
}
return registrytypes.EncodeAuthConfig(authConfig)
return EncodeAuthToBase64(authConfig)
}
}
@ -51,19 +62,19 @@ func RegistryAuthenticationPrivilegedFunc(cli Cli, index *registrytypes.IndexInf
//
// It is similar to [registry.ResolveAuthConfig], but uses the credentials-
// store, instead of looking up credentials from a map.
func ResolveAuthConfig(_ context.Context, cli Cli, index *registrytypes.IndexInfo) registrytypes.AuthConfig {
func ResolveAuthConfig(_ context.Context, cli Cli, index *registrytypes.IndexInfo) types.AuthConfig {
configKey := index.Name
if index.Official {
configKey = registry.IndexServer
}
a, _ := cli.ConfigFile().GetAuthConfig(configKey)
return registrytypes.AuthConfig(a)
return types.AuthConfig(a)
}
// GetDefaultAuthConfig gets the default auth config given a serverAddress
// If credentials for given serverAddress exists in the credential store, the configuration will be populated with values in it
func GetDefaultAuthConfig(cli Cli, checkCredStore bool, serverAddress string, isDefaultRegistry bool) (registrytypes.AuthConfig, error) {
func GetDefaultAuthConfig(cli Cli, checkCredStore bool, serverAddress string, isDefaultRegistry bool) (types.AuthConfig, error) {
if !isDefaultRegistry {
serverAddress = registry.ConvertToHostname(serverAddress)
}
@ -72,27 +83,20 @@ func GetDefaultAuthConfig(cli Cli, checkCredStore bool, serverAddress string, is
if checkCredStore {
authconfig, err = cli.ConfigFile().GetAuthConfig(serverAddress)
if err != nil {
return registrytypes.AuthConfig{
return types.AuthConfig{
ServerAddress: serverAddress,
}, err
}
}
authconfig.ServerAddress = serverAddress
authconfig.IdentityToken = ""
res := registrytypes.AuthConfig(authconfig)
res := types.AuthConfig(authconfig)
return res, nil
}
// ConfigureAuth handles prompting of user's username and password if needed
func ConfigureAuth(cli Cli, flUser, flPassword string, authconfig *registrytypes.AuthConfig, isDefaultRegistry bool) error {
// On Windows, force the use of the regular OS stdin stream.
//
// See:
// - https://github.com/moby/moby/issues/14336
// - https://github.com/moby/moby/issues/14210
// - https://github.com/moby/moby/pull/17738
//
// TODO(thaJeztah): we need to confirm if this special handling is still needed, as we may not be doing this in other places.
func ConfigureAuth(cli Cli, flUser, flPassword string, authconfig *types.AuthConfig, isDefaultRegistry bool) error {
// On Windows, force the use of the regular OS stdin stream. Fixes #14336/#14210
if runtime.GOOS == "windows" {
cli.SetIn(streams.NewIn(os.Stdin))
}
@ -116,11 +120,8 @@ func ConfigureAuth(cli Cli, flUser, flPassword string, authconfig *registrytypes
fmt.Fprintln(cli.Out(), "Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.")
}
promptWithDefault(cli.Out(), "Username", authconfig.Username)
var err error
flUser, err = readInput(cli.In())
if err != nil {
return err
}
flUser = readInput(cli.In(), cli.Out())
flUser = strings.TrimSpace(flUser)
if flUser == "" {
flUser = authconfig.Username
}
@ -134,15 +135,12 @@ func ConfigureAuth(cli Cli, flUser, flPassword string, authconfig *registrytypes
return err
}
fmt.Fprintf(cli.Out(), "Password: ")
_ = term.DisableEcho(cli.In().FD(), oldState)
defer func() {
_ = term.RestoreTerminal(cli.In().FD(), oldState)
}()
flPassword, err = readInput(cli.In())
if err != nil {
return err
}
term.DisableEcho(cli.In().FD(), oldState)
flPassword = readInput(cli.In(), cli.Out())
fmt.Fprint(cli.Out(), "\n")
term.RestoreTerminal(cli.In().FD(), oldState)
if flPassword == "" {
return errors.Errorf("Error: Password Required")
}
@ -154,15 +152,14 @@ func ConfigureAuth(cli Cli, flUser, flPassword string, authconfig *registrytypes
return nil
}
// readInput reads, and returns user input from in. It tries to return a
// single line, not including the end-of-line bytes, and trims leading
// and trailing whitespace.
func readInput(in io.Reader) (string, error) {
line, _, err := bufio.NewReader(in).ReadLine()
func readInput(in io.Reader, out io.Writer) string {
reader := bufio.NewReader(in)
line, _, err := reader.ReadLine()
if err != nil {
return "", errors.Wrap(err, "error while reading input")
fmt.Fprintln(out, err.Error())
os.Exit(1)
}
return strings.TrimSpace(string(line)), nil
return string(line)
}
func promptWithDefault(out io.Writer, prompt string, configDefault string) {
@ -173,19 +170,14 @@ func promptWithDefault(out io.Writer, prompt string, configDefault string) {
}
}
// RetrieveAuthTokenFromImage retrieves an encoded auth token given a complete
// image. The auth configuration is serialized as a base64url encoded RFC4648,
// section 5) JSON string for sending through the X-Registry-Auth header.
//
// For details on base64url encoding, see:
// - RFC4648, section 5: https://tools.ietf.org/html/rfc4648#section-5
// RetrieveAuthTokenFromImage retrieves an encoded auth token given a complete image
func RetrieveAuthTokenFromImage(ctx context.Context, cli Cli, image string) (string, error) {
// Retrieve encoded auth token from the image reference
authConfig, err := resolveAuthConfigFromImage(ctx, cli, image)
if err != nil {
return "", err
}
encodedAuth, err := registrytypes.EncodeAuthConfig(authConfig)
encodedAuth, err := EncodeAuthToBase64(authConfig)
if err != nil {
return "", err
}
@ -193,14 +185,14 @@ func RetrieveAuthTokenFromImage(ctx context.Context, cli Cli, image string) (str
}
// resolveAuthConfigFromImage retrieves that AuthConfig using the image string
func resolveAuthConfigFromImage(ctx context.Context, cli Cli, image string) (registrytypes.AuthConfig, error) {
func resolveAuthConfigFromImage(ctx context.Context, cli Cli, image string) (types.AuthConfig, error) {
registryRef, err := reference.ParseNormalizedNamed(image)
if err != nil {
return registrytypes.AuthConfig{}, err
return types.AuthConfig{}, err
}
repoInfo, err := registry.ParseRepositoryInfo(registryRef)
if err != nil {
return registrytypes.AuthConfig{}, err
return types.AuthConfig{}, err
}
return ResolveAuthConfig(ctx, cli, repoInfo.Index), nil
}

View File

@ -10,6 +10,7 @@ import (
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
configtypes "github.com/docker/cli/cli/config/types"
"github.com/docker/docker/api/types"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/client"
"github.com/docker/docker/errdefs"
@ -163,7 +164,7 @@ func runLogin(dockerCli command.Cli, opts loginOptions) error { //nolint:gocyclo
return nil
}
func loginWithCredStoreCreds(ctx context.Context, dockerCli command.Cli, authConfig *registrytypes.AuthConfig) (registrytypes.AuthenticateOKBody, error) {
func loginWithCredStoreCreds(ctx context.Context, dockerCli command.Cli, authConfig *types.AuthConfig) (registrytypes.AuthenticateOKBody, error) {
fmt.Fprintf(dockerCli.Out(), "Authenticating with existing credentials...\n")
cliClient := dockerCli.Client()
response, err := cliClient.RegistryLogin(ctx, *authConfig)
@ -177,7 +178,7 @@ func loginWithCredStoreCreds(ctx context.Context, dockerCli command.Cli, authCon
return response, err
}
func loginClientSide(ctx context.Context, auth registrytypes.AuthConfig) (registrytypes.AuthenticateOKBody, error) {
func loginClientSide(ctx context.Context, auth types.AuthConfig) (registrytypes.AuthenticateOKBody, error) {
svc, err := registry.NewService(registry.ServiceOptions{})
if err != nil {
return registrytypes.AuthenticateOKBody{}, err

View File

@ -34,11 +34,11 @@ type fakeClient struct {
client.Client
}
func (c fakeClient) Info(context.Context) (types.Info, error) {
func (c fakeClient) Info(ctx context.Context) (types.Info, error) {
return types.Info{}, nil
}
func (c fakeClient) RegistryLogin(_ context.Context, auth registrytypes.AuthConfig) (registrytypes.AuthenticateOKBody, error) {
func (c fakeClient) RegistryLogin(ctx context.Context, auth types.AuthConfig) (registrytypes.AuthenticateOKBody, error) {
if auth.Password == expiredPassword {
return registrytypes.AuthenticateOKBody{}, fmt.Errorf("Invalid Username or Password")
}
@ -53,16 +53,16 @@ func (c fakeClient) RegistryLogin(_ context.Context, auth registrytypes.AuthConf
func TestLoginWithCredStoreCreds(t *testing.T) {
testCases := []struct {
inputAuthConfig registrytypes.AuthConfig
inputAuthConfig types.AuthConfig
expectedMsg string
expectedErr string
}{
{
inputAuthConfig: registrytypes.AuthConfig{},
inputAuthConfig: types.AuthConfig{},
expectedMsg: "Authenticating with existing credentials...\n",
},
{
inputAuthConfig: registrytypes.AuthConfig{
inputAuthConfig: types.AuthConfig{
Username: userErr,
},
expectedMsg: "Authenticating with existing credentials...\n",

View File

@ -8,7 +8,6 @@ import (
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/registry"
"github.com/spf13/cobra"
)
@ -55,19 +54,25 @@ func runSearch(dockerCli command.Cli, options searchOptions) error {
}
ctx := context.Background()
authConfig := command.ResolveAuthConfig(ctx, dockerCli, indexInfo)
encodedAuth, err := registrytypes.EncodeAuthConfig(authConfig)
requestPrivilege := command.RegistryAuthenticationPrivilegedFunc(dockerCli, indexInfo, "search")
encodedAuth, err := command.EncodeAuthToBase64(authConfig)
if err != nil {
return err
}
requestPrivilege := command.RegistryAuthenticationPrivilegedFunc(dockerCli, indexInfo, "search")
results, err := dockerCli.Client().ImageSearch(ctx, options.term, types.ImageSearchOptions{
searchOptions := types.ImageSearchOptions{
RegistryAuth: encodedAuth,
PrivilegeFunc: requestPrivilege,
Filters: options.filter.Value(),
Limit: options.limit,
})
}
clnt := dockerCli.Client()
results, err := clnt.ImageSearch(ctx, options.term, searchOptions)
if err != nil {
return err
}

View File

@ -10,7 +10,6 @@ import (
configtypes "github.com/docker/cli/cli/config/types"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/client"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
@ -21,7 +20,7 @@ type fakeClient struct {
infoFunc func() (types.Info, error)
}
var testAuthConfigs = []registry.AuthConfig{
var testAuthConfigs = []types.AuthConfig{
{
ServerAddress: "https://index.docker.io/v1/",
Username: "u0",
@ -46,13 +45,13 @@ func TestGetDefaultAuthConfig(t *testing.T) {
checkCredStore bool
inputServerAddress string
expectedErr string
expectedAuthConfig registry.AuthConfig
expectedAuthConfig types.AuthConfig
}{
{
checkCredStore: false,
inputServerAddress: "",
expectedErr: "",
expectedAuthConfig: registry.AuthConfig{
expectedAuthConfig: types.AuthConfig{
ServerAddress: "",
Username: "",
Password: "",
@ -102,7 +101,7 @@ func TestGetDefaultAuthConfig_HelperError(t *testing.T) {
cli.SetErr(errBuf)
cli.ConfigFile().CredentialsStore = "fake-does-not-exist"
serverAddress := "test-server-address"
expectedAuthConfig := registry.AuthConfig{
expectedAuthConfig := types.AuthConfig{
ServerAddress: serverAddress,
}
authconfig, err := GetDefaultAuthConfig(cli, true, serverAddress, serverAddress == "https://index.docker.io/v1/")

View File

@ -10,36 +10,36 @@ import (
type fakeClient struct {
client.Client
secretCreateFunc func(context.Context, swarm.SecretSpec) (types.SecretCreateResponse, error)
secretInspectFunc func(context.Context, string) (swarm.Secret, []byte, error)
secretListFunc func(context.Context, types.SecretListOptions) ([]swarm.Secret, error)
secretRemoveFunc func(context.Context, string) error
secretCreateFunc func(swarm.SecretSpec) (types.SecretCreateResponse, error)
secretInspectFunc func(string) (swarm.Secret, []byte, error)
secretListFunc func(types.SecretListOptions) ([]swarm.Secret, error)
secretRemoveFunc func(string) error
}
func (c *fakeClient) SecretCreate(ctx context.Context, spec swarm.SecretSpec) (types.SecretCreateResponse, error) {
if c.secretCreateFunc != nil {
return c.secretCreateFunc(ctx, spec)
return c.secretCreateFunc(spec)
}
return types.SecretCreateResponse{}, nil
}
func (c *fakeClient) SecretInspectWithRaw(ctx context.Context, id string) (swarm.Secret, []byte, error) {
if c.secretInspectFunc != nil {
return c.secretInspectFunc(ctx, id)
return c.secretInspectFunc(id)
}
return swarm.Secret{}, nil, nil
}
func (c *fakeClient) SecretList(ctx context.Context, options types.SecretListOptions) ([]swarm.Secret, error) {
if c.secretListFunc != nil {
return c.secretListFunc(ctx, options)
return c.secretListFunc(options)
}
return []swarm.Secret{}, nil
}
func (c *fakeClient) SecretRemove(ctx context.Context, name string) error {
if c.secretRemoveFunc != nil {
return c.secretRemoveFunc(ctx, name)
return c.secretRemoveFunc(name)
}
return nil
}

View File

@ -1,7 +1,6 @@
package secret
import (
"context"
"io"
"os"
"path/filepath"
@ -22,7 +21,7 @@ const secretDataFile = "secret-create-with-name.golden"
func TestSecretCreateErrors(t *testing.T) {
testCases := []struct {
args []string
secretCreateFunc func(context.Context, swarm.SecretSpec) (types.SecretCreateResponse, error)
secretCreateFunc func(swarm.SecretSpec) (types.SecretCreateResponse, error)
expectedError string
}{
{
@ -35,7 +34,7 @@ func TestSecretCreateErrors(t *testing.T) {
},
{
args: []string{"name", filepath.Join("testdata", secretDataFile)},
secretCreateFunc: func(_ context.Context, secretSpec swarm.SecretSpec) (types.SecretCreateResponse, error) {
secretCreateFunc: func(secretSpec swarm.SecretSpec) (types.SecretCreateResponse, error) {
return types.SecretCreateResponse{}, errors.Errorf("error creating secret")
},
expectedError: "error creating secret",
@ -67,7 +66,7 @@ func TestSecretCreateWithName(t *testing.T) {
}
cli := test.NewFakeCli(&fakeClient{
secretCreateFunc: func(_ context.Context, spec swarm.SecretSpec) (types.SecretCreateResponse, error) {
secretCreateFunc: func(spec swarm.SecretSpec) (types.SecretCreateResponse, error) {
if !reflect.DeepEqual(spec, expected) {
return types.SecretCreateResponse{}, errors.Errorf("expected %+v, got %+v", expected, spec)
}
@ -90,7 +89,7 @@ func TestSecretCreateWithDriver(t *testing.T) {
name := "foo"
cli := test.NewFakeCli(&fakeClient{
secretCreateFunc: func(_ context.Context, spec swarm.SecretSpec) (types.SecretCreateResponse, error) {
secretCreateFunc: func(spec swarm.SecretSpec) (types.SecretCreateResponse, error) {
if spec.Name != name {
return types.SecretCreateResponse{}, errors.Errorf("expected name %q, got %q", name, spec.Name)
}
@ -119,7 +118,7 @@ func TestSecretCreateWithTemplatingDriver(t *testing.T) {
name := "foo"
cli := test.NewFakeCli(&fakeClient{
secretCreateFunc: func(_ context.Context, spec swarm.SecretSpec) (types.SecretCreateResponse, error) {
secretCreateFunc: func(spec swarm.SecretSpec) (types.SecretCreateResponse, error) {
if spec.Name != name {
return types.SecretCreateResponse{}, errors.Errorf("expected name %q, got %q", name, spec.Name)
}
@ -149,7 +148,7 @@ func TestSecretCreateWithLabels(t *testing.T) {
name := "foo"
cli := test.NewFakeCli(&fakeClient{
secretCreateFunc: func(_ context.Context, spec swarm.SecretSpec) (types.SecretCreateResponse, error) {
secretCreateFunc: func(spec swarm.SecretSpec) (types.SecretCreateResponse, error) {
if spec.Name != name {
return types.SecretCreateResponse{}, errors.Errorf("expected name %q, got %q", name, spec.Name)
}

View File

@ -1,7 +1,6 @@
package secret
import (
"context"
"fmt"
"io"
"testing"
@ -19,7 +18,7 @@ func TestSecretInspectErrors(t *testing.T) {
testCases := []struct {
args []string
flags map[string]string
secretInspectFunc func(ctx context.Context, secretID string) (swarm.Secret, []byte, error)
secretInspectFunc func(secretID string) (swarm.Secret, []byte, error)
expectedError string
}{
{
@ -27,7 +26,7 @@ func TestSecretInspectErrors(t *testing.T) {
},
{
args: []string{"foo"},
secretInspectFunc: func(_ context.Context, secretID string) (swarm.Secret, []byte, error) {
secretInspectFunc: func(secretID string) (swarm.Secret, []byte, error) {
return swarm.Secret{}, nil, errors.Errorf("error while inspecting the secret")
},
expectedError: "error while inspecting the secret",
@ -41,7 +40,7 @@ func TestSecretInspectErrors(t *testing.T) {
},
{
args: []string{"foo", "bar"},
secretInspectFunc: func(_ context.Context, secretID string) (swarm.Secret, []byte, error) {
secretInspectFunc: func(secretID string) (swarm.Secret, []byte, error) {
if secretID == "foo" {
return *Secret(SecretName("foo")), nil, nil
}
@ -69,12 +68,12 @@ func TestSecretInspectWithoutFormat(t *testing.T) {
testCases := []struct {
name string
args []string
secretInspectFunc func(ctx context.Context, secretID string) (swarm.Secret, []byte, error)
secretInspectFunc func(secretID string) (swarm.Secret, []byte, error)
}{
{
name: "single-secret",
args: []string{"foo"},
secretInspectFunc: func(_ context.Context, name string) (swarm.Secret, []byte, error) {
secretInspectFunc: func(name string) (swarm.Secret, []byte, error) {
if name != "foo" {
return swarm.Secret{}, nil, errors.Errorf("Invalid name, expected %s, got %s", "foo", name)
}
@ -84,7 +83,7 @@ func TestSecretInspectWithoutFormat(t *testing.T) {
{
name: "multiple-secrets-with-labels",
args: []string{"foo", "bar"},
secretInspectFunc: func(_ context.Context, name string) (swarm.Secret, []byte, error) {
secretInspectFunc: func(name string) (swarm.Secret, []byte, error) {
return *Secret(SecretID("ID-"+name), SecretName(name), SecretLabels(map[string]string{
"label1": "label-foo",
})), nil, nil
@ -103,7 +102,7 @@ func TestSecretInspectWithoutFormat(t *testing.T) {
}
func TestSecretInspectWithFormat(t *testing.T) {
secretInspectFunc := func(_ context.Context, name string) (swarm.Secret, []byte, error) {
secretInspectFunc := func(name string) (swarm.Secret, []byte, error) {
return *Secret(SecretName("foo"), SecretLabels(map[string]string{
"label1": "label-foo",
})), nil, nil
@ -112,7 +111,7 @@ func TestSecretInspectWithFormat(t *testing.T) {
name string
format string
args []string
secretInspectFunc func(_ context.Context, name string) (swarm.Secret, []byte, error)
secretInspectFunc func(name string) (swarm.Secret, []byte, error)
}{
{
name: "simple-template",
@ -142,11 +141,11 @@ func TestSecretInspectWithFormat(t *testing.T) {
func TestSecretInspectPretty(t *testing.T) {
testCases := []struct {
name string
secretInspectFunc func(context.Context, string) (swarm.Secret, []byte, error)
secretInspectFunc func(string) (swarm.Secret, []byte, error)
}{
{
name: "simple",
secretInspectFunc: func(_ context.Context, id string) (swarm.Secret, []byte, error) {
secretInspectFunc: func(id string) (swarm.Secret, []byte, error) {
return *Secret(
SecretLabels(map[string]string{
"lbl1": "value1",

View File

@ -1,7 +1,6 @@
package secret
import (
"context"
"io"
"testing"
"time"
@ -20,7 +19,7 @@ import (
func TestSecretListErrors(t *testing.T) {
testCases := []struct {
args []string
secretListFunc func(context.Context, types.SecretListOptions) ([]swarm.Secret, error)
secretListFunc func(types.SecretListOptions) ([]swarm.Secret, error)
expectedError string
}{
{
@ -28,7 +27,7 @@ func TestSecretListErrors(t *testing.T) {
expectedError: "accepts no argument",
},
{
secretListFunc: func(_ context.Context, options types.SecretListOptions) ([]swarm.Secret, error) {
secretListFunc: func(options types.SecretListOptions) ([]swarm.Secret, error) {
return []swarm.Secret{}, errors.Errorf("error listing secrets")
},
expectedError: "error listing secrets",
@ -48,7 +47,7 @@ func TestSecretListErrors(t *testing.T) {
func TestSecretList(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
secretListFunc: func(_ context.Context, options types.SecretListOptions) ([]swarm.Secret, error) {
secretListFunc: func(options types.SecretListOptions) ([]swarm.Secret, error) {
return []swarm.Secret{
*Secret(SecretID("ID-1-foo"),
SecretName("1-foo"),
@ -80,7 +79,7 @@ func TestSecretList(t *testing.T) {
func TestSecretListWithQuietOption(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
secretListFunc: func(_ context.Context, options types.SecretListOptions) ([]swarm.Secret, error) {
secretListFunc: func(options types.SecretListOptions) ([]swarm.Secret, error) {
return []swarm.Secret{
*Secret(SecretID("ID-foo"), SecretName("foo")),
*Secret(SecretID("ID-bar"), SecretName("bar"), SecretLabels(map[string]string{
@ -97,7 +96,7 @@ func TestSecretListWithQuietOption(t *testing.T) {
func TestSecretListWithConfigFormat(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
secretListFunc: func(_ context.Context, options types.SecretListOptions) ([]swarm.Secret, error) {
secretListFunc: func(options types.SecretListOptions) ([]swarm.Secret, error) {
return []swarm.Secret{
*Secret(SecretID("ID-foo"), SecretName("foo")),
*Secret(SecretID("ID-bar"), SecretName("bar"), SecretLabels(map[string]string{
@ -116,7 +115,7 @@ func TestSecretListWithConfigFormat(t *testing.T) {
func TestSecretListWithFormat(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
secretListFunc: func(_ context.Context, options types.SecretListOptions) ([]swarm.Secret, error) {
secretListFunc: func(options types.SecretListOptions) ([]swarm.Secret, error) {
return []swarm.Secret{
*Secret(SecretID("ID-foo"), SecretName("foo")),
*Secret(SecretID("ID-bar"), SecretName("bar"), SecretLabels(map[string]string{
@ -133,7 +132,7 @@ func TestSecretListWithFormat(t *testing.T) {
func TestSecretListWithFilter(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
secretListFunc: func(_ context.Context, options types.SecretListOptions) ([]swarm.Secret, error) {
secretListFunc: func(options types.SecretListOptions) ([]swarm.Secret, error) {
assert.Check(t, is.Equal("foo", options.Filters.Get("name")[0]), "foo")
assert.Check(t, is.Equal("lbl1=Label-bar", options.Filters.Get("label")[0]))
return []swarm.Secret{

View File

@ -1,7 +1,6 @@
package secret
import (
"context"
"io"
"strings"
"testing"
@ -15,7 +14,7 @@ import (
func TestSecretRemoveErrors(t *testing.T) {
testCases := []struct {
args []string
secretRemoveFunc func(context.Context, string) error
secretRemoveFunc func(string) error
expectedError string
}{
{
@ -24,7 +23,7 @@ func TestSecretRemoveErrors(t *testing.T) {
},
{
args: []string{"foo"},
secretRemoveFunc: func(_ context.Context, name string) error {
secretRemoveFunc: func(name string) error {
return errors.Errorf("error removing secret")
},
expectedError: "error removing secret",
@ -46,7 +45,7 @@ func TestSecretRemoveWithName(t *testing.T) {
names := []string{"foo", "bar"}
var removedSecrets []string
cli := test.NewFakeCli(&fakeClient{
secretRemoveFunc: func(_ context.Context, name string) error {
secretRemoveFunc: func(name string) error {
removedSecrets = append(removedSecrets, name)
return nil
},
@ -63,7 +62,7 @@ func TestSecretRemoveContinueAfterError(t *testing.T) {
var removedSecrets []string
cli := test.NewFakeCli(&fakeClient{
secretRemoveFunc: func(_ context.Context, name string) error {
secretRemoveFunc: func(name string) error {
removedSecrets = append(removedSecrets, name)
if name == "foo" {
return errors.Errorf("error removing secret: %s", name)

View File

@ -414,7 +414,7 @@ type globalProgressUpdater struct {
done bool
}
func (u *globalProgressUpdater) update(_ swarm.Service, tasks []swarm.Task, activeNodes map[string]struct{}, rollback bool) (bool, error) {
func (u *globalProgressUpdater) update(service swarm.Service, tasks []swarm.Task, activeNodes map[string]struct{}, rollback bool) (bool, error) {
tasksByNode := u.tasksByNode(tasks)
// We don't have perfect knowledge of how many nodes meet the

View File

@ -504,23 +504,23 @@ type secretAPIClientMock struct {
listResult []swarm.Secret
}
func (s secretAPIClientMock) SecretList(context.Context, types.SecretListOptions) ([]swarm.Secret, error) {
func (s secretAPIClientMock) SecretList(ctx context.Context, options types.SecretListOptions) ([]swarm.Secret, error) {
return s.listResult, nil
}
func (s secretAPIClientMock) SecretCreate(context.Context, swarm.SecretSpec) (types.SecretCreateResponse, error) {
func (s secretAPIClientMock) SecretCreate(ctx context.Context, secret swarm.SecretSpec) (types.SecretCreateResponse, error) {
return types.SecretCreateResponse{}, nil
}
func (s secretAPIClientMock) SecretRemove(context.Context, string) error {
func (s secretAPIClientMock) SecretRemove(ctx context.Context, id string) error {
return nil
}
func (s secretAPIClientMock) SecretInspectWithRaw(context.Context, string) (swarm.Secret, []byte, error) {
func (s secretAPIClientMock) SecretInspectWithRaw(ctx context.Context, name string) (swarm.Secret, []byte, error) {
return swarm.Secret{}, []byte{}, nil
}
func (s secretAPIClientMock) SecretUpdate(context.Context, string, swarm.Version, swarm.SecretSpec) error {
func (s secretAPIClientMock) SecretUpdate(ctx context.Context, id string, version swarm.Version, secret swarm.SecretSpec) error {
return nil
}

View File

@ -43,7 +43,7 @@ type fakeClient struct {
configRemoveFunc func(configID string) error
}
func (cli *fakeClient) ServerVersion(context.Context) (types.Version, error) {
func (cli *fakeClient) ServerVersion(ctx context.Context) (types.Version, error) {
return types.Version{
Version: "docker-dev",
APIVersion: api.DefaultVersion,
@ -54,7 +54,7 @@ func (cli *fakeClient) ClientVersion() string {
return cli.version
}
func (cli *fakeClient) ServiceList(_ context.Context, options types.ServiceListOptions) ([]swarm.Service, error) {
func (cli *fakeClient) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error) {
if cli.serviceListFunc != nil {
return cli.serviceListFunc(options)
}
@ -69,7 +69,7 @@ func (cli *fakeClient) ServiceList(_ context.Context, options types.ServiceListO
return servicesList, nil
}
func (cli *fakeClient) NetworkList(_ context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) {
func (cli *fakeClient) NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) {
if cli.networkListFunc != nil {
return cli.networkListFunc(options)
}
@ -84,7 +84,7 @@ func (cli *fakeClient) NetworkList(_ context.Context, options types.NetworkListO
return networksList, nil
}
func (cli *fakeClient) SecretList(_ context.Context, options types.SecretListOptions) ([]swarm.Secret, error) {
func (cli *fakeClient) SecretList(ctx context.Context, options types.SecretListOptions) ([]swarm.Secret, error) {
if cli.secretListFunc != nil {
return cli.secretListFunc(options)
}
@ -99,7 +99,7 @@ func (cli *fakeClient) SecretList(_ context.Context, options types.SecretListOpt
return secretsList, nil
}
func (cli *fakeClient) ConfigList(_ context.Context, options types.ConfigListOptions) ([]swarm.Config, error) {
func (cli *fakeClient) ConfigList(ctx context.Context, options types.ConfigListOptions) ([]swarm.Config, error) {
if cli.configListFunc != nil {
return cli.configListFunc(options)
}
@ -114,28 +114,28 @@ func (cli *fakeClient) ConfigList(_ context.Context, options types.ConfigListOpt
return configsList, nil
}
func (cli *fakeClient) TaskList(_ context.Context, options types.TaskListOptions) ([]swarm.Task, error) {
func (cli *fakeClient) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) {
if cli.taskListFunc != nil {
return cli.taskListFunc(options)
}
return []swarm.Task{}, nil
}
func (cli *fakeClient) NodeList(_ context.Context, options types.NodeListOptions) ([]swarm.Node, error) {
func (cli *fakeClient) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error) {
if cli.nodeListFunc != nil {
return cli.nodeListFunc(options)
}
return []swarm.Node{}, nil
}
func (cli *fakeClient) NodeInspectWithRaw(_ context.Context, ref string) (swarm.Node, []byte, error) {
func (cli *fakeClient) NodeInspectWithRaw(ctx context.Context, ref string) (swarm.Node, []byte, error) {
if cli.nodeInspectWithRaw != nil {
return cli.nodeInspectWithRaw(ref)
}
return swarm.Node{}, nil, nil
}
func (cli *fakeClient) ServiceUpdate(_ context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error) {
func (cli *fakeClient) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error) {
if cli.serviceUpdateFunc != nil {
return cli.serviceUpdateFunc(serviceID, version, service, options)
}
@ -143,7 +143,7 @@ func (cli *fakeClient) ServiceUpdate(_ context.Context, serviceID string, versio
return types.ServiceUpdateResponse{}, nil
}
func (cli *fakeClient) ServiceRemove(_ context.Context, serviceID string) error {
func (cli *fakeClient) ServiceRemove(ctx context.Context, serviceID string) error {
if cli.serviceRemoveFunc != nil {
return cli.serviceRemoveFunc(serviceID)
}
@ -152,7 +152,7 @@ func (cli *fakeClient) ServiceRemove(_ context.Context, serviceID string) error
return nil
}
func (cli *fakeClient) NetworkRemove(_ context.Context, networkID string) error {
func (cli *fakeClient) NetworkRemove(ctx context.Context, networkID string) error {
if cli.networkRemoveFunc != nil {
return cli.networkRemoveFunc(networkID)
}
@ -161,7 +161,7 @@ func (cli *fakeClient) NetworkRemove(_ context.Context, networkID string) error
return nil
}
func (cli *fakeClient) SecretRemove(_ context.Context, secretID string) error {
func (cli *fakeClient) SecretRemove(ctx context.Context, secretID string) error {
if cli.secretRemoveFunc != nil {
return cli.secretRemoveFunc(secretID)
}
@ -170,7 +170,7 @@ func (cli *fakeClient) SecretRemove(_ context.Context, secretID string) error {
return nil
}
func (cli *fakeClient) ConfigRemove(_ context.Context, configID string) error {
func (cli *fakeClient) ConfigRemove(ctx context.Context, configID string) error {
if cli.configRemoveFunc != nil {
return cli.configRemoveFunc(configID)
}
@ -179,7 +179,7 @@ func (cli *fakeClient) ConfigRemove(_ context.Context, configID string) error {
return nil
}
func (cli *fakeClient) ServiceInspectWithRaw(_ context.Context, serviceID string, _ types.ServiceInspectOptions) (swarm.Service, []byte, error) {
func (cli *fakeClient) ServiceInspectWithRaw(ctx context.Context, serviceID string, opts types.ServiceInspectOptions) (swarm.Service, []byte, error) {
return swarm.Service{
ID: serviceID,
Spec: swarm.ServiceSpec{

View File

@ -28,7 +28,7 @@ func newDeployCommand(dockerCli command.Cli) *cobra.Command {
if err != nil {
return err
}
return swarm.RunDeploy(dockerCli, opts, config)
return RunDeploy(dockerCli, cmd.Flags(), config, opts)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completeNames(dockerCli)(cmd, args, toComplete)
@ -47,9 +47,7 @@ func newDeployCommand(dockerCli command.Cli) *cobra.Command {
return cmd
}
// RunDeploy performs a stack deploy against the specified swarm cluster.
//
// Deprecated: use [swarm.RunDeploy] instead.
func RunDeploy(dockerCli command.Cli, _ *pflag.FlagSet, config *composetypes.Config, opts options.Deploy) error {
// RunDeploy performs a stack deploy against the specified swarm cluster
func RunDeploy(dockerCli command.Cli, flags *pflag.FlagSet, config *composetypes.Config, opts options.Deploy) error {
return swarm.RunDeploy(dockerCli, opts, config)
}

View File

@ -23,7 +23,7 @@ func newListCommand(dockerCli command.Cli) *cobra.Command {
Short: "List stacks",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return RunList(dockerCli, opts)
return RunList(cmd, dockerCli, opts)
},
ValidArgsFunction: completion.NoComplete,
}
@ -34,24 +34,24 @@ func newListCommand(dockerCli command.Cli) *cobra.Command {
}
// RunList performs a stack list against the specified swarm cluster
func RunList(dockerCli command.Cli, opts options.List) error {
func RunList(cmd *cobra.Command, dockerCli command.Cli, opts options.List) error {
stacks := []*formatter.Stack{}
ss, err := swarm.GetStacks(dockerCli)
if err != nil {
return err
}
stacks := make([]*formatter.Stack, 0, len(ss))
stacks = append(stacks, ss...)
return format(dockerCli, opts, stacks)
}
func format(dockerCli command.Cli, opts options.List, stacks []*formatter.Stack) error {
fmt := formatter.Format(opts.Format)
if fmt == "" || fmt == formatter.TableFormatKey {
fmt = formatter.SwarmStackTableFormat
format := formatter.Format(opts.Format)
if format == "" || format == formatter.TableFormatKey {
format = formatter.SwarmStackTableFormat
}
stackCtx := formatter.Context{
Output: dockerCli.Out(),
Format: fmt,
Format: format,
}
sort.Slice(stacks, func(i, j int) bool {
return sortorder.NaturalLess(stacks[i].Name, stacks[j].Name) ||

View File

@ -23,7 +23,7 @@ func newPsCommand(dockerCli command.Cli) *cobra.Command {
if err := validateStackName(opts.Namespace); err != nil {
return err
}
return swarm.RunPS(dockerCli, opts)
return RunPs(dockerCli, cmd.Flags(), opts)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completeNames(dockerCli)(cmd, args, toComplete)
@ -38,9 +38,7 @@ func newPsCommand(dockerCli command.Cli) *cobra.Command {
return cmd
}
// RunPs performs a stack ps against the specified swarm cluster.
//
// Deprecated: use [swarm.RunPS] instead.
func RunPs(dockerCli command.Cli, _ *pflag.FlagSet, opts options.PS) error {
// RunPs performs a stack ps against the specified swarm cluster
func RunPs(dockerCli command.Cli, flags *pflag.FlagSet, opts options.PS) error {
return swarm.RunPS(dockerCli, opts)
}

View File

@ -22,7 +22,7 @@ func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
if err := validateStackNames(opts.Namespaces); err != nil {
return err
}
return swarm.RunRemove(dockerCli, opts)
return RunRemove(dockerCli, cmd.Flags(), opts)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completeNames(dockerCli)(cmd, args, toComplete)
@ -31,9 +31,7 @@ func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
return cmd
}
// RunRemove performs a stack remove against the specified swarm cluster.
//
// Deprecated: use [swarm.RunRemove] instead.
func RunRemove(dockerCli command.Cli, _ *pflag.FlagSet, opts options.Remove) error {
// RunRemove performs a stack remove against the specified swarm cluster
func RunRemove(dockerCli command.Cli, flags *pflag.FlagSet, opts options.Remove) error {
return swarm.RunRemove(dockerCli, opts)
}

View File

@ -30,7 +30,7 @@ func newServicesCommand(dockerCli command.Cli) *cobra.Command {
if err := validateStackName(opts.Namespace); err != nil {
return err
}
return RunServices(dockerCli, opts)
return RunServices(dockerCli, cmd.Flags(), opts)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completeNames(dockerCli)(cmd, args, toComplete)
@ -44,18 +44,16 @@ func newServicesCommand(dockerCli command.Cli) *cobra.Command {
}
// RunServices performs a stack services against the specified swarm cluster
func RunServices(dockerCli command.Cli, opts options.Services) error {
services, err := swarm.GetServices(dockerCli, opts)
func RunServices(dockerCli command.Cli, flags *pflag.FlagSet, opts options.Services) error {
services, err := GetServices(dockerCli, flags, opts)
if err != nil {
return err
}
return formatWrite(dockerCli, services, opts)
}
// GetServices returns the services for the specified swarm cluster.
//
// Deprecated: use [swarm.GetServices] instead.
func GetServices(dockerCli command.Cli, _ *pflag.FlagSet, opts options.Services) ([]swarmtypes.Service, error) {
// GetServices returns the services for the specified swarm cluster
func GetServices(dockerCli command.Cli, flags *pflag.FlagSet, opts options.Services) ([]swarmtypes.Service, error) {
return swarm.GetServices(dockerCli, opts)
}

View File

@ -43,7 +43,7 @@ type fakeClient struct {
configRemoveFunc func(configID string) error
}
func (cli *fakeClient) ServerVersion(context.Context) (types.Version, error) {
func (cli *fakeClient) ServerVersion(ctx context.Context) (types.Version, error) {
return types.Version{
Version: "docker-dev",
APIVersion: api.DefaultVersion,
@ -54,7 +54,7 @@ func (cli *fakeClient) ClientVersion() string {
return cli.version
}
func (cli *fakeClient) ServiceList(_ context.Context, options types.ServiceListOptions) ([]swarm.Service, error) {
func (cli *fakeClient) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error) {
if cli.serviceListFunc != nil {
return cli.serviceListFunc(options)
}
@ -69,7 +69,7 @@ func (cli *fakeClient) ServiceList(_ context.Context, options types.ServiceListO
return servicesList, nil
}
func (cli *fakeClient) NetworkList(_ context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) {
func (cli *fakeClient) NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) {
if cli.networkListFunc != nil {
return cli.networkListFunc(options)
}
@ -84,7 +84,7 @@ func (cli *fakeClient) NetworkList(_ context.Context, options types.NetworkListO
return networksList, nil
}
func (cli *fakeClient) SecretList(_ context.Context, options types.SecretListOptions) ([]swarm.Secret, error) {
func (cli *fakeClient) SecretList(ctx context.Context, options types.SecretListOptions) ([]swarm.Secret, error) {
if cli.secretListFunc != nil {
return cli.secretListFunc(options)
}
@ -99,7 +99,7 @@ func (cli *fakeClient) SecretList(_ context.Context, options types.SecretListOpt
return secretsList, nil
}
func (cli *fakeClient) ConfigList(_ context.Context, options types.ConfigListOptions) ([]swarm.Config, error) {
func (cli *fakeClient) ConfigList(ctx context.Context, options types.ConfigListOptions) ([]swarm.Config, error) {
if cli.configListFunc != nil {
return cli.configListFunc(options)
}
@ -114,28 +114,28 @@ func (cli *fakeClient) ConfigList(_ context.Context, options types.ConfigListOpt
return configsList, nil
}
func (cli *fakeClient) TaskList(_ context.Context, options types.TaskListOptions) ([]swarm.Task, error) {
func (cli *fakeClient) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) {
if cli.taskListFunc != nil {
return cli.taskListFunc(options)
}
return []swarm.Task{}, nil
}
func (cli *fakeClient) NodeList(_ context.Context, options types.NodeListOptions) ([]swarm.Node, error) {
func (cli *fakeClient) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error) {
if cli.nodeListFunc != nil {
return cli.nodeListFunc(options)
}
return []swarm.Node{}, nil
}
func (cli *fakeClient) NodeInspectWithRaw(_ context.Context, ref string) (swarm.Node, []byte, error) {
func (cli *fakeClient) NodeInspectWithRaw(ctx context.Context, ref string) (swarm.Node, []byte, error) {
if cli.nodeInspectWithRaw != nil {
return cli.nodeInspectWithRaw(ref)
}
return swarm.Node{}, nil, nil
}
func (cli *fakeClient) ServiceUpdate(_ context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error) {
func (cli *fakeClient) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error) {
if cli.serviceUpdateFunc != nil {
return cli.serviceUpdateFunc(serviceID, version, service, options)
}
@ -143,7 +143,7 @@ func (cli *fakeClient) ServiceUpdate(_ context.Context, serviceID string, versio
return types.ServiceUpdateResponse{}, nil
}
func (cli *fakeClient) ServiceRemove(_ context.Context, serviceID string) error {
func (cli *fakeClient) ServiceRemove(ctx context.Context, serviceID string) error {
if cli.serviceRemoveFunc != nil {
return cli.serviceRemoveFunc(serviceID)
}
@ -152,7 +152,7 @@ func (cli *fakeClient) ServiceRemove(_ context.Context, serviceID string) error
return nil
}
func (cli *fakeClient) NetworkRemove(_ context.Context, networkID string) error {
func (cli *fakeClient) NetworkRemove(ctx context.Context, networkID string) error {
if cli.networkRemoveFunc != nil {
return cli.networkRemoveFunc(networkID)
}
@ -161,7 +161,7 @@ func (cli *fakeClient) NetworkRemove(_ context.Context, networkID string) error
return nil
}
func (cli *fakeClient) SecretRemove(_ context.Context, secretID string) error {
func (cli *fakeClient) SecretRemove(ctx context.Context, secretID string) error {
if cli.secretRemoveFunc != nil {
return cli.secretRemoveFunc(secretID)
}
@ -170,7 +170,7 @@ func (cli *fakeClient) SecretRemove(_ context.Context, secretID string) error {
return nil
}
func (cli *fakeClient) ConfigRemove(_ context.Context, configID string) error {
func (cli *fakeClient) ConfigRemove(ctx context.Context, configID string) error {
if cli.configRemoveFunc != nil {
return cli.configRemoveFunc(configID)
}

32
cli/command/streams.go Normal file
View File

@ -0,0 +1,32 @@
package command
import (
"io"
"github.com/docker/cli/cli/streams"
)
// InStream is an input stream used by the DockerCli to read user input
//
// Deprecated: Use [streams.In] instead.
type InStream = streams.In
// OutStream is an output stream used by the DockerCli to write normal program
// output.
//
// Deprecated: Use [streams.Out] instead.
type OutStream = streams.Out
// NewInStream returns a new [streams.In] from an [io.ReadCloser].
//
// Deprecated: Use [streams.NewIn] instead.
func NewInStream(in io.ReadCloser) *streams.In {
return streams.NewIn(in)
}
// NewOutStream returns a new [streams.Out] from an [io.Writer].
//
// Deprecated: Use [streams.NewOut] instead.
func NewOutStream(out io.Writer) *streams.Out {
return streams.NewOut(out)
}

View File

@ -21,63 +21,63 @@ type fakeClient struct {
swarmUnlockFunc func(req swarm.UnlockRequest) error
}
func (cli *fakeClient) Info(context.Context) (types.Info, error) {
func (cli *fakeClient) Info(ctx context.Context) (types.Info, error) {
if cli.infoFunc != nil {
return cli.infoFunc()
}
return types.Info{}, nil
}
func (cli *fakeClient) NodeInspectWithRaw(context.Context, string) (swarm.Node, []byte, error) {
func (cli *fakeClient) NodeInspectWithRaw(ctx context.Context, ref string) (swarm.Node, []byte, error) {
if cli.nodeInspectFunc != nil {
return cli.nodeInspectFunc()
}
return swarm.Node{}, []byte{}, nil
}
func (cli *fakeClient) SwarmInit(context.Context, swarm.InitRequest) (string, error) {
func (cli *fakeClient) SwarmInit(ctx context.Context, req swarm.InitRequest) (string, error) {
if cli.swarmInitFunc != nil {
return cli.swarmInitFunc()
}
return "", nil
}
func (cli *fakeClient) SwarmInspect(context.Context) (swarm.Swarm, error) {
func (cli *fakeClient) SwarmInspect(ctx context.Context) (swarm.Swarm, error) {
if cli.swarmInspectFunc != nil {
return cli.swarmInspectFunc()
}
return swarm.Swarm{}, nil
}
func (cli *fakeClient) SwarmGetUnlockKey(context.Context) (types.SwarmUnlockKeyResponse, error) {
func (cli *fakeClient) SwarmGetUnlockKey(ctx context.Context) (types.SwarmUnlockKeyResponse, error) {
if cli.swarmGetUnlockKeyFunc != nil {
return cli.swarmGetUnlockKeyFunc()
}
return types.SwarmUnlockKeyResponse{}, nil
}
func (cli *fakeClient) SwarmJoin(context.Context, swarm.JoinRequest) error {
func (cli *fakeClient) SwarmJoin(ctx context.Context, req swarm.JoinRequest) error {
if cli.swarmJoinFunc != nil {
return cli.swarmJoinFunc()
}
return nil
}
func (cli *fakeClient) SwarmLeave(context.Context, bool) error {
func (cli *fakeClient) SwarmLeave(ctx context.Context, force bool) error {
if cli.swarmLeaveFunc != nil {
return cli.swarmLeaveFunc()
}
return nil
}
func (cli *fakeClient) SwarmUpdate(_ context.Context, _ swarm.Version, swarm swarm.Spec, flags swarm.UpdateFlags) error {
func (cli *fakeClient) SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags swarm.UpdateFlags) error {
if cli.swarmUpdateFunc != nil {
return cli.swarmUpdateFunc(swarm, flags)
}
return nil
}
func (cli *fakeClient) SwarmUnlock(_ context.Context, req swarm.UnlockRequest) error {
func (cli *fakeClient) SwarmUnlock(ctx context.Context, req swarm.UnlockRequest) error {
if cli.swarmUnlockFunc != nil {
return cli.swarmUnlockFunc(req)
}

View File

@ -10,7 +10,7 @@ import (
)
// Helper function to set static slices
func getCIDR(_ net.IP, cidr *net.IPNet, _ error) net.IPNet {
func getCIDR(ip net.IP, cidr *net.IPNet, err error) net.IPNet {
return *cidr
}

View File

@ -12,14 +12,11 @@ import (
pluginmanager "github.com/docker/cli/cli-plugins/manager"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/cli/debug"
flagsHelper "github.com/docker/cli/cli/flags"
"github.com/docker/cli/templates"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/registry"
"github.com/docker/go-units"
"github.com/spf13/cobra"
)
@ -29,8 +26,8 @@ type infoOptions struct {
}
type clientInfo struct {
Debug bool
clientVersion
Debug bool
Context string
Plugins []pluginmanager.Plugin
Warnings []string
}
@ -42,19 +39,11 @@ type info struct {
// object.
*types.Info `json:",omitempty"`
ServerErrors []string `json:",omitempty"`
UserName string `json:"-"`
ClientInfo *clientInfo `json:",omitempty"`
ClientErrors []string `json:",omitempty"`
}
func (i *info) clientPlatform() string {
if i.ClientInfo != nil && i.ClientInfo.Platform != nil {
return i.ClientInfo.Platform.Name
}
return ""
}
// NewInfoCommand creates a new cobra.Command for `docker info`
func NewInfoCommand(dockerCli command.Cli) *cobra.Command {
var opts infoOptions
@ -73,18 +62,18 @@ func NewInfoCommand(dockerCli command.Cli) *cobra.Command {
ValidArgsFunction: completion.NoComplete,
}
cmd.Flags().StringVarP(&opts.format, "format", "f", "", flagsHelper.InspectFormatHelp)
flags := cmd.Flags()
flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template")
return cmd
}
func runInfo(cmd *cobra.Command, dockerCli command.Cli, opts *infoOptions) error {
info := info{
ClientInfo: &clientInfo{
// Don't pass a dockerCLI to newClientVersion(), because we currently
// don't include negotiated API version, and want to avoid making an
// API connection when only printing the Client section.
clientVersion: newClientVersion(dockerCli.CurrentContext(), nil),
Debug: debug.IsEnabled(),
Context: dockerCli.CurrentContext(),
Debug: debug.IsEnabled(),
},
Info: &types.Info{},
}
@ -108,17 +97,15 @@ func runInfo(cmd *cobra.Command, dockerCli command.Cli, opts *infoOptions) error
} else {
// if a format is provided, print the error, as it may be hidden
// otherwise if the template doesn't include the ServerErrors field.
fprintln(dockerCli.Err(), err)
fmt.Fprintln(dockerCli.Err(), err)
}
}
}
if opts.format == "" {
info.UserName = dockerCli.ConfigFile().AuthConfigs[registry.IndexServer].Username
info.ClientInfo.APIVersion = dockerCli.CurrentVersion()
return prettyPrintInfo(dockerCli, info)
}
return formatInfo(dockerCli.Out(), info, opts.format)
return formatInfo(dockerCli, info, opts.format)
}
// placeHolders does a rudimentary match for possible placeholders in a
@ -160,29 +147,24 @@ func needsServerInfo(template string, info info) bool {
return err != nil
}
func prettyPrintInfo(streams command.Streams, info info) error {
// Only append the platform info if it's not empty, to prevent printing a trailing space.
if p := info.clientPlatform(); p != "" {
fprintln(streams.Out(), "Client:", p)
} else {
fprintln(streams.Out(), "Client:")
}
func prettyPrintInfo(dockerCli command.Cli, info info) error {
fmt.Fprintln(dockerCli.Out(), "Client:")
if info.ClientInfo != nil {
prettyPrintClientInfo(streams, *info.ClientInfo)
prettyPrintClientInfo(dockerCli, *info.ClientInfo)
}
for _, err := range info.ClientErrors {
fprintln(streams.Err(), "ERROR:", err)
fmt.Fprintln(dockerCli.Err(), "ERROR:", err)
}
fprintln(streams.Out())
fprintln(streams.Out(), "Server:")
fmt.Fprintln(dockerCli.Out())
fmt.Fprintln(dockerCli.Out(), "Server:")
if info.Info != nil {
for _, err := range prettyPrintServerInfo(streams, &info) {
for _, err := range prettyPrintServerInfo(dockerCli, *info.Info) {
info.ServerErrors = append(info.ServerErrors, err.Error())
}
}
for _, err := range info.ServerErrors {
fprintln(streams.Err(), "ERROR:", err)
fmt.Fprintln(dockerCli.Err(), "ERROR:", err)
}
if len(info.ServerErrors) > 0 || len(info.ClientErrors) > 0 {
@ -191,18 +173,17 @@ func prettyPrintInfo(streams command.Streams, info info) error {
return nil
}
func prettyPrintClientInfo(streams command.Streams, info clientInfo) {
fprintlnNonEmpty(streams.Out(), " Version: ", info.Version)
fprintln(streams.Out(), " Context: ", info.Context)
fprintln(streams.Out(), " Debug Mode:", info.Debug)
func prettyPrintClientInfo(dockerCli command.Cli, info clientInfo) {
fmt.Fprintln(dockerCli.Out(), " Context: ", info.Context)
fmt.Fprintln(dockerCli.Out(), " Debug Mode:", info.Debug)
if len(info.Plugins) > 0 {
fprintln(streams.Out(), " Plugins:")
fmt.Fprintln(dockerCli.Out(), " Plugins:")
for _, p := range info.Plugins {
if p.Err == nil {
fprintf(streams.Out(), " %s: %s (%s)\n", p.Name, p.ShortDescription, p.Vendor)
fprintlnNonEmpty(streams.Out(), " Version: ", p.Version)
fprintlnNonEmpty(streams.Out(), " Path: ", p.Path)
fmt.Fprintf(dockerCli.Out(), " %s: %s (%s)\n", p.Name, p.ShortDescription, p.Vendor)
fprintlnNonEmpty(dockerCli.Out(), " Version: ", p.Version)
fprintlnNonEmpty(dockerCli.Out(), " Path: ", p.Path)
} else {
info.Warnings = append(info.Warnings, fmt.Sprintf("WARNING: Plugin %q is not valid: %s", p.Path, p.Err))
}
@ -210,60 +191,59 @@ func prettyPrintClientInfo(streams command.Streams, info clientInfo) {
}
if len(info.Warnings) > 0 {
fprintln(streams.Err(), strings.Join(info.Warnings, "\n"))
fmt.Fprintln(dockerCli.Err(), strings.Join(info.Warnings, "\n"))
}
}
//nolint:gocyclo
func prettyPrintServerInfo(streams command.Streams, info *info) []error {
func prettyPrintServerInfo(dockerCli command.Cli, info types.Info) []error {
var errs []error
output := streams.Out()
fprintln(output, " Containers:", info.Containers)
fprintln(output, " Running:", info.ContainersRunning)
fprintln(output, " Paused:", info.ContainersPaused)
fprintln(output, " Stopped:", info.ContainersStopped)
fprintln(output, " Images:", info.Images)
fprintlnNonEmpty(output, " Server Version:", info.ServerVersion)
fprintlnNonEmpty(output, " Storage Driver:", info.Driver)
fmt.Fprintln(dockerCli.Out(), " Containers:", info.Containers)
fmt.Fprintln(dockerCli.Out(), " Running:", info.ContainersRunning)
fmt.Fprintln(dockerCli.Out(), " Paused:", info.ContainersPaused)
fmt.Fprintln(dockerCli.Out(), " Stopped:", info.ContainersStopped)
fmt.Fprintln(dockerCli.Out(), " Images:", info.Images)
fprintlnNonEmpty(dockerCli.Out(), " Server Version:", info.ServerVersion)
fprintlnNonEmpty(dockerCli.Out(), " Storage Driver:", info.Driver)
if info.DriverStatus != nil {
for _, pair := range info.DriverStatus {
fprintf(output, " %s: %s\n", pair[0], pair[1])
fmt.Fprintf(dockerCli.Out(), " %s: %s\n", pair[0], pair[1])
}
}
if info.SystemStatus != nil {
for _, pair := range info.SystemStatus {
fprintf(output, " %s: %s\n", pair[0], pair[1])
fmt.Fprintf(dockerCli.Out(), " %s: %s\n", pair[0], pair[1])
}
}
fprintlnNonEmpty(output, " Logging Driver:", info.LoggingDriver)
fprintlnNonEmpty(output, " Cgroup Driver:", info.CgroupDriver)
fprintlnNonEmpty(output, " Cgroup Version:", info.CgroupVersion)
fprintlnNonEmpty(dockerCli.Out(), " Logging Driver:", info.LoggingDriver)
fprintlnNonEmpty(dockerCli.Out(), " Cgroup Driver:", info.CgroupDriver)
fprintlnNonEmpty(dockerCli.Out(), " Cgroup Version:", info.CgroupVersion)
fprintln(output, " Plugins:")
fprintln(output, " Volume:", strings.Join(info.Plugins.Volume, " "))
fprintln(output, " Network:", strings.Join(info.Plugins.Network, " "))
fmt.Fprintln(dockerCli.Out(), " Plugins:")
fmt.Fprintln(dockerCli.Out(), " Volume:", strings.Join(info.Plugins.Volume, " "))
fmt.Fprintln(dockerCli.Out(), " Network:", strings.Join(info.Plugins.Network, " "))
if len(info.Plugins.Authorization) != 0 {
fprintln(output, " Authorization:", strings.Join(info.Plugins.Authorization, " "))
fmt.Fprintln(dockerCli.Out(), " Authorization:", strings.Join(info.Plugins.Authorization, " "))
}
fprintln(output, " Log:", strings.Join(info.Plugins.Log, " "))
fmt.Fprintln(dockerCli.Out(), " Log:", strings.Join(info.Plugins.Log, " "))
fprintln(output, " Swarm:", info.Swarm.LocalNodeState)
printSwarmInfo(output, *info.Info)
fmt.Fprintln(dockerCli.Out(), " Swarm:", info.Swarm.LocalNodeState)
printSwarmInfo(dockerCli, info)
if len(info.Runtimes) > 0 {
names := make([]string, 0, len(info.Runtimes))
fmt.Fprint(dockerCli.Out(), " Runtimes:")
for name := range info.Runtimes {
names = append(names, name)
fmt.Fprintf(dockerCli.Out(), " %s", name)
}
fprintln(output, " Runtimes:", strings.Join(names, " "))
fprintln(output, " Default Runtime:", info.DefaultRuntime)
fmt.Fprint(dockerCli.Out(), "\n")
fmt.Fprintln(dockerCli.Out(), " Default Runtime:", info.DefaultRuntime)
}
if info.OSType == "linux" {
fprintln(output, " Init Binary:", info.InitBinary)
fmt.Fprintln(dockerCli.Out(), " Init Binary:", info.InitBinary)
for _, ci := range []struct {
Name string
@ -273,23 +253,23 @@ func prettyPrintServerInfo(streams command.Streams, info *info) []error {
{"runc", info.RuncCommit},
{"init", info.InitCommit},
} {
fprintf(output, " %s version: %s", ci.Name, ci.Commit.ID)
fmt.Fprintf(dockerCli.Out(), " %s version: %s", ci.Name, ci.Commit.ID)
if ci.Commit.ID != ci.Commit.Expected {
fprintf(output, " (expected: %s)", ci.Commit.Expected)
fmt.Fprintf(dockerCli.Out(), " (expected: %s)", ci.Commit.Expected)
}
fprintln(output)
fmt.Fprint(dockerCli.Out(), "\n")
}
if len(info.SecurityOptions) != 0 {
if kvs, err := types.DecodeSecurityOptions(info.SecurityOptions); err != nil {
errs = append(errs, err)
} else {
fprintln(output, " Security Options:")
fmt.Fprintln(dockerCli.Out(), " Security Options:")
for _, so := range kvs {
fprintln(output, " "+so.Name)
fmt.Fprintln(dockerCli.Out(), " "+so.Name)
for _, o := range so.Options {
switch o.Key {
case "profile":
fprintln(output, " Profile:", o.Value)
fmt.Fprintln(dockerCli.Out(), " Profile:", o.Value)
}
}
}
@ -299,163 +279,167 @@ func prettyPrintServerInfo(streams command.Streams, info *info) []error {
// Isolation only has meaning on a Windows daemon.
if info.OSType == "windows" {
fprintln(output, " Default Isolation:", info.Isolation)
fmt.Fprintln(dockerCli.Out(), " Default Isolation:", info.Isolation)
}
fprintlnNonEmpty(output, " Kernel Version:", info.KernelVersion)
fprintlnNonEmpty(output, " Operating System:", info.OperatingSystem)
fprintlnNonEmpty(output, " OSType:", info.OSType)
fprintlnNonEmpty(output, " Architecture:", info.Architecture)
fprintln(output, " CPUs:", info.NCPU)
fprintln(output, " Total Memory:", units.BytesSize(float64(info.MemTotal)))
fprintlnNonEmpty(output, " Name:", info.Name)
fprintlnNonEmpty(output, " ID:", info.ID)
fprintln(output, " Docker Root Dir:", info.DockerRootDir)
fprintln(output, " Debug Mode:", info.Debug)
fprintlnNonEmpty(dockerCli.Out(), " Kernel Version:", info.KernelVersion)
fprintlnNonEmpty(dockerCli.Out(), " Operating System:", info.OperatingSystem)
fprintlnNonEmpty(dockerCli.Out(), " OSType:", info.OSType)
fprintlnNonEmpty(dockerCli.Out(), " Architecture:", info.Architecture)
fmt.Fprintln(dockerCli.Out(), " CPUs:", info.NCPU)
fmt.Fprintln(dockerCli.Out(), " Total Memory:", units.BytesSize(float64(info.MemTotal)))
fprintlnNonEmpty(dockerCli.Out(), " Name:", info.Name)
fprintlnNonEmpty(dockerCli.Out(), " ID:", info.ID)
fmt.Fprintln(dockerCli.Out(), " Docker Root Dir:", info.DockerRootDir)
fmt.Fprintln(dockerCli.Out(), " Debug Mode:", info.Debug)
// The daemon collects this information regardless if "debug" is
// enabled. Print the debugging information if either the daemon,
// or the client has debug enabled. We should probably improve this
// logic and print any of these if set (but some special rules are
// needed for file-descriptors, which may use "-1".
if info.Debug || debug.IsEnabled() {
fprintln(output, " File Descriptors:", info.NFd)
fprintln(output, " Goroutines:", info.NGoroutines)
fprintln(output, " System Time:", info.SystemTime)
fprintln(output, " EventsListeners:", info.NEventsListener)
if info.Debug {
fmt.Fprintln(dockerCli.Out(), " File Descriptors:", info.NFd)
fmt.Fprintln(dockerCli.Out(), " Goroutines:", info.NGoroutines)
fmt.Fprintln(dockerCli.Out(), " System Time:", info.SystemTime)
fmt.Fprintln(dockerCli.Out(), " EventsListeners:", info.NEventsListener)
}
fprintlnNonEmpty(dockerCli.Out(), " HTTP Proxy:", info.HTTPProxy)
fprintlnNonEmpty(dockerCli.Out(), " HTTPS Proxy:", info.HTTPSProxy)
fprintlnNonEmpty(dockerCli.Out(), " No Proxy:", info.NoProxy)
if info.IndexServerAddress != "" {
u := dockerCli.ConfigFile().AuthConfigs[info.IndexServerAddress].Username
if len(u) > 0 {
fmt.Fprintln(dockerCli.Out(), " Username:", u)
}
fmt.Fprintln(dockerCli.Out(), " Registry:", info.IndexServerAddress)
}
fprintlnNonEmpty(output, " HTTP Proxy:", info.HTTPProxy)
fprintlnNonEmpty(output, " HTTPS Proxy:", info.HTTPSProxy)
fprintlnNonEmpty(output, " No Proxy:", info.NoProxy)
fprintlnNonEmpty(output, " Username:", info.UserName)
if len(info.Labels) > 0 {
fprintln(output, " Labels:")
fmt.Fprintln(dockerCli.Out(), " Labels:")
for _, lbl := range info.Labels {
fprintln(output, " "+lbl)
fmt.Fprintln(dockerCli.Out(), " "+lbl)
}
}
fprintln(output, " Experimental:", info.ExperimentalBuild)
fmt.Fprintln(dockerCli.Out(), " Experimental:", info.ExperimentalBuild)
if info.RegistryConfig != nil && (len(info.RegistryConfig.InsecureRegistryCIDRs) > 0 || len(info.RegistryConfig.IndexConfigs) > 0) {
fprintln(output, " Insecure Registries:")
for _, registryConfig := range info.RegistryConfig.IndexConfigs {
if !registryConfig.Secure {
fprintln(output, " "+registryConfig.Name)
fmt.Fprintln(dockerCli.Out(), " Insecure Registries:")
for _, registry := range info.RegistryConfig.IndexConfigs {
if !registry.Secure {
fmt.Fprintln(dockerCli.Out(), " "+registry.Name)
}
}
for _, registryConfig := range info.RegistryConfig.InsecureRegistryCIDRs {
mask, _ := registryConfig.Mask.Size()
fprintf(output, " %s/%d\n", registryConfig.IP.String(), mask)
for _, registry := range info.RegistryConfig.InsecureRegistryCIDRs {
mask, _ := registry.Mask.Size()
fmt.Fprintf(dockerCli.Out(), " %s/%d\n", registry.IP.String(), mask)
}
}
if info.RegistryConfig != nil && len(info.RegistryConfig.Mirrors) > 0 {
fprintln(output, " Registry Mirrors:")
fmt.Fprintln(dockerCli.Out(), " Registry Mirrors:")
for _, mirror := range info.RegistryConfig.Mirrors {
fprintln(output, " "+mirror)
fmt.Fprintln(dockerCli.Out(), " "+mirror)
}
}
fprintln(output, " Live Restore Enabled:", info.LiveRestoreEnabled)
fmt.Fprintln(dockerCli.Out(), " Live Restore Enabled:", info.LiveRestoreEnabled)
if info.ProductLicense != "" {
fprintln(output, " Product License:", info.ProductLicense)
fmt.Fprintln(dockerCli.Out(), " Product License:", info.ProductLicense)
}
if info.DefaultAddressPools != nil && len(info.DefaultAddressPools) > 0 {
fprintln(output, " Default Address Pools:")
fmt.Fprintln(dockerCli.Out(), " Default Address Pools:")
for _, pool := range info.DefaultAddressPools {
fprintf(output, " Base: %s, Size: %d\n", pool.Base, pool.Size)
fmt.Fprintf(dockerCli.Out(), " Base: %s, Size: %d\n", pool.Base, pool.Size)
}
}
fprintln(output)
printServerWarnings(streams.Err(), info)
fmt.Fprint(dockerCli.Out(), "\n")
printServerWarnings(dockerCli, info)
return errs
}
//nolint:gocyclo
func printSwarmInfo(output io.Writer, info types.Info) {
func printSwarmInfo(dockerCli command.Cli, info types.Info) {
if info.Swarm.LocalNodeState == swarm.LocalNodeStateInactive || info.Swarm.LocalNodeState == swarm.LocalNodeStateLocked {
return
}
fprintln(output, " NodeID:", info.Swarm.NodeID)
fmt.Fprintln(dockerCli.Out(), " NodeID:", info.Swarm.NodeID)
if info.Swarm.Error != "" {
fprintln(output, " Error:", info.Swarm.Error)
fmt.Fprintln(dockerCli.Out(), " Error:", info.Swarm.Error)
}
fprintln(output, " Is Manager:", info.Swarm.ControlAvailable)
fmt.Fprintln(dockerCli.Out(), " Is Manager:", info.Swarm.ControlAvailable)
if info.Swarm.Cluster != nil && info.Swarm.ControlAvailable && info.Swarm.Error == "" && info.Swarm.LocalNodeState != swarm.LocalNodeStateError {
fprintln(output, " ClusterID:", info.Swarm.Cluster.ID)
fprintln(output, " Managers:", info.Swarm.Managers)
fprintln(output, " Nodes:", info.Swarm.Nodes)
fmt.Fprintln(dockerCli.Out(), " ClusterID:", info.Swarm.Cluster.ID)
fmt.Fprintln(dockerCli.Out(), " Managers:", info.Swarm.Managers)
fmt.Fprintln(dockerCli.Out(), " Nodes:", info.Swarm.Nodes)
var strAddrPool strings.Builder
if info.Swarm.Cluster.DefaultAddrPool != nil {
for _, p := range info.Swarm.Cluster.DefaultAddrPool {
strAddrPool.WriteString(p + " ")
}
fprintln(output, " Default Address Pool:", strAddrPool.String())
fprintln(output, " SubnetSize:", info.Swarm.Cluster.SubnetSize)
fmt.Fprintln(dockerCli.Out(), " Default Address Pool:", strAddrPool.String())
fmt.Fprintln(dockerCli.Out(), " SubnetSize:", info.Swarm.Cluster.SubnetSize)
}
if info.Swarm.Cluster.DataPathPort > 0 {
fprintln(output, " Data Path Port:", info.Swarm.Cluster.DataPathPort)
fmt.Fprintln(dockerCli.Out(), " Data Path Port:", info.Swarm.Cluster.DataPathPort)
}
fprintln(output, " Orchestration:")
fmt.Fprintln(dockerCli.Out(), " Orchestration:")
taskHistoryRetentionLimit := int64(0)
if info.Swarm.Cluster.Spec.Orchestration.TaskHistoryRetentionLimit != nil {
taskHistoryRetentionLimit = *info.Swarm.Cluster.Spec.Orchestration.TaskHistoryRetentionLimit
}
fprintln(output, " Task History Retention Limit:", taskHistoryRetentionLimit)
fprintln(output, " Raft:")
fprintln(output, " Snapshot Interval:", info.Swarm.Cluster.Spec.Raft.SnapshotInterval)
fmt.Fprintln(dockerCli.Out(), " Task History Retention Limit:", taskHistoryRetentionLimit)
fmt.Fprintln(dockerCli.Out(), " Raft:")
fmt.Fprintln(dockerCli.Out(), " Snapshot Interval:", info.Swarm.Cluster.Spec.Raft.SnapshotInterval)
if info.Swarm.Cluster.Spec.Raft.KeepOldSnapshots != nil {
fprintf(output, " Number of Old Snapshots to Retain: %d\n", *info.Swarm.Cluster.Spec.Raft.KeepOldSnapshots)
fmt.Fprintf(dockerCli.Out(), " Number of Old Snapshots to Retain: %d\n", *info.Swarm.Cluster.Spec.Raft.KeepOldSnapshots)
}
fprintln(output, " Heartbeat Tick:", info.Swarm.Cluster.Spec.Raft.HeartbeatTick)
fprintln(output, " Election Tick:", info.Swarm.Cluster.Spec.Raft.ElectionTick)
fprintln(output, " Dispatcher:")
fprintln(output, " Heartbeat Period:", units.HumanDuration(info.Swarm.Cluster.Spec.Dispatcher.HeartbeatPeriod))
fprintln(output, " CA Configuration:")
fprintln(output, " Expiry Duration:", units.HumanDuration(info.Swarm.Cluster.Spec.CAConfig.NodeCertExpiry))
fprintln(output, " Force Rotate:", info.Swarm.Cluster.Spec.CAConfig.ForceRotate)
fmt.Fprintln(dockerCli.Out(), " Heartbeat Tick:", info.Swarm.Cluster.Spec.Raft.HeartbeatTick)
fmt.Fprintln(dockerCli.Out(), " Election Tick:", info.Swarm.Cluster.Spec.Raft.ElectionTick)
fmt.Fprintln(dockerCli.Out(), " Dispatcher:")
fmt.Fprintln(dockerCli.Out(), " Heartbeat Period:", units.HumanDuration(info.Swarm.Cluster.Spec.Dispatcher.HeartbeatPeriod))
fmt.Fprintln(dockerCli.Out(), " CA Configuration:")
fmt.Fprintln(dockerCli.Out(), " Expiry Duration:", units.HumanDuration(info.Swarm.Cluster.Spec.CAConfig.NodeCertExpiry))
fmt.Fprintln(dockerCli.Out(), " Force Rotate:", info.Swarm.Cluster.Spec.CAConfig.ForceRotate)
if caCert := strings.TrimSpace(info.Swarm.Cluster.Spec.CAConfig.SigningCACert); caCert != "" {
fprintf(output, " Signing CA Certificate: \n%s\n\n", caCert)
fmt.Fprintf(dockerCli.Out(), " Signing CA Certificate: \n%s\n\n", caCert)
}
if len(info.Swarm.Cluster.Spec.CAConfig.ExternalCAs) > 0 {
fprintln(output, " External CAs:")
fmt.Fprintln(dockerCli.Out(), " External CAs:")
for _, entry := range info.Swarm.Cluster.Spec.CAConfig.ExternalCAs {
fprintf(output, " %s: %s\n", entry.Protocol, entry.URL)
fmt.Fprintf(dockerCli.Out(), " %s: %s\n", entry.Protocol, entry.URL)
}
}
fprintln(output, " Autolock Managers:", info.Swarm.Cluster.Spec.EncryptionConfig.AutoLockManagers)
fprintln(output, " Root Rotation In Progress:", info.Swarm.Cluster.RootRotationInProgress)
fmt.Fprintln(dockerCli.Out(), " Autolock Managers:", info.Swarm.Cluster.Spec.EncryptionConfig.AutoLockManagers)
fmt.Fprintln(dockerCli.Out(), " Root Rotation In Progress:", info.Swarm.Cluster.RootRotationInProgress)
}
fprintln(output, " Node Address:", info.Swarm.NodeAddr)
fmt.Fprintln(dockerCli.Out(), " Node Address:", info.Swarm.NodeAddr)
if len(info.Swarm.RemoteManagers) > 0 {
managers := []string{}
for _, entry := range info.Swarm.RemoteManagers {
managers = append(managers, entry.Addr)
}
sort.Strings(managers)
fprintln(output, " Manager Addresses:")
fmt.Fprintln(dockerCli.Out(), " Manager Addresses:")
for _, entry := range managers {
fprintf(output, " %s\n", entry)
fmt.Fprintf(dockerCli.Out(), " %s\n", entry)
}
}
}
func printServerWarnings(stdErr io.Writer, info *info) {
if versions.LessThan(info.ClientInfo.APIVersion, "1.42") {
printSecurityOptionsWarnings(stdErr, *info.Info)
func printServerWarnings(dockerCli command.Cli, info types.Info) {
if versions.LessThan(dockerCli.Client().ClientVersion(), "1.42") {
printSecurityOptionsWarnings(dockerCli, info)
}
if len(info.Warnings) > 0 {
fprintln(stdErr, strings.Join(info.Warnings, "\n"))
fmt.Fprintln(dockerCli.Err(), strings.Join(info.Warnings, "\n"))
return
}
// daemon didn't return warnings. Fallback to old behavior
printServerWarningsLegacy(stdErr, *info.Info)
printServerWarningsLegacy(dockerCli, info)
}
// printSecurityOptionsWarnings prints warnings based on the security options
@ -464,7 +448,7 @@ func printServerWarnings(stdErr io.Writer, info *info) {
// info.Warnings. This function is used to provide backward compatibility with
// daemons that do not provide these warnings. No new warnings should be added
// here.
func printSecurityOptionsWarnings(stdErr io.Writer, info types.Info) {
func printSecurityOptionsWarnings(dockerCli command.Cli, info types.Info) {
if info.OSType == "windows" {
return
}
@ -475,7 +459,7 @@ func printSecurityOptionsWarnings(stdErr io.Writer, info types.Info) {
}
for _, o := range so.Options {
if o.Key == "profile" && o.Value != "default" && o.Value != "builtin" {
_, _ = fmt.Fprintln(stdErr, "WARNING: You're not using the default seccomp profile")
_, _ = fmt.Fprintln(dockerCli.Err(), "WARNING: You're not using the default seccomp profile")
}
}
}
@ -486,47 +470,43 @@ func printSecurityOptionsWarnings(stdErr io.Writer, info types.Info) {
// info.Warnings. This function is used to provide backward compatibility with
// daemons that do not provide these warnings. No new warnings should be added
// here.
func printServerWarningsLegacy(stdErr io.Writer, info types.Info) {
func printServerWarningsLegacy(dockerCli command.Cli, info types.Info) {
if info.OSType == "windows" {
return
}
if !info.MemoryLimit {
fprintln(stdErr, "WARNING: No memory limit support")
fmt.Fprintln(dockerCli.Err(), "WARNING: No memory limit support")
}
if !info.SwapLimit {
fprintln(stdErr, "WARNING: No swap limit support")
fmt.Fprintln(dockerCli.Err(), "WARNING: No swap limit support")
}
if !info.OomKillDisable && info.CgroupVersion != "2" {
fprintln(stdErr, "WARNING: No oom kill disable support")
fmt.Fprintln(dockerCli.Err(), "WARNING: No oom kill disable support")
}
if !info.CPUCfsQuota {
fprintln(stdErr, "WARNING: No cpu cfs quota support")
fmt.Fprintln(dockerCli.Err(), "WARNING: No cpu cfs quota support")
}
if !info.CPUCfsPeriod {
fprintln(stdErr, "WARNING: No cpu cfs period support")
fmt.Fprintln(dockerCli.Err(), "WARNING: No cpu cfs period support")
}
if !info.CPUShares {
fprintln(stdErr, "WARNING: No cpu shares support")
fmt.Fprintln(dockerCli.Err(), "WARNING: No cpu shares support")
}
if !info.CPUSet {
fprintln(stdErr, "WARNING: No cpuset support")
fmt.Fprintln(dockerCli.Err(), "WARNING: No cpuset support")
}
if !info.IPv4Forwarding {
fprintln(stdErr, "WARNING: IPv4 forwarding is disabled")
fmt.Fprintln(dockerCli.Err(), "WARNING: IPv4 forwarding is disabled")
}
if !info.BridgeNfIptables {
fprintln(stdErr, "WARNING: bridge-nf-call-iptables is disabled")
fmt.Fprintln(dockerCli.Err(), "WARNING: bridge-nf-call-iptables is disabled")
}
if !info.BridgeNfIP6tables {
fprintln(stdErr, "WARNING: bridge-nf-call-ip6tables is disabled")
fmt.Fprintln(dockerCli.Err(), "WARNING: bridge-nf-call-ip6tables is disabled")
}
}
func formatInfo(output io.Writer, info info, format string) error {
if format == formatter.JSONFormatKey {
format = formatter.JSONFormat
}
func formatInfo(dockerCli command.Cli, info info, format string) error {
// Ensure slice/array fields render as `[]` not `null`
if info.ClientInfo != nil && info.ClientInfo.Plugins == nil {
info.ClientInfo.Plugins = make([]pluginmanager.Plugin, 0)
@ -539,21 +519,13 @@ func formatInfo(output io.Writer, info info, format string) error {
Status: "template parsing error: " + err.Error(),
}
}
err = tmpl.Execute(output, info)
fprintln(output)
err = tmpl.Execute(dockerCli.Out(), info)
dockerCli.Out().Write([]byte{'\n'})
return err
}
func fprintf(w io.Writer, format string, a ...any) {
_, _ = fmt.Fprintf(w, format, a...)
}
func fprintln(w io.Writer, a ...any) {
_, _ = fmt.Fprintln(w, a...)
}
func fprintlnNonEmpty(w io.Writer, label, value string) {
if value != "" {
_, _ = fmt.Fprintln(w, label, value)
fmt.Fprintln(w, label, value)
}
}

View File

@ -278,12 +278,8 @@ func TestPrettyPrintInfo(t *testing.T) {
dockerInfo: info{
Info: &sampleInfoNoSwarm,
ClientInfo: &clientInfo{
clientVersion: clientVersion{
Platform: &platformInfo{Name: "Docker Engine - Community"},
Version: "24.0.0",
Context: "default",
},
Debug: true,
Context: "default",
Debug: true,
},
},
prettyGolden: "docker-info-no-swarm",
@ -294,8 +290,8 @@ func TestPrettyPrintInfo(t *testing.T) {
dockerInfo: info{
Info: &sampleInfoNoSwarm,
ClientInfo: &clientInfo{
clientVersion: clientVersion{Context: "default"},
Plugins: samplePluginsInfo,
Context: "default",
Plugins: samplePluginsInfo,
},
},
prettyGolden: "docker-info-plugins",
@ -306,7 +302,7 @@ func TestPrettyPrintInfo(t *testing.T) {
doc: "info with nil labels",
dockerInfo: info{
Info: &sampleInfoLabelsNil,
ClientInfo: &clientInfo{clientVersion: clientVersion{Context: "default"}},
ClientInfo: &clientInfo{Context: "default"},
},
prettyGolden: "docker-info-with-labels-nil",
},
@ -314,7 +310,7 @@ func TestPrettyPrintInfo(t *testing.T) {
doc: "info with empty labels",
dockerInfo: info{
Info: &sampleInfoLabelsEmpty,
ClientInfo: &clientInfo{clientVersion: clientVersion{Context: "default"}},
ClientInfo: &clientInfo{Context: "default"},
},
prettyGolden: "docker-info-with-labels-empty",
},
@ -323,8 +319,8 @@ func TestPrettyPrintInfo(t *testing.T) {
dockerInfo: info{
Info: &infoWithSwarm,
ClientInfo: &clientInfo{
clientVersion: clientVersion{Context: "default"},
Debug: false,
Context: "default",
Debug: false,
},
},
prettyGolden: "docker-info-with-swarm",
@ -335,12 +331,8 @@ func TestPrettyPrintInfo(t *testing.T) {
dockerInfo: info{
Info: &infoWithWarningsLinux,
ClientInfo: &clientInfo{
clientVersion: clientVersion{
Platform: &platformInfo{Name: "Docker Engine - Community"},
Version: "24.0.0",
Context: "default",
},
Debug: true,
Context: "default",
Debug: true,
},
},
prettyGolden: "docker-info-no-swarm",
@ -352,12 +344,8 @@ func TestPrettyPrintInfo(t *testing.T) {
dockerInfo: info{
Info: &sampleInfoDaemonWarnings,
ClientInfo: &clientInfo{
clientVersion: clientVersion{
Platform: &platformInfo{Name: "Docker Engine - Community"},
Version: "24.0.0",
Context: "default",
},
Debug: true,
Context: "default",
Debug: true,
},
},
prettyGolden: "docker-info-no-swarm",
@ -388,7 +376,6 @@ func TestPrettyPrintInfo(t *testing.T) {
expectedError: "errors pretty printing info",
},
} {
tc := tc
t.Run(tc.doc, func(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{})
err := prettyPrintInfo(cli, tc.dockerInfo)
@ -406,12 +393,7 @@ func TestPrettyPrintInfo(t *testing.T) {
if tc.jsonGolden != "" {
cli = test.NewFakeCli(&fakeClient{})
assert.NilError(t, formatInfo(cli.Out(), tc.dockerInfo, "{{json .}}"))
golden.Assert(t, cli.OutBuffer().String(), tc.jsonGolden+".json.golden")
assert.Check(t, is.Equal("", cli.ErrBuffer().String()))
cli = test.NewFakeCli(&fakeClient{})
assert.NilError(t, formatInfo(cli.Out(), tc.dockerInfo, "json"))
assert.NilError(t, formatInfo(cli, tc.dockerInfo, "{{json .}}"))
golden.Assert(t, cli.OutBuffer().String(), tc.jsonGolden+".json.golden")
assert.Check(t, is.Equal("", cli.ErrBuffer().String()))
}
@ -419,30 +401,6 @@ func TestPrettyPrintInfo(t *testing.T) {
}
}
func BenchmarkPrettyPrintInfo(b *testing.B) {
infoWithSwarm := sampleInfoNoSwarm
infoWithSwarm.Swarm = sampleSwarmInfo
dockerInfo := info{
Info: &infoWithSwarm,
ClientInfo: &clientInfo{
clientVersion: clientVersion{
Platform: &platformInfo{Name: "Docker Engine - Community"},
Version: "24.0.0",
Context: "default",
},
Debug: true,
},
}
cli := test.NewFakeCli(&fakeClient{})
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = prettyPrintInfo(cli, dockerInfo)
cli.ResetOutputBuffers()
}
}
func TestFormatInfo(t *testing.T) {
for _, tc := range []struct {
doc string
@ -466,14 +424,13 @@ func TestFormatInfo(t *testing.T) {
expectedError: `template: :1:2: executing "" at <.badString>: can't evaluate field badString in type system.info`,
},
} {
tc := tc
t.Run(tc.doc, func(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{})
info := info{
Info: &sampleInfoNoSwarm,
ClientInfo: &clientInfo{Debug: true},
}
err := formatInfo(cli.Out(), info, tc.template)
err := formatInfo(cli, info, tc.template)
if tc.expectedOut != "" {
assert.NilError(t, err)
assert.Equal(t, cli.OutBuffer().String(), tc.expectedOut)

View File

@ -1 +0,0 @@
{"Client":{"Version":"18.99.5-ce","ApiVersion":"1.38","DefaultAPIVersion":"1.38","GitCommit":"deadbeef","GoVersion":"go1.10.2","Os":"linux","Arch":"amd64","BuildTime":"Wed May 30 22:21:05 2018","Context":"my-context"},"Server":{"Platform":{"Name":"Docker Enterprise Edition (EE) 2.0"},"Components":[{"Name":"Engine","Version":"17.06.2-ee-15","Details":{"ApiVersion":"1.30","Arch":"amd64","BuildTime":"Mon Jul 9 23:38:38 2018","Experimental":"false","GitCommit":"64ddfa6","GoVersion":"go1.8.7","MinAPIVersion":"1.12","Os":"linux"}},{"Name":"Universal Control Plane","Version":"17.06.2-ee-15","Details":{"ApiVersion":"1.30","Arch":"amd64","BuildTime":"Mon Jul 2 21:24:07 UTC 2018","GitCommit":"4513922","GoVersion":"go1.9.4","MinApiVersion":"1.20","Os":"linux","Version":"3.0.3-tp2"}},{"Name":"Kubernetes","Version":"1.8+","Details":{"buildDate":"2018-04-26T16:51:21Z","compiler":"gc","gitCommit":"8d637aedf46b9c21dde723e29c645b9f27106fa5","gitTreeState":"clean","gitVersion":"v1.8.11-docker-8d637ae","goVersion":"go1.8.3","major":"1","minor":"8+","platform":"linux/amd64"}},{"Name":"Calico","Version":"v3.0.8","Details":{"cni":"v2.0.6","kube-controllers":"v2.0.5","node":"v3.0.8"}}],"Version":"","ApiVersion":"","GitCommit":"","GoVersion":"","Os":"","Arch":""}}

View File

@ -41,6 +41,7 @@ Server:
Goroutines: 135
System Time: 2017-08-24T17:44:34.077811894Z
EventsListeners: 0
Registry: https://index.docker.io/v1/
Labels:
provider=digitalocean
Experimental: false

View File

@ -1 +1 @@
{"ID":"EKHL:QDUU:QZ7U:MKGD:VDXK:S27Q:GIPU:24B7:R7VT:DGN6:QCSF:2UBX","Containers":0,"ContainersRunning":0,"ContainersPaused":0,"ContainersStopped":0,"Images":0,"Driver":"aufs","DriverStatus":[["Root Dir","/var/lib/docker/aufs"],["Backing Filesystem","extfs"],["Dirs","0"],["Dirperm1 Supported","true"]],"Plugins":{"Volume":["local"],"Network":["bridge","host","macvlan","null","overlay"],"Authorization":null,"Log":["awslogs","fluentd","gcplogs","gelf","journald","json-file","logentries","splunk","syslog"]},"MemoryLimit":true,"SwapLimit":true,"KernelMemory":true,"CpuCfsPeriod":true,"CpuCfsQuota":true,"CPUShares":true,"CPUSet":true,"PidsLimit":false,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":true,"NFd":33,"OomKillDisable":true,"NGoroutines":135,"SystemTime":"2017-08-24T17:44:34.077811894Z","LoggingDriver":"json-file","CgroupDriver":"cgroupfs","NEventsListener":0,"KernelVersion":"4.4.0-87-generic","OperatingSystem":"Ubuntu 16.04.3 LTS","OSVersion":"","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"AllowNondistributableArtifactsCIDRs":null,"AllowNondistributableArtifactsHostnames":null,"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":null,"Secure":true,"Official":true}},"Mirrors":null},"NCPU":2,"MemTotal":2097356800,"GenericResources":null,"DockerRootDir":"/var/lib/docker","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"system-sample","Labels":["provider=digitalocean"],"ExperimentalBuild":false,"ServerVersion":"17.06.1-ce","Runtimes":{"runc":{"path":"docker-runc"}},"DefaultRuntime":"runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null},"LiveRestoreEnabled":false,"Isolation":"","InitBinary":"docker-init","ContainerdCommit":{"ID":"6e23458c129b551d5c9871e5174f6b1b7f6d1170","Expected":"6e23458c129b551d5c9871e5174f6b1b7f6d1170"},"RuncCommit":{"ID":"810190ceaa507aa2727d7ae6f4790c76ec150bd2","Expected":"810190ceaa507aa2727d7ae6f4790c76ec150bd2"},"InitCommit":{"ID":"949e6fa","Expected":"949e6fa"},"SecurityOptions":["name=apparmor","name=seccomp,profile=default"],"DefaultAddressPools":[{"Base":"10.123.0.0/16","Size":24}],"Warnings":["WARNING: No memory limit support","WARNING: No swap limit support","WARNING: No oom kill disable support","WARNING: No cpu cfs quota support","WARNING: No cpu cfs period support","WARNING: No cpu shares support","WARNING: No cpuset support","WARNING: IPv4 forwarding is disabled","WARNING: bridge-nf-call-iptables is disabled","WARNING: bridge-nf-call-ip6tables is disabled"],"ClientInfo":{"Debug":true,"Platform":{"Name":"Docker Engine - Community"},"Version":"24.0.0","Context":"default","Plugins":[],"Warnings":null}}
{"ID":"EKHL:QDUU:QZ7U:MKGD:VDXK:S27Q:GIPU:24B7:R7VT:DGN6:QCSF:2UBX","Containers":0,"ContainersRunning":0,"ContainersPaused":0,"ContainersStopped":0,"Images":0,"Driver":"aufs","DriverStatus":[["Root Dir","/var/lib/docker/aufs"],["Backing Filesystem","extfs"],["Dirs","0"],["Dirperm1 Supported","true"]],"Plugins":{"Volume":["local"],"Network":["bridge","host","macvlan","null","overlay"],"Authorization":null,"Log":["awslogs","fluentd","gcplogs","gelf","journald","json-file","logentries","splunk","syslog"]},"MemoryLimit":true,"SwapLimit":true,"KernelMemory":true,"CpuCfsPeriod":true,"CpuCfsQuota":true,"CPUShares":true,"CPUSet":true,"PidsLimit":false,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":true,"NFd":33,"OomKillDisable":true,"NGoroutines":135,"SystemTime":"2017-08-24T17:44:34.077811894Z","LoggingDriver":"json-file","CgroupDriver":"cgroupfs","NEventsListener":0,"KernelVersion":"4.4.0-87-generic","OperatingSystem":"Ubuntu 16.04.3 LTS","OSVersion":"","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"AllowNondistributableArtifactsCIDRs":null,"AllowNondistributableArtifactsHostnames":null,"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":null,"Secure":true,"Official":true}},"Mirrors":null},"NCPU":2,"MemTotal":2097356800,"GenericResources":null,"DockerRootDir":"/var/lib/docker","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"system-sample","Labels":["provider=digitalocean"],"ExperimentalBuild":false,"ServerVersion":"17.06.1-ce","Runtimes":{"runc":{"path":"docker-runc"}},"DefaultRuntime":"runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null},"LiveRestoreEnabled":false,"Isolation":"","InitBinary":"docker-init","ContainerdCommit":{"ID":"6e23458c129b551d5c9871e5174f6b1b7f6d1170","Expected":"6e23458c129b551d5c9871e5174f6b1b7f6d1170"},"RuncCommit":{"ID":"810190ceaa507aa2727d7ae6f4790c76ec150bd2","Expected":"810190ceaa507aa2727d7ae6f4790c76ec150bd2"},"InitCommit":{"ID":"949e6fa","Expected":"949e6fa"},"SecurityOptions":["name=apparmor","name=seccomp,profile=default"],"DefaultAddressPools":[{"Base":"10.123.0.0/16","Size":24}],"Warnings":["WARNING: No memory limit support","WARNING: No swap limit support","WARNING: No oom kill disable support","WARNING: No cpu cfs quota support","WARNING: No cpu cfs period support","WARNING: No cpu shares support","WARNING: No cpuset support","WARNING: IPv4 forwarding is disabled","WARNING: bridge-nf-call-iptables is disabled","WARNING: bridge-nf-call-ip6tables is disabled"],"ClientInfo":{"Debug":true,"Context":"default","Plugins":[],"Warnings":null}}

View File

@ -1 +1 @@
{"ID":"EKHL:QDUU:QZ7U:MKGD:VDXK:S27Q:GIPU:24B7:R7VT:DGN6:QCSF:2UBX","Containers":0,"ContainersRunning":0,"ContainersPaused":0,"ContainersStopped":0,"Images":0,"Driver":"aufs","DriverStatus":[["Root Dir","/var/lib/docker/aufs"],["Backing Filesystem","extfs"],["Dirs","0"],["Dirperm1 Supported","true"]],"Plugins":{"Volume":["local"],"Network":["bridge","host","macvlan","null","overlay"],"Authorization":null,"Log":["awslogs","fluentd","gcplogs","gelf","journald","json-file","logentries","splunk","syslog"]},"MemoryLimit":false,"SwapLimit":false,"CpuCfsPeriod":false,"CpuCfsQuota":false,"CPUShares":false,"CPUSet":false,"PidsLimit":false,"IPv4Forwarding":false,"BridgeNfIptables":false,"BridgeNfIp6tables":false,"Debug":true,"NFd":33,"OomKillDisable":false,"NGoroutines":135,"SystemTime":"2017-08-24T17:44:34.077811894Z","LoggingDriver":"json-file","CgroupDriver":"cgroupfs","NEventsListener":0,"KernelVersion":"4.4.0-87-generic","OperatingSystem":"Ubuntu 16.04.3 LTS","OSVersion":"","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"AllowNondistributableArtifactsCIDRs":null,"AllowNondistributableArtifactsHostnames":null,"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":null,"Secure":true,"Official":true}},"Mirrors":null},"NCPU":2,"MemTotal":2097356800,"GenericResources":null,"DockerRootDir":"/var/lib/docker","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"system-sample","Labels":["provider=digitalocean"],"ExperimentalBuild":false,"ServerVersion":"17.06.1-ce","Runtimes":{"runc":{"path":"docker-runc"}},"DefaultRuntime":"runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null},"LiveRestoreEnabled":false,"Isolation":"","InitBinary":"docker-init","ContainerdCommit":{"ID":"6e23458c129b551d5c9871e5174f6b1b7f6d1170","Expected":"6e23458c129b551d5c9871e5174f6b1b7f6d1170"},"RuncCommit":{"ID":"810190ceaa507aa2727d7ae6f4790c76ec150bd2","Expected":"810190ceaa507aa2727d7ae6f4790c76ec150bd2"},"InitCommit":{"ID":"949e6fa","Expected":"949e6fa"},"SecurityOptions":["name=apparmor","name=seccomp,profile=default"],"DefaultAddressPools":[{"Base":"10.123.0.0/16","Size":24}],"Warnings":null,"ClientInfo":{"Debug":true,"Platform":{"Name":"Docker Engine - Community"},"Version":"24.0.0","Context":"default","Plugins":[],"Warnings":null}}
{"ID":"EKHL:QDUU:QZ7U:MKGD:VDXK:S27Q:GIPU:24B7:R7VT:DGN6:QCSF:2UBX","Containers":0,"ContainersRunning":0,"ContainersPaused":0,"ContainersStopped":0,"Images":0,"Driver":"aufs","DriverStatus":[["Root Dir","/var/lib/docker/aufs"],["Backing Filesystem","extfs"],["Dirs","0"],["Dirperm1 Supported","true"]],"Plugins":{"Volume":["local"],"Network":["bridge","host","macvlan","null","overlay"],"Authorization":null,"Log":["awslogs","fluentd","gcplogs","gelf","journald","json-file","logentries","splunk","syslog"]},"MemoryLimit":false,"SwapLimit":false,"CpuCfsPeriod":false,"CpuCfsQuota":false,"CPUShares":false,"CPUSet":false,"PidsLimit":false,"IPv4Forwarding":false,"BridgeNfIptables":false,"BridgeNfIp6tables":false,"Debug":true,"NFd":33,"OomKillDisable":false,"NGoroutines":135,"SystemTime":"2017-08-24T17:44:34.077811894Z","LoggingDriver":"json-file","CgroupDriver":"cgroupfs","NEventsListener":0,"KernelVersion":"4.4.0-87-generic","OperatingSystem":"Ubuntu 16.04.3 LTS","OSVersion":"","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"AllowNondistributableArtifactsCIDRs":null,"AllowNondistributableArtifactsHostnames":null,"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":null,"Secure":true,"Official":true}},"Mirrors":null},"NCPU":2,"MemTotal":2097356800,"GenericResources":null,"DockerRootDir":"/var/lib/docker","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"system-sample","Labels":["provider=digitalocean"],"ExperimentalBuild":false,"ServerVersion":"17.06.1-ce","Runtimes":{"runc":{"path":"docker-runc"}},"DefaultRuntime":"runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null},"LiveRestoreEnabled":false,"Isolation":"","InitBinary":"docker-init","ContainerdCommit":{"ID":"6e23458c129b551d5c9871e5174f6b1b7f6d1170","Expected":"6e23458c129b551d5c9871e5174f6b1b7f6d1170"},"RuncCommit":{"ID":"810190ceaa507aa2727d7ae6f4790c76ec150bd2","Expected":"810190ceaa507aa2727d7ae6f4790c76ec150bd2"},"InitCommit":{"ID":"949e6fa","Expected":"949e6fa"},"SecurityOptions":["name=apparmor","name=seccomp,profile=default"],"DefaultAddressPools":[{"Base":"10.123.0.0/16","Size":24}],"Warnings":null,"ClientInfo":{"Debug":true,"Context":"default","Plugins":[],"Warnings":null}}

View File

@ -1,5 +1,4 @@
Client: Docker Engine - Community
Version: 24.0.0
Client:
Context: default
Debug Mode: true
@ -46,6 +45,7 @@ Server:
Goroutines: 135
System Time: 2017-08-24T17:44:34.077811894Z
EventsListeners: 0
Registry: https://index.docker.io/v1/
Labels:
provider=digitalocean
Experimental: false

View File

@ -1 +1 @@
{"ID":"EKHL:QDUU:QZ7U:MKGD:VDXK:S27Q:GIPU:24B7:R7VT:DGN6:QCSF:2UBX","Containers":0,"ContainersRunning":0,"ContainersPaused":0,"ContainersStopped":0,"Images":0,"Driver":"aufs","DriverStatus":[["Root Dir","/var/lib/docker/aufs"],["Backing Filesystem","extfs"],["Dirs","0"],["Dirperm1 Supported","true"]],"Plugins":{"Volume":["local"],"Network":["bridge","host","macvlan","null","overlay"],"Authorization":null,"Log":["awslogs","fluentd","gcplogs","gelf","journald","json-file","logentries","splunk","syslog"]},"MemoryLimit":true,"SwapLimit":true,"KernelMemory":true,"CpuCfsPeriod":true,"CpuCfsQuota":true,"CPUShares":true,"CPUSet":true,"PidsLimit":false,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":true,"NFd":33,"OomKillDisable":true,"NGoroutines":135,"SystemTime":"2017-08-24T17:44:34.077811894Z","LoggingDriver":"json-file","CgroupDriver":"cgroupfs","NEventsListener":0,"KernelVersion":"4.4.0-87-generic","OperatingSystem":"Ubuntu 16.04.3 LTS","OSVersion":"","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"AllowNondistributableArtifactsCIDRs":null,"AllowNondistributableArtifactsHostnames":null,"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":null,"Secure":true,"Official":true}},"Mirrors":null},"NCPU":2,"MemTotal":2097356800,"GenericResources":null,"DockerRootDir":"/var/lib/docker","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"system-sample","Labels":["provider=digitalocean"],"ExperimentalBuild":false,"ServerVersion":"17.06.1-ce","Runtimes":{"runc":{"path":"docker-runc"}},"DefaultRuntime":"runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null},"LiveRestoreEnabled":false,"Isolation":"","InitBinary":"docker-init","ContainerdCommit":{"ID":"6e23458c129b551d5c9871e5174f6b1b7f6d1170","Expected":"6e23458c129b551d5c9871e5174f6b1b7f6d1170"},"RuncCommit":{"ID":"810190ceaa507aa2727d7ae6f4790c76ec150bd2","Expected":"810190ceaa507aa2727d7ae6f4790c76ec150bd2"},"InitCommit":{"ID":"949e6fa","Expected":"949e6fa"},"SecurityOptions":["name=apparmor","name=seccomp,profile=default"],"DefaultAddressPools":[{"Base":"10.123.0.0/16","Size":24}],"Warnings":null,"ClientInfo":{"Debug":true,"Platform":{"Name":"Docker Engine - Community"},"Version":"24.0.0","Context":"default","Plugins":[],"Warnings":null}}
{"ID":"EKHL:QDUU:QZ7U:MKGD:VDXK:S27Q:GIPU:24B7:R7VT:DGN6:QCSF:2UBX","Containers":0,"ContainersRunning":0,"ContainersPaused":0,"ContainersStopped":0,"Images":0,"Driver":"aufs","DriverStatus":[["Root Dir","/var/lib/docker/aufs"],["Backing Filesystem","extfs"],["Dirs","0"],["Dirperm1 Supported","true"]],"Plugins":{"Volume":["local"],"Network":["bridge","host","macvlan","null","overlay"],"Authorization":null,"Log":["awslogs","fluentd","gcplogs","gelf","journald","json-file","logentries","splunk","syslog"]},"MemoryLimit":true,"SwapLimit":true,"KernelMemory":true,"CpuCfsPeriod":true,"CpuCfsQuota":true,"CPUShares":true,"CPUSet":true,"PidsLimit":false,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":true,"NFd":33,"OomKillDisable":true,"NGoroutines":135,"SystemTime":"2017-08-24T17:44:34.077811894Z","LoggingDriver":"json-file","CgroupDriver":"cgroupfs","NEventsListener":0,"KernelVersion":"4.4.0-87-generic","OperatingSystem":"Ubuntu 16.04.3 LTS","OSVersion":"","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"AllowNondistributableArtifactsCIDRs":null,"AllowNondistributableArtifactsHostnames":null,"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":null,"Secure":true,"Official":true}},"Mirrors":null},"NCPU":2,"MemTotal":2097356800,"GenericResources":null,"DockerRootDir":"/var/lib/docker","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"system-sample","Labels":["provider=digitalocean"],"ExperimentalBuild":false,"ServerVersion":"17.06.1-ce","Runtimes":{"runc":{"path":"docker-runc"}},"DefaultRuntime":"runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null},"LiveRestoreEnabled":false,"Isolation":"","InitBinary":"docker-init","ContainerdCommit":{"ID":"6e23458c129b551d5c9871e5174f6b1b7f6d1170","Expected":"6e23458c129b551d5c9871e5174f6b1b7f6d1170"},"RuncCommit":{"ID":"810190ceaa507aa2727d7ae6f4790c76ec150bd2","Expected":"810190ceaa507aa2727d7ae6f4790c76ec150bd2"},"InitCommit":{"ID":"949e6fa","Expected":"949e6fa"},"SecurityOptions":["name=apparmor","name=seccomp,profile=default"],"DefaultAddressPools":[{"Base":"10.123.0.0/16","Size":24}],"Warnings":null,"ClientInfo":{"Debug":true,"Context":"default","Plugins":[],"Warnings":null}}

View File

@ -51,6 +51,7 @@ Server:
Goroutines: 135
System Time: 2017-08-24T17:44:34.077811894Z
EventsListeners: 0
Registry: https://index.docker.io/v1/
Labels:
provider=digitalocean
Experimental: false

View File

@ -45,6 +45,7 @@ Server:
Goroutines: 135
System Time: 2017-08-24T17:44:34.077811894Z
EventsListeners: 0
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8

View File

@ -45,6 +45,7 @@ Server:
Goroutines: 135
System Time: 2017-08-24T17:44:34.077811894Z
EventsListeners: 0
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8

View File

@ -67,6 +67,7 @@ Server:
Goroutines: 135
System Time: 2017-08-24T17:44:34.077811894Z
EventsListeners: 0
Registry: https://index.docker.io/v1/
Labels:
provider=digitalocean
Experimental: false

View File

@ -11,9 +11,7 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/cli/command/formatter/tabwriter"
flagsHelper "github.com/docker/cli/cli/flags"
"github.com/docker/cli/cli/version"
"github.com/docker/cli/templates"
"github.com/docker/docker/api/types"
@ -22,8 +20,8 @@ import (
"github.com/tonistiigi/go-rosetta"
)
const defaultVersionTemplate = `{{with .Client -}}
Client:{{if ne .Platform nil}}{{if ne .Platform.Name ""}} {{.Platform.Name}}{{end}}{{end}}
var versionTemplate = `{{with .Client -}}
Client:{{if ne .Platform.Name ""}} {{.Platform.Name}}{{end}}
Version: {{.Version}}
API version: {{.APIVersion}}{{if ne .APIVersion .DefaultAPIVersion}} (downgraded from {{.DefaultAPIVersion}}){{end}}
Go version: {{.GoVersion}}
@ -33,7 +31,7 @@ Client:{{if ne .Platform nil}}{{if ne .Platform.Name ""}} {{.Platform.Name}}{{en
Context: {{.Context}}
{{- end}}
{{- if ne .Server nil}}{{with .Server}}
{{- if .ServerOK}}{{with .Server}}
Server:{{if ne .Platform.Name ""}} {{.Platform.Name}}{{end}}
{{- range $component := .Components}}
@ -66,45 +64,24 @@ type versionInfo struct {
Server *types.Version
}
type platformInfo struct {
Name string `json:"Name,omitempty"`
}
type clientVersion struct {
Platform *platformInfo `json:"Platform,omitempty"`
Version string `json:"Version,omitempty"`
APIVersion string `json:"ApiVersion,omitempty"`
DefaultAPIVersion string `json:"DefaultAPIVersion,omitempty"`
GitCommit string `json:"GitCommit,omitempty"`
GoVersion string `json:"GoVersion,omitempty"`
Os string `json:"Os,omitempty"`
Arch string `json:"Arch,omitempty"`
BuildTime string `json:"BuildTime,omitempty"`
Context string `json:"Context"`
Platform struct{ Name string } `json:",omitempty"`
Version string
APIVersion string `json:"ApiVersion"`
DefaultAPIVersion string `json:"DefaultAPIVersion,omitempty"`
GitCommit string
GoVersion string
Os string
Arch string
BuildTime string `json:",omitempty"`
Context string
}
// newClientVersion constructs a new clientVersion. If a dockerCLI is
// passed as argument, additional information is included (API version),
// which may invoke an API connection. Pass nil to omit the additional
// information.
func newClientVersion(contextName string, dockerCli command.Cli) clientVersion {
v := clientVersion{
Version: version.Version,
GoVersion: runtime.Version(),
GitCommit: version.GitCommit,
BuildTime: reformatDate(version.BuildTime),
Os: runtime.GOOS,
Arch: arch(),
Context: contextName,
}
if version.PlatformName != "" {
v.Platform = &platformInfo{Name: version.PlatformName}
}
if dockerCli != nil {
v.APIVersion = dockerCli.CurrentVersion()
v.DefaultAPIVersion = dockerCli.DefaultVersion()
}
return v
// ServerOK returns true when the client could connect to the docker server
// and parse the information received. It returns false otherwise.
func (v versionInfo) ServerOK() bool {
return v.Server != nil
}
// NewVersionCommand creates a new cobra.Command for `docker version`
@ -124,7 +101,9 @@ func NewVersionCommand(dockerCli command.Cli) *cobra.Command {
ValidArgsFunction: completion.NoComplete,
}
cmd.Flags().StringVarP(&opts.format, "format", "f", "", flagsHelper.InspectFormatHelp)
flags := cmd.Flags()
flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template")
return cmd
}
@ -154,8 +133,20 @@ func runVersion(dockerCli command.Cli, opts *versionOptions) error {
// TODO print error if kubernetes is used?
vd := versionInfo{
Client: newClientVersion(dockerCli.CurrentContext(), dockerCli),
Client: clientVersion{
Platform: struct{ Name string }{version.PlatformName},
Version: version.Version,
APIVersion: dockerCli.CurrentVersion(),
DefaultAPIVersion: dockerCli.DefaultVersion(),
GoVersion: runtime.Version(),
GitCommit: version.GitCommit,
BuildTime: reformatDate(version.BuildTime),
Os: runtime.GOOS,
Arch: arch(),
Context: dockerCli.CurrentContext(),
},
}
sv, err := dockerCli.Client().ServerVersion(context.Background())
if err == nil {
vd.Server = &sv
@ -203,11 +194,8 @@ func prettyPrintVersion(dockerCli command.Cli, vd versionInfo, tmpl *template.Te
}
func newVersionTemplate(templateFormat string) (*template.Template, error) {
switch templateFormat {
case "":
templateFormat = defaultVersionTemplate
case formatter.JSONFormatKey:
templateFormat = formatter.JSONFormat
if templateFormat == "" {
templateFormat = versionTemplate
}
tmpl := templates.New("version").Funcs(template.FuncMap{"getDetailsOrder": getDetailsOrder})
tmpl, err := tmpl.Parse(templateFormat)

View File

@ -6,11 +6,12 @@ import (
"strings"
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/golden"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
)
func TestVersionWithoutServer(t *testing.T) {
@ -29,7 +30,7 @@ func TestVersionWithoutServer(t *testing.T) {
assert.Assert(t, !strings.Contains(out, "Server:"), "actual: %s", out)
}
func TestVersionFormat(t *testing.T) {
func TestVersionAlign(t *testing.T) {
vi := versionInfo{
Client: clientVersion{
Version: "18.99.5-ce",
@ -103,28 +104,10 @@ func TestVersionFormat(t *testing.T) {
},
})
t.Run("default", func(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{})
tmpl, err := newVersionTemplate("")
assert.NilError(t, err)
assert.NilError(t, prettyPrintVersion(cli, vi, tmpl))
assert.Check(t, golden.String(cli.OutBuffer().String(), "docker-client-version.golden"))
assert.Check(t, is.Equal("", cli.ErrBuffer().String()))
})
t.Run("json", func(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{})
tmpl, err := newVersionTemplate("json")
assert.NilError(t, err)
assert.NilError(t, prettyPrintVersion(cli, vi, tmpl))
assert.Check(t, golden.String(cli.OutBuffer().String(), "docker-client-version.json.golden"))
assert.Check(t, is.Equal("", cli.ErrBuffer().String()))
})
t.Run("json template", func(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{})
tmpl, err := newVersionTemplate("{{json .}}")
assert.NilError(t, err)
assert.NilError(t, prettyPrintVersion(cli, vi, tmpl))
assert.Check(t, golden.String(cli.OutBuffer().String(), "docker-client-version.json.golden"))
assert.Check(t, is.Equal("", cli.ErrBuffer().String()))
})
cli := test.NewFakeCli(&fakeClient{})
tmpl, err := newVersionTemplate("")
assert.NilError(t, err)
assert.NilError(t, prettyPrintVersion(cli, vi, tmpl))
assert.Check(t, golden.String(cli.OutBuffer().String(), "docker-client-version.golden"))
assert.Check(t, is.Equal("", cli.ErrBuffer().String()))
}

View File

@ -14,14 +14,14 @@ type fakeClient struct {
serviceInspectWithRaw func(ref string, options types.ServiceInspectOptions) (swarm.Service, []byte, error)
}
func (cli *fakeClient) NodeInspectWithRaw(_ context.Context, ref string) (swarm.Node, []byte, error) {
func (cli *fakeClient) NodeInspectWithRaw(ctx context.Context, ref string) (swarm.Node, []byte, error) {
if cli.nodeInspectWithRaw != nil {
return cli.nodeInspectWithRaw(ref)
}
return swarm.Node{}, nil, nil
}
func (cli *fakeClient) ServiceInspectWithRaw(_ context.Context, ref string, options types.ServiceInspectOptions) (swarm.Service, []byte, error) {
func (cli *fakeClient) ServiceInspectWithRaw(ctx context.Context, ref string, options types.ServiceInspectOptions) (swarm.Service, []byte, error) {
if cli.serviceInspectWithRaw != nil {
return cli.serviceInspectWithRaw(ref, options)
}

View File

@ -53,7 +53,7 @@ type trustKey struct {
// This information is to be pretty printed or serialized into a machine-readable format.
func lookupTrustInfo(cli command.Cli, remote string) ([]trustTagRow, []client.RoleWithSignatures, []data.Role, error) {
ctx := context.Background()
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, image.AuthResolver(cli), remote)
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, nil, image.AuthResolver(cli), remote)
if err != nil {
return []trustTagRow{}, []client.RoleWithSignatures{}, []data.Role{}, err
}

View File

@ -27,15 +27,15 @@ type fakeClient struct {
apiclient.Client
}
func (c *fakeClient) Info(context.Context) (types.Info, error) {
func (c *fakeClient) Info(ctx context.Context) (types.Info, error) {
return types.Info{}, nil
}
func (c *fakeClient) ImageInspectWithRaw(context.Context, string) (types.ImageInspect, []byte, error) {
func (c *fakeClient) ImageInspectWithRaw(ctx context.Context, imageID string) (types.ImageInspect, []byte, error) {
return types.ImageInspect{}, []byte{}, nil
}
func (c *fakeClient) ImagePush(context.Context, string, types.ImagePushOptions) (io.ReadCloser, error) {
func (c *fakeClient) ImagePush(ctx context.Context, image string, options types.ImagePushOptions) (io.ReadCloser, error) {
return &utils.NoopCloser{Reader: bytes.NewBuffer([]byte{})}, nil
}

View File

@ -36,7 +36,7 @@ func newRevokeCommand(dockerCli command.Cli) *cobra.Command {
func revokeTrust(cli command.Cli, remote string, options revokeOptions) error {
ctx := context.Background()
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, image.AuthResolver(cli), remote)
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, nil, image.AuthResolver(cli), remote)
if err != nil {
return err
}

View File

@ -13,7 +13,6 @@ import (
"github.com/docker/cli/cli/command/image"
"github.com/docker/cli/cli/trust"
"github.com/docker/docker/api/types"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/theupdateframework/notary/client"
@ -44,7 +43,7 @@ func newSignCommand(dockerCli command.Cli) *cobra.Command {
func runSignImage(cli command.Cli, options signOptions) error {
imageName := options.imageName
ctx := context.Background()
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, image.AuthResolver(cli), imageName)
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, nil, image.AuthResolver(cli), imageName)
if err != nil {
return err
}
@ -94,7 +93,7 @@ func runSignImage(cli command.Cli, options signOptions) error {
fmt.Fprintf(cli.Err(), "Signing and pushing trust data for local image %s, may overwrite remote trust data\n", imageName)
authConfig := command.ResolveAuthConfig(ctx, cli, imgRefAndAuth.RepoInfo().Index)
encodedAuth, err := registrytypes.EncodeAuthConfig(authConfig)
encodedAuth, err := command.EncodeAuthToBase64(authConfig)
if err != nil {
return err
}

View File

@ -81,7 +81,7 @@ func addSigner(cli command.Cli, options signerAddOptions) error {
func addSignerToRepo(cli command.Cli, signerName string, repoName string, signerPubKeys []data.PublicKey) error {
ctx := context.Background()
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, image.AuthResolver(cli), repoName)
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, nil, image.AuthResolver(cli), repoName)
if err != nil {
return err
}

View File

@ -80,7 +80,7 @@ func isLastSignerForReleases(roleWithSig data.Role, allRoles []client.RoleWithSi
// The signer not being removed doesn't necessarily raise an error e.g. user choosing "No" when prompted for confirmation.
func removeSingleSigner(cli command.Cli, repoName, signerName string, forceYes bool) (bool, error) {
ctx := context.Background()
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, image.AuthResolver(cli), repoName)
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, nil, image.AuthResolver(cli), repoName)
if err != nil {
return false, err
}

View File

@ -32,9 +32,9 @@ func (c *fakeClient) VolumeInspect(_ context.Context, volumeID string) (volume.V
return volume.Volume{}, nil
}
func (c *fakeClient) VolumeList(_ context.Context, options volume.ListOptions) (volume.ListResponse, error) {
func (c *fakeClient) VolumeList(_ context.Context, filter filters.Args) (volume.ListResponse, error) {
if c.volumeListFunc != nil {
return c.volumeListFunc(options.Filters)
return c.volumeListFunc(filter)
}
return volume.ListResponse{}, nil
}

View File

@ -50,7 +50,6 @@ func TestVolumeCreateErrors(t *testing.T) {
cmd.Flags().Set(key, value)
}
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}

View File

@ -62,7 +62,6 @@ func TestVolumeInspectErrors(t *testing.T) {
cmd.Flags().Set(key, value)
}
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}

View File

@ -10,7 +10,6 @@ import (
"github.com/docker/cli/cli/command/formatter"
flagsHelper "github.com/docker/cli/cli/flags"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/volume"
"github.com/fvbommel/sortorder"
"github.com/spf13/cobra"
)
@ -53,7 +52,7 @@ func newListCommand(dockerCli command.Cli) *cobra.Command {
func runList(dockerCli command.Cli, options listOptions) error {
client := dockerCli.Client()
volumes, err := client.VolumeList(context.Background(), volume.ListOptions{Filters: options.filter.Value()})
volumes, err := client.VolumeList(context.Background(), options.filter.Value())
if err != nil {
return err
}
@ -71,9 +70,9 @@ func runList(dockerCli command.Cli, options listOptions) error {
// trick for filtering in place
n := 0
for _, vol := range volumes.Volumes {
if vol.ClusterVolume != nil {
volumes.Volumes[n] = vol
for _, volume := range volumes.Volumes {
if volume.ClusterVolume != nil {
volumes.Volumes[n] = volume
n++
}
}

View File

@ -43,7 +43,6 @@ func TestVolumeListErrors(t *testing.T) {
cmd.Flags().Set(key, value)
}
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}

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