Debian

Available patches from Ubuntu

To see Ubuntu differences wrt. to Debian, write down a grep-dctrl query identifying the packages you're interested in:
grep-dctrl -n -sPackage Sources.Debian
(e.g. -FPackage linux-ntfs or linux-ntfs)

Modified packages are listed below:

Debian ( Changelog | PTS | Bugs ) Ubuntu ( Changelog | txt | LP | Bugs ) | Diff from Ubuntu

Source: docker.io

docker.io (19.03.8-0ubuntu3) groovy; urgency=medium * Provide the rootless component in golang dev package, mirroring Debian (addresses nomad FTBFS). -- Logan Rosen <logan@ubuntu.com> Tue, 26 May 2020 21:06:20 -0400 docker.io (19.03.8-0ubuntu2) groovy; urgency=medium [ Jean-Baptiste Lallement ] [ Didier Roche ] * Fix use with ZFS on root: - docker creates one dataset for any layer of containers that were created. Create now a <pool>/var/lib/docker for creating them in the persistent namespace and migrate existing one here. - purge the automated historic that was created. The migration only impacts the ubuntu desktop installation with experimental ZFS on root, and we have thus to stop and start the daemon to migrate data. (LP: #1879473) -- Didier Roche <didrocks@ubuntu.com> Tue, 19 May 2020 11:01:22 +0200 docker.io (19.03.8-0ubuntu1) focal; urgency=medium * Update to 19.03.8 upstream release (LP: #1867068) - Improve mitigation for CVE-2019-14271 for some nscd configuration. -- Tianon Gravi <tianon@debian.org> Wed, 11 Mar 2020 15:48:33 -0700 docker.io (19.03.6-0ubuntu1) focal; urgency=medium * Update to 19.03.6 upstream release -- Tianon Gravi <tianon@debian.org> Tue, 18 Feb 2020 09:03:26 +1300 docker.io (19.03.2-0ubuntu1) eoan; urgency=medium * Update to 19.03.2 -- Tianon Gravi <tianon@debian.org> Wed, 11 Sep 2019 15:45:55 -0700 docker.io (18.09.9-0ubuntu1) eoan; urgency=medium * Update to 18.09.9 * Remove leftover sysvinit/upstart patches - cgroupfs-mount-convenience-copy.patch - devicemapper-cleanup.patch -- Tianon Gravi <tianon@debian.org> Wed, 11 Sep 2019 15:21:11 -0700 docker.io (18.09.8-0ubuntu5) eoan; urgency=medium * Set GOCACHE to a safely writable directory during build as the cache is mandatory with Go 1.12. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Mon, 26 Aug 2019 10:20:12 +1200 docker.io (18.09.8-0ubuntu4) eoan; urgency=medium * Add dependency on golang-github-docker-docker-credential-helpers-dev, needed by github.com/docker/cli/cli/config/credentials/native_store.go. -- Steve Langasek <steve.langasek@ubuntu.com> Fri, 23 Aug 2019 14:21:42 -0700 docker.io (18.09.8-0ubuntu3) eoan; urgency=medium * d/tests/docker-in-lxd: skip on eoan+/i386 as lxd images are no longer provided. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Thu, 18 Jul 2019 22:44:03 +1200 docker.io (18.09.8-0ubuntu2) eoan; urgency=medium * Remove extraneous start/stop of docker via init.d script from basic-smoke autopkgtest. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Thu, 18 Jul 2019 15:42:38 +1200 docker.io (18.09.8-0ubuntu1) eoan; urgency=medium [ Michael Hudson-Doyle ] * Version dependency on containerd. [ Tianon Gravi ] * Remove sysvinit and upstart scripts (LP: #1832819) * Update to 18.09.8 (CVE-2019-13509, LP: #1836987) -- Tianon Gravi <tianon@debian.org> Wed, 17 Jul 2019 18:26:58 -0700 docker.io (18.09.7-0ubuntu1) eoan; urgency=medium * Update to 18.09.7. (LP: #1834690) - Includes fix for CVE-2018-15664. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Fri, 28 Jun 2019 21:13:02 +0100 docker.io (18.09.5-0ubuntu1) disco; urgency=medium * Update to 18.09.5. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Fri, 12 Apr 2019 12:27:37 +1200 docker.io (18.09.3-0ubuntu1) disco; urgency=medium * Update to 18.09.3. - update d/upstream-version-commits - refresh d/patches/docker-prefix.patch to maintain dependence on docker-specific containerd daemon. - remove d/patches/0001-nsenter-clone-proc-self-exe-to-avoid-exposing-host-b.patch, now included upstream. * Stop bundling containerd and runc and instead depend on the containerd package from the archive. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Thu, 14 Mar 2019 11:22:11 +1300 docker.io (18.09.2-0ubuntu1) disco; urgency=medium * Update to 18.09.2, including fix for CVE-2019-5736. - Convert components/engine/git-bundles/CVE-2019-5736.bundle into d/patches/0001-nsenter-clone-proc-self-exe-to-avoid-exposing-host-b.patch. - Hard code RUNC_COMMIT in d/rules for now. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Tue, 12 Feb 2019 10:55:11 +1300 docker.io (18.09.1-0ubuntu2) disco; urgency=medium * Update "docker-prefix.patch" to also fix "docker.service" -- Tianon Gravi <tianon@debian.org> Fri, 08 Feb 2019 14:52:47 -0800 docker.io (18.09.1-0~ubuntu1) disco; urgency=medium [ Michael Hudson-Doyle ] * d/tests/docker-in-lxd: Increase timeout passed to lxd waitready. [ Tianon Gravi ] * Update to 18.09.1 upstream release [ Michael Hudson-Doyle ] * d/rules: Empty XDG_RUNTIME_DIR when smoke testing runc to avoid it doing silly things. * d/golang-github-docker-docker-dev.install: install some more go packages that other packages in the archive depend on. -- Tianon Gravi <tianon@debian.org> Thu, 17 Jan 2019 16:14:51 -0800 docker.io (18.06.1-0ubuntu2) disco; urgency=medium * Fix containerd/runc embedded commit values * Add "libsystemd-dev" to "Build-Depends" (LP: #1802979) -- Tianon Gravi <tianon@debian.org> Fri, 19 Oct 2018 13:06:35 -0700 docker.io (18.06.1-0ubuntu1) cosmic; urgency=medium * Update to 18.06.1 upstream release (LP: #1794396) - drop "fix-btrfs-constants.patch" (applied upstream) * Update debconf to prompt more aggressively (LP: #1784602) 1. does not prompt on initial install (but does start the daemon) 2. does prompt on every reinstall / upgrade (if the daemon is running) 3. does prompt during "dpkg-reconfigure docker.io" (but does _not_ [re]start the daemon) 4. works properly with DEBIAN_FRONTEND=noninteractive -- user's previous/stored answer to the question automatically applies with no prompt * Check if "docker" group exists before creating it (LP: #1769911) -- Tianon Gravi <tianon@debian.org> Mon, 24 Sep 2018 15:42:19 -0700 docker.io (17.12.1-0ubuntu6) cosmic; urgency=medium * d/tests/docker-in-lxd: Avoid startup race and drop lxd-client depends -- Stéphane Graber <stgraber@ubuntu.com> Sat, 15 Sep 2018 03:07:49 +0200 docker.io (17.12.1-0ubuntu5) cosmic; urgency=medium * Fix ftbfs by cherry-picking https://github.com/containerd/btrfs/pull/16. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Wed, 01 Aug 2018 11:40:05 +1200 docker.io (17.12.1-0ubuntu4) cosmic; urgency=medium * d/tests/docker-in-lxd: only setup network bridge if missing -- Stéphane Graber <stgraber@ubuntu.com> Tue, 05 Jun 2018 22:58:51 -0400 docker.io (17.12.1-0ubuntu3) cosmic; urgency=medium * d/tests/docker-in-lxd: switch to ubuntu-daily lxd remote and wait for cloud-init to finish before running commands in the container. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Tue, 22 May 2018 10:54:00 +1200 docker.io (17.12.1-0ubuntu2) cosmic; urgency=medium * Update btrfs dependencies to use the new libbtrfs-dev & btrfs-progs. -- Dimitri John Ledkov <xnox@ubuntu.com> Thu, 17 May 2018 09:27:15 +0100 docker.io (17.12.1-0ubuntu1) bionic; urgency=medium [ Tianon Gravi ] * Update to 17.12.1-ce upstream release - swap from github.com/docker/docker to .../docker/docker-ce - build separate components in a way that can be parallelized - remove older (unsupported) contrib/ bits from being shipped - drop a lot of unnecessary packaging bits from debian/ * Adjust debconf prompt: - ask during _every_ upgrade - default to not restarting [ Michael Hudson-Doyle ] * Switch to building with default version of Go. * Adjust debconf template to match change in behavior. -- Tianon Gravi <tianon@debian.org> Wed, 28 Feb 2018 09:46:05 -0800 docker.io (17.03.2-0ubuntu5) bionic; urgency=medium * d/control, d/rules: Fix FTBFS when built with golang 1.10 by build depending on golang-1.9-go. See https://github.com/moby/moby/pull/35739 for upstream discussion on golang 1.10 compatibility. -- Tyler Hicks <tyhicks@canonical.com> Tue, 20 Mar 2018 13:57:16 +0000 docker.io (17.03.2-0ubuntu4) bionic; urgency=medium * d/tests/docker-in-lxd: Fix failing test due to /etc/resolv.conf being a symlink in Bionic. The 'lxc file pull <path> -' command prints the symlink contents (the target path) to stdout, rather than the contents of the target file, so use 'lxc exec' to grep /etc/resolv.conf. Grep will follow the symlink in situations where /etc/resolv.conf is a symlink. -- Tyler Hicks <tyhicks@canonical.com> Mon, 19 Mar 2018 19:35:52 +0000 docker.io (17.03.2-0ubuntu3) bionic; urgency=medium * d/tests/docker-in-lxd: set DEBIAN_FRONTEND=noninteractive when installing docker in the lxd container -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Wed, 21 Feb 2018 10:49:58 +1300 docker.io (17.03.2-0ubuntu2) bionic; urgency=medium * Replace "--no-restart-on-upgrade" with "--no-start" and a debconf prompt - not restarting Docker causes many issues (LP: #1658691) - suggested methods for keeping containers up are to use a restart policy ("--restart=..." on "docker run"), Swarm Mode services, or rolling replacement of k8s workers * Backport 30519 for bashism (LP: #1744599) - https://github.com/docker/docker/pull/30519 -- Tianon Gravi <tianon@debian.org> Thu, 07 Dec 2017 09:42:53 -0800 docker.io (17.03.2-0ubuntu1) bionic; urgency=medium * Update to 17.03.2 upstream release -- Tianon Gravi <tianon@debian.org> Wed, 01 Nov 2017 12:30:17 -0700 docker.io (1.13.1-0ubuntu6) artful; urgency=medium * Add missing "runc" patches for LXD-enablement -- Tianon Gravi <tianon@debian.org> Wed, 11 Oct 2017 19:38:03 -0700 docker.io (1.13.1-0ubuntu5) artful; urgency=medium * Replace "runc" dependency with a multiorig copy of Docker's exact supported commit contents (installed as "/usr/bin/docker-runc" mirroring upstream's package) * Replace "containerd" in the same way (with the exact upstream-supported commit, binaries installed as "/usr/bin/docker-containerd*") -- Tianon Gravi <tianon@debian.org> Fri, 29 Sep 2017 13:22:39 -0700 docker.io (1.13.1-0ubuntu4) artful; urgency=medium * d/tests/docker-in-lxd: Better handle DNS with systemd-resolved. -- Stéphane Graber <stgraber@ubuntu.com> Thu, 21 Sep 2017 01:12:33 -0400 docker.io (1.13.1-0ubuntu3) artful; urgency=medium * d/tests/docker-in-lxd: check for network-up has a race condition when systemd-resolved is used. Add an additional check for a real DNS server in systemd-resolve --status. -- Steve Langasek <steve.langasek@ubuntu.com> Fri, 15 Sep 2017 23:32:16 -0700 docker.io (1.13.1-0ubuntu2) artful; urgency=medium * d/tests/docker-in-lxd: copy more apt config into container * d/golang-github-docker-docker-dev.install: install missing packages. (LP: #1714564) * d/control: Add Build-Depend on tzdata. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Mon, 04 Sep 2017 13:31:34 +1200 docker.io (1.13.1-0ubuntu1) artful; urgency=medium * Update to 1.13.1 upstream release - refresh patches (removing many that are applied upstream in 1.13+) - use dh_clean (via debian/clean) instead of explicit "rm" in rules - pull in explicit libnetwork sources for "docker-proxy" - drop unnecessary dh_golang usage (only used for Built-Using calculation) - update "upstream-version-gitcommits" with a more recent list of commits - add "tini" for building "docker-init" (used by "docker run --init") - prefer Go 1.7 explicitly if it's available -- Tianon Gravi <tianon@debian.org> Tue, 22 Aug 2017 09:30:24 -0700 docker.io (1.12.6-0ubuntu7) artful; urgency=medium * Make sure to set security.nesting for the LXD autopkgtest. -- Stéphane Graber <stgraber@ubuntu.com> Tue, 06 Jun 2017 14:55:34 -0600 docker.io (1.12.6-0ubuntu6) artful; urgency=medium * Fix FTBFS on Go 1.8. -- Stéphane Graber <stgraber@ubuntu.com> Mon, 05 Jun 2017 16:21:16 -0600 docker.io (1.12.6-0ubuntu5) artful; urgency=medium * Update LXD autopkgtest now that the "docker" profile is deprecated. -- Stéphane Graber <stgraber@ubuntu.com> Mon, 05 Jun 2017 15:59:18 -0600 docker.io (1.12.6-0ubuntu4) zesty; urgency=medium * Revert 1.12.6-0ubuntu2 as it does not achieve the stated goal on both s390x and armhf. And lxc/lxd adt runners are too restrictive to e.g. import an ubuntu-base container for a minimal functional test. -- Dimitri John Ledkov <xnox@ubuntu.com> Tue, 14 Mar 2017 09:41:30 +0000 docker.io (1.12.6-0ubuntu3) zesty; urgency=medium * debian/tests/docker-in-lxd: Fix a latent version comparison bug that was causing migration failures due to the script thinking it was dealing with an old LXD (< 2.2) when it was really dealing with a recent LXD (>= 2.10). The fix is to use `lxc info` to check if the network extension is supported, rather than trying to compare version strings. -- Tyler Hicks <tyhicks@canonical.com> Fri, 10 Mar 2017 17:40:22 +0000 docker.io (1.12.6-0ubuntu2) zesty; urgency=medium * Remove isolation-machine restriction from adt smoke-test testcase. Should pass on s390x lxd runners; will fails on armhf runners but that is not a regressions since previously all tests were simply skipped on armhf. LP: #1658150 -- Dimitri John Ledkov <xnox@ubuntu.com> Wed, 01 Feb 2017 10:08:00 +0000 docker.io (1.12.6-0ubuntu1) zesty; urgency=medium * Update to 1.12.6 upstream release (LP: #1655906) - add a few new privileged tests to "skip-privileged-unit-tests.patch" * Adjust runc Depends to ensure fix for CVE-2016-9962 is included -- Tianon Gravi <tianon@debian.org> Fri, 13 Jan 2017 11:57:24 +1300 docker.io (1.12.3-0ubuntu4) zesty; urgency=medium * Explicity depend on the version of runc that was built with seccomp support. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Mon, 12 Dec 2016 11:15:01 +1300 docker.io (1.12.3-0ubuntu3) zesty; urgency=medium [ Michael Hudson-Doyle ] * d/test/docker-in-lxd: make test for "is network up" more robust. [ Stefan Bader ] * Backport upstream 1.13 change to keep existing bridges untouched (LP: #1647376) - upstream-1.13-Vendor-libnetwork-51d88e9ae63f.patch -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Thu, 08 Dec 2016 11:53:36 +1300 docker.io (1.12.3-0ubuntu2) zesty; urgency=medium [ Tianon Gravi ] * Enable seccomp support (LP: #1639407) -- Steve Langasek <steve.langasek@ubuntu.com> Wed, 30 Nov 2016 12:34:22 -0800 docker.io (1.12.3-0ubuntu1) zesty; urgency=medium * Update to 1.12.3 upstream release - https://github.com/docker/docker/releases/tag/v1.12.2 - https://github.com/docker/docker/releases/tag/v1.12.3 -- Tianon Gravi <tianon@debian.org> Tue, 15 Nov 2016 15:50:32 -0800 docker.io (1.12.1-0ubuntu15) yakkety; urgency=medium * d/test/docker-in-lxd: use images:ubuntu/${suite}/${arch} instead of ubuntu-daily:${suite} because the former does not have cloud-init in it to rewrite /etc/apt/sources.list at unexpected times. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Mon, 10 Oct 2016 21:38:17 +1300 docker.io (1.12.1-0ubuntu14) yakkety; urgency=medium * d/test/docker-in-lxd: cope with changes in lxd 2.3. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Mon, 10 Oct 2016 15:30:42 +1300 docker.io (1.12.1-0ubuntu13) yakkety; urgency=medium * d/tests/docker-in-lxd: copy apt config from host to container rather than just enabling all of the -proposed pocket. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Tue, 27 Sep 2016 12:23:56 +1300 docker.io (1.12.1-0ubuntu12) yakkety; urgency=medium * Final(?) docker-in-lxd fix: of course, alpine:latest is only the name of the image on amd64. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Mon, 19 Sep 2016 20:34:59 +1200 docker.io (1.12.1-0ubuntu11) yakkety; urgency=medium * Even more docker-in-lxd fixes. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Mon, 19 Sep 2016 14:14:33 +1200 docker.io (1.12.1-0ubuntu10) yakkety; urgency=medium * Yet another docker-in-lxd fix. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Fri, 16 Sep 2016 19:02:41 +1200 docker.io (1.12.1-0ubuntu9) yakkety; urgency=medium * Proxy related fix for docker-in-lxd. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Fri, 16 Sep 2016 18:59:54 +1200 docker.io (1.12.1-0ubuntu8) yakkety; urgency=medium * Re-enable docker-in-lxd again after many fixes. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Fri, 16 Sep 2016 12:26:04 +1200 docker.io (1.12.1-0ubuntu7) yakkety; urgency=medium * d/tests/control: disable docker-in-lxd again, does not work in production infrastructure. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Thu, 08 Sep 2016 09:41:13 +1200 docker.io (1.12.1-0ubuntu6) yakkety; urgency=medium * d/tests/control: docker-in-lxd needs to depend on lxd-client as well. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Wed, 07 Sep 2016 21:18:18 +1200 docker.io (1.12.1-0ubuntu5) yakkety; urgency=medium * Ignore failure to set oom_score_adj, as happens in an unprivileged container. * Use $DOCKER_OPTS in service file again. * Add an autopkgtest to test docker-in-lxd. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Wed, 07 Sep 2016 15:36:50 +1200 docker.io (1.12.1-0ubuntu4) yakkety; urgency=medium * Fix service file. -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Wed, 07 Sep 2016 14:13:12 +1200 docker.io (1.12.1-0ubuntu3) yakkety; urgency=medium * Skip "TestOverlay50LayerRead" on "overlay" driver too (in "skip-privileged-unit-tests.patch") -- Tianon Gravi <tianon@debian.org> Mon, 29 Aug 2016 16:00:00 -0700 docker.io (1.12.1-0ubuntu2) yakkety; urgency=medium * Add new "overlay2" driver's tests to "skip-privileged-unit-tests.patch" (FTBFS fix) -- Tianon Gravi <tianon@debian.org> Fri, 26 Aug 2016 10:20:24 -0700 docker.io (1.12.1-0ubuntu1) yakkety; urgency=medium * Update to 1.12.1 upstream release (LP: #1602243) - refresh "cgroupfs-mount-convenience-copy.patch" - remove "fatal-error-old-kernels.patch"; applied upstream, https://github.com/docker/docker/commit/51b23d88422918c24291f5876df35f91b23a446a - refresh "change-system-unit-env-file.patch" - refresh "21491--systemd-tasksmax.patch" - remove "22000--ignore-invalid-host-header.patch"; applied upstream, https://github.com/docker/docker/pull/22000 https://github.com/docker/docker/pull/22888 https://github.com/docker/docker/pull/23046 - refresh "remove-docker-prefix.patch" - refresh "skip-privileged-unit-tests.patch"; add new privileged tests, + TestMakeRemoteContext + TestMakeSumTarContext + TestDispatch + TestEmptyDockerfile + TestDockerfileOutsideTheBuildContext + TestRealodNoOpts - replace "lxd--20902--docker-in-userns.patch" with the upstream-applied "lxd--25672--docker-in-userns.patch" - remove "lxd--runc-617.patch"; no longer necessary (due to kernel fixes), https://github.com/opencontainers/runc/pull/617#issuecomment-223654149 - remove "21714--no-aufs-in-userns.patch"; applied upstream, https://github.com/docker/docker/pull/21714 - add "man" to "DH_GOLANG_EXCLUDES" (has new "generate.go" which imports the non-vendored "github.com/spf13/cobra/doc", causing dh_golang to choke) - add "docker-proxy-vendor.patch" to account for "vendor/..." vs "vendor/src/..." - install new explicit "dockerd" and "docker-proxy" binaries - update containerd dependency (>= 0.2.3) - update runc dependency (>= 1.0.0-rc1) * Update "debian/watch" to use "uscan.tianon.xyz" so older versions are still easily fetchable without excess work outside uscan -- Tianon Gravi <tianon@debian.org> Wed, 24 Aug 2016 11:48:34 -0700 docker.io (1.11.2-0ubuntu6) yakkety; urgency=medium * Merge from Debian Unstable: - more README.Debian notes (including a fixed href) - new "docker-doc" package which contains the documentation - use "dh-golang" for building (generates appropriate Built-Using) - run upstream unit tests during dh_auto_test - convert upstream-discouraged "/etc/default/docker" to comments-only - utilize dh_install (w/dh-exec) more fully to simplify debian/rules - fix "/etc/docker" permissions for co-existence with docker-registry - remove "/var/lib/docker" on purge * Remaining Ubuntu delta: - non-pruned vendor/ (included in golang-github-docker-docker-dev) - Docker-in-userns patches * Changes from pending Debian upload: - build from within GOPATH so Go packages are resolved properly - split "dh_auto_build-arch" from "dh_auto_build-indep" - include vendor/ in golang-github-docker-docker-dev (since we don't necessarily have the appropriate packages for Depends on that package) -- Tianon Gravi <tianon@debian.org> Fri, 19 Aug 2016 10:15:14 -0700

Modifications :
  1. Download patch cli/cli/command/container/testdata/container-create-localhost-dns-ipv6.golden

    --- 19.03.7+dfsg1-3/cli/cli/command/container/testdata/container-create-localhost-dns-ipv6.golden 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/testdata/container-create-localhost-dns-ipv6.golden 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -WARNING: Localhost DNS setting (--dns=::1) may fail in containers.
  2. Download patch cli/cli/command/container/list_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/list_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/list_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,163 +0,0 @@ -package container - -import ( - "fmt" - "io/ioutil" - "testing" - - "github.com/docker/cli/cli/config/configfile" - "github.com/docker/cli/internal/test" - . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function - "github.com/docker/docker/api/types" - "gotest.tools/assert" - "gotest.tools/golden" -) - -func TestContainerListErrors(t *testing.T) { - testCases := []struct { - args []string - flags map[string]string - containerListFunc func(types.ContainerListOptions) ([]types.Container, error) - expectedError string - }{ - { - flags: map[string]string{ - "format": "{{invalid}}", - }, - expectedError: `function "invalid" not defined`, - }, - { - flags: map[string]string{ - "format": "{{join}}", - }, - expectedError: `wrong number of args for join`, - }, - { - containerListFunc: func(_ types.ContainerListOptions) ([]types.Container, error) { - return nil, fmt.Errorf("error listing containers") - }, - expectedError: "error listing containers", - }, - } - for _, tc := range testCases { - cmd := newListCommand( - test.NewFakeCli(&fakeClient{ - containerListFunc: tc.containerListFunc, - }), - ) - cmd.SetArgs(tc.args) - for key, value := range tc.flags { - cmd.Flags().Set(key, value) - } - cmd.SetOutput(ioutil.Discard) - assert.ErrorContains(t, cmd.Execute(), tc.expectedError) - } -} - -func TestContainerListWithoutFormat(t *testing.T) { - cli := test.NewFakeCli(&fakeClient{ - containerListFunc: func(_ types.ContainerListOptions) ([]types.Container, error) { - return []types.Container{ - *Container("c1"), - *Container("c2", WithName("foo")), - *Container("c3", WithPort(80, 80, TCP), WithPort(81, 81, TCP), WithPort(82, 82, TCP)), - *Container("c4", WithPort(81, 81, UDP)), - *Container("c5", WithPort(82, 82, IP("8.8.8.8"), TCP)), - }, nil - }, - }) - cmd := newListCommand(cli) - assert.NilError(t, cmd.Execute()) - golden.Assert(t, cli.OutBuffer().String(), "container-list-without-format.golden") -} - -func TestContainerListNoTrunc(t *testing.T) { - cli := test.NewFakeCli(&fakeClient{ - containerListFunc: func(_ types.ContainerListOptions) ([]types.Container, error) { - return []types.Container{ - *Container("c1"), - *Container("c2", WithName("foo/bar")), - }, nil - }, - }) - cmd := newListCommand(cli) - cmd.Flags().Set("no-trunc", "true") - assert.NilError(t, cmd.Execute()) - golden.Assert(t, cli.OutBuffer().String(), "container-list-without-format-no-trunc.golden") -} - -// Test for GitHub issue docker/docker#21772 -func TestContainerListNamesMultipleTime(t *testing.T) { - cli := test.NewFakeCli(&fakeClient{ - containerListFunc: func(_ types.ContainerListOptions) ([]types.Container, error) { - return []types.Container{ - *Container("c1"), - *Container("c2", WithName("foo/bar")), - }, nil - }, - }) - cmd := newListCommand(cli) - cmd.Flags().Set("format", "{{.Names}} {{.Names}}") - assert.NilError(t, cmd.Execute()) - golden.Assert(t, cli.OutBuffer().String(), "container-list-format-name-name.golden") -} - -// Test for GitHub issue docker/docker#30291 -func TestContainerListFormatTemplateWithArg(t *testing.T) { - cli := test.NewFakeCli(&fakeClient{ - containerListFunc: func(_ types.ContainerListOptions) ([]types.Container, error) { - return []types.Container{ - *Container("c1", WithLabel("some.label", "value")), - *Container("c2", WithName("foo/bar"), WithLabel("foo", "bar")), - }, nil - }, - }) - cmd := newListCommand(cli) - cmd.Flags().Set("format", `{{.Names}} {{.Label "some.label"}}`) - assert.NilError(t, cmd.Execute()) - golden.Assert(t, cli.OutBuffer().String(), "container-list-format-with-arg.golden") -} - -func TestContainerListFormatSizeSetsOption(t *testing.T) { - cli := test.NewFakeCli(&fakeClient{ - containerListFunc: func(options types.ContainerListOptions) ([]types.Container, error) { - assert.Check(t, options.Size) - return []types.Container{}, nil - }, - }) - cmd := newListCommand(cli) - cmd.Flags().Set("format", `{{.Size}}`) - assert.NilError(t, cmd.Execute()) -} - -func TestContainerListWithConfigFormat(t *testing.T) { - cli := test.NewFakeCli(&fakeClient{ - containerListFunc: func(_ types.ContainerListOptions) ([]types.Container, error) { - return []types.Container{ - *Container("c1", WithLabel("some.label", "value")), - *Container("c2", WithName("foo/bar"), WithLabel("foo", "bar")), - }, nil - }, - }) - cli.SetConfigFile(&configfile.ConfigFile{ - PsFormat: "{{ .Names }} {{ .Image }} {{ .Labels }}", - }) - cmd := newListCommand(cli) - assert.NilError(t, cmd.Execute()) - golden.Assert(t, cli.OutBuffer().String(), "container-list-with-config-format.golden") -} - -func TestContainerListWithFormat(t *testing.T) { - cli := test.NewFakeCli(&fakeClient{ - containerListFunc: func(_ types.ContainerListOptions) ([]types.Container, error) { - return []types.Container{ - *Container("c1", WithLabel("some.label", "value")), - *Container("c2", WithName("foo/bar"), WithLabel("foo", "bar")), - }, nil - }, - }) - 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") -}
  3. Download patch cli/cli/command/config/create.go

    --- 19.03.7+dfsg1-3/cli/cli/command/config/create.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/create.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,88 +0,0 @@ -package config - -import ( - "context" - "fmt" - "io" - "io/ioutil" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/docker/cli/opts" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/pkg/system" - "github.com/pkg/errors" - "github.com/spf13/cobra" -) - -// CreateOptions specifies some options that are used when creating a config. -type CreateOptions struct { - Name string - TemplateDriver string - File string - Labels opts.ListOpts -} - -func newConfigCreateCommand(dockerCli command.Cli) *cobra.Command { - createOpts := CreateOptions{ - Labels: opts.NewListOpts(opts.ValidateLabel), - } - - cmd := &cobra.Command{ - Use: "create [OPTIONS] CONFIG file|-", - Short: "Create a config from a file or STDIN", - Args: cli.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - createOpts.Name = args[0] - createOpts.File = args[1] - return RunConfigCreate(dockerCli, createOpts) - }, - } - flags := cmd.Flags() - flags.VarP(&createOpts.Labels, "label", "l", "Config labels") - flags.StringVar(&createOpts.TemplateDriver, "template-driver", "", "Template driver") - flags.SetAnnotation("template-driver", "version", []string{"1.37"}) - - return cmd -} - -// RunConfigCreate creates a config with the given options. -func RunConfigCreate(dockerCli command.Cli, options CreateOptions) error { - client := dockerCli.Client() - ctx := context.Background() - - var in io.Reader = dockerCli.In() - if options.File != "-" { - file, err := system.OpenSequential(options.File) - if err != nil { - return err - } - in = file - defer file.Close() - } - - configData, err := ioutil.ReadAll(in) - if err != nil { - return errors.Errorf("Error reading content from %q: %v", options.File, err) - } - - spec := swarm.ConfigSpec{ - Annotations: swarm.Annotations{ - Name: options.Name, - Labels: opts.ConvertKVStringsToMap(options.Labels.GetAll()), - }, - Data: configData, - } - if options.TemplateDriver != "" { - spec.Templating = &swarm.Driver{ - Name: options.TemplateDriver, - } - } - r, err := client.ConfigCreate(ctx, spec) - if err != nil { - return err - } - - fmt.Fprintln(dockerCli.Out(), r.ID) - return nil -}
  4. Download patch cli/cli/command/checkpoint/remove_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/checkpoint/remove_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/checkpoint/remove_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,65 +0,0 @@ -package checkpoint - -import ( - "io/ioutil" - "testing" - - "github.com/docker/cli/internal/test" - "github.com/docker/docker/api/types" - "github.com/pkg/errors" - "gotest.tools/assert" - is "gotest.tools/assert/cmp" -) - -func TestCheckpointRemoveErrors(t *testing.T) { - testCases := []struct { - args []string - checkpointDeleteFunc func(container string, options types.CheckpointDeleteOptions) error - expectedError string - }{ - { - args: []string{"too-few-arguments"}, - expectedError: "requires exactly 2 arguments", - }, - { - args: []string{"too", "many", "arguments"}, - expectedError: "requires exactly 2 arguments", - }, - { - args: []string{"foo", "bar"}, - checkpointDeleteFunc: func(container string, options types.CheckpointDeleteOptions) error { - return errors.Errorf("error deleting checkpoint") - }, - expectedError: "error deleting checkpoint", - }, - } - - for _, tc := range testCases { - cli := test.NewFakeCli(&fakeClient{ - checkpointDeleteFunc: tc.checkpointDeleteFunc, - }) - cmd := newRemoveCommand(cli) - cmd.SetArgs(tc.args) - cmd.SetOutput(ioutil.Discard) - assert.ErrorContains(t, cmd.Execute(), tc.expectedError) - } -} - -func TestCheckpointRemoveWithOptions(t *testing.T) { - var containerID, checkpointID, checkpointDir string - cli := test.NewFakeCli(&fakeClient{ - checkpointDeleteFunc: func(container string, options types.CheckpointDeleteOptions) error { - containerID = container - checkpointID = options.CheckpointID - checkpointDir = options.CheckpointDir - return nil - }, - }) - cmd := newRemoveCommand(cli) - cmd.SetArgs([]string{"container-foo", "checkpoint-bar"}) - cmd.Flags().Set("checkpoint-dir", "/dir/foo") - assert.NilError(t, cmd.Execute()) - assert.Check(t, is.Equal("container-foo", containerID)) - assert.Check(t, is.Equal("checkpoint-bar", checkpointID)) - assert.Check(t, is.Equal("/dir/foo", checkpointDir)) -}
  5. Download patch cli/cli/command/container/stats_unit_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/stats_unit_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/stats_unit_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,30 +0,0 @@ -package container - -import ( - "testing" - - "github.com/docker/docker/api/types" -) - -func TestCalculateBlockIO(t *testing.T) { - blkio := types.BlkioStats{ - IoServiceBytesRecursive: []types.BlkioStatEntry{ - {Major: 8, Minor: 0, Op: "read", Value: 1234}, - {Major: 8, Minor: 1, Op: "read", Value: 4567}, - {Major: 8, Minor: 0, Op: "Read", Value: 6}, - {Major: 8, Minor: 1, Op: "Read", Value: 8}, - {Major: 8, Minor: 0, Op: "write", Value: 123}, - {Major: 8, Minor: 1, Op: "write", Value: 456}, - {Major: 8, Minor: 0, Op: "Write", Value: 6}, - {Major: 8, Minor: 1, Op: "Write", Value: 8}, - {Major: 8, Minor: 1, Op: "", Value: 456}, - }, - } - blkRead, blkWrite := calculateBlockIO(blkio) - if blkRead != 5815 { - t.Fatalf("blkRead = %d, want 5815", blkRead) - } - if blkWrite != 593 { - t.Fatalf("blkWrite = %d, want 593", blkWrite) - } -}
  6. Download patch cli/cli/command/container/stats_helpers_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/stats_helpers_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/stats_helpers_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,47 +0,0 @@ -package container - -import ( - "fmt" - "testing" - - "github.com/docker/docker/api/types" - "gotest.tools/assert" -) - -func TestCalculateMemUsageUnixNoCache(t *testing.T) { - // Given - stats := types.MemoryStats{Usage: 500, Stats: map[string]uint64{"cache": 400}} - - // When - result := calculateMemUsageUnixNoCache(stats) - - // Then - assert.Assert(t, inDelta(100.0, result, 1e-6)) -} - -func TestCalculateMemPercentUnixNoCache(t *testing.T) { - // Given - someLimit := float64(100.0) - noLimit := float64(0.0) - used := float64(70.0) - - // When and Then - t.Run("Limit is set", func(t *testing.T) { - result := calculateMemPercentUnixNoCache(someLimit, used) - assert.Assert(t, inDelta(70.0, result, 1e-6)) - }) - t.Run("No limit, no cgroup data", func(t *testing.T) { - result := calculateMemPercentUnixNoCache(noLimit, used) - assert.Assert(t, inDelta(0.0, result, 1e-6)) - }) -} - -func inDelta(x, y, delta float64) func() (bool, string) { - return func() (bool, string) { - diff := x - y - if diff < -delta || diff > delta { - return false, fmt.Sprintf("%f != %f within %f", x, y, delta) - } - return true, "" - } -}
  7. Download patch cli/cli/command/container/testdata/container-create-oom-kill-without-memory-limit.golden

    --- 19.03.7+dfsg1-3/cli/cli/command/container/testdata/container-create-oom-kill-without-memory-limit.golden 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/testdata/container-create-oom-kill-without-memory-limit.golden 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -WARNING: Disabling the OOM killer on containers without setting a '-m/--memory' limit may be dangerous.
  8. Download patch cli/cli/command/container/opts_test.go
  9. Download patch cli/cli/command/container/exec_test.go
  10. Download patch cli/cli/command/config/testdata/config-inspect-without-format.single-config.golden

    --- 19.03.7+dfsg1-3/cli/cli/command/config/testdata/config-inspect-without-format.single-config.golden 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/testdata/config-inspect-without-format.single-config.golden 1970-01-01 00:00:00.000000000 +0000 @@ -1,12 +0,0 @@ -[ - { - "ID": "ID-foo", - "Version": {}, - "CreatedAt": "0001-01-01T00:00:00Z", - "UpdatedAt": "0001-01-01T00:00:00Z", - "Spec": { - "Name": "foo", - "Labels": null - } - } -]
  11. Download patch cli/cli/command/config/testdata/config-inspect-with-format.json-template.golden

    --- 19.03.7+dfsg1-3/cli/cli/command/config/testdata/config-inspect-with-format.json-template.golden 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/testdata/config-inspect-with-format.json-template.golden 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -{"label1":"label-foo"}
  12. Download patch cli/cli/command/container/export_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/export_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/export_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,49 +0,0 @@ -package container - -import ( - "io" - "io/ioutil" - "strings" - "testing" - - "github.com/docker/cli/internal/test" - "gotest.tools/assert" - "gotest.tools/fs" -) - -func TestContainerExportOutputToFile(t *testing.T) { - dir := fs.NewDir(t, "export-test") - defer dir.Remove() - - cli := test.NewFakeCli(&fakeClient{ - containerExportFunc: func(container string) (io.ReadCloser, error) { - return ioutil.NopCloser(strings.NewReader("bar")), nil - }, - }) - cmd := NewExportCommand(cli) - cmd.SetOutput(ioutil.Discard) - cmd.SetArgs([]string{"-o", dir.Join("foo"), "container"}) - assert.NilError(t, cmd.Execute()) - - expected := fs.Expected(t, - fs.WithFile("foo", "bar", fs.MatchAnyFileMode), - ) - - assert.Assert(t, fs.Equal(dir.Path(), expected)) -} - -func TestContainerExportOutputToIrregularFile(t *testing.T) { - cli := test.NewFakeCli(&fakeClient{ - containerExportFunc: func(container string) (io.ReadCloser, error) { - return ioutil.NopCloser(strings.NewReader("foo")), nil - }, - }) - cmd := NewExportCommand(cli) - cmd.SetOutput(ioutil.Discard) - cmd.SetArgs([]string{"-o", "/dev/random", "container"}) - - err := cmd.Execute() - assert.Assert(t, err != nil) - expected := `"/dev/random" must be a directory or a regular file` - assert.ErrorContains(t, err, expected) -}
  13. Download patch cli/cli/command/checkpoint/list_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/checkpoint/list_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/checkpoint/list_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,67 +0,0 @@ -package checkpoint - -import ( - "io/ioutil" - "testing" - - "github.com/docker/cli/internal/test" - "github.com/docker/docker/api/types" - "github.com/pkg/errors" - "gotest.tools/assert" - is "gotest.tools/assert/cmp" - "gotest.tools/golden" -) - -func TestCheckpointListErrors(t *testing.T) { - testCases := []struct { - args []string - checkpointListFunc func(container string, options types.CheckpointListOptions) ([]types.Checkpoint, error) - expectedError string - }{ - { - args: []string{}, - expectedError: "requires exactly 1 argument", - }, - { - args: []string{"too", "many", "arguments"}, - expectedError: "requires exactly 1 argument", - }, - { - args: []string{"foo"}, - checkpointListFunc: func(container string, options types.CheckpointListOptions) ([]types.Checkpoint, error) { - return []types.Checkpoint{}, errors.Errorf("error getting checkpoints for container foo") - }, - expectedError: "error getting checkpoints for container foo", - }, - } - - for _, tc := range testCases { - cli := test.NewFakeCli(&fakeClient{ - checkpointListFunc: tc.checkpointListFunc, - }) - cmd := newListCommand(cli) - cmd.SetArgs(tc.args) - cmd.SetOutput(ioutil.Discard) - assert.ErrorContains(t, cmd.Execute(), tc.expectedError) - } -} - -func TestCheckpointListWithOptions(t *testing.T) { - var containerID, checkpointDir string - cli := test.NewFakeCli(&fakeClient{ - checkpointListFunc: func(container string, options types.CheckpointListOptions) ([]types.Checkpoint, error) { - containerID = container - checkpointDir = options.CheckpointDir - return []types.Checkpoint{ - {Name: "checkpoint-foo"}, - }, nil - }, - }) - cmd := newListCommand(cli) - cmd.SetArgs([]string{"container-foo"}) - cmd.Flags().Set("checkpoint-dir", "/dir/foo") - assert.NilError(t, cmd.Execute()) - assert.Check(t, is.Equal("container-foo", containerID)) - assert.Check(t, is.Equal("/dir/foo", checkpointDir)) - golden.Assert(t, cli.OutBuffer().String(), "checkpoint-list-with-options.golden") -}
  14. Download patch cli/cli/command/container/exec.go
  15. Download patch cli/cli/command/config/formatter_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/config/formatter_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/formatter_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,65 +0,0 @@ -package config - -import ( - "bytes" - "testing" - "time" - - "github.com/docker/cli/cli/command/formatter" - "github.com/docker/docker/api/types/swarm" - "gotest.tools/assert" - is "gotest.tools/assert/cmp" -) - -func TestConfigContextFormatWrite(t *testing.T) { - // Check default output format (verbose and non-verbose mode) for table headers - cases := []struct { - context formatter.Context - expected string - }{ - // Errors - { - formatter.Context{Format: "{{InvalidFunction}}"}, - `Template parsing error: template: :1: function "InvalidFunction" not defined -`, - }, - { - formatter.Context{Format: "{{nil}}"}, - `Template parsing error: template: :1:2: executing "" at <nil>: nil is not a command -`, - }, - // Table format - {formatter.Context{Format: NewFormat("table", false)}, - `ID NAME CREATED UPDATED -1 passwords Less than a second ago Less than a second ago -2 id_rsa Less than a second ago Less than a second ago -`}, - {formatter.Context{Format: NewFormat("table {{.Name}}", true)}, - `NAME -passwords -id_rsa -`}, - {formatter.Context{Format: NewFormat("{{.ID}}-{{.Name}}", false)}, - `1-passwords -2-id_rsa -`}, - } - - configs := []swarm.Config{ - {ID: "1", - Meta: swarm.Meta{CreatedAt: time.Now(), UpdatedAt: time.Now()}, - Spec: swarm.ConfigSpec{Annotations: swarm.Annotations{Name: "passwords"}}}, - {ID: "2", - Meta: swarm.Meta{CreatedAt: time.Now(), UpdatedAt: time.Now()}, - Spec: swarm.ConfigSpec{Annotations: swarm.Annotations{Name: "id_rsa"}}}, - } - for _, testcase := range cases { - out := bytes.NewBufferString("") - testcase.context.Output = out - if err := FormatWrite(testcase.context, configs); err != nil { - assert.ErrorContains(t, err, testcase.expected) - } else { - assert.Check(t, is.Equal(out.String(), testcase.expected)) - } - } -}
  16. Download patch cli/cli/command/container/run_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/run_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/run_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,74 +0,0 @@ -package container - -import ( - "fmt" - "io/ioutil" - "testing" - - "github.com/docker/cli/internal/test" - "github.com/docker/cli/internal/test/notary" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/network" - "gotest.tools/assert" - is "gotest.tools/assert/cmp" -) - -func TestRunLabel(t *testing.T) { - cli := test.NewFakeCli(&fakeClient{ - createContainerFunc: func(_ *container.Config, _ *container.HostConfig, _ *network.NetworkingConfig, _ string) (container.ContainerCreateCreatedBody, error) { - return container.ContainerCreateCreatedBody{ - ID: "id", - }, nil - }, - Version: "1.36", - }) - cmd := NewRunCommand(cli) - cmd.SetArgs([]string{"--detach=true", "--label", "foo", "busybox"}) - assert.NilError(t, cmd.Execute()) -} - -func TestRunCommandWithContentTrustErrors(t *testing.T) { - testCases := []struct { - name string - args []string - expectedError string - notaryFunc test.NotaryClientFuncType - }{ - { - name: "offline-notary-server", - notaryFunc: notary.GetOfflineNotaryRepository, - expectedError: "client is offline", - args: []string{"image:tag"}, - }, - { - name: "uninitialized-notary-server", - notaryFunc: notary.GetUninitializedNotaryRepository, - expectedError: "remote trust data does not exist", - args: []string{"image:tag"}, - }, - { - name: "empty-notary-server", - notaryFunc: notary.GetEmptyTargetsNotaryRepository, - expectedError: "No valid trust data for tag", - args: []string{"image:tag"}, - }, - } - for _, tc := range testCases { - cli := test.NewFakeCli(&fakeClient{ - createContainerFunc: func(config *container.Config, - hostConfig *container.HostConfig, - networkingConfig *network.NetworkingConfig, - containerName string, - ) (container.ContainerCreateCreatedBody, error) { - return container.ContainerCreateCreatedBody{}, fmt.Errorf("shouldn't try to pull image") - }, - }, test.EnableContentTrust) - cli.SetNotaryClient(tc.notaryFunc) - cmd := NewRunCommand(cli) - cmd.SetArgs(tc.args) - cmd.SetOutput(ioutil.Discard) - err := cmd.Execute() - assert.Assert(t, err != nil) - assert.Assert(t, is.Contains(cli.ErrBuffer().String(), tc.expectedError)) - } -}
  17. Download patch cli/cli/command/checkpoint/remove.go

    --- 19.03.7+dfsg1-3/cli/cli/command/checkpoint/remove.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/checkpoint/remove.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,44 +0,0 @@ -package checkpoint - -import ( - "context" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/docker/docker/api/types" - "github.com/spf13/cobra" -) - -type removeOptions struct { - checkpointDir string -} - -func newRemoveCommand(dockerCli command.Cli) *cobra.Command { - var opts removeOptions - - cmd := &cobra.Command{ - Use: "rm [OPTIONS] CONTAINER CHECKPOINT", - Aliases: []string{"remove"}, - Short: "Remove a checkpoint", - Args: cli.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - return runRemove(dockerCli, args[0], args[1], opts) - }, - } - - flags := cmd.Flags() - flags.StringVarP(&opts.checkpointDir, "checkpoint-dir", "", "", "Use a custom checkpoint storage directory") - - return cmd -} - -func runRemove(dockerCli command.Cli, container string, checkpoint string, opts removeOptions) error { - client := dockerCli.Client() - - removeOpts := types.CheckpointDeleteOptions{ - CheckpointID: checkpoint, - CheckpointDir: opts.checkpointDir, - } - - return client.CheckpointDelete(context.Background(), container, removeOpts) -}
  18. Download patch cli/cli/command/checkpoint/formatter_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/checkpoint/formatter_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/checkpoint/formatter_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,53 +0,0 @@ -package checkpoint - -import ( - "bytes" - "testing" - - "github.com/docker/cli/cli/command/formatter" - "github.com/docker/docker/api/types" - "gotest.tools/assert" -) - -func TestCheckpointContextFormatWrite(t *testing.T) { - cases := []struct { - context formatter.Context - expected string - }{ - { - formatter.Context{Format: NewFormat(defaultCheckpointFormat)}, - `CHECKPOINT NAME -checkpoint-1 -checkpoint-2 -checkpoint-3 -`, - }, - { - formatter.Context{Format: NewFormat("{{.Name}}")}, - `checkpoint-1 -checkpoint-2 -checkpoint-3 -`, - }, - { - formatter.Context{Format: NewFormat("{{.Name}}:")}, - `checkpoint-1: -checkpoint-2: -checkpoint-3: -`, - }, - } - - checkpoints := []types.Checkpoint{ - {Name: "checkpoint-1"}, - {Name: "checkpoint-2"}, - {Name: "checkpoint-3"}, - } - for _, testcase := range cases { - out := bytes.NewBufferString("") - testcase.context.Output = out - err := FormatWrite(testcase.context, checkpoints) - assert.NilError(t, err) - assert.Equal(t, out.String(), testcase.expected) - } -}
  19. Download patch cli/cli/command/container/prune.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/prune.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/prune.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,78 +0,0 @@ -package container - -import ( - "context" - "fmt" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/docker/cli/opts" - units "github.com/docker/go-units" - "github.com/spf13/cobra" -) - -type pruneOptions struct { - force bool - filter opts.FilterOpt -} - -// NewPruneCommand returns a new cobra prune command for containers -func NewPruneCommand(dockerCli command.Cli) *cobra.Command { - options := pruneOptions{filter: opts.NewFilterOpt()} - - cmd := &cobra.Command{ - Use: "prune [OPTIONS]", - Short: "Remove all stopped containers", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - spaceReclaimed, output, err := runPrune(dockerCli, options) - if err != nil { - return err - } - if output != "" { - fmt.Fprintln(dockerCli.Out(), output) - } - fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed))) - return nil - }, - Annotations: map[string]string{"version": "1.25"}, - } - - flags := cmd.Flags() - flags.BoolVarP(&options.force, "force", "f", false, "Do not prompt for confirmation") - flags.Var(&options.filter, "filter", "Provide filter values (e.g. 'until=<timestamp>')") - - return cmd -} - -const warning = `WARNING! This will remove all stopped containers. -Are you sure you want to continue?` - -func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint64, output string, err error) { - pruneFilters := command.PruneFilters(dockerCli, options.filter.Value()) - - if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) { - return 0, "", nil - } - - report, err := dockerCli.Client().ContainersPrune(context.Background(), pruneFilters) - if err != nil { - return 0, "", err - } - - if len(report.ContainersDeleted) > 0 { - output = "Deleted Containers:\n" - for _, id := range report.ContainersDeleted { - output += id + "\n" - } - spaceReclaimed = report.SpaceReclaimed - } - - return spaceReclaimed, output, nil -} - -// RunPrune calls the Container Prune API -// This returns the amount of space reclaimed and a detailed output string -func RunPrune(dockerCli command.Cli, all bool, filter opts.FilterOpt) (uint64, string, error) { - return runPrune(dockerCli, pruneOptions{force: true, filter: filter}) -}
  20. Download patch cli/cli/command/config/testdata/config-inspect-pretty.simple.golden

    --- 19.03.7+dfsg1-3/cli/cli/command/config/testdata/config-inspect-pretty.simple.golden 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/testdata/config-inspect-pretty.simple.golden 1970-01-01 00:00:00.000000000 +0000 @@ -1,8 +0,0 @@ -ID: configID -Name: configName -Labels: - - lbl1=value1 -Created at: 0001-01-01 00:00:00 +0000 utc -Updated at: 0001-01-01 00:00:00 +0000 utc -Data: -payload here
  21. Download patch cli/cli/command/container/client_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/client_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/client_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,145 +0,0 @@ -package container - -import ( - "context" - "io" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/network" - "github.com/docker/docker/client" -) - -type fakeClient struct { - client.Client - inspectFunc func(string) (types.ContainerJSON, error) - execInspectFunc func(execID string) (types.ContainerExecInspect, error) - execCreateFunc func(container string, config types.ExecConfig) (types.IDResponse, error) - createContainerFunc func(config *container.Config, - hostConfig *container.HostConfig, - networkingConfig *network.NetworkingConfig, - containerName string) (container.ContainerCreateCreatedBody, error) - containerStartFunc func(container string, options types.ContainerStartOptions) error - imageCreateFunc func(parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error) - infoFunc func() (types.Info, error) - containerStatPathFunc func(container, path string) (types.ContainerPathStat, error) - containerCopyFromFunc func(container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) - logFunc func(string, types.ContainerLogsOptions) (io.ReadCloser, error) - waitFunc func(string) (<-chan container.ContainerWaitOKBody, <-chan error) - containerListFunc func(types.ContainerListOptions) ([]types.Container, error) - containerExportFunc func(string) (io.ReadCloser, error) - containerExecResizeFunc func(id string, options types.ResizeOptions) error - Version string -} - -func (f *fakeClient) ContainerList(_ context.Context, options types.ContainerListOptions) ([]types.Container, error) { - if f.containerListFunc != nil { - return f.containerListFunc(options) - } - return []types.Container{}, nil -} - -func (f *fakeClient) ContainerInspect(_ context.Context, containerID string) (types.ContainerJSON, error) { - if f.inspectFunc != nil { - return f.inspectFunc(containerID) - } - return types.ContainerJSON{}, nil -} - -func (f *fakeClient) ContainerExecCreate(_ context.Context, container string, config types.ExecConfig) (types.IDResponse, error) { - if f.execCreateFunc != nil { - return f.execCreateFunc(container, config) - } - return types.IDResponse{}, nil -} - -func (f *fakeClient) ContainerExecInspect(_ context.Context, execID string) (types.ContainerExecInspect, error) { - if f.execInspectFunc != nil { - return f.execInspectFunc(execID) - } - return types.ContainerExecInspect{}, nil -} - -func (f *fakeClient) ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) error { - return nil -} - -func (f *fakeClient) ContainerCreate( - _ context.Context, - config *container.Config, - hostConfig *container.HostConfig, - networkingConfig *network.NetworkingConfig, - containerName string, -) (container.ContainerCreateCreatedBody, error) { - if f.createContainerFunc != nil { - return f.createContainerFunc(config, hostConfig, networkingConfig, containerName) - } - return container.ContainerCreateCreatedBody{}, nil -} - -func (f *fakeClient) ImageCreate(ctx context.Context, parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error) { - if f.imageCreateFunc != nil { - return f.imageCreateFunc(parentReference, options) - } - return nil, nil -} - -func (f *fakeClient) Info(_ context.Context) (types.Info, error) { - if f.infoFunc != nil { - return f.infoFunc() - } - return types.Info{}, nil -} - -func (f *fakeClient) ContainerStatPath(_ context.Context, container, path string) (types.ContainerPathStat, error) { - if f.containerStatPathFunc != nil { - return f.containerStatPathFunc(container, path) - } - return types.ContainerPathStat{}, nil -} - -func (f *fakeClient) CopyFromContainer(_ context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) { - if f.containerCopyFromFunc != nil { - return f.containerCopyFromFunc(container, srcPath) - } - return nil, types.ContainerPathStat{}, nil -} - -func (f *fakeClient) ContainerLogs(_ context.Context, container string, options types.ContainerLogsOptions) (io.ReadCloser, error) { - if f.logFunc != nil { - return f.logFunc(container, options) - } - return nil, nil -} - -func (f *fakeClient) ClientVersion() string { - return f.Version -} - -func (f *fakeClient) ContainerWait(_ context.Context, container string, _ container.WaitCondition) (<-chan container.ContainerWaitOKBody, <-chan error) { - if f.waitFunc != nil { - return f.waitFunc(container) - } - return nil, nil -} - -func (f *fakeClient) ContainerStart(_ context.Context, container string, options types.ContainerStartOptions) error { - if f.containerStartFunc != nil { - return f.containerStartFunc(container, options) - } - return nil -} - -func (f *fakeClient) ContainerExport(_ context.Context, container string) (io.ReadCloser, error) { - if f.containerExportFunc != nil { - return f.containerExportFunc(container) - } - return nil, nil -} - -func (f *fakeClient) ContainerExecResize(_ context.Context, id string, options types.ResizeOptions) error { - if f.containerExecResizeFunc != nil { - return f.containerExecResizeFunc(id, options) - } - return nil -}
  22. Download patch cli/cli/command/container/testdata/container-create-localhost-dns.golden

    --- 19.03.7+dfsg1-3/cli/cli/command/container/testdata/container-create-localhost-dns.golden 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/testdata/container-create-localhost-dns.golden 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -WARNING: Localhost DNS setting (--dns=127.0.0.11) may fail in containers.
  23. Download patch cli/cli/command/container/inspect.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/inspect.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/inspect.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,47 +0,0 @@ -package container - -import ( - "context" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/docker/cli/cli/command/inspect" - "github.com/spf13/cobra" -) - -type inspectOptions struct { - format string - size bool - refs []string -} - -// newInspectCommand creates a new cobra.Command for `docker container inspect` -func newInspectCommand(dockerCli command.Cli) *cobra.Command { - var opts inspectOptions - - cmd := &cobra.Command{ - Use: "inspect [OPTIONS] CONTAINER [CONTAINER...]", - Short: "Display detailed information on one or more containers", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.refs = args - return runInspect(dockerCli, opts) - }, - } - - flags := cmd.Flags() - flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template") - flags.BoolVarP(&opts.size, "size", "s", false, "Display total file sizes") - - return cmd -} - -func runInspect(dockerCli command.Cli, opts inspectOptions) error { - client := dockerCli.Client() - ctx := context.Background() - - getRefFunc := func(ref string) (interface{}, []byte, error) { - return client.ContainerInspectWithRaw(ctx, ref, opts.size) - } - return inspect.Inspect(dockerCli.Out(), opts.refs, opts.format, getRefFunc) -}
  24. Download patch cli/cli/command/config/testdata/config-inspect-with-format.simple-template.golden

    --- 19.03.7+dfsg1-3/cli/cli/command/config/testdata/config-inspect-with-format.simple-template.golden 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/testdata/config-inspect-with-format.simple-template.golden 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -foo
  25. Download patch cli/cli/command/cli_test.go
  26. Download patch cli/cli/command/checkpoint/formatter.go

    --- 19.03.7+dfsg1-3/cli/cli/command/checkpoint/formatter.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/checkpoint/formatter.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,55 +0,0 @@ -package checkpoint - -import ( - "github.com/docker/cli/cli/command/formatter" - "github.com/docker/docker/api/types" -) - -const ( - defaultCheckpointFormat = "table {{.Name}}" - - checkpointNameHeader = "CHECKPOINT NAME" -) - -// NewFormat returns a format for use with a checkpoint Context -func NewFormat(source string) formatter.Format { - switch source { - case formatter.TableFormatKey: - return defaultCheckpointFormat - } - return formatter.Format(source) -} - -// FormatWrite writes formatted checkpoints using the Context -func FormatWrite(ctx formatter.Context, checkpoints []types.Checkpoint) error { - render := func(format func(subContext formatter.SubContext) error) error { - for _, checkpoint := range checkpoints { - if err := format(&checkpointContext{c: checkpoint}); err != nil { - return err - } - } - return nil - } - return ctx.Write(newCheckpointContext(), render) -} - -type checkpointContext struct { - formatter.HeaderContext - c types.Checkpoint -} - -func newCheckpointContext() *checkpointContext { - cpCtx := checkpointContext{} - cpCtx.Header = formatter.SubHeaderContext{ - "Name": checkpointNameHeader, - } - return &cpCtx -} - -func (c *checkpointContext) MarshalJSON() ([]byte, error) { - return formatter.MarshalJSON(c) -} - -func (c *checkpointContext) Name() string { - return c.c.Name -}
  27. Download patch cli/cli/command/checkpoint/create.go

    --- 19.03.7+dfsg1-3/cli/cli/command/checkpoint/create.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/checkpoint/create.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,57 +0,0 @@ -package checkpoint - -import ( - "context" - "fmt" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/docker/docker/api/types" - "github.com/spf13/cobra" -) - -type createOptions struct { - container string - checkpoint string - checkpointDir string - leaveRunning bool -} - -func newCreateCommand(dockerCli command.Cli) *cobra.Command { - var opts createOptions - - cmd := &cobra.Command{ - Use: "create [OPTIONS] CONTAINER CHECKPOINT", - Short: "Create a checkpoint from a running container", - Args: cli.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - opts.container = args[0] - opts.checkpoint = args[1] - return runCreate(dockerCli, opts) - }, - } - - flags := cmd.Flags() - flags.BoolVar(&opts.leaveRunning, "leave-running", false, "Leave the container running after checkpoint") - flags.StringVarP(&opts.checkpointDir, "checkpoint-dir", "", "", "Use a custom checkpoint storage directory") - - return cmd -} - -func runCreate(dockerCli command.Cli, opts createOptions) error { - client := dockerCli.Client() - - checkpointOpts := types.CheckpointCreateOptions{ - CheckpointID: opts.checkpoint, - CheckpointDir: opts.checkpointDir, - Exit: !opts.leaveRunning, - } - - err := client.CheckpointCreate(context.Background(), opts.container, checkpointOpts) - if err != nil { - return err - } - - fmt.Fprintf(dockerCli.Out(), "%s\n", opts.checkpoint) - return nil -}
  28. Download patch cli/cli/command/container/testdata/container-list-without-format.golden

    --- 19.03.7+dfsg1-3/cli/cli/command/container/testdata/container-list-without-format.golden 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/testdata/container-list-without-format.golden 1970-01-01 00:00:00.000000000 +0000 @@ -1,6 +0,0 @@ -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -container_id busybox:latest "top" Less than a second ago Up 1 second c1 -container_id busybox:latest "top" Less than a second ago Up 1 second c2 -container_id busybox:latest "top" Less than a second ago Up 1 second 80-82/tcp c3 -container_id busybox:latest "top" Less than a second ago Up 1 second 81/udp c4 -container_id busybox:latest "top" Less than a second ago Up 1 second 8.8.8.8:82->82/tcp c5
  29. Download patch cli/cli/command/checkpoint/cmd.go

    --- 19.03.7+dfsg1-3/cli/cli/command/checkpoint/cmd.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/checkpoint/cmd.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,28 +0,0 @@ -package checkpoint - -import ( - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/spf13/cobra" -) - -// NewCheckpointCommand returns the `checkpoint` subcommand (only in experimental) -func NewCheckpointCommand(dockerCli command.Cli) *cobra.Command { - cmd := &cobra.Command{ - Use: "checkpoint", - Short: "Manage checkpoints", - Args: cli.NoArgs, - RunE: command.ShowHelp(dockerCli.Err()), - Annotations: map[string]string{ - "experimental": "", - "ostype": "linux", - "version": "1.25", - }, - } - cmd.AddCommand( - newCreateCommand(dockerCli), - newListCommand(dockerCli), - newRemoveCommand(dockerCli), - ) - return cmd -}
  30. Download patch cli/cli/command/config/testdata/config-list-with-config-format.golden

    --- 19.03.7+dfsg1-3/cli/cli/command/config/testdata/config-list-with-config-format.golden 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/testdata/config-list-with-config-format.golden 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -bar label=label-bar -foo
  31. Download patch cli/cli/command/config/ls.go

    --- 19.03.7+dfsg1-3/cli/cli/command/config/ls.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/ls.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,72 +0,0 @@ -package config - -import ( - "context" - "sort" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/docker/cli/cli/command/formatter" - "github.com/docker/cli/opts" - "github.com/docker/docker/api/types" - "github.com/spf13/cobra" - "vbom.ml/util/sortorder" -) - -// ListOptions contains options for the docker config ls command. -type ListOptions struct { - Quiet bool - Format string - Filter opts.FilterOpt -} - -func newConfigListCommand(dockerCli command.Cli) *cobra.Command { - listOpts := ListOptions{Filter: opts.NewFilterOpt()} - - cmd := &cobra.Command{ - Use: "ls [OPTIONS]", - Aliases: []string{"list"}, - Short: "List configs", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return RunConfigList(dockerCli, listOpts) - }, - } - - flags := cmd.Flags() - flags.BoolVarP(&listOpts.Quiet, "quiet", "q", false, "Only display IDs") - flags.StringVarP(&listOpts.Format, "format", "", "", "Pretty-print configs using a Go template") - flags.VarP(&listOpts.Filter, "filter", "f", "Filter output based on conditions provided") - - return cmd -} - -// RunConfigList lists Swarm configs. -func RunConfigList(dockerCli command.Cli, options ListOptions) error { - client := dockerCli.Client() - ctx := context.Background() - - configs, err := client.ConfigList(ctx, types.ConfigListOptions{Filters: options.Filter.Value()}) - if err != nil { - return err - } - - format := options.Format - if len(format) == 0 { - if len(dockerCli.ConfigFile().ConfigFormat) > 0 && !options.Quiet { - format = dockerCli.ConfigFile().ConfigFormat - } else { - format = formatter.TableFormatKey - } - } - - sort.Slice(configs, func(i, j int) bool { - return sortorder.NaturalLess(configs[i].Spec.Name, configs[j].Spec.Name) - }) - - configCtx := formatter.Context{ - Output: dockerCli.Out(), - Format: NewFormat(format, options.Quiet), - } - return FormatWrite(configCtx, configs) -}
  32. Download patch cli/cli/command/checkpoint/testdata/checkpoint-list-with-options.golden

    --- 19.03.7+dfsg1-3/cli/cli/command/checkpoint/testdata/checkpoint-list-with-options.golden 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/checkpoint/testdata/checkpoint-list-with-options.golden 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -CHECKPOINT NAME -checkpoint-foo
  33. Download patch cli/cli/command/container/pause.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/pause.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/pause.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,49 +0,0 @@ -package container - -import ( - "context" - "fmt" - "strings" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/pkg/errors" - "github.com/spf13/cobra" -) - -type pauseOptions struct { - containers []string -} - -// NewPauseCommand creates a new cobra.Command for `docker pause` -func NewPauseCommand(dockerCli command.Cli) *cobra.Command { - var opts pauseOptions - - return &cobra.Command{ - Use: "pause CONTAINER [CONTAINER...]", - Short: "Pause all processes within one or more containers", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.containers = args - return runPause(dockerCli, &opts) - }, - } -} - -func runPause(dockerCli command.Cli, opts *pauseOptions) error { - ctx := context.Background() - - var errs []string - errChan := parallelOperation(ctx, opts.containers, dockerCli.Client().ContainerPause) - for _, container := range opts.containers { - if err := <-errChan; err != nil { - errs = append(errs, err.Error()) - continue - } - fmt.Fprintln(dockerCli.Out(), container) - } - if len(errs) > 0 { - return errors.New(strings.Join(errs, "\n")) - } - return nil -}
  34. Download patch cli/cli/command/container/formatter_diff.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/formatter_diff.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/formatter_diff.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,73 +0,0 @@ -package container - -import ( - "github.com/docker/cli/cli/command/formatter" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/pkg/archive" -) - -const ( - defaultDiffTableFormat = "table {{.Type}}\t{{.Path}}" - - changeTypeHeader = "CHANGE TYPE" - pathHeader = "PATH" -) - -// NewDiffFormat returns a format for use with a diff Context -func NewDiffFormat(source string) formatter.Format { - switch source { - case formatter.TableFormatKey: - return defaultDiffTableFormat - } - return formatter.Format(source) -} - -// DiffFormatWrite writes formatted diff using the Context -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 { - return err - } - } - return nil - } - return ctx.Write(newDiffContext(), render) -} - -type diffContext struct { - formatter.HeaderContext - c container.ContainerChangeResponseItem -} - -func newDiffContext() *diffContext { - diffCtx := diffContext{} - diffCtx.Header = formatter.SubHeaderContext{ - "Type": changeTypeHeader, - "Path": pathHeader, - } - return &diffCtx -} - -func (d *diffContext) MarshalJSON() ([]byte, error) { - return formatter.MarshalJSON(d) -} - -func (d *diffContext) Type() 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 { - return d.c.Path -}
  35. Download patch cli/cli/command/container/ps_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/ps_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/ps_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,119 +0,0 @@ -package container - -import ( - "testing" - - "github.com/docker/cli/opts" - "gotest.tools/assert" - is "gotest.tools/assert/cmp" -) - -func TestBuildContainerListOptions(t *testing.T) { - filters := opts.NewFilterOpt() - assert.NilError(t, filters.Set("foo=bar")) - assert.NilError(t, filters.Set("baz=foo")) - - contexts := []struct { - psOpts *psOptions - expectedAll bool - expectedSize bool - expectedLimit int - expectedFilters map[string]string - }{ - { - psOpts: &psOptions{ - all: true, - size: true, - last: 5, - filter: filters, - }, - expectedAll: true, - expectedSize: true, - expectedLimit: 5, - expectedFilters: map[string]string{ - "foo": "bar", - "baz": "foo", - }, - }, - { - psOpts: &psOptions{ - all: true, - size: true, - last: -1, - nLatest: true, - }, - expectedAll: true, - expectedSize: true, - expectedLimit: 1, - expectedFilters: make(map[string]string), - }, - { - psOpts: &psOptions{ - all: true, - size: false, - last: 5, - filter: filters, - // With .Size, size should be true - format: "{{.Size}}", - }, - expectedAll: true, - expectedSize: true, - expectedLimit: 5, - expectedFilters: map[string]string{ - "foo": "bar", - "baz": "foo", - }, - }, - { - psOpts: &psOptions{ - all: true, - size: false, - last: 5, - filter: filters, - // With .Size, size should be true - format: "{{.Size}} {{.CreatedAt}} {{.Networks}}", - }, - expectedAll: true, - expectedSize: true, - expectedLimit: 5, - expectedFilters: map[string]string{ - "foo": "bar", - "baz": "foo", - }, - }, - { - psOpts: &psOptions{ - all: true, - size: false, - last: 5, - filter: filters, - // Without .Size, size should be false - format: "{{.CreatedAt}} {{.Networks}}", - }, - expectedAll: true, - expectedSize: false, - expectedLimit: 5, - expectedFilters: map[string]string{ - "foo": "bar", - "baz": "foo", - }, - }, - } - - for _, c := range contexts { - options, err := buildContainerListOptions(c.psOpts) - assert.NilError(t, err) - - assert.Check(t, is.Equal(c.expectedAll, options.All)) - assert.Check(t, is.Equal(c.expectedSize, options.Size)) - assert.Check(t, is.Equal(c.expectedLimit, options.Limit)) - assert.Check(t, is.Equal(len(c.expectedFilters), options.Filters.Len())) - - for k, v := range c.expectedFilters { - f := options.Filters - if !f.ExactMatch(k, v) { - t.Fatalf("Expected filter with key %s to be %s but got %s", k, v, f.Get(k)) - } - } - } -}
  36. Download patch cli/cli/command/container/list.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/list.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/list.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,140 +0,0 @@ -package container - -import ( - "context" - "io/ioutil" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/docker/cli/cli/command/formatter" - "github.com/docker/cli/opts" - "github.com/docker/cli/templates" - "github.com/docker/docker/api/types" - "github.com/spf13/cobra" -) - -type psOptions struct { - quiet bool - size bool - all bool - noTrunc bool - nLatest bool - last int - format string - filter opts.FilterOpt -} - -// NewPsCommand creates a new cobra.Command for `docker ps` -func NewPsCommand(dockerCli command.Cli) *cobra.Command { - options := psOptions{filter: opts.NewFilterOpt()} - - cmd := &cobra.Command{ - Use: "ps [OPTIONS]", - Short: "List containers", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runPs(dockerCli, &options) - }, - } - - flags := cmd.Flags() - - flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display numeric IDs") - flags.BoolVarP(&options.size, "size", "s", false, "Display total file sizes") - flags.BoolVarP(&options.all, "all", "a", false, "Show all containers (default shows just running)") - flags.BoolVar(&options.noTrunc, "no-trunc", false, "Don't truncate output") - flags.BoolVarP(&options.nLatest, "latest", "l", false, "Show the latest created container (includes all states)") - flags.IntVarP(&options.last, "last", "n", -1, "Show n last created containers (includes all states)") - flags.StringVarP(&options.format, "format", "", "", "Pretty-print containers using a Go template") - flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided") - - return cmd -} - -func newListCommand(dockerCli command.Cli) *cobra.Command { - cmd := *NewPsCommand(dockerCli) - cmd.Aliases = []string{"ps", "list"} - cmd.Use = "ls [OPTIONS]" - return &cmd -} - -// listOptionsProcessor is used to set any container list options which may only -// be embedded in the format template. -// This is passed directly into tmpl.Execute in order to allow the preprocessor -// to set any list options that were not provided by flags (e.g. `.Size`). -// It is using a `map[string]bool` so that unknown fields passed into the -// template format do not cause errors. These errors will get picked up when -// running through the actual template processor. -type listOptionsProcessor map[string]bool - -// Size sets the size of the map when called by a template execution. -func (o listOptionsProcessor) Size() bool { - o["size"] = true - return true -} - -// Label is needed here as it allows the correct pre-processing -// because Label() is a method with arguments -func (o listOptionsProcessor) Label(name string) string { - return "" -} - -func buildContainerListOptions(opts *psOptions) (*types.ContainerListOptions, error) { - options := &types.ContainerListOptions{ - All: opts.all, - Limit: opts.last, - Size: opts.size, - Filters: opts.filter.Value(), - } - - if opts.nLatest && opts.last == -1 { - options.Limit = 1 - } - - tmpl, err := templates.Parse(opts.format) - - if err != nil { - return nil, err - } - - optionsProcessor := listOptionsProcessor{} - // This shouldn't error out but swallowing the error makes it harder - // to track down if preProcessor issues come up. Ref #24696 - if err := tmpl.Execute(ioutil.Discard, optionsProcessor); err != nil { - return nil, err - } - // At the moment all we need is to capture .Size for preprocessor - options.Size = opts.size || optionsProcessor["size"] - - return options, nil -} - -func runPs(dockerCli command.Cli, options *psOptions) error { - ctx := context.Background() - - listOptions, err := buildContainerListOptions(options) - if err != nil { - return err - } - - containers, err := dockerCli.Client().ContainerList(ctx, *listOptions) - if err != nil { - return err - } - - format := options.format - if len(format) == 0 { - if len(dockerCli.ConfigFile().PsFormat) > 0 && !options.quiet { - format = dockerCli.ConfigFile().PsFormat - } else { - format = formatter.TableFormatKey - } - } - - containerCtx := formatter.Context{ - Output: dockerCli.Out(), - Format: formatter.NewContainerFormat(format, options.quiet, listOptions.Size), - Trunc: !options.noTrunc, - } - return formatter.ContainerWrite(containerCtx, containers) -}
  37. Download patch cli/cli/command/container/hijack.go
  38. Download patch cli/cli/command/builder/prune.go

    --- 19.03.7+dfsg1-3/cli/cli/command/builder/prune.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/builder/prune.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,96 +0,0 @@ -package builder - -import ( - "context" - "fmt" - "strings" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/docker/cli/opts" - "github.com/docker/docker/api/types" - units "github.com/docker/go-units" - "github.com/spf13/cobra" -) - -type pruneOptions struct { - force bool - all bool - filter opts.FilterOpt - keepStorage opts.MemBytes -} - -// NewPruneCommand returns a new cobra prune command for images -func NewPruneCommand(dockerCli command.Cli) *cobra.Command { - options := pruneOptions{filter: opts.NewFilterOpt()} - - cmd := &cobra.Command{ - Use: "prune", - Short: "Remove build cache", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - spaceReclaimed, output, err := runPrune(dockerCli, options) - if err != nil { - return err - } - if output != "" { - fmt.Fprintln(dockerCli.Out(), output) - } - fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed))) - return nil - }, - Annotations: map[string]string{"version": "1.39"}, - } - - flags := cmd.Flags() - flags.BoolVarP(&options.force, "force", "f", false, "Do not prompt for confirmation") - flags.BoolVarP(&options.all, "all", "a", false, "Remove all unused build cache, not just dangling ones") - flags.Var(&options.filter, "filter", "Provide filter values (e.g. 'until=24h')") - flags.Var(&options.keepStorage, "keep-storage", "Amount of disk space to keep for cache") - - return cmd -} - -const ( - normalWarning = `WARNING! This will remove all dangling build cache. Are you sure you want to continue?` - allCacheWarning = `WARNING! This will remove all build cache. Are you sure you want to continue?` -) - -func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint64, output string, err error) { - pruneFilters := options.filter.Value() - pruneFilters = command.PruneFilters(dockerCli, pruneFilters) - - warning := normalWarning - if options.all { - warning = allCacheWarning - } - if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) { - return 0, "", nil - } - - report, err := dockerCli.Client().BuildCachePrune(context.Background(), types.BuildCachePruneOptions{ - All: options.all, - KeepStorage: options.keepStorage.Value(), - Filters: pruneFilters, - }) - if err != nil { - return 0, "", err - } - - if len(report.CachesDeleted) > 0 { - var sb strings.Builder - sb.WriteString("Deleted build cache objects:\n") - for _, id := range report.CachesDeleted { - sb.WriteString(id) - sb.WriteByte('\n') - } - output = sb.String() - } - - return report.SpaceReclaimed, output, nil -} - -// CachePrune executes a prune command for build cache -func CachePrune(dockerCli command.Cli, all bool, filter opts.FilterOpt) (uint64, string, error) { - return runPrune(dockerCli, pruneOptions{force: true, all: all, filter: filter}) -}
  39. Download patch cli/cli/command/container/create.go
  40. Download patch cli/cli/command/checkpoint/create_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/checkpoint/create_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/checkpoint/create_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,72 +0,0 @@ -package checkpoint - -import ( - "io/ioutil" - "strings" - "testing" - - "github.com/docker/cli/internal/test" - "github.com/docker/docker/api/types" - "github.com/pkg/errors" - "gotest.tools/assert" - is "gotest.tools/assert/cmp" -) - -func TestCheckpointCreateErrors(t *testing.T) { - testCases := []struct { - args []string - checkpointCreateFunc func(container string, options types.CheckpointCreateOptions) error - expectedError string - }{ - { - args: []string{"too-few-arguments"}, - expectedError: "requires exactly 2 arguments", - }, - { - args: []string{"too", "many", "arguments"}, - expectedError: "requires exactly 2 arguments", - }, - { - args: []string{"foo", "bar"}, - checkpointCreateFunc: func(container string, options types.CheckpointCreateOptions) error { - return errors.Errorf("error creating checkpoint for container foo") - }, - expectedError: "error creating checkpoint for container foo", - }, - } - - for _, tc := range testCases { - cli := test.NewFakeCli(&fakeClient{ - checkpointCreateFunc: tc.checkpointCreateFunc, - }) - cmd := newCreateCommand(cli) - cmd.SetArgs(tc.args) - cmd.SetOutput(ioutil.Discard) - assert.ErrorContains(t, cmd.Execute(), tc.expectedError) - } -} - -func TestCheckpointCreateWithOptions(t *testing.T) { - var containerID, checkpointID, checkpointDir string - var exit bool - cli := test.NewFakeCli(&fakeClient{ - checkpointCreateFunc: func(container string, options types.CheckpointCreateOptions) error { - containerID = container - checkpointID = options.CheckpointID - checkpointDir = options.CheckpointDir - exit = options.Exit - return nil - }, - }) - cmd := newCreateCommand(cli) - checkpoint := "checkpoint-bar" - cmd.SetArgs([]string{"container-foo", checkpoint}) - cmd.Flags().Set("leave-running", "true") - cmd.Flags().Set("checkpoint-dir", "/dir/foo") - assert.NilError(t, cmd.Execute()) - assert.Check(t, is.Equal("container-foo", containerID)) - assert.Check(t, is.Equal(checkpoint, checkpointID)) - assert.Check(t, is.Equal("/dir/foo", checkpointDir)) - assert.Check(t, is.Equal(false, exit)) - assert.Check(t, is.Equal(checkpoint, strings.TrimSpace(cli.OutBuffer().String()))) -}
  41. Download patch cli/cli/command/config/inspect.go

    --- 19.03.7+dfsg1-3/cli/cli/command/config/inspect.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/inspect.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,68 +0,0 @@ -package config - -import ( - "context" - "fmt" - "strings" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/docker/cli/cli/command/formatter" - "github.com/spf13/cobra" -) - -// InspectOptions contains options for the docker config inspect command. -type InspectOptions struct { - Names []string - Format string - Pretty bool -} - -func newConfigInspectCommand(dockerCli command.Cli) *cobra.Command { - opts := InspectOptions{} - cmd := &cobra.Command{ - Use: "inspect [OPTIONS] CONFIG [CONFIG...]", - Short: "Display detailed information on one or more configs", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.Names = args - return RunConfigInspect(dockerCli, opts) - }, - } - - cmd.Flags().StringVarP(&opts.Format, "format", "f", "", "Format the output using the given Go template") - cmd.Flags().BoolVar(&opts.Pretty, "pretty", false, "Print the information in a human friendly format") - return cmd -} - -// RunConfigInspect inspects the given Swarm config. -func RunConfigInspect(dockerCli command.Cli, opts InspectOptions) error { - client := dockerCli.Client() - ctx := context.Background() - - if opts.Pretty { - opts.Format = "pretty" - } - - getRef := func(id string) (interface{}, []byte, error) { - return client.ConfigInspectWithRaw(ctx, id) - } - f := opts.Format - - // check if the user is trying to apply a template to the pretty format, which - // is not supported - if strings.HasPrefix(f, "pretty") && f != "pretty" { - return fmt.Errorf("Cannot supply extra formatting options to the pretty template") - } - - configCtx := formatter.Context{ - Output: dockerCli.Out(), - Format: NewFormat(f, false), - } - - if err := InspectFormatWrite(configCtx, opts.Names, getRef); err != nil { - return cli.StatusError{StatusCode: 1, Status: err.Error()} - } - return nil - -}
  42. Download patch cli/cli/command/checkpoint/list.go

    --- 19.03.7+dfsg1-3/cli/cli/command/checkpoint/list.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/checkpoint/list.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,54 +0,0 @@ -package checkpoint - -import ( - "context" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/docker/cli/cli/command/formatter" - "github.com/docker/docker/api/types" - "github.com/spf13/cobra" -) - -type listOptions struct { - checkpointDir string -} - -func newListCommand(dockerCli command.Cli) *cobra.Command { - var opts listOptions - - cmd := &cobra.Command{ - Use: "ls [OPTIONS] CONTAINER", - Aliases: []string{"list"}, - Short: "List checkpoints for a container", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - return runList(dockerCli, args[0], opts) - }, - } - - flags := cmd.Flags() - flags.StringVarP(&opts.checkpointDir, "checkpoint-dir", "", "", "Use a custom checkpoint storage directory") - - return cmd - -} - -func runList(dockerCli command.Cli, container string, opts listOptions) error { - client := dockerCli.Client() - - listOpts := types.CheckpointListOptions{ - CheckpointDir: opts.checkpointDir, - } - - checkpoints, err := client.CheckpointList(context.Background(), container, listOpts) - if err != nil { - return err - } - - cpCtx := formatter.Context{ - Output: dockerCli.Out(), - Format: NewFormat(formatter.TableFormatKey), - } - return FormatWrite(cpCtx, checkpoints) -}
  43. Download patch cli/cli/command/container/rm.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/rm.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/rm.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,73 +0,0 @@ -package container - -import ( - "context" - "fmt" - "strings" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/docker/docker/api/types" - "github.com/pkg/errors" - "github.com/spf13/cobra" -) - -type rmOptions struct { - rmVolumes bool - rmLink bool - force bool - - containers []string -} - -// NewRmCommand creates a new cobra.Command for `docker rm` -func NewRmCommand(dockerCli command.Cli) *cobra.Command { - var opts rmOptions - - cmd := &cobra.Command{ - Use: "rm [OPTIONS] CONTAINER [CONTAINER...]", - Short: "Remove one or more containers", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.containers = args - return runRm(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - flags.BoolVarP(&opts.rmVolumes, "volumes", "v", false, "Remove anonymous volumes associated with the container") - flags.BoolVarP(&opts.rmLink, "link", "l", false, "Remove the specified link") - flags.BoolVarP(&opts.force, "force", "f", false, "Force the removal of a running container (uses SIGKILL)") - return cmd -} - -func runRm(dockerCli command.Cli, opts *rmOptions) error { - ctx := context.Background() - - var errs []string - options := types.ContainerRemoveOptions{ - RemoveVolumes: opts.rmVolumes, - RemoveLinks: opts.rmLink, - Force: opts.force, - } - - errChan := parallelOperation(ctx, opts.containers, func(ctx context.Context, container string) error { - container = strings.Trim(container, "/") - if container == "" { - return errors.New("Container name cannot be empty") - } - return dockerCli.Client().ContainerRemove(ctx, container, options) - }) - - for _, name := range opts.containers { - if err := <-errChan; err != nil { - errs = append(errs, err.Error()) - continue - } - fmt.Fprintln(dockerCli.Out(), name) - } - if len(errs) > 0 { - return errors.New(strings.Join(errs, "\n")) - } - return nil -}
  44. Download patch cli/cli/command/container/logs.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/logs.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/logs.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,80 +0,0 @@ -package container - -import ( - "context" - "io" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/stdcopy" - "github.com/spf13/cobra" -) - -type logsOptions struct { - follow bool - since string - until string - timestamps bool - details bool - tail string - - container string -} - -// NewLogsCommand creates a new cobra.Command for `docker logs` -func NewLogsCommand(dockerCli command.Cli) *cobra.Command { - var opts logsOptions - - cmd := &cobra.Command{ - Use: "logs [OPTIONS] CONTAINER", - Short: "Fetch the logs of a container", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.container = args[0] - return runLogs(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - flags.BoolVarP(&opts.follow, "follow", "f", false, "Follow log output") - flags.StringVar(&opts.since, "since", "", "Show logs since timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)") - flags.StringVar(&opts.until, "until", "", "Show logs before a timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)") - flags.SetAnnotation("until", "version", []string{"1.35"}) - flags.BoolVarP(&opts.timestamps, "timestamps", "t", false, "Show timestamps") - flags.BoolVar(&opts.details, "details", false, "Show extra details provided to logs") - flags.StringVar(&opts.tail, "tail", "all", "Number of lines to show from the end of the logs") - return cmd -} - -func runLogs(dockerCli command.Cli, opts *logsOptions) error { - ctx := context.Background() - - c, err := dockerCli.Client().ContainerInspect(ctx, opts.container) - if err != nil { - return err - } - - options := types.ContainerLogsOptions{ - ShowStdout: true, - ShowStderr: true, - Since: opts.since, - Until: opts.until, - Timestamps: opts.timestamps, - Follow: opts.follow, - Tail: opts.tail, - Details: opts.details, - } - responseBody, err := dockerCli.Client().ContainerLogs(ctx, c.ID, options) - if err != nil { - return err - } - defer responseBody.Close() - - if c.Config.Tty { - _, err = io.Copy(dockerCli.Out(), responseBody) - } else { - _, err = stdcopy.StdCopy(dockerCli.Out(), dockerCli.Err(), responseBody) - } - return err -}
  45. Download patch cli/cli/command/config/formatter.go

    --- 19.03.7+dfsg1-3/cli/cli/command/config/formatter.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/formatter.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,172 +0,0 @@ -package config - -import ( - "fmt" - "strings" - "time" - - "github.com/docker/cli/cli/command" - "github.com/docker/cli/cli/command/formatter" - "github.com/docker/cli/cli/command/inspect" - "github.com/docker/docker/api/types/swarm" - units "github.com/docker/go-units" -) - -const ( - defaultConfigTableFormat = "table {{.ID}}\t{{.Name}}\t{{.CreatedAt}}\t{{.UpdatedAt}}" - configIDHeader = "ID" - configCreatedHeader = "CREATED" - configUpdatedHeader = "UPDATED" - configInspectPrettyTemplate formatter.Format = `ID: {{.ID}} -Name: {{.Name}} -{{- if .Labels }} -Labels: -{{- range $k, $v := .Labels }} - - {{ $k }}{{if $v }}={{ $v }}{{ end }} -{{- end }}{{ end }} -Created at: {{.CreatedAt}} -Updated at: {{.UpdatedAt}} -Data: -{{.Data}}` -) - -// NewFormat returns a Format for rendering using a config Context -func NewFormat(source string, quiet bool) formatter.Format { - switch source { - case formatter.PrettyFormatKey: - return configInspectPrettyTemplate - case formatter.TableFormatKey: - if quiet { - return formatter.DefaultQuietFormat - } - return defaultConfigTableFormat - } - return formatter.Format(source) -} - -// FormatWrite writes the context -func FormatWrite(ctx formatter.Context, configs []swarm.Config) error { - render := func(format func(subContext formatter.SubContext) error) error { - for _, config := range configs { - configCtx := &configContext{c: config} - if err := format(configCtx); err != nil { - return err - } - } - return nil - } - return ctx.Write(newConfigContext(), render) -} - -func newConfigContext() *configContext { - cCtx := &configContext{} - - cCtx.Header = formatter.SubHeaderContext{ - "ID": configIDHeader, - "Name": formatter.NameHeader, - "CreatedAt": configCreatedHeader, - "UpdatedAt": configUpdatedHeader, - "Labels": formatter.LabelsHeader, - } - return cCtx -} - -type configContext struct { - formatter.HeaderContext - c swarm.Config -} - -func (c *configContext) MarshalJSON() ([]byte, error) { - return formatter.MarshalJSON(c) -} - -func (c *configContext) ID() string { - return c.c.ID -} - -func (c *configContext) Name() string { - return c.c.Spec.Annotations.Name -} - -func (c *configContext) CreatedAt() string { - return units.HumanDuration(time.Now().UTC().Sub(c.c.Meta.CreatedAt)) + " ago" -} - -func (c *configContext) UpdatedAt() string { - return units.HumanDuration(time.Now().UTC().Sub(c.c.Meta.UpdatedAt)) + " ago" -} - -func (c *configContext) Labels() string { - mapLabels := c.c.Spec.Annotations.Labels - if mapLabels == nil { - return "" - } - var joinLabels []string - for k, v := range mapLabels { - joinLabels = append(joinLabels, fmt.Sprintf("%s=%s", k, v)) - } - return strings.Join(joinLabels, ",") -} - -func (c *configContext) Label(name string) string { - if c.c.Spec.Annotations.Labels == nil { - return "" - } - return c.c.Spec.Annotations.Labels[name] -} - -// InspectFormatWrite renders the context for a list of configs -func InspectFormatWrite(ctx formatter.Context, refs []string, getRef inspect.GetRefFunc) error { - if ctx.Format != configInspectPrettyTemplate { - return inspect.Inspect(ctx.Output, refs, string(ctx.Format), getRef) - } - render := func(format func(subContext formatter.SubContext) error) error { - for _, ref := range refs { - configI, _, err := getRef(ref) - if err != nil { - return err - } - config, ok := configI.(swarm.Config) - if !ok { - return fmt.Errorf("got wrong object to inspect :%v", ok) - } - if err := format(&configInspectContext{Config: config}); err != nil { - return err - } - } - return nil - } - return ctx.Write(&configInspectContext{}, render) -} - -type configInspectContext struct { - swarm.Config - formatter.SubContext -} - -func (ctx *configInspectContext) ID() string { - return ctx.Config.ID -} - -func (ctx *configInspectContext) Name() string { - return ctx.Config.Spec.Name -} - -func (ctx *configInspectContext) Labels() map[string]string { - return ctx.Config.Spec.Labels -} - -func (ctx *configInspectContext) CreatedAt() string { - return command.PrettyPrint(ctx.Config.CreatedAt) -} - -func (ctx *configInspectContext) UpdatedAt() string { - return command.PrettyPrint(ctx.Config.UpdatedAt) -} - -func (ctx *configInspectContext) Data() string { - if ctx.Config.Spec.Data == nil { - return "" - } - return string(ctx.Config.Spec.Data) -}
  46. Download patch cli/cli/command/container/testdata/container-list-with-format.golden

    --- 19.03.7+dfsg1-3/cli/cli/command/container/testdata/container-list-with-format.golden 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/testdata/container-list-with-format.golden 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -c1 busybox:latest some.label=value -c2 busybox:latest foo=bar
  47. Download patch cli/cli/command/cli_options_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/cli_options_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/cli_options_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,37 +0,0 @@ -package command - -import ( - "os" - "testing" - - "gotest.tools/assert" -) - -func contentTrustEnabled(t *testing.T) bool { - var cli DockerCli - assert.NilError(t, WithContentTrustFromEnv()(&cli)) - return cli.contentTrust -} - -// NB: Do not t.Parallel() this test -- it messes with the process environment. -func TestWithContentTrustFromEnv(t *testing.T) { - envvar := "DOCKER_CONTENT_TRUST" - if orig, ok := os.LookupEnv(envvar); ok { - defer func() { - os.Setenv(envvar, orig) - }() - } else { - defer func() { - os.Unsetenv(envvar) - }() - } - - os.Setenv(envvar, "true") - assert.Assert(t, contentTrustEnabled(t)) - os.Setenv(envvar, "false") - assert.Assert(t, !contentTrustEnabled(t)) - os.Setenv(envvar, "invalid") - assert.Assert(t, contentTrustEnabled(t)) - os.Unsetenv(envvar) - assert.Assert(t, !contentTrustEnabled(t)) -}
  48. Download patch cli/cli/command/container/port.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/port.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/port.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,78 +0,0 @@ -package container - -import ( - "context" - "fmt" - "strings" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/docker/go-connections/nat" - "github.com/pkg/errors" - "github.com/spf13/cobra" -) - -type portOptions struct { - container string - - port string -} - -// NewPortCommand creates a new cobra.Command for `docker port` -func NewPortCommand(dockerCli command.Cli) *cobra.Command { - var opts portOptions - - cmd := &cobra.Command{ - Use: "port CONTAINER [PRIVATE_PORT[/PROTO]]", - Short: "List port mappings or a specific mapping for the container", - Args: cli.RequiresRangeArgs(1, 2), - RunE: func(cmd *cobra.Command, args []string) error { - opts.container = args[0] - if len(args) > 1 { - opts.port = args[1] - } - return runPort(dockerCli, &opts) - }, - } - return cmd -} - -func runPort(dockerCli command.Cli, opts *portOptions) error { - ctx := context.Background() - - c, err := dockerCli.Client().ContainerInspect(ctx, opts.container) - if err != nil { - return err - } - - if opts.port != "" { - port := opts.port - proto := "tcp" - parts := strings.SplitN(port, "/", 2) - - if len(parts) == 2 && len(parts[1]) != 0 { - port = parts[0] - proto = parts[1] - } - natPort := port + "/" + proto - newP, err := nat.NewPort(proto, port) - if err != nil { - return err - } - if frontends, exists := c.NetworkSettings.Ports[newP]; exists && frontends != nil { - for _, frontend := range frontends { - fmt.Fprintf(dockerCli.Out(), "%s:%s\n", frontend.HostIP, frontend.HostPort) - } - return nil - } - return errors.Errorf("Error: No public port '%s' published for %s", natPort, opts.container) - } - - for from, frontends := range c.NetworkSettings.Ports { - for _, frontend := range frontends { - fmt.Fprintf(dockerCli.Out(), "%s -> %s:%s\n", from, frontend.HostIP, frontend.HostPort) - } - } - - return nil -}
  49. Download patch cli/cli/command/container/opts.go
  50. Download patch cli/cli/command/config/testdata/config-list-sort.golden

    --- 19.03.7+dfsg1-3/cli/cli/command/config/testdata/config-list-sort.golden 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/testdata/config-list-sort.golden 1970-01-01 00:00:00.000000000 +0000 @@ -1,4 +0,0 @@ -ID NAME CREATED UPDATED -ID-1-foo 1-foo 2 hours ago About an hour ago -ID-2-foo 2-foo 2 hours ago About an hour ago -ID-10-foo 10-foo 2 hours ago About an hour ago
  51. Download patch cli/cli/command/cli.go
  52. Download patch cli/cli/command/container/start.go
  53. Download patch cli/cli/command/container/run.go
  54. Download patch cli/cli/command/container/formatter_diff_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/formatter_diff_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/formatter_diff_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,61 +0,0 @@ -package container - -import ( - "bytes" - "testing" - - "github.com/docker/cli/cli/command/formatter" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/pkg/archive" - "gotest.tools/assert" - is "gotest.tools/assert/cmp" -) - -func TestDiffContextFormatWrite(t *testing.T) { - // Check default output format (verbose and non-verbose mode) for table headers - cases := []struct { - context formatter.Context - expected string - }{ - { - formatter.Context{Format: NewDiffFormat("table")}, - `CHANGE TYPE PATH -C /var/log/app.log -A /usr/app/app.js -D /usr/app/old_app.js -`, - }, - { - formatter.Context{Format: NewDiffFormat("table {{.Path}}")}, - `PATH -/var/log/app.log -/usr/app/app.js -/usr/app/old_app.js -`, - }, - { - formatter.Context{Format: NewDiffFormat("{{.Type}}: {{.Path}}")}, - `C: /var/log/app.log -A: /usr/app/app.js -D: /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 _, testcase := range cases { - out := bytes.NewBufferString("") - testcase.context.Output = out - err := DiffFormatWrite(testcase.context, diffs) - if err != nil { - assert.Error(t, err, testcase.expected) - } else { - assert.Check(t, is.Equal(testcase.expected, out.String())) - } - } -}
  55. Download patch cli/cli/command/config/create_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/config/create_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/create_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,143 +0,0 @@ -package config - -import ( - "io/ioutil" - "path/filepath" - "reflect" - "strings" - "testing" - - "github.com/docker/cli/internal/test" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" - "gotest.tools/assert" - is "gotest.tools/assert/cmp" - "gotest.tools/golden" -) - -const configDataFile = "config-create-with-name.golden" - -func TestConfigCreateErrors(t *testing.T) { - testCases := []struct { - args []string - configCreateFunc func(swarm.ConfigSpec) (types.ConfigCreateResponse, error) - expectedError string - }{ - { - args: []string{"too_few"}, - expectedError: "requires exactly 2 arguments", - }, - {args: []string{"too", "many", "arguments"}, - expectedError: "requires exactly 2 arguments", - }, - { - args: []string{"name", filepath.Join("testdata", configDataFile)}, - configCreateFunc: func(configSpec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { - return types.ConfigCreateResponse{}, errors.Errorf("error creating config") - }, - expectedError: "error creating config", - }, - } - for _, tc := range testCases { - cmd := newConfigCreateCommand( - test.NewFakeCli(&fakeClient{ - configCreateFunc: tc.configCreateFunc, - }), - ) - cmd.SetArgs(tc.args) - cmd.SetOutput(ioutil.Discard) - assert.ErrorContains(t, cmd.Execute(), tc.expectedError) - } -} - -func TestConfigCreateWithName(t *testing.T) { - name := "foo" - var actual []byte - cli := test.NewFakeCli(&fakeClient{ - 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) - } - - actual = spec.Data - - return types.ConfigCreateResponse{ - ID: "ID-" + spec.Name, - }, nil - }, - }) - - cmd := newConfigCreateCommand(cli) - cmd.SetArgs([]string{name, filepath.Join("testdata", configDataFile)}) - assert.NilError(t, cmd.Execute()) - golden.Assert(t, string(actual), configDataFile) - assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String()))) -} - -func TestConfigCreateWithLabels(t *testing.T) { - expectedLabels := map[string]string{ - "lbl1": "Label-foo", - "lbl2": "Label-bar", - } - name := "foo" - - data, err := ioutil.ReadFile(filepath.Join("testdata", configDataFile)) - assert.NilError(t, err) - - expected := swarm.ConfigSpec{ - Annotations: swarm.Annotations{ - Name: name, - Labels: expectedLabels, - }, - Data: data, - } - - cli := test.NewFakeCli(&fakeClient{ - configCreateFunc: func(spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { - if !reflect.DeepEqual(spec, expected) { - return types.ConfigCreateResponse{}, errors.Errorf("expected %+v, got %+v", expected, spec) - } - - return types.ConfigCreateResponse{ - ID: "ID-" + spec.Name, - }, nil - }, - }) - - cmd := newConfigCreateCommand(cli) - cmd.SetArgs([]string{name, filepath.Join("testdata", configDataFile)}) - cmd.Flags().Set("label", "lbl1=Label-foo") - cmd.Flags().Set("label", "lbl2=Label-bar") - assert.NilError(t, cmd.Execute()) - assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String()))) -} - -func TestConfigCreateWithTemplatingDriver(t *testing.T) { - expectedDriver := &swarm.Driver{ - Name: "template-driver", - } - name := "foo" - - cli := test.NewFakeCli(&fakeClient{ - 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) - } - - if spec.Templating.Name != expectedDriver.Name { - return types.ConfigCreateResponse{}, errors.Errorf("expected driver %v, got %v", expectedDriver, spec.Labels) - } - - return types.ConfigCreateResponse{ - ID: "ID-" + spec.Name, - }, nil - }, - }) - - cmd := newConfigCreateCommand(cli) - cmd.SetArgs([]string{name, filepath.Join("testdata", configDataFile)}) - cmd.Flags().Set("template-driver", expectedDriver.Name) - assert.NilError(t, cmd.Execute()) - assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String()))) -}
  56. Download patch cli/cli/command/container/testdata/container-list-format-with-arg.golden

    --- 19.03.7+dfsg1-3/cli/cli/command/container/testdata/container-list-format-with-arg.golden 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/testdata/container-list-format-with-arg.golden 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -c1 value -c2
  57. Download patch cli/cli/command/cli_options.go

    --- 19.03.7+dfsg1-3/cli/cli/command/cli_options.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/cli_options.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,105 +0,0 @@ -package command - -import ( - "fmt" - "io" - "os" - "strconv" - - "github.com/docker/cli/cli/context/docker" - "github.com/docker/cli/cli/context/store" - "github.com/docker/cli/cli/streams" - clitypes "github.com/docker/cli/types" - "github.com/docker/docker/pkg/term" -) - -// DockerCliOption applies a modification on a DockerCli. -type DockerCliOption func(cli *DockerCli) error - -// WithStandardStreams sets a cli in, out and err streams with the standard streams. -func WithStandardStreams() DockerCliOption { - return func(cli *DockerCli) error { - // Set terminal emulation based on platform as required. - stdin, stdout, stderr := term.StdStreams() - cli.in = streams.NewIn(stdin) - cli.out = streams.NewOut(stdout) - cli.err = stderr - return nil - } -} - -// WithCombinedStreams uses the same stream for the output and error streams. -func WithCombinedStreams(combined io.Writer) DockerCliOption { - return func(cli *DockerCli) error { - cli.out = streams.NewOut(combined) - cli.err = combined - return nil - } -} - -// WithInputStream sets a cli input stream. -func WithInputStream(in io.ReadCloser) DockerCliOption { - return func(cli *DockerCli) error { - cli.in = streams.NewIn(in) - return nil - } -} - -// WithOutputStream sets a cli output stream. -func WithOutputStream(out io.Writer) DockerCliOption { - return func(cli *DockerCli) error { - cli.out = streams.NewOut(out) - return nil - } -} - -// WithErrorStream sets a cli error stream. -func WithErrorStream(err io.Writer) DockerCliOption { - return func(cli *DockerCli) error { - cli.err = err - return nil - } -} - -// WithContentTrustFromEnv enables content trust on a cli from environment variable DOCKER_CONTENT_TRUST value. -func WithContentTrustFromEnv() DockerCliOption { - return func(cli *DockerCli) error { - cli.contentTrust = false - if e := os.Getenv("DOCKER_CONTENT_TRUST"); e != "" { - if t, err := strconv.ParseBool(e); t || err != nil { - // treat any other value as true - cli.contentTrust = true - } - } - return nil - } -} - -// WithContentTrust enables content trust on a cli. -func WithContentTrust(enabled bool) DockerCliOption { - return func(cli *DockerCli) error { - cli.contentTrust = enabled - return nil - } -} - -// WithContainerizedClient sets the containerized client constructor on a cli. -func WithContainerizedClient(containerizedFn func(string) (clitypes.ContainerizedClient, error)) DockerCliOption { - return func(cli *DockerCli) error { - cli.newContainerizeClient = containerizedFn - return nil - } -} - -// WithContextEndpointType add support for an additional typed endpoint in the context store -// Plugins should use this to store additional endpoints configuration in the context store -func WithContextEndpointType(endpointName string, endpointType store.TypeGetter) DockerCliOption { - return func(cli *DockerCli) error { - switch endpointName { - case docker.DockerEndpoint: - return fmt.Errorf("cannot change %q endpoint type", endpointName) - } - cli.contextStoreConfig.SetEndpoint(endpointName, endpointType) - return nil - } -}
  58. Download patch cli/cli/command/container/rename.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/rename.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/rename.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,51 +0,0 @@ -package container - -import ( - "context" - "fmt" - "strings" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/pkg/errors" - "github.com/spf13/cobra" -) - -type renameOptions struct { - oldName string - newName string -} - -// NewRenameCommand creates a new cobra.Command for `docker rename` -func NewRenameCommand(dockerCli command.Cli) *cobra.Command { - var opts renameOptions - - cmd := &cobra.Command{ - Use: "rename CONTAINER NEW_NAME", - Short: "Rename a container", - Args: cli.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - opts.oldName = args[0] - opts.newName = args[1] - return runRename(dockerCli, &opts) - }, - } - return cmd -} - -func runRename(dockerCli command.Cli, opts *renameOptions) error { - ctx := context.Background() - - oldName := strings.TrimSpace(opts.oldName) - newName := strings.TrimSpace(opts.newName) - - if oldName == "" || newName == "" { - return errors.New("Error: Neither old nor new names may be empty") - } - - if err := dockerCli.Client().ContainerRename(ctx, oldName, newName); err != nil { - fmt.Fprintln(dockerCli.Err(), err) - return errors.Errorf("Error: failed to rename container named %s", oldName) - } - return nil -}
  59. Download patch cli/cli/cobra_test.go

    --- 19.03.7+dfsg1-3/cli/cli/cobra_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/cobra_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,88 +0,0 @@ -package cli - -import ( - "testing" - - pluginmanager "github.com/docker/cli/cli-plugins/manager" - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/spf13/cobra" - "gotest.tools/assert" - is "gotest.tools/assert/cmp" -) - -func TestVisitAll(t *testing.T) { - root := &cobra.Command{Use: "root"} - sub1 := &cobra.Command{Use: "sub1"} - sub1sub1 := &cobra.Command{Use: "sub1sub1"} - sub1sub2 := &cobra.Command{Use: "sub1sub2"} - sub2 := &cobra.Command{Use: "sub2"} - - root.AddCommand(sub1, sub2) - sub1.AddCommand(sub1sub1, sub1sub2) - - // Take the opportunity to test DisableFlagsInUseLine too - DisableFlagsInUseLine(root) - - var visited []string - VisitAll(root, func(ccmd *cobra.Command) { - visited = append(visited, ccmd.Name()) - assert.Assert(t, ccmd.DisableFlagsInUseLine, "DisableFlagsInUseLine not set on %q", ccmd.Name()) - }) - expected := []string{"sub1sub1", "sub1sub2", "sub1", "sub2", "root"} - assert.DeepEqual(t, expected, visited) -} - -func TestVendorAndVersion(t *testing.T) { - // Non plugin. - assert.Equal(t, vendorAndVersion(&cobra.Command{Use: "test"}), "") - - // Plugins with various lengths of vendor. - for _, tc := range []struct { - vendor string - version string - expected string - }{ - {vendor: "vendor", expected: "(vendor)"}, - {vendor: "vendor", version: "testing", expected: "(vendor, testing)"}, - } { - t.Run(tc.vendor, func(t *testing.T) { - cmd := &cobra.Command{ - Use: "test", - Annotations: map[string]string{ - pluginmanager.CommandAnnotationPlugin: "true", - pluginmanager.CommandAnnotationPluginVendor: tc.vendor, - pluginmanager.CommandAnnotationPluginVersion: tc.version, - }, - } - assert.Equal(t, vendorAndVersion(cmd), tc.expected) - }) - } -} - -func TestInvalidPlugin(t *testing.T) { - root := &cobra.Command{Use: "root"} - sub1 := &cobra.Command{Use: "sub1"} - sub1sub1 := &cobra.Command{Use: "sub1sub1"} - sub1sub2 := &cobra.Command{Use: "sub1sub2"} - sub2 := &cobra.Command{Use: "sub2"} - - assert.Assert(t, is.Len(invalidPlugins(root), 0)) - - sub1.Annotations = map[string]string{ - pluginmanager.CommandAnnotationPlugin: "true", - pluginmanager.CommandAnnotationPluginInvalid: "foo", - } - root.AddCommand(sub1, sub2) - sub1.AddCommand(sub1sub1, sub1sub2) - - assert.DeepEqual(t, invalidPlugins(root), []*cobra.Command{sub1}, cmpopts.IgnoreUnexported(cobra.Command{})) -} - -func TestDecoratedName(t *testing.T) { - root := &cobra.Command{Use: "root"} - topLevelCommand := &cobra.Command{Use: "pluginTopLevelCommand"} - root.AddCommand(topLevelCommand) - assert.Equal(t, decoratedName(topLevelCommand), "pluginTopLevelCommand ") - topLevelCommand.Annotations = map[string]string{pluginmanager.CommandAnnotationPlugin: "true"} - assert.Equal(t, decoratedName(topLevelCommand), "pluginTopLevelCommand*") -}
  60. Download patch cli/cli/command/container/formatter_stats_test.go
  61. Download patch cli/circle.yml

    --- 19.03.7+dfsg1-3/cli/circle.yml 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/circle.yml 1970-01-01 00:00:00.000000000 +0000 @@ -1,159 +0,0 @@ -version: 2 - -jobs: - - lint: - working_directory: /work - docker: [{image: 'docker:18.09-git'}] - environment: - DOCKER_BUILDKIT: 1 - steps: - - checkout - - setup_remote_docker: - version: 18.09.3 - reusable: true - exclusive: false - - run: - name: "Docker version" - command: docker version - - run: - name: "Docker info" - command: docker info - - run: - name: "Shellcheck - build image" - command: | - docker build --progress=plain -f dockerfiles/Dockerfile.shellcheck --tag cli-validator:$CIRCLE_BUILD_NUM . - - run: - name: "Shellcheck" - command: | - docker run --rm cli-validator:$CIRCLE_BUILD_NUM \ - make shellcheck - - run: - name: "Lint - build image" - command: | - docker build --progress=plain -f dockerfiles/Dockerfile.lint --tag cli-linter:$CIRCLE_BUILD_NUM . - - run: - name: "Lint" - command: | - docker run --rm cli-linter:$CIRCLE_BUILD_NUM - - cross: - working_directory: /work - docker: [{image: 'docker:18.09-git'}] - environment: - DOCKER_BUILDKIT: 1 - parallelism: 3 - steps: - - checkout - - setup_remote_docker: - version: 18.09.3 - reusable: true - exclusive: false - - run: - name: "Docker version" - command: docker version - - run: - name: "Docker info" - command: docker info - - run: - name: "Cross - build image" - command: | - docker build --progress=plain -f dockerfiles/Dockerfile.cross --tag cli-builder:$CIRCLE_BUILD_NUM . - - run: - name: "Cross" - command: | - name=cross-$CIRCLE_BUILD_NUM-$CIRCLE_NODE_INDEX - docker run \ - -e CROSS_GROUP=$CIRCLE_NODE_INDEX \ - --name $name cli-builder:$CIRCLE_BUILD_NUM \ - make cross - docker cp \ - $name:/go/src/github.com/docker/cli/build \ - /work/build - - store_artifacts: - path: /work/build - - test: - working_directory: /work - docker: [{image: 'docker:18.09-git'}] - environment: - DOCKER_BUILDKIT: 1 - steps: - - checkout - - setup_remote_docker: - version: 18.09.3 - reusable: true - exclusive: false - - run: - name: "Docker version" - command: docker version - - run: - name: "Docker info" - command: docker info - - run: - name: "Unit Test with Coverage - build image" - command: | - mkdir -p test-results/unit-tests - docker build --progress=plain -f dockerfiles/Dockerfile.dev --tag cli-builder:$CIRCLE_BUILD_NUM . - - run: - name: "Unit Test with Coverage" - command: | - docker run \ - -e GOTESTSUM_JUNITFILE=/tmp/junit.xml \ - --name \ - test-$CIRCLE_BUILD_NUM cli-builder:$CIRCLE_BUILD_NUM \ - make test-coverage - docker cp \ - test-$CIRCLE_BUILD_NUM:/tmp/junit.xml \ - ./test-results/unit-tests/junit.xml - - run: - name: "Upload to Codecov" - command: | - docker cp \ - test-$CIRCLE_BUILD_NUM:/go/src/github.com/docker/cli/coverage.txt \ - coverage.txt - apk add -U bash curl - curl -s https://codecov.io/bash | bash || \ - echo 'Codecov failed to upload' - - store_test_results: - path: test-results - - store_artifacts: - path: test-results - - validate: - working_directory: /work - docker: [{image: 'docker:18.09-git'}] - environment: - DOCKER_BUILDKIT: 1 - steps: - - checkout - - setup_remote_docker: - version: 18.09.3 - reusable: true - exclusive: false - - run: - name: "Docker version" - command: docker version - - run: - name: "Docker info" - command: docker info - - run: - name: "Validate - build image" - command: | - rm -f .dockerignore # include .git - docker build --progress=plain -f dockerfiles/Dockerfile.dev --tag cli-builder-with-git:$CIRCLE_BUILD_NUM . - - run: - name: "Validate Vendor, Docs, and Code Generation" - command: | - docker run --rm cli-builder-with-git:$CIRCLE_BUILD_NUM \ - make ci-validate - no_output_timeout: 15m - -workflows: - version: 2 - ci: - jobs: - - lint - - cross - - test - - validate
  62. Download patch CHANGELOG.md

    --- 19.03.7+dfsg1-3/CHANGELOG.md 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/CHANGELOG.md 2020-03-10 19:42:48.000000000 +0000 @@ -3,6 +3,12 @@ For official release notes for Docker Engine CE and Docker Engine EE, visit the [release notes page](https://docs.docker.com/engine/release-notes/). +## 19.03.8 (2020-03-10) + +### Runtime + +- Improve mitigation for [CVE-2019-14271](https://nvd.nist.gov/vuln/detail/CVE-2019-14271) for some nscd configuration. + ## 19.03.7 (2020-03-03) ### Builder
  63. Download patch cli/cli/command/container/formatter_stats.go
  64. Download patch cli/cli/command/container/export.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/export.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/export.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,62 +0,0 @@ -package container - -import ( - "context" - "io" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/pkg/errors" - "github.com/spf13/cobra" -) - -type exportOptions struct { - container string - output string -} - -// NewExportCommand creates a new `docker export` command -func NewExportCommand(dockerCli command.Cli) *cobra.Command { - var opts exportOptions - - cmd := &cobra.Command{ - Use: "export [OPTIONS] CONTAINER", - Short: "Export a container's filesystem as a tar archive", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.container = args[0] - return runExport(dockerCli, opts) - }, - } - - flags := cmd.Flags() - - flags.StringVarP(&opts.output, "output", "o", "", "Write to a file, instead of STDOUT") - - return cmd -} - -func runExport(dockerCli command.Cli, opts exportOptions) error { - if opts.output == "" && dockerCli.Out().IsTerminal() { - return errors.New("cowardly refusing to save to a terminal. Use the -o flag or redirect") - } - - if err := command.ValidateOutputPath(opts.output); err != nil { - return errors.Wrap(err, "failed to export container") - } - - clnt := dockerCli.Client() - - responseBody, err := clnt.ContainerExport(context.Background(), opts.container) - if err != nil { - return err - } - defer responseBody.Close() - - if opts.output == "" { - _, err := io.Copy(dockerCli.Out(), responseBody) - return err - } - - return command.CopyToFile(opts.output, responseBody) -}
  65. Download patch cli/cli/command/container/cp.go
  66. Download patch cli/cli/command/config/testdata/config-list-with-filter.golden

    --- 19.03.7+dfsg1-3/cli/cli/command/config/testdata/config-list-with-filter.golden 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/testdata/config-list-with-filter.golden 1970-01-01 00:00:00.000000000 +0000 @@ -1,3 +0,0 @@ -ID NAME CREATED UPDATED -ID-bar bar 2 hours ago About an hour ago -ID-foo foo 2 hours ago About an hour ago
  67. Download patch cli/cli/command/config/remove.go

    --- 19.03.7+dfsg1-3/cli/cli/command/config/remove.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/remove.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,55 +0,0 @@ -package config - -import ( - "context" - "fmt" - "strings" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/pkg/errors" - "github.com/spf13/cobra" -) - -// RemoveOptions contains options for the docker config rm command. -type RemoveOptions struct { - Names []string -} - -func newConfigRemoveCommand(dockerCli command.Cli) *cobra.Command { - return &cobra.Command{ - Use: "rm CONFIG [CONFIG...]", - Aliases: []string{"remove"}, - Short: "Remove one or more configs", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts := RemoveOptions{ - Names: args, - } - return RunConfigRemove(dockerCli, opts) - }, - } -} - -// RunConfigRemove removes the given Swarm configs. -func RunConfigRemove(dockerCli command.Cli, opts RemoveOptions) error { - client := dockerCli.Client() - ctx := context.Background() - - var errs []string - - for _, name := range opts.Names { - if err := client.ConfigRemove(ctx, name); err != nil { - errs = append(errs, err.Error()) - continue - } - - fmt.Fprintln(dockerCli.Out(), name) - } - - if len(errs) > 0 { - return errors.Errorf("%s", strings.Join(errs, "\n")) - } - - return nil -}
  68. Download patch cli/cli/command/config/testdata/config-create-with-name.golden

    --- 19.03.7+dfsg1-3/cli/cli/command/config/testdata/config-create-with-name.golden 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/testdata/config-create-with-name.golden 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -config_foo_bar
  69. Download patch cli/cli/command/container/cp_test.go
  70. Download patch cli/cli/command/container/attach.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/attach.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/attach.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,173 +0,0 @@ -package container - -import ( - "context" - "fmt" - "io" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/client" - "github.com/docker/docker/pkg/signal" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" - "github.com/spf13/cobra" -) - -type attachOptions struct { - noStdin bool - proxy bool - detachKeys string - - container string -} - -func inspectContainerAndCheckState(ctx context.Context, cli client.APIClient, args string) (*types.ContainerJSON, error) { - c, err := cli.ContainerInspect(ctx, args) - if err != nil { - return nil, err - } - if !c.State.Running { - return nil, errors.New("You cannot attach to a stopped container, start it first") - } - if c.State.Paused { - return nil, errors.New("You cannot attach to a paused container, unpause it first") - } - if c.State.Restarting { - return nil, errors.New("You cannot attach to a restarting container, wait until it is running") - } - - return &c, nil -} - -// NewAttachCommand creates a new cobra.Command for `docker attach` -func NewAttachCommand(dockerCli command.Cli) *cobra.Command { - var opts attachOptions - - cmd := &cobra.Command{ - Use: "attach [OPTIONS] CONTAINER", - Short: "Attach local standard input, output, and error streams to a running container", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.container = args[0] - return runAttach(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - flags.BoolVar(&opts.noStdin, "no-stdin", false, "Do not attach STDIN") - flags.BoolVar(&opts.proxy, "sig-proxy", true, "Proxy all received signals to the process") - flags.StringVar(&opts.detachKeys, "detach-keys", "", "Override the key sequence for detaching a container") - return cmd -} - -func runAttach(dockerCli command.Cli, opts *attachOptions) error { - ctx := context.Background() - client := dockerCli.Client() - - // request channel to wait for client - resultC, errC := client.ContainerWait(ctx, opts.container, "") - - c, err := inspectContainerAndCheckState(ctx, client, opts.container) - if err != nil { - return err - } - - if err := dockerCli.In().CheckTty(!opts.noStdin, c.Config.Tty); err != nil { - return err - } - - if opts.detachKeys != "" { - dockerCli.ConfigFile().DetachKeys = opts.detachKeys - } - - options := types.ContainerAttachOptions{ - Stream: true, - Stdin: !opts.noStdin && c.Config.OpenStdin, - Stdout: true, - Stderr: true, - DetachKeys: dockerCli.ConfigFile().DetachKeys, - } - - var in io.ReadCloser - if options.Stdin { - in = dockerCli.In() - } - - if opts.proxy && !c.Config.Tty { - sigc := ForwardAllSignals(ctx, dockerCli, opts.container) - defer signal.StopCatch(sigc) - } - - resp, errAttach := client.ContainerAttach(ctx, opts.container, options) - if errAttach != nil { - return errAttach - } - defer resp.Close() - - // If use docker attach command to attach to a stop container, it will return - // "You cannot attach to a stopped container" error, it's ok, but when - // attach to a running container, it(docker attach) use inspect to check - // the container's state, if it pass the state check on the client side, - // and then the container is stopped, docker attach command still attach to - // the container and not exit. - // - // Recheck the container's state to avoid attach block. - _, err = inspectContainerAndCheckState(ctx, client, opts.container) - if err != nil { - return err - } - - if c.Config.Tty && dockerCli.Out().IsTerminal() { - resizeTTY(ctx, dockerCli, opts.container) - } - - streamer := hijackedIOStreamer{ - streams: dockerCli, - inputStream: in, - outputStream: dockerCli.Out(), - errorStream: dockerCli.Err(), - resp: resp, - tty: c.Config.Tty, - detachKeys: options.DetachKeys, - } - - if err := streamer.stream(ctx); err != nil { - return err - } - - return getExitStatus(errC, resultC) -} - -func getExitStatus(errC <-chan error, resultC <-chan container.ContainerWaitOKBody) error { - select { - case result := <-resultC: - if result.Error != nil { - return fmt.Errorf(result.Error.Message) - } - if result.StatusCode != 0 { - return cli.StatusError{StatusCode: int(result.StatusCode)} - } - case err := <-errC: - return err - } - - return nil -} - -func resizeTTY(ctx context.Context, dockerCli command.Cli, containerID string) { - height, width := dockerCli.Out().GetTtySize() - // To handle the case where a user repeatedly attaches/detaches without resizing their - // terminal, the only way to get the shell prompt to display for attaches 2+ is to artificially - // resize it, then go back to normal. Without this, every attach after the first will - // require the user to manually resize or hit enter. - resizeTtyTo(ctx, dockerCli.Client(), containerID, height+1, width+1, false) - - // After the above resizing occurs, the call to MonitorTtySize below will handle resetting back - // to the actual size. - if err := MonitorTtySize(ctx, dockerCli, containerID, false); err != nil { - logrus.Debugf("Error monitoring TTY size: %s", err) - } -}
  71. Download patch cli/cli/command/config/testdata/config-inspect-without-format.multiple-configs-with-labels.golden

    --- 19.03.7+dfsg1-3/cli/cli/command/config/testdata/config-inspect-without-format.multiple-configs-with-labels.golden 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/testdata/config-inspect-without-format.multiple-configs-with-labels.golden 1970-01-01 00:00:00.000000000 +0000 @@ -1,26 +0,0 @@ -[ - { - "ID": "ID-foo", - "Version": {}, - "CreatedAt": "0001-01-01T00:00:00Z", - "UpdatedAt": "0001-01-01T00:00:00Z", - "Spec": { - "Name": "foo", - "Labels": { - "label1": "label-foo" - } - } - }, - { - "ID": "ID-bar", - "Version": {}, - "CreatedAt": "0001-01-01T00:00:00Z", - "UpdatedAt": "0001-01-01T00:00:00Z", - "Spec": { - "Name": "bar", - "Labels": { - "label1": "label-foo" - } - } - } -]
  72. Download patch cli/cli/command/checkpoint/client_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/checkpoint/client_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/checkpoint/client_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,36 +0,0 @@ -package checkpoint - -import ( - "context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/client" -) - -type fakeClient struct { - client.Client - checkpointCreateFunc func(container string, options types.CheckpointCreateOptions) error - checkpointDeleteFunc func(container string, options types.CheckpointDeleteOptions) error - checkpointListFunc func(container string, options types.CheckpointListOptions) ([]types.Checkpoint, 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(ctx context.Context, container string, options types.CheckpointDeleteOptions) error { - if cli.checkpointDeleteFunc != nil { - return cli.checkpointDeleteFunc(container, options) - } - return nil -} - -func (cli *fakeClient) CheckpointList(ctx context.Context, container string, options types.CheckpointListOptions) ([]types.Checkpoint, error) { - if cli.checkpointListFunc != nil { - return cli.checkpointListFunc(container, options) - } - return []types.Checkpoint{}, nil -}
  73. Download patch cli/cli/command/config/ls_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/config/ls_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/ls_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,157 +0,0 @@ -package config - -import ( - "io/ioutil" - "testing" - "time" - - "github.com/docker/cli/cli/config/configfile" - "github.com/docker/cli/internal/test" - . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" - "gotest.tools/assert" - is "gotest.tools/assert/cmp" - "gotest.tools/golden" -) - -func TestConfigListErrors(t *testing.T) { - testCases := []struct { - args []string - configListFunc func(types.ConfigListOptions) ([]swarm.Config, error) - expectedError string - }{ - { - args: []string{"foo"}, - expectedError: "accepts no argument", - }, - { - configListFunc: func(options types.ConfigListOptions) ([]swarm.Config, error) { - return []swarm.Config{}, errors.Errorf("error listing configs") - }, - expectedError: "error listing configs", - }, - } - for _, tc := range testCases { - cmd := newConfigListCommand( - test.NewFakeCli(&fakeClient{ - configListFunc: tc.configListFunc, - }), - ) - cmd.SetArgs(tc.args) - cmd.SetOutput(ioutil.Discard) - assert.ErrorContains(t, cmd.Execute(), tc.expectedError) - } -} - -func TestConfigList(t *testing.T) { - cli := test.NewFakeCli(&fakeClient{ - configListFunc: func(options types.ConfigListOptions) ([]swarm.Config, error) { - return []swarm.Config{ - *Config(ConfigID("ID-1-foo"), - ConfigName("1-foo"), - ConfigVersion(swarm.Version{Index: 10}), - ConfigCreatedAt(time.Now().Add(-2*time.Hour)), - ConfigUpdatedAt(time.Now().Add(-1*time.Hour)), - ), - *Config(ConfigID("ID-10-foo"), - ConfigName("10-foo"), - ConfigVersion(swarm.Version{Index: 11}), - ConfigCreatedAt(time.Now().Add(-2*time.Hour)), - ConfigUpdatedAt(time.Now().Add(-1*time.Hour)), - ), - *Config(ConfigID("ID-2-foo"), - ConfigName("2-foo"), - ConfigVersion(swarm.Version{Index: 11}), - ConfigCreatedAt(time.Now().Add(-2*time.Hour)), - ConfigUpdatedAt(time.Now().Add(-1*time.Hour)), - ), - }, nil - }, - }) - cmd := newConfigListCommand(cli) - assert.NilError(t, cmd.Execute()) - golden.Assert(t, cli.OutBuffer().String(), "config-list-sort.golden") -} - -func TestConfigListWithQuietOption(t *testing.T) { - cli := test.NewFakeCli(&fakeClient{ - 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{ - "label": "label-bar", - })), - }, nil - }, - }) - cmd := newConfigListCommand(cli) - cmd.Flags().Set("quiet", "true") - assert.NilError(t, cmd.Execute()) - golden.Assert(t, cli.OutBuffer().String(), "config-list-with-quiet-option.golden") -} - -func TestConfigListWithConfigFormat(t *testing.T) { - cli := test.NewFakeCli(&fakeClient{ - 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{ - "label": "label-bar", - })), - }, nil - }, - }) - cli.SetConfigFile(&configfile.ConfigFile{ - ConfigFormat: "{{ .Name }} {{ .Labels }}", - }) - cmd := newConfigListCommand(cli) - assert.NilError(t, cmd.Execute()) - golden.Assert(t, cli.OutBuffer().String(), "config-list-with-config-format.golden") -} - -func TestConfigListWithFormat(t *testing.T) { - cli := test.NewFakeCli(&fakeClient{ - 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{ - "label": "label-bar", - })), - }, nil - }, - }) - cmd := newConfigListCommand(cli) - cmd.Flags().Set("format", "{{ .Name }} {{ .Labels }}") - assert.NilError(t, cmd.Execute()) - golden.Assert(t, cli.OutBuffer().String(), "config-list-with-format.golden") -} - -func TestConfigListWithFilter(t *testing.T) { - cli := test.NewFakeCli(&fakeClient{ - 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{ - *Config(ConfigID("ID-foo"), - ConfigName("foo"), - ConfigVersion(swarm.Version{Index: 10}), - ConfigCreatedAt(time.Now().Add(-2*time.Hour)), - ConfigUpdatedAt(time.Now().Add(-1*time.Hour)), - ), - *Config(ConfigID("ID-bar"), - ConfigName("bar"), - ConfigVersion(swarm.Version{Index: 11}), - ConfigCreatedAt(time.Now().Add(-2*time.Hour)), - ConfigUpdatedAt(time.Now().Add(-1*time.Hour)), - ), - }, nil - }, - }) - cmd := newConfigListCommand(cli) - cmd.Flags().Set("filter", "name=foo") - cmd.Flags().Set("filter", "label=lbl1=Label-bar") - assert.NilError(t, cmd.Execute()) - golden.Assert(t, cli.OutBuffer().String(), "config-list-with-filter.golden") -}
  74. Download patch cli/cli/command/bundlefile/bundlefile.go

    --- 19.03.7+dfsg1-3/cli/cli/command/bundlefile/bundlefile.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/bundlefile/bundlefile.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,70 +0,0 @@ -package bundlefile - -import ( - "encoding/json" - "io" - - "github.com/pkg/errors" -) - -// Bundlefile stores the contents of a bundlefile -type Bundlefile struct { - Version string - Services map[string]Service -} - -// Service is a service from a bundlefile -type Service struct { - Image string - Command []string `json:",omitempty"` - Args []string `json:",omitempty"` - Env []string `json:",omitempty"` - Labels map[string]string `json:",omitempty"` - Ports []Port `json:",omitempty"` - WorkingDir *string `json:",omitempty"` - User *string `json:",omitempty"` - Networks []string `json:",omitempty"` -} - -// Port is a port as defined in a bundlefile -type Port struct { - Protocol string - Port uint32 -} - -// LoadFile loads a bundlefile from a path to the file -func LoadFile(reader io.Reader) (*Bundlefile, error) { - bundlefile := &Bundlefile{} - - decoder := json.NewDecoder(reader) - if err := decoder.Decode(bundlefile); err != nil { - switch jsonErr := err.(type) { - case *json.SyntaxError: - return nil, errors.Errorf( - "JSON syntax error at byte %v: %s", - jsonErr.Offset, - jsonErr.Error()) - case *json.UnmarshalTypeError: - return nil, errors.Errorf( - "Unexpected type at byte %v. Expected %s but received %s.", - jsonErr.Offset, - jsonErr.Type, - jsonErr.Value) - } - return nil, err - } - - return bundlefile, nil -} - -// Print writes the contents of the bundlefile to the output writer -// as human readable json -func Print(out io.Writer, bundle *Bundlefile) error { - bytes, err := json.MarshalIndent(*bundle, "", " ") - if err != nil { - return err - } - - _, err = out.Write(bytes) - return err -}
  75. Download patch cli/cli/command/config/inspect_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/config/inspect_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/inspect_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,171 +0,0 @@ -package config - -import ( - "fmt" - "io/ioutil" - "testing" - "time" - - "github.com/docker/cli/internal/test" - . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function - "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" - "gotest.tools/assert" - "gotest.tools/golden" -) - -func TestConfigInspectErrors(t *testing.T) { - testCases := []struct { - args []string - flags map[string]string - configInspectFunc func(configID string) (swarm.Config, []byte, error) - expectedError string - }{ - { - expectedError: "requires at least 1 argument", - }, - { - args: []string{"foo"}, - 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", - }, - { - args: []string{"foo"}, - flags: map[string]string{ - "format": "{{invalid format}}", - }, - expectedError: "Template parsing error", - }, - { - args: []string{"foo", "bar"}, - configInspectFunc: func(configID string) (swarm.Config, []byte, error) { - if configID == "foo" { - return *Config(ConfigName("foo")), nil, nil - } - return swarm.Config{}, nil, errors.Errorf("error while inspecting the config") - }, - expectedError: "error while inspecting the config", - }, - } - for _, tc := range testCases { - cmd := newConfigInspectCommand( - test.NewFakeCli(&fakeClient{ - configInspectFunc: tc.configInspectFunc, - }), - ) - cmd.SetArgs(tc.args) - for key, value := range tc.flags { - cmd.Flags().Set(key, value) - } - cmd.SetOutput(ioutil.Discard) - assert.ErrorContains(t, cmd.Execute(), tc.expectedError) - } -} - -func TestConfigInspectWithoutFormat(t *testing.T) { - testCases := []struct { - name string - args []string - configInspectFunc func(configID string) (swarm.Config, []byte, error) - }{ - { - name: "single-config", - args: []string{"foo"}, - 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) - } - return *Config(ConfigID("ID-foo"), ConfigName("foo")), nil, nil - }, - }, - { - name: "multiple-configs-with-labels", - args: []string{"foo", "bar"}, - configInspectFunc: func(name string) (swarm.Config, []byte, error) { - return *Config(ConfigID("ID-"+name), ConfigName(name), ConfigLabels(map[string]string{ - "label1": "label-foo", - })), nil, nil - }, - }, - } - for _, tc := range testCases { - cli := test.NewFakeCli(&fakeClient{configInspectFunc: tc.configInspectFunc}) - cmd := newConfigInspectCommand(cli) - cmd.SetArgs(tc.args) - assert.NilError(t, cmd.Execute()) - golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("config-inspect-without-format.%s.golden", tc.name)) - } -} - -func TestConfigInspectWithFormat(t *testing.T) { - configInspectFunc := func(name string) (swarm.Config, []byte, error) { - return *Config(ConfigName("foo"), ConfigLabels(map[string]string{ - "label1": "label-foo", - })), nil, nil - } - testCases := []struct { - name string - format string - args []string - configInspectFunc func(name string) (swarm.Config, []byte, error) - }{ - { - name: "simple-template", - format: "{{.Spec.Name}}", - args: []string{"foo"}, - configInspectFunc: configInspectFunc, - }, - { - name: "json-template", - format: "{{json .Spec.Labels}}", - args: []string{"foo"}, - configInspectFunc: configInspectFunc, - }, - } - for _, tc := range testCases { - cli := test.NewFakeCli(&fakeClient{ - configInspectFunc: tc.configInspectFunc, - }) - cmd := newConfigInspectCommand(cli) - cmd.SetArgs(tc.args) - cmd.Flags().Set("format", tc.format) - assert.NilError(t, cmd.Execute()) - golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("config-inspect-with-format.%s.golden", tc.name)) - } -} - -func TestConfigInspectPretty(t *testing.T) { - testCases := []struct { - name string - configInspectFunc func(string) (swarm.Config, []byte, error) - }{ - { - name: "simple", - configInspectFunc: func(id string) (swarm.Config, []byte, error) { - return *Config( - ConfigLabels(map[string]string{ - "lbl1": "value1", - }), - ConfigID("configID"), - ConfigName("configName"), - ConfigCreatedAt(time.Time{}), - ConfigUpdatedAt(time.Time{}), - ConfigData([]byte("payload here")), - ), []byte{}, nil - }, - }, - } - for _, tc := range testCases { - cli := test.NewFakeCli(&fakeClient{ - configInspectFunc: tc.configInspectFunc, - }) - cmd := newConfigInspectCommand(cli) - - cmd.SetArgs([]string{"configID"}) - cmd.Flags().Set("pretty", "true") - assert.NilError(t, cmd.Execute()) - golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("config-inspect-pretty.%s.golden", tc.name)) - } -}
  76. Download patch cli/cli/command/config/cmd.go

    --- 19.03.7+dfsg1-3/cli/cli/command/config/cmd.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/cmd.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,29 +0,0 @@ -package config - -import ( - "github.com/spf13/cobra" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" -) - -// NewConfigCommand returns a cobra command for `config` subcommands -func NewConfigCommand(dockerCli command.Cli) *cobra.Command { - cmd := &cobra.Command{ - Use: "config", - Short: "Manage Docker configs", - Args: cli.NoArgs, - RunE: command.ShowHelp(dockerCli.Err()), - Annotations: map[string]string{ - "version": "1.30", - "swarm": "", - }, - } - cmd.AddCommand( - newConfigListCommand(dockerCli), - newConfigCreateCommand(dockerCli), - newConfigInspectCommand(dockerCli), - newConfigRemoveCommand(dockerCli), - ) - return cmd -}
  77. Download patch cli/cli/command/container/testdata/container-list-with-config-format.golden

    --- 19.03.7+dfsg1-3/cli/cli/command/container/testdata/container-list-with-config-format.golden 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/testdata/container-list-with-config-format.golden 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -c1 busybox:latest some.label=value -c2 busybox:latest foo=bar
  78. Download patch cli/cli/command/container/create_test.go
  79. Download patch cli/cli/cobra.go
  80. Download patch cli/cli/command/container/testdata/container-list-format-name-name.golden

    --- 19.03.7+dfsg1-3/cli/cli/command/container/testdata/container-list-format-name-name.golden 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/testdata/container-list-format-name-name.golden 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -c1 c1 -c2 c2
  81. Download patch cli/appveyor.yml

    --- 19.03.7+dfsg1-3/cli/appveyor.yml 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/appveyor.yml 1970-01-01 00:00:00.000000000 +0000 @@ -1,23 +0,0 @@ -version: "{build}" - -clone_folder: c:\gopath\src\github.com\docker\cli - -environment: - GOPATH: c:\gopath - GOVERSION: 1.12.17 - DEPVERSION: v0.4.1 - -install: - - rmdir c:\go /s /q - - appveyor DownloadFile https://storage.googleapis.com/golang/go%GOVERSION%.windows-amd64.msi - - msiexec /i go%GOVERSION%.windows-amd64.msi /q - - go version - - go env - -deploy: false - -build_script: - - ps: .\scripts\make.ps1 -Binary - -test_script: - - ps: .\scripts\make.ps1 -TestUnit
  82. Download patch cli/cli/command/container/restart.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/restart.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/restart.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,62 +0,0 @@ -package container - -import ( - "context" - "fmt" - "strings" - "time" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/pkg/errors" - "github.com/spf13/cobra" -) - -type restartOptions struct { - nSeconds int - nSecondsChanged bool - - containers []string -} - -// NewRestartCommand creates a new cobra.Command for `docker restart` -func NewRestartCommand(dockerCli command.Cli) *cobra.Command { - var opts restartOptions - - cmd := &cobra.Command{ - Use: "restart [OPTIONS] CONTAINER [CONTAINER...]", - Short: "Restart one or more containers", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.containers = args - opts.nSecondsChanged = cmd.Flags().Changed("time") - return runRestart(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - flags.IntVarP(&opts.nSeconds, "time", "t", 10, "Seconds to wait for stop before killing the container") - return cmd -} - -func runRestart(dockerCli command.Cli, opts *restartOptions) error { - ctx := context.Background() - var errs []string - var timeout *time.Duration - if opts.nSecondsChanged { - timeoutValue := time.Duration(opts.nSeconds) * time.Second - timeout = &timeoutValue - } - - for _, name := range opts.containers { - if err := dockerCli.Client().ContainerRestart(ctx, name, timeout); err != nil { - errs = append(errs, err.Error()) - continue - } - fmt.Fprintln(dockerCli.Out(), name) - } - if len(errs) > 0 { - return errors.New(strings.Join(errs, "\n")) - } - return nil -}
  83. Download patch cli/cli/command/config/testdata/config-list-with-format.golden

    --- 19.03.7+dfsg1-3/cli/cli/command/config/testdata/config-list-with-format.golden 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/testdata/config-list-with-format.golden 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -bar label=label-bar -foo
  84. Download patch cli/cli/command/commands/commands.go

    --- 19.03.7+dfsg1-3/cli/cli/command/commands/commands.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/commands/commands.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,146 +0,0 @@ -package commands - -import ( - "os" - "runtime" - - "github.com/docker/cli/cli/command" - "github.com/docker/cli/cli/command/builder" - "github.com/docker/cli/cli/command/checkpoint" - "github.com/docker/cli/cli/command/config" - "github.com/docker/cli/cli/command/container" - "github.com/docker/cli/cli/command/context" - "github.com/docker/cli/cli/command/engine" - "github.com/docker/cli/cli/command/image" - "github.com/docker/cli/cli/command/manifest" - "github.com/docker/cli/cli/command/network" - "github.com/docker/cli/cli/command/node" - "github.com/docker/cli/cli/command/plugin" - "github.com/docker/cli/cli/command/registry" - "github.com/docker/cli/cli/command/secret" - "github.com/docker/cli/cli/command/service" - "github.com/docker/cli/cli/command/stack" - "github.com/docker/cli/cli/command/swarm" - "github.com/docker/cli/cli/command/system" - "github.com/docker/cli/cli/command/trust" - "github.com/docker/cli/cli/command/volume" - "github.com/spf13/cobra" -) - -// AddCommands adds all the commands from cli/command to the root command -func AddCommands(cmd *cobra.Command, dockerCli command.Cli) { - cmd.AddCommand( - // checkpoint - checkpoint.NewCheckpointCommand(dockerCli), - - // config - config.NewConfigCommand(dockerCli), - - // container - container.NewContainerCommand(dockerCli), - container.NewRunCommand(dockerCli), - - // image - image.NewImageCommand(dockerCli), - image.NewBuildCommand(dockerCli), - - // builder - builder.NewBuilderCommand(dockerCli), - - // manifest - manifest.NewManifestCommand(dockerCli), - - // network - network.NewNetworkCommand(dockerCli), - - // node - node.NewNodeCommand(dockerCli), - - // plugin - plugin.NewPluginCommand(dockerCli), - - // registry - registry.NewLoginCommand(dockerCli), - registry.NewLogoutCommand(dockerCli), - registry.NewSearchCommand(dockerCli), - - // secret - secret.NewSecretCommand(dockerCli), - - // service - service.NewServiceCommand(dockerCli), - - // system - system.NewSystemCommand(dockerCli), - system.NewVersionCommand(dockerCli), - - // stack - stack.NewStackCommand(dockerCli), - - // swarm - swarm.NewSwarmCommand(dockerCli), - - // trust - trust.NewTrustCommand(dockerCli), - - // volume - volume.NewVolumeCommand(dockerCli), - - // context - context.NewContextCommand(dockerCli), - - // legacy commands may be hidden - hide(stack.NewTopLevelDeployCommand(dockerCli)), - hide(system.NewEventsCommand(dockerCli)), - hide(system.NewInfoCommand(dockerCli)), - hide(system.NewInspectCommand(dockerCli)), - hide(container.NewAttachCommand(dockerCli)), - hide(container.NewCommitCommand(dockerCli)), - hide(container.NewCopyCommand(dockerCli)), - hide(container.NewCreateCommand(dockerCli)), - hide(container.NewDiffCommand(dockerCli)), - hide(container.NewExecCommand(dockerCli)), - hide(container.NewExportCommand(dockerCli)), - hide(container.NewKillCommand(dockerCli)), - hide(container.NewLogsCommand(dockerCli)), - hide(container.NewPauseCommand(dockerCli)), - hide(container.NewPortCommand(dockerCli)), - hide(container.NewPsCommand(dockerCli)), - hide(container.NewRenameCommand(dockerCli)), - hide(container.NewRestartCommand(dockerCli)), - hide(container.NewRmCommand(dockerCli)), - hide(container.NewStartCommand(dockerCli)), - hide(container.NewStatsCommand(dockerCli)), - hide(container.NewStopCommand(dockerCli)), - hide(container.NewTopCommand(dockerCli)), - hide(container.NewUnpauseCommand(dockerCli)), - hide(container.NewUpdateCommand(dockerCli)), - hide(container.NewWaitCommand(dockerCli)), - hide(image.NewHistoryCommand(dockerCli)), - hide(image.NewImagesCommand(dockerCli)), - hide(image.NewImportCommand(dockerCli)), - hide(image.NewLoadCommand(dockerCli)), - hide(image.NewPullCommand(dockerCli)), - hide(image.NewPushCommand(dockerCli)), - hide(image.NewRemoveCommand(dockerCli)), - hide(image.NewSaveCommand(dockerCli)), - hide(image.NewTagCommand(dockerCli)), - ) - if runtime.GOOS == "linux" { - // engine - cmd.AddCommand(engine.NewEngineCommand(dockerCli)) - } -} - -func hide(cmd *cobra.Command) *cobra.Command { - // If the environment variable with name "DOCKER_HIDE_LEGACY_COMMANDS" is not empty, - // these legacy commands (such as `docker ps`, `docker exec`, etc) - // will not be shown in output console. - if os.Getenv("DOCKER_HIDE_LEGACY_COMMANDS") == "" { - return cmd - } - cmdCopy := *cmd - cmdCopy.Hidden = true - cmdCopy.Aliases = []string{} - return &cmdCopy -}
  85. Download patch cli/cli/command/container/stop.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/stop.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/stop.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,67 +0,0 @@ -package container - -import ( - "context" - "fmt" - "strings" - "time" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/pkg/errors" - "github.com/spf13/cobra" -) - -type stopOptions struct { - time int - timeChanged bool - - containers []string -} - -// NewStopCommand creates a new cobra.Command for `docker stop` -func NewStopCommand(dockerCli command.Cli) *cobra.Command { - var opts stopOptions - - cmd := &cobra.Command{ - Use: "stop [OPTIONS] CONTAINER [CONTAINER...]", - Short: "Stop one or more running containers", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.containers = args - opts.timeChanged = cmd.Flags().Changed("time") - return runStop(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - flags.IntVarP(&opts.time, "time", "t", 10, "Seconds to wait for stop before killing it") - return cmd -} - -func runStop(dockerCli command.Cli, opts *stopOptions) error { - ctx := context.Background() - - var timeout *time.Duration - if opts.timeChanged { - timeoutValue := time.Duration(opts.time) * time.Second - timeout = &timeoutValue - } - - var errs []string - - errChan := parallelOperation(ctx, opts.containers, func(ctx context.Context, id string) error { - return dockerCli.Client().ContainerStop(ctx, id, timeout) - }) - for _, container := range opts.containers { - if err := <-errChan; err != nil { - errs = append(errs, err.Error()) - continue - } - fmt.Fprintln(dockerCli.Out(), container) - } - if len(errs) > 0 { - return errors.New(strings.Join(errs, "\n")) - } - return nil -}
  86. Download patch cli/cli/command/container/attach_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/attach_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/attach_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,129 +0,0 @@ -package container - -import ( - "fmt" - "io/ioutil" - "testing" - - "github.com/docker/cli/cli" - "github.com/docker/cli/internal/test" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/container" - "github.com/pkg/errors" - "gotest.tools/assert" -) - -func TestNewAttachCommandErrors(t *testing.T) { - testCases := []struct { - name string - args []string - expectedError string - containerInspectFunc func(img string) (types.ContainerJSON, error) - }{ - { - name: "client-error", - args: []string{"5cb5bb5e4a3b"}, - expectedError: "something went wrong", - containerInspectFunc: func(containerID string) (types.ContainerJSON, error) { - return types.ContainerJSON{}, errors.Errorf("something went wrong") - }, - }, - { - name: "client-stopped", - args: []string{"5cb5bb5e4a3b"}, - expectedError: "You cannot attach to a stopped container", - containerInspectFunc: func(containerID string) (types.ContainerJSON, error) { - c := types.ContainerJSON{} - c.ContainerJSONBase = &types.ContainerJSONBase{} - c.ContainerJSONBase.State = &types.ContainerState{Running: false} - return c, nil - }, - }, - { - name: "client-paused", - args: []string{"5cb5bb5e4a3b"}, - expectedError: "You cannot attach to a paused container", - containerInspectFunc: func(containerID string) (types.ContainerJSON, error) { - c := types.ContainerJSON{} - c.ContainerJSONBase = &types.ContainerJSONBase{} - c.ContainerJSONBase.State = &types.ContainerState{ - Running: true, - Paused: true, - } - return c, nil - }, - }, - { - name: "client-restarting", - args: []string{"5cb5bb5e4a3b"}, - expectedError: "You cannot attach to a restarting container", - containerInspectFunc: func(containerID string) (types.ContainerJSON, error) { - c := types.ContainerJSON{} - c.ContainerJSONBase = &types.ContainerJSONBase{} - c.ContainerJSONBase.State = &types.ContainerState{ - Running: true, - Paused: false, - Restarting: true, - } - return c, nil - }, - }, - } - for _, tc := range testCases { - cmd := NewAttachCommand(test.NewFakeCli(&fakeClient{inspectFunc: tc.containerInspectFunc})) - cmd.SetOutput(ioutil.Discard) - cmd.SetArgs(tc.args) - assert.ErrorContains(t, cmd.Execute(), tc.expectedError) - } -} - -func TestGetExitStatus(t *testing.T) { - var ( - expectedErr = fmt.Errorf("unexpected error") - errC = make(chan error, 1) - resultC = make(chan container.ContainerWaitOKBody, 1) - ) - - testcases := []struct { - result *container.ContainerWaitOKBody - err error - expectedError error - }{ - { - result: &container.ContainerWaitOKBody{ - StatusCode: 0, - }, - }, - { - err: expectedErr, - expectedError: expectedErr, - }, - { - result: &container.ContainerWaitOKBody{ - Error: &container.ContainerWaitOKBodyError{Message: expectedErr.Error()}, - }, - expectedError: expectedErr, - }, - { - result: &container.ContainerWaitOKBody{ - StatusCode: 15, - }, - expectedError: cli.StatusError{StatusCode: 15}, - }, - } - - for _, testcase := range testcases { - if testcase.err != nil { - errC <- testcase.err - } - if testcase.result != nil { - resultC <- *testcase.result - } - err := getExitStatus(errC, resultC) - if testcase.expectedError == nil { - assert.NilError(t, err) - } else { - assert.Error(t, err, testcase.expectedError.Error()) - } - } -}
  87. Download patch cli/cli/command/container/kill.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/kill.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/kill.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,56 +0,0 @@ -package container - -import ( - "context" - "fmt" - "strings" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/pkg/errors" - "github.com/spf13/cobra" -) - -type killOptions struct { - signal string - - containers []string -} - -// NewKillCommand creates a new cobra.Command for `docker kill` -func NewKillCommand(dockerCli command.Cli) *cobra.Command { - var opts killOptions - - cmd := &cobra.Command{ - Use: "kill [OPTIONS] CONTAINER [CONTAINER...]", - Short: "Kill one or more running containers", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.containers = args - return runKill(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - flags.StringVarP(&opts.signal, "signal", "s", "KILL", "Signal to send to the container") - return cmd -} - -func runKill(dockerCli command.Cli, opts *killOptions) error { - var errs []string - ctx := context.Background() - errChan := parallelOperation(ctx, opts.containers, func(ctx context.Context, container string) error { - return dockerCli.Client().ContainerKill(ctx, container, opts.signal) - }) - for _, name := range opts.containers { - if err := <-errChan; err != nil { - errs = append(errs, err.Error()) - } else { - fmt.Fprintln(dockerCli.Out(), name) - } - } - if len(errs) > 0 { - return errors.New(strings.Join(errs, "\n")) - } - return nil -}
  88. Download patch cli/cli/command/container/stats_helpers.go
  89. Download patch cli/cli/command/container/diff.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/diff.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/diff.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,47 +0,0 @@ -package container - -import ( - "context" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/docker/cli/cli/command/formatter" - "github.com/pkg/errors" - "github.com/spf13/cobra" -) - -type diffOptions struct { - container string -} - -// NewDiffCommand creates a new cobra.Command for `docker diff` -func NewDiffCommand(dockerCli command.Cli) *cobra.Command { - var opts diffOptions - - return &cobra.Command{ - Use: "diff CONTAINER", - Short: "Inspect changes to files or directories on a container's filesystem", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.container = args[0] - return runDiff(dockerCli, &opts) - }, - } -} - -func runDiff(dockerCli command.Cli, opts *diffOptions) error { - if opts.container == "" { - return errors.New("Container name cannot be empty") - } - ctx := context.Background() - - changes, err := dockerCli.Client().ContainerDiff(ctx, opts.container) - if err != nil { - return err - } - diffCtx := formatter.Context{ - Output: dockerCli.Out(), - Format: NewDiffFormat("{{.Type}} {{.Path}}"), - } - return DiffFormatWrite(diffCtx, changes) -}
  90. Download patch cli/cli/command/config/testdata/config-list-with-quiet-option.golden

    --- 19.03.7+dfsg1-3/cli/cli/command/config/testdata/config-list-with-quiet-option.golden 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/testdata/config-list-with-quiet-option.golden 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -ID-bar -ID-foo
  91. Download patch cli/cli/command/builder/cmd.go

    --- 19.03.7+dfsg1-3/cli/cli/command/builder/cmd.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/builder/cmd.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,25 +0,0 @@ -package builder - -import ( - "github.com/spf13/cobra" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/docker/cli/cli/command/image" -) - -// NewBuilderCommand returns a cobra command for `builder` subcommands -func NewBuilderCommand(dockerCli command.Cli) *cobra.Command { - cmd := &cobra.Command{ - Use: "builder", - Short: "Manage builds", - Args: cli.NoArgs, - RunE: command.ShowHelp(dockerCli.Err()), - Annotations: map[string]string{"version": "1.31"}, - } - cmd.AddCommand( - NewPruneCommand(dockerCli), - image.NewBuildCommand(dockerCli), - ) - return cmd -}
  92. Download patch cli/cli/command/container/cmd.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/cmd.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/cmd.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,45 +0,0 @@ -package container - -import ( - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/spf13/cobra" -) - -// NewContainerCommand returns a cobra command for `container` subcommands -func NewContainerCommand(dockerCli command.Cli) *cobra.Command { - cmd := &cobra.Command{ - Use: "container", - Short: "Manage containers", - Args: cli.NoArgs, - RunE: command.ShowHelp(dockerCli.Err()), - } - cmd.AddCommand( - NewAttachCommand(dockerCli), - NewCommitCommand(dockerCli), - NewCopyCommand(dockerCli), - NewCreateCommand(dockerCli), - NewDiffCommand(dockerCli), - NewExecCommand(dockerCli), - NewExportCommand(dockerCli), - NewKillCommand(dockerCli), - NewLogsCommand(dockerCli), - NewPauseCommand(dockerCli), - NewPortCommand(dockerCli), - NewRenameCommand(dockerCli), - NewRestartCommand(dockerCli), - NewRmCommand(dockerCli), - NewRunCommand(dockerCli), - NewStartCommand(dockerCli), - NewStatsCommand(dockerCli), - NewStopCommand(dockerCli), - NewTopCommand(dockerCli), - NewUnpauseCommand(dockerCli), - NewUpdateCommand(dockerCli), - NewWaitCommand(dockerCli), - newListCommand(dockerCli), - newInspectCommand(dockerCli), - NewPruneCommand(dockerCli), - ) - return cmd -}
  93. Download patch cli/cli/command/bundlefile/bundlefile_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/bundlefile/bundlefile_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/bundlefile/bundlefile_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,78 +0,0 @@ -package bundlefile - -import ( - "bytes" - "strings" - "testing" - - "gotest.tools/assert" - is "gotest.tools/assert/cmp" -) - -func TestLoadFileV01Success(t *testing.T) { - reader := strings.NewReader(`{ - "Version": "0.1", - "Services": { - "redis": { - "Image": "redis@sha256:4b24131101fa0117bcaa18ac37055fffd9176aa1a240392bb8ea85e0be50f2ce", - "Networks": ["default"] - }, - "web": { - "Image": "dockercloud/hello-world@sha256:fe79a2cfbd17eefc344fb8419420808df95a1e22d93b7f621a7399fd1e9dca1d", - "Networks": ["default"], - "User": "web" - } - } - }`) - - bundle, err := LoadFile(reader) - assert.NilError(t, err) - assert.Check(t, is.Equal("0.1", bundle.Version)) - assert.Check(t, is.Len(bundle.Services, 2)) -} - -func TestLoadFileSyntaxError(t *testing.T) { - reader := strings.NewReader(`{ - "Version": "0.1", - "Services": unquoted string - }`) - - _, err := LoadFile(reader) - assert.Error(t, err, "JSON syntax error at byte 37: invalid character 'u' looking for beginning of value") -} - -func TestLoadFileTypeError(t *testing.T) { - reader := strings.NewReader(`{ - "Version": "0.1", - "Services": { - "web": { - "Image": "redis", - "Networks": "none" - } - } - }`) - - _, err := LoadFile(reader) - assert.Error(t, err, "Unexpected type at byte 94. Expected []string but received string.") -} - -func TestPrint(t *testing.T) { - var buffer bytes.Buffer - bundle := &Bundlefile{ - Version: "0.1", - Services: map[string]Service{ - "web": { - Image: "image", - Command: []string{"echo", "something"}, - }, - }, - } - assert.Check(t, Print(&buffer, bundle)) - output := buffer.String() - assert.Check(t, is.Contains(output, "\"Image\": \"image\"")) - assert.Check(t, is.Contains(output, - `"Command": [ - "echo", - "something" - ]`)) -}
  94. Download patch cli/AUTHORS
  95. Download patch cli/cli/command/container/commit.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/commit.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/commit.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,75 +0,0 @@ -package container - -import ( - "context" - "fmt" - - "github.com/docker/cli/cli" - "github.com/docker/cli/cli/command" - "github.com/docker/cli/opts" - "github.com/docker/docker/api/types" - "github.com/spf13/cobra" -) - -type commitOptions struct { - container string - reference string - - pause bool - comment string - author string - changes opts.ListOpts -} - -// NewCommitCommand creates a new cobra.Command for `docker commit` -func NewCommitCommand(dockerCli command.Cli) *cobra.Command { - var options commitOptions - - cmd := &cobra.Command{ - Use: "commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]", - Short: "Create a new image from a container's changes", - Args: cli.RequiresRangeArgs(1, 2), - RunE: func(cmd *cobra.Command, args []string) error { - options.container = args[0] - if len(args) > 1 { - options.reference = args[1] - } - return runCommit(dockerCli, &options) - }, - } - - flags := cmd.Flags() - flags.SetInterspersed(false) - - flags.BoolVarP(&options.pause, "pause", "p", true, "Pause container during commit") - flags.StringVarP(&options.comment, "message", "m", "", "Commit message") - flags.StringVarP(&options.author, "author", "a", "", "Author (e.g., \"John Hannibal Smith <hannibal@a-team.com>\")") - - options.changes = opts.NewListOpts(nil) - flags.VarP(&options.changes, "change", "c", "Apply Dockerfile instruction to the created image") - - return cmd -} - -func runCommit(dockerCli command.Cli, options *commitOptions) error { - ctx := context.Background() - - name := options.container - reference := options.reference - - commitOptions := types.ContainerCommitOptions{ - Reference: reference, - Comment: options.comment, - Author: options.author, - Changes: options.changes.GetAll(), - Pause: options.pause, - } - - response, err := dockerCli.Client().ContainerCommit(ctx, name, commitOptions) - if err != nil { - return err - } - - fmt.Fprintln(dockerCli.Out(), response.ID) - return nil -}
  96. Download patch cli/cli/command/container/stats.go
  97. Download patch cli/cli/command/container/logs_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/container/logs_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/logs_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,62 +0,0 @@ -package container - -import ( - "io" - "io/ioutil" - "strings" - "testing" - - "github.com/docker/cli/internal/test" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/container" - "gotest.tools/assert" - is "gotest.tools/assert/cmp" -) - -var logFn = func(expectedOut string) func(string, types.ContainerLogsOptions) (io.ReadCloser, error) { - return func(container string, opts types.ContainerLogsOptions) (io.ReadCloser, error) { - return ioutil.NopCloser(strings.NewReader(expectedOut)), nil - } -} - -func TestRunLogs(t *testing.T) { - inspectFn := func(containerID string) (types.ContainerJSON, error) { - return types.ContainerJSON{ - Config: &container.Config{Tty: true}, - ContainerJSONBase: &types.ContainerJSONBase{State: &types.ContainerState{Running: false}}, - }, nil - } - - var testcases = []struct { - doc string - options *logsOptions - client fakeClient - expectedError string - expectedOut string - expectedErr string - }{ - { - doc: "successful logs", - expectedOut: "foo", - options: &logsOptions{}, - client: fakeClient{logFunc: logFn("foo"), inspectFunc: inspectFn}, - }, - } - - for _, testcase := range testcases { - t.Run(testcase.doc, func(t *testing.T) { - cli := test.NewFakeCli(&testcase.client) - - err := runLogs(cli, testcase.options) - if testcase.expectedError != "" { - assert.ErrorContains(t, err, testcase.expectedError) - } else { - if !assert.Check(t, err) { - return - } - } - assert.Check(t, is.Equal(testcase.expectedOut, cli.OutBuffer().String())) - assert.Check(t, is.Equal(testcase.expectedErr, cli.ErrBuffer().String())) - }) - } -}
  98. Download patch cli/cli/command/config/remove_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/config/remove_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/remove_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,79 +0,0 @@ -package config - -import ( - "io/ioutil" - "strings" - "testing" - - "github.com/docker/cli/internal/test" - "github.com/pkg/errors" - "gotest.tools/assert" - is "gotest.tools/assert/cmp" -) - -func TestConfigRemoveErrors(t *testing.T) { - testCases := []struct { - args []string - configRemoveFunc func(string) error - expectedError string - }{ - { - args: []string{}, - expectedError: "requires at least 1 argument.", - }, - { - args: []string{"foo"}, - configRemoveFunc: func(name string) error { - return errors.Errorf("error removing config") - }, - expectedError: "error removing config", - }, - } - for _, tc := range testCases { - cmd := newConfigRemoveCommand( - test.NewFakeCli(&fakeClient{ - configRemoveFunc: tc.configRemoveFunc, - }), - ) - cmd.SetArgs(tc.args) - cmd.SetOutput(ioutil.Discard) - assert.ErrorContains(t, cmd.Execute(), tc.expectedError) - } -} - -func TestConfigRemoveWithName(t *testing.T) { - names := []string{"foo", "bar"} - var removedConfigs []string - cli := test.NewFakeCli(&fakeClient{ - configRemoveFunc: func(name string) error { - removedConfigs = append(removedConfigs, name) - return nil - }, - }) - cmd := newConfigRemoveCommand(cli) - cmd.SetArgs(names) - assert.NilError(t, cmd.Execute()) - assert.Check(t, is.DeepEqual(names, strings.Split(strings.TrimSpace(cli.OutBuffer().String()), "\n"))) - assert.Check(t, is.DeepEqual(names, removedConfigs)) -} - -func TestConfigRemoveContinueAfterError(t *testing.T) { - names := []string{"foo", "bar"} - var removedConfigs []string - - cli := test.NewFakeCli(&fakeClient{ - configRemoveFunc: func(name string) error { - removedConfigs = append(removedConfigs, name) - if name == "foo" { - return errors.Errorf("error removing config: %s", name) - } - return nil - }, - }) - - cmd := newConfigRemoveCommand(cli) - cmd.SetArgs(names) - cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), "error removing config: foo") - assert.Check(t, is.DeepEqual(names, removedConfigs)) -}
  99. Download patch cli/cli/command/config/client_test.go

    --- 19.03.7+dfsg1-3/cli/cli/command/config/client_test.go 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/config/client_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,45 +0,0 @@ -package config - -import ( - "context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/client" -) - -type fakeClient struct { - client.Client - 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(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(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(options) - } - return []swarm.Config{}, nil -} - -func (c *fakeClient) ConfigRemove(ctx context.Context, name string) error { - if c.configRemoveFunc != nil { - return c.configRemoveFunc(name) - } - return nil -}
  100. Download patch cli/cli/command/container/testdata/container-create-oom-kill-true-without-memory-limit.golden

    --- 19.03.7+dfsg1-3/cli/cli/command/container/testdata/container-create-oom-kill-true-without-memory-limit.golden 2020-03-03 22:54:17.000000000 +0000 +++ 19.03.8-0ubuntu3/cli/cli/command/container/testdata/container-create-oom-kill-true-without-memory-limit.golden 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -WARNING: Disabling the OOM killer on containers without setting a '-m/--memory' limit may be dangerous.
  101. ...
  1. docker.io