Compare commits

..

414 Commits

Author SHA1 Message Date
3d479c0af6 Merge pull request #500 from seemethere/bump
[18.04] Bump version to 18.04.0-ce
2018-04-10 11:09:07 -07:00
51032254ad Merge pull request #496 from andrewhsu/c
[18.04] update changelog for docker-ce 18.04.0 ga
2018-04-10 11:08:41 -07:00
237393c19a Bump version to 18.04.0-ce
Signed-off-by: Eli Uriegas <eli.uriegas@docker.com>
2018-04-10 16:56:34 +00:00
8ef46a235c update changelog for docker-ce 18.04.0 ga
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
2018-04-09 20:09:26 +00:00
f4926a265f Merge pull request #488 from jose-bigio/18.04_version
[18.04] Bump version to 18.04.0-ce-rc2
2018-04-04 22:34:43 -07:00
7f624d4fbb Merge pull request #489 from jose-bigio/18.04_changelog
[18.04]  Changelog update
2018-04-04 22:34:21 -07:00
788bd7e0de Merge pull request #491 from cpuguy83/18.04_backport_36711
[18.04] Don't sort plugin mounts slice
2018-04-04 22:33:36 -07:00
754a827543 Merge pull request #493 from andrewhsu/t
[18.04] Expose swarm raft tuning parameters in engine config
2018-04-04 19:07:10 -07:00
7af5eea2a6 Merge pull request #492 from andrewhsu/s
[18.04] Bump SwarmKit to 831df679a0b8a21b4dccd5791667d030642de7ff
2018-04-04 19:06:47 -07:00
04f0435f8f Changelog update
Signed-off-by: jose-bigio <jose.bigio@docker.com>
2018-04-04 17:47:17 -07:00
cb49c70a36 bump defaultReconciliationTimeout to 60 sec
To accomodate for increase in leader election from 3 seconds to 10
seconds. This will give more cycles to find another leader.

Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
(cherry picked from commit f040bf8e51cd76082729340342c7123cdc53d5b8)
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
2018-04-04 23:39:46 +00:00
2a17bd8923 Merge pull request #486 from thaJeztah/18.04-backport-update-containerd-1.0.3
[18.04] containerd: update to 1.0.3 release
2018-04-04 16:38:01 -07:00
c2ba010bf0 Expose swarm raft tuning parameters in engine config
Signed-off-by: David Chung <david.chung@docker.com>
(cherry picked from commit 275a1ca7c8ec1d556c37bb50ac574beffbb16e5a)
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
2018-04-04 20:40:15 +00:00
f08871ac09 Bump SwarmKit to 831df679a0b8a21b4dccd5791667d030642de7ff
Changes included:

- Ingress network should not be attachable
- [manager/state] Add fernet as an option for raft encryption
- Log GRPC server errors
- Log leadership changes at manager level
- [state/raft] Increase raft ElectionTick to 10xHeartbeatTick
- Remove the containerd executor
- agent: backoff session when no remotes are available
- [ca/manager] Remove root CA key encryption support entirely
- Fix agent logging race (fixes https://github.com/docker/swarmkit/issues/2576)
- Adding logic to restore networks in order

Also adds github.com/fernet/fernet-go as a new dependency

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 27749659d5a30999691e401a351221780a483099)
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
2018-04-04 20:29:10 +00:00
42dab3545d Don't sort plugin mounts slice
This was added as part of a53930a04fa81b082aa78e66b342ff19cc63cc5f with
the intent to sort the mounts in the plugin config, but this was sorting
*all* the mounts from the default OCI spec which is problematic.

In reality we don't need to sort this because we are only adding a
self-binded mount to flag it as rshared.

We may want to look at sorting the plugin mounts before they are added
to the OCI spec in the future, but for now I think the existing behavior
is fine since the plugin author has control of the order (except for the
propagated mount).

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit ec90839ca302ca53a7d55e4c7f79e7b4779f5e15)
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2018-04-04 08:28:17 -04:00
5a12e3cd82 Merge pull request #485 from andrewhsu/p
[18.04] Make sure plugin container is removed on failure
2018-04-03 14:07:38 -07:00
456461a786 Bump version to 18.04.0-ce-rc2
Signed-off-by: jose-bigio <jose.bigio@docker.com>
2018-04-03 13:51:48 -07:00
88185a70e6 containerd: update to 1.0.3 release
Signed-off-by: Stephen J Day <stephen.day@docker.com>
(cherry picked from commit 554d657c1f7a0f4dce51f0d26407fb05a0580fa1)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2018-04-03 13:33:55 -07:00
7762d78538 Make sure plugin container is removed on failure
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit f81172b9031160218e51fb2a7dbeee19962a60a9)
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
2018-04-03 17:02:29 +00:00
0c7f7c6ff4 Merge pull request #483 from andrewhsu/v
[18.04] bump version to docker-ce 18.04.0 rc1
2018-03-28 15:55:13 -07:00
03b5f310ee bump version to docker-ce 18.04.0 rc1
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
2018-03-28 11:00:20 -07:00
efd1651c73 Merge pull request #480 from andrewhsu/v
[18.04] bump version to docker-ce 18.04.0-ce-beta1
2018-03-27 17:22:38 -07:00
87da396125 Merge pull request #481 from jose-bigio/18.04_changelog
[18.04] changelog update
2018-03-27 17:22:24 -07:00
05ecbbaa3f Deleted irrelevant changelog entries
Signed-off-by: jose-bigio <jose.bigio@docker.com>
2018-03-27 17:21:36 -07:00
3c0af78681 Merge pull request #482 from andrewhsu/ven
[18.04] vendor: update moby to ed7b6428
2018-03-27 17:19:26 -07:00
9d2aaa8400 vendor: update moby to ed7b6428
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>(cherry picked from commit a1cbaa827b)
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
2018-03-27 14:19:59 -07:00
290bbf8158 18.04 changelog
Signed-off-by: jose-bigio <jose.bigio@docker.com>
2018-03-27 13:40:41 -07:00
8d0fc8a2b4 bump version to docker-ce 18.04.0-ce-beta1
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
2018-03-27 11:10:44 -07:00
10cad8c455 Bump version to 18.04.0-ce-rc1
Signed-off-by: GordonTheTurtle <engine-team@docker.com>
2018-03-27 17:52:17 +00:00
8a9fee12ae Merge component 'engine' from git@github.com:moby/moby master 2018-03-27 17:07:12 +00:00
f2d857fcec Merge component 'cli' from git@github.com:docker/cli master 2018-03-27 16:41:30 +00:00
610793fe1f Merge pull request #561 from tych0/deprecate-unencrypted-storage
Deprecate unencrypted storage
Upstream-commit: e6e47d95b5
Component: cli
2018-03-27 14:52:03 +02:00
cfbe3fef1b Merge pull request #36704 from thaJeztah/bump-go-digest
Bump go-digest to v1.0.0-rc.1
Upstream-commit: ed7b6428c133e7c59404251a09b7d6b02fa83cc2
Component: engine
2018-03-27 14:31:50 +02:00
e985ce6103 Merge pull request #941 from dnephin/fix-compose-network-name
Fix compose network name
Upstream-commit: 236a84759a
Component: cli
2018-03-26 23:41:44 +02:00
113504a7f3 Merge pull request #35089 from Microsoft/jjh/fromplatformbuilder
LCOW - Change platform parser directive to FROM statement flag
Upstream-commit: 29fc64b590badcb1c3f5beff7563ffd31eb58974
Component: engine
2018-03-26 14:17:49 -07:00
11ecbed64c Merge pull request #36700 from dnephin/remove-myself-as-codeowner
Remove myself from CODEOWNERS
Upstream-commit: e2062f7571babe8ba31f01c3c93bad07b7c0584f
Component: engine
2018-03-26 16:37:22 -04:00
7f54d33379 Bump go-digest to v1.0.0-rc.1
Changes included:

- digest: allow separators in algorithm field
- disallow upper characters (/A-F/) in hex-encoded portion

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: 82c44711cc59c150d09c87506a9bd648599ea0d6
Component: engine
2018-03-26 22:17:35 +02:00
ee50259e4c Merge pull request #931 from dnephin/refactor-build-unit-tests
Refactor build tests to re-use more code and not require root
Upstream-commit: d3efe30878
Component: cli
2018-03-26 14:44:13 -04:00
5d37083ce3 Refactor build tests to re-use more code and not require root
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 0f1bb35342
Component: cli
2018-03-26 14:27:52 -04:00
80e0c0b83d Remove myself from CODEOWNERS
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 92dfe76911c8ce9beea367e7e906ea138b467135
Component: engine
2018-03-26 13:45:05 -04:00
286d3fed3d Merge component 'engine' from git@github.com:moby/moby master 2018-03-26 17:06:55 +00:00
36283420d9 Merge component 'cli' from git@github.com:docker/cli master 2018-03-26 16:41:30 +00:00
72976c8bb6 print a big warning about cleartext passwords
Signed-off-by: Tycho Andersen <tycho@docker.com>
Upstream-commit: 4290df3958
Component: cli
2018-03-26 16:18:32 +02:00
6b1c8c09b1 Merge pull request #962 from davidjb/run-docs
Clarify behaviour of restart policy in run ref doc
Upstream-commit: db11cffe37
Component: cli
2018-03-26 13:14:44 +01:00
e222bd5a48 Merge pull request #943 from silvin-lubecki/fix-kubernetes-published-service
Fix docker stack services command Port output
Upstream-commit: 27f66e39f4
Component: cli
2018-03-26 12:50:07 +01:00
95b93fdfcd Merge pull request #36692 from katakonst/unique_names_container_rename_Test
Use unique names for container/rename_test.go
Upstream-commit: 7cfd3f4229c82ba61fa13a8818b8ecf58a2dcdbf
Component: engine
2018-03-26 11:29:01 +01:00
8590eff8c7 Merge pull request #36694 from thaJeztah/update-ripcurld-handle
Update curators list
Upstream-commit: e5eb527ebd773ed3e40fcb0d2b74a37ab807d777
Component: engine
2018-03-26 11:13:58 +01:00
2f8d388ea0 Merge pull request #36646 from anusha-ragunathan/err_return
Add missing error return for plugin creation.
Upstream-commit: 6b3f66c4188b573534a6887668b9fb213cc489e9
Component: engine
2018-03-26 18:34:47 +09:00
744fc0b049 Update curators list
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: c85ee9828cb718f2ef83ee3876cef46b9eb3b82c
Component: engine
2018-03-26 10:39:52 +02:00
d1631a824d Use unique names for container/rename_test.go
Signed-off-by: Catalin Pirvu <pirvu.catalin94@gmail.com>
Upstream-commit: 90b514922bb6405bc06428702b1a55bb248bdac3
Component: engine
2018-03-25 21:16:32 +03:00
40d437f5bc Clarify behaviour of restart policy in run ref doc
This clarifies that the behaviour of `unless-stopped` will restart the container on daemon start.  This was implied before, but now the restart-on-daemon-start behaviour is mentioned directly.

Signed-off-by: David Beitey <david@davidjb.com>
Upstream-commit: 8ca237054f
Component: cli
2018-03-26 00:21:40 +10:00
6c4f2b4ad2 Merge component 'engine' from git@github.com:moby/moby master 2018-03-24 17:06:16 +00:00
e3d080dac1 Add missing error return for plugin creation.
Signed-off-by: Anusha Ragunathan <anusha.ragunathan@docker.com>
Upstream-commit: 89a882e2f1706e567a8514209701892b40da7a62
Component: engine
2018-03-23 12:07:43 -07:00
6b1f053c14 Merge pull request #36672 from anshulpundir/election
Increase raft ElectionTick to 10xHeartbeatTick
Upstream-commit: 5f17312653c3e4dc5474f86692b09f06262a1ebd
Component: engine
2018-03-23 19:57:24 +01:00
65c691f4bb Merge component 'engine' from git@github.com:moby/moby master 2018-03-23 17:06:08 +00:00
32d715f231 Merge component 'cli' from git@github.com:docker/cli master 2018-03-23 16:41:26 +00:00
160d042de0 Merge pull request #35149 from AkihiroSuda/image-v1
image/spec: add historical information about v1 spec
Upstream-commit: 2e3056128cc839b5fdee8edeb651f4ecc244db78
Component: engine
2018-03-23 16:47:16 +01:00
e1bf73660b Merge pull request #953 from silvin-lubecki/fix-docker-version-kubernetes
Fix Kubernetes duplication in version command
Upstream-commit: c3991d0673
Component: cli
2018-03-23 15:59:37 +01:00
86110646cc Fix Kubernetes duplication in version command when the server already exposes one Kubernetes component
Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
Upstream-commit: 54bb5ffeca
Component: cli
2018-03-23 15:52:25 +01:00
38f9066976 Merge pull request #36676 from arm64b/enable-criu-on-non-arm64-v2
Enable CRIU on non-amd64 architectures (v2)
Upstream-commit: 52d3dceac548e70ad9cebc4c755adc2c0774dc11
Component: engine
2018-03-23 13:05:45 +01:00
dd8e748718 Merge pull request #36509 from xujihui1985/master
fix(distribution): digest cache should not be moved if it was an auth
Upstream-commit: c3b3be529693316412111e81860ba293a3668f0f
Component: engine
2018-03-23 11:17:43 +01:00
2bc1fa895f Remove the uname -m in Dockerfile
Using `dpkg --print-architecture` instead of the `uname -m` to abstract
the architecture value from the container images, which the build process
is running inside, to match exactly the behavior specified by the following
Docker file while not 'passthru' to the host.

Signed-off-by: Dennis Chen <dennis.chen@arm.com>
Upstream-commit: 803a756941f5e4b68429a3642d52585c8ea6dbaa
Component: engine
2018-03-23 08:56:35 +00:00
985dd23e4a Enable CRIU on non-amd64 architectures
Since the recent release of CRIU has already supported other
arches such as AArch64, ppc64le, and s390x, so we can enable
it now.

Signed-off-by: Dennis Chen <dennis.chen@arm.com>
Upstream-commit: 7fd54a7a48f9f1bb2b28144e38c886d1fe813a04
Component: engine
2018-03-23 05:52:35 +00:00
5656978b1e Merge pull request #36662 from adshmh/use-unique-resource-names-for-container-inspect-ps-stop-integration-tests
Use unique names for test resources of container/inspect, container/ps, container/stop tests
Upstream-commit: 57c504799d979caa706142e6f5dc4be4a5b1e3e2
Component: engine
2018-03-23 12:16:53 +09:00
de2245153e Increase raft ElectionTick to 10xHeartbeatTick
Signed-off-by: Anshul Pundir <anshul.pundir@docker.com>
Upstream-commit: 6abee2008b314a65553202b15d9a333d171e3433
Component: engine
2018-03-22 15:04:10 -07:00
780a0b27cc Merge pull request #36670 from stevvooe/use-context-error
daemon: use context error rather than inventing new one
Upstream-commit: 766d9edf39b79e11018bb0f55056b5bd915ddf3c
Component: engine
2018-03-22 20:45:20 +01:00
9b231b4ae9 Merge pull request #959 from vdemeester/help-use-available-flags
Use HasAvailableFlags instead of HasFlags for Options in help
Upstream-commit: a6d235430a
Component: cli
2018-03-22 19:13:26 +01:00
14f21513ed Merge pull request #957 from thaJeztah/docs-touch-ups
Docs touch-ups for "autoremove" and broken anchor
Upstream-commit: ad4fe148d6
Component: cli
2018-03-22 18:26:45 +01:00
5fd56df388 Merge component 'engine' from git@github.com:moby/moby master 2018-03-22 17:07:05 +00:00
f358bd4b47 daemon: use context error rather than inventing new one
Signed-off-by: Stephen J Day <stephen.day@docker.com>
Upstream-commit: d84da75f01e0a0d20fbddb8b051a325e3b21eded
Component: engine
2018-03-22 09:38:59 -07:00
10376dc96a Merge pull request #36663 from tonistiigi/hijackconn-fix
client: fix hijackedconn reading from buffer
Upstream-commit: 69091990c72f3a3a6143fe6417a769e7a1a1ff1a
Component: engine
2018-03-22 17:10:06 +01:00
4758c92085 Use HasAvailableFlags instead of HasFlags for Options in help
> HasAvailableFlags checks if the command contains any flags (local
> plus persistent from the entire structure) which are not hidden or
> deprecated.

This fix the `--help` display when the `Options` is empty (but
showing), like on `docker trust key`

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: 66fdd085a5
Component: cli
2018-03-22 15:24:31 +01:00
1f699969f9 Merge pull request #36587 from justincormack/unpriv-caps
If container will run as non root user, drop permitted, effective caps early
Upstream-commit: b67c1e078c7eeb20199dce301e95fa8999c98109
Component: engine
2018-03-22 14:51:29 +01:00
34dd223936 Merge pull request #36647 from adshmh/use-unique-names-for-container-nat-test-containers
use unique names for test containers of container/nat integration tests 
Upstream-commit: 00c59ed77e186b6f9056bb8e0a2700767b4be383
Component: engine
2018-03-22 14:03:36 +01:00
3db81e37ca Merge pull request #36172 from kolyshkin/systemd-memlimit
Test for systemd cgroupdriver memory setting
Upstream-commit: e2bede01e4a6a6f84e33e2a6debf2cfed5938828
Component: engine
2018-03-22 13:36:43 +01:00
2748b681fe Merge pull request #36653 from thaJeztah/refactor-windows-service-code
Split daemon service code to _windows file
Upstream-commit: 3baa5889592894a9d39938aa8fdf08e879cb8a25
Component: engine
2018-03-22 21:14:17 +09:00
082579ff1b Merge pull request #36551 from selansen/36247
Fix for Flaky test TestServiceWithPredefinedNetwork
Upstream-commit: cd01c147b1c4b483a75f02de9c9c8416bc8d9ac2
Component: engine
2018-03-22 10:01:20 +01:00
4ad54eacb8 client: fix hijackedconn reading from buffer
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Upstream-commit: f094a05e260d8748f0fd2018a8a908b4189e454d
Component: engine
2018-03-21 15:29:44 -07:00
809b43730d use unique names for resources used by integration tests container/inspect_test, container/ps_test, container/stop_test
Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
Upstream-commit: 78e4be91332e2237c0fa14eb3ba0fb5b915c3256
Component: engine
2018-03-21 17:47:49 -04:00
e2458dab76 Docs touch-ups for "autoremove" and broken anchor
`--rm` moved to the daemon, so is now also supported
when combined with `-d`.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: e9ce688d6e
Component: cli
2018-03-21 19:00:11 +01:00
ea449e9b10 Merge component 'packaging' from git@github.com:docker/docker-ce-packaging master 2018-03-21 17:05:32 +00:00
0545caf82a Merge component 'engine' from git@github.com:moby/moby master 2018-03-21 17:05:26 +00:00
f1b44852ef Merge component 'cli' from git@github.com:docker/cli master 2018-03-21 16:41:19 +00:00
f95a3e7bb8 Fix for Flaky test TestServiceWithPredefinedNetwork
TestServiceWithPredefinedNetwork test case was failing
	at times. To fix the issue, added new API to check
	for services after we clean up all services. Tested
	multiple times and this sould fix flaky issue.

Signed-off-by: selansen <elango.siva@docker.com>
Upstream-commit: dabffd806c98ab13dbc25e57bee21c5291b9a50c
Component: engine
2018-03-21 11:49:23 -04:00
48f3c4dac0 Merge pull request #955 from dnephin/remove-filewatcher
Remove filewatcher
Upstream-commit: c1b58a9096
Component: cli
2018-03-21 14:31:26 +01:00
bc6cc53700 Split daemon service code to _windows file
This moves some of the code that was conditionally
executed on Windows to a separate, windows-only file.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: cd3e84c6b38e74d03ab31db804bc9b49dcab8243
Component: engine
2018-03-21 12:57:53 +01:00
5509cd2416 Merge pull request #36594 from vdemeester/e2e-more-run
integration/*: make e2e run without failure
Upstream-commit: 4460472f4ee419794bb416d131c92dc296b5c625
Component: engine
2018-03-21 08:54:39 +01:00
81ade09fe5 Merge pull request #36515 from vdemeester/migrate-trusted-suite
Remove DockerTrustSuite to docker/cli e2e tests
Upstream-commit: 8aa694c91ac727351ebb1deaacad62149e984fd6
Component: engine
2018-03-21 08:50:59 +01:00
3d78b27c6b Remove filewatcher
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: c0588a9c8f
Component: cli
2018-03-20 20:13:27 -04:00
3d5d533860 container/nat integration tests use unique names for test containers
Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
Upstream-commit: b4d1547af6b91baa2ffcb8a391c35d9bc5cdc48f
Component: engine
2018-03-20 17:11:03 -04:00
674cdcc02a Merge pull request #95 from seemethere/no_number
Don't append number when doing a dev build
Upstream-commit: 468d37e0d6d303b785eb9bfc42612397d683c7e5
Component: packaging
2018-03-19 16:06:31 -07:00
b5921cde4f Don't append number when doing a dev build
Found a bug where a number was being appended to the nightly dev builds
package name causing the latest packages not to be considered as the
latest packages by the package manager.

This makes it so that the nubmer is not included on dev builds.

Signed-off-by: Eli Uriegas <eli.uriegas@docker.com>
Upstream-commit: 63be84fc6ed88847a003dfb32e0dc8bc9126411e
Component: packaging
2018-03-19 22:17:15 +00:00
1c15bdeddb Merge pull request #36466 from thaJeztah/fix-exec-apparmor
Fix AppArmor not being applied to Exec processes
Upstream-commit: 0c1006f1abc1af7aa6b9847754370d054dfa6c68
Component: engine
2018-03-19 15:12:41 -07:00
3d783d5dbf If container will run as non root user, drop permitted, effective caps early
As soon as the initial executable in the container is executed as a non root user,
permitted and effective capabilities are dropped. Drop them earlier than this, so
that they are dropped before executing the file. The main effect of this is that
if `CAP_DAC_OVERRIDE` is set (the default) the user will not be able to execute
files they do not have permission to execute, which previously they could.

The old behaviour was somewhat surprising and the new one is definitely correct,
but it is not in any meaningful way exploitable, and I do not think it is
necessary to backport this fix. It is unlikely to have any negative effects as
almost all executables have world execute permission anyway.

Use the bounding set not the effective set as the canonical set of capabilities, as
effective will now vary.

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
Upstream-commit: 15ff09395c001bcb0f284461abbc404a1d8bab4d
Component: engine
2018-03-19 14:45:27 -07:00
d649560b32 Builder: Review feedback
Signed-off-by: John Howard <jhoward@microsoft.com>
Upstream-commit: 14429056d3745ca052fba448d879788d16bbb01b
Component: engine
2018-03-19 14:29:36 -07:00
60e6ee9365 Builder: Fix CI issues
Signed-off-by: John Howard <jhoward@microsoft.com>
Upstream-commit: 317513d6984c0ba5df41dc578b22eb32fec55b55
Component: engine
2018-03-19 14:29:36 -07:00
d7c0222450 Builder: Plumbing through platform in FROM statement
Signed-off-by: John Howard <jhoward@microsoft.com>
Upstream-commit: 69fa84bc3d57dafd19800642c5ba196bc6d45f90
Component: engine
2018-03-19 14:29:36 -07:00
fe74b4e69a Builder - add --platform to FROM statement
Signed-off-by: John Howard <jhoward@microsoft.com>
Upstream-commit: 7f0c2d23e11485c7f026dd8c111c60c2e1e03375
Component: engine
2018-03-19 14:29:36 -07:00
96ca7d0f59 Builder - Parser. Remove platform parser directive
Signed-off-by: John Howard <jhoward@microsoft.com>
Upstream-commit: 9cae03900fc27ff39e913978ca8f084691954881
Component: engine
2018-03-19 14:29:35 -07:00
bf670c6435 Builder - dockerfile - just use API for now, and unit test fix
Signed-off-by: John Howard <jhoward@microsoft.com>
Upstream-commit: 735e5d22b7ca208acc9ad7373bb8f93167ee3f85
Component: engine
2018-03-19 14:29:35 -07:00
66621995e0 Builder - parser - remove OS
Signed-off-by: John Howard <jhoward@microsoft.com>
Upstream-commit: 98dd1fdca1f5b82cbc7066c4a48f9ddd8f135095
Component: engine
2018-03-19 14:29:35 -07:00
fbfb3a897f Merge pull request #93 from seemethere/r
Be less restrictive when moving packages
Upstream-commit: b988c25492369aa89af91fb4c80724153d2a1b0a
Component: packaging
2018-03-19 14:28:37 -07:00
72a2de1d85 Be less restrictive when moving packages
Signed-off-by: Eli Uriegas <eli.uriegas@docker.com>
Upstream-commit: 941d99ff6ae57bc06b06b85b7b07210301f454b2
Component: packaging
2018-03-19 21:26:38 +00:00
24ded82e63 Merge pull request #36633 from adshmh/add-missing-setup-test-call-to-TestNetworkLoopbackNat
Add the missing call to setupTest to TestNetworkLoopbackNat test
Upstream-commit: 60e2dc26864370a315dbbb8e3325fe5cc78ba5d5
Component: engine
2018-03-19 20:45:22 +01:00
c9d18328ef Merge pull request #29932 from miaoyq/container-log-add-archive
add support for compressibility of log file
Upstream-commit: c4e93da8a6fcd206e3fbfb07b821b5743f90f437
Component: engine
2018-03-19 15:20:17 -04:00
6bad7e6180 Test for systemd cgroupdriver memory setting
This is a test case for issue https://github.com/moby/moby/issues/35123,
making sure we can set container's memory limit when using
`native.cgroupdriver=systemd`.

[v2: skip if no systemd present]
[v3: add --iptables=false to avoid flaky tests with t.Parallel()]
[v4: rebase after PR#36507 merge]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Upstream-commit: 4ca5c5361059e29ed31074ca5b96f8b2030b5f99
Component: engine
2018-03-19 10:33:03 -07:00
4836f8c6fc Merge component 'engine' from git@github.com:moby/moby master 2018-03-19 17:08:23 +00:00
b6ec97e6cd Merge component 'cli' from git@github.com:docker/cli master 2018-03-19 16:43:04 +00:00
ef1461a872 Add the missing call to setupTest to TestNetworkLoopbackNat test function, to avoid leaving behind test containers
Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
Upstream-commit: a0052b8f190f38bcdd24e4bf794c3ad6d2fd1b41
Component: engine
2018-03-19 10:56:13 -04:00
27bd98bb9a Merge pull request #36617 from Microsoft/jjh/kernel-registry
Windows: Move kernel_windows to use golang registry functions
Upstream-commit: 7270b01e5dd1fca3fd7fed0d6fb9d2769ec5f4ba
Component: engine
2018-03-19 11:47:17 +01:00
da9476e6ad Merge pull request #924 from vdemeester/trust-suite-tests
Add some content trust tests
Upstream-commit: c0ffb9491c
Component: cli
2018-03-19 11:24:00 +01:00
0aa2494ead Add more content trust tests
Importing from moby's DockerTrustSuite tests.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: 8b00c5cfd8
Component: cli
2018-03-19 10:02:40 +01:00
d36e75fc44 integration/*: make e2e run without failure
… mainly by skipping if daemon is remote.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: 6016e79d2552b21643f4bfd093ce76d8ef956d79
Component: engine
2018-03-19 09:47:17 +01:00
aac739f262 Migrate DockerTrustSuite to docker/cli e2e tests
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: 5433ceb12ead305d8c85e8e27c4b4d842ef88ae0
Component: engine
2018-03-19 09:26:35 +01:00
559e0317a4 Merge pull request #36507 from dnephin/use-gty-assert
Replace testify/assert with gotestyourself/assert
Upstream-commit: 7bda5be956eb1123d597b3c497d938c4d6df3327
Component: engine
2018-03-19 09:08:06 +01:00
84547b2a93 Merge component 'packaging' from git@github.com:docker/docker-ce-packaging master 2018-03-17 17:06:55 +00:00
574c2dfe88 Merge component 'engine' from git@github.com:moby/moby master 2018-03-17 17:06:48 +00:00
dd2d0c4792 fix(distribution): digest cache should not be moved if it was an auth
error

local digest cache will be removed when error occured on push image
but it should not be removed if it is an auth error while on auth was
provided

https://github.com/moby/moby/issues/36309
Signed-off-by: 慕陶 <jihui.xjh@alibaba-inc.com>
Upstream-commit: 8b387b165ab2eaab3f9fdac25caa186d05d236a0
Component: engine
2018-03-17 17:29:01 +08:00
e4c18f1d24 Merge pull request #91 from seemethere/new_ver_scheme
Enable new test versioning scheme
Upstream-commit: 27d07d7e2dbf81001e402657c0e45c375e73a369
Component: packaging
2018-03-16 11:42:56 -07:00
903f63444d Merge pull request #92 from seemethere/refactor_epoch
Refactor epoch to be a passable variable for debian packaging
Upstream-commit: c9e56d1cf88bac85b289f364b7fc2e38d9340b96
Component: packaging
2018-03-16 11:42:46 -07:00
5c48fab022 Merge pull request #36609 from thaJeztah/fix-stats-loop
Fix stats collector spinning CPU if no stats are collected
Upstream-commit: 72ba7f593fa4dbb628cf5ee83cd7daf955934cf5
Component: engine
2018-03-16 10:35:10 -07:00
d69cb642d7 Merge component 'engine' from git@github.com:moby/moby master 2018-03-16 17:07:01 +00:00
ad67257ea2 Windows: Move kernel_windows to use golang registry functions
Signed-off-by: John Howard <jhoward@microsoft.com>
Upstream-commit: 29f93c4bc7bb2fbbaaa8c3f809e858ce1f12a0f2
Component: engine
2018-03-16 09:47:45 -07:00
18927a1fa0 Merge component 'cli' from git@github.com:docker/cli master 2018-03-16 16:42:15 +00:00
047c647903 Update testing doc
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 58de6277821698a2f97d1a0c83664ab34ff2e8d8
Component: engine
2018-03-16 11:03:47 -04:00
0fdeea8152 Cleanup pkg/jsonmessage progress tests
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 7d8815ea705e85a73248b5d9e468f9dc65277bb8
Component: engine
2018-03-16 11:03:47 -04:00
0331f04e35 Post migration assertion fixes
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: c9e52bd0da0461e605a3678b85702f83081504a7
Component: engine
2018-03-16 11:03:46 -04:00
60daf5fa97 Automated migration using
gty-migrate-from-testify --ignore-build-tags

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 6be0f709830113966f295401327b027ec2f0bbca
Component: engine
2018-03-16 11:03:43 -04:00
1c9c9f9e72 Cleanup some assertions
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: ef01dea8935932486f03a37069720987e805dce6
Component: engine
2018-03-16 10:54:54 -04:00
59efca5b6e Update vendor
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 073963e3b770efbdf8bd4b4f92d46b2c62eaf434
Component: engine
2018-03-16 10:54:54 -04:00
8366463034 Merge pull request #36606 from kolyshkin/t-36561
integration/TestExportContainerAfterDaemonRestart: add
Upstream-commit: 823de22db611d5079fcc92788a89897daba6f389
Component: engine
2018-03-16 12:07:46 +01:00
7d839876b1 Merge pull request #945 from vdemeester/trust-follow-up
Small content trust enhancement
Upstream-commit: a5bd2973b1
Component: cli
2018-03-16 11:09:00 +01:00
da9945b5a8 Merge pull request #36584 from cpuguy83/volume_store_tests
Add some tests to the volume store
Upstream-commit: bbf568e41c15b609b14a07806cc028972aa7dcd2
Component: engine
2018-03-16 09:12:55 +01:00
19d8f3bc64 Merge pull request #36610 from Microsoft/jjh/unbreakxenon
Windows: Hyper-V containers are broken after 36586 was merged
Upstream-commit: d16c77bc01002368a5e9c532e796072ee80214b5
Component: engine
2018-03-15 21:38:15 -07:00
ca5f3626a1 Allow epoch to be changed by a make variable
Signed-off-by: Eli Uriegas <eli.uriegas@docker.com>
Upstream-commit: bf9bb7e74e692a829c2058dbcca81349d7d42005
Component: packaging
2018-03-15 23:34:28 +00:00
f925996d4a Move same parts to common variables
There was a lot of repeated parts in this Makefile, I moved them to a
common variable so that if / when we decide to change how things are run
then it's easy to do so.

Signed-off-by: Eli Uriegas <eli.uriegas@docker.com>
Upstream-commit: c869c9fcf510d1a6c4e25c1a14ea6cb0bb3e6aa4
Component: packaging
2018-03-15 23:31:46 +00:00
f89e535fb8 Windows: Fix Hyper-V containers regression from 36586
Signed-off-by: John Howard <jhoward@microsoft.com>
Upstream-commit: 0f5fe3f9cf17457761dab28473ece5a7c94f4a0c
Component: engine
2018-03-15 15:36:36 -07:00
7998309733 Enable new test versioning scheme
Enables the usage of a new versioning scheme for test builds:
* tp -> Technical Previews
* beta -> Beta Releases
* rc -> Release Candidates
* ga -> General Availability Releases

This PR fixes the versioning order for both `deb` and `rpm` packages
when it relates to the new versioning scheme (which may or may not be
used).

Signed-off-by: Eli Uriegas <eli.uriegas@docker.com>
Upstream-commit: 9ba8e36e8588ea75209d813558c8065844c953a0
Component: packaging
2018-03-15 22:16:30 +00:00
8fabfd2555 Merge component 'engine' from git@github.com:moby/moby master 2018-03-15 17:06:50 +00:00
3daa4b4cdd Fix stats collector spinning CPU if no stats are collected
Commit fd0e24b7189374e0fe7c55b6d26ee916d3ee1655 changed
the stats collection loop to use a `sleep()` instead
of `time.Tick()` in the for-loop.

This change caused a regression in situations where
no stats are being collected, or an error is hit
in the loop (in which case the loop would `continue`,
and the `sleep()` is not hit).

This patch puts the sleep at the start of the loop
to guarantee it's always hit.

This will delay the sampling, which is similar to the
behavior before fd0e24b7189374e0fe7c55b6d26ee916d3ee1655.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: 481b8e54b45955e40075f49a9af321afce439320
Component: engine
2018-03-15 17:56:15 +01:00
145731fe4b Merge component 'cli' from git@github.com:docker/cli master 2018-03-15 16:41:54 +00:00
ce28c959c9 Merge pull request #946 from thaJeztah/bump-moby
Bump moby to ae7016427f8cba4e4d8fcb979d6ba313ee2c0702
Upstream-commit: 37eebe5cb6
Component: cli
2018-03-15 09:49:25 -04:00
5fc2230d23 add compress option for 'jsonfiles' log driver
This PR adds support for compressibility of log file.
I added a new option conpression for the jsonfile log driver,
this option allows the user to specify compression algorithm to
compress the log files. By default, the log files will be
not compressed. At present, only support 'gzip'.

Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>

'docker logs' can read from compressed files

Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>

Add Metadata to the gzip header, optmize 'readlog'

Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>
Upstream-commit: f69f09f44ce9fedbc9d70f11980c1fc8d7f77cec
Component: engine
2018-03-15 20:20:05 +08:00
6a0b3c07e8 integration/TestExportContainerAfterDaemonRestart: add
This test case checks that a container created before start
of the currently running dockerd can be exported (as reported
in #36561). To satisfy this condition, either a pre-existing
container is required, or a daemon restart after container
creation.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Upstream-commit: 6e7141c7a2c0de6fa3d6c9dcc56978a81f9d835e
Component: engine
2018-03-15 00:30:11 -07:00
8cec80b17b Merge pull request #36603 from thaJeztah/fix-stale-hns-endpoints
Update libnetwork to fix stale HNS endpoints on Windows
Upstream-commit: 3d14173a2900b60200d9b1475abd5138f4315981
Component: engine
2018-03-14 21:05:27 -07:00
30deffedde Bump moby to ae7016427f8cba4e4d8fcb979d6ba313ee2c0702
Bring in:

- moby 36517 ensure hijackedConn implements CloseWrite function
- moby 36489 (fixes `errdefs.ErrSystem` interface)
- moby 36506 pkg/mount: use sort.Slice
- moby 36451 Windows: Report Version and UBR

Also update moby dependencies to keep them in sync

- golang.org/x/sync (no code changes)
- Bump runc to 4fc53a81fb7c994640722ac585fa9ca548971871
- Bump swarmkit to 49a9d7f6ba3c1925262641e694c18eb43575f74b

no local code changes

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: b17215c456
Component: cli
2018-03-15 01:51:31 +01:00
1629147864 Merge pull request #36586 from kolyshkin/do-not-panic
ExportContainer: do not panic
Upstream-commit: ae7016427f8cba4e4d8fcb979d6ba313ee2c0702
Component: engine
2018-03-15 00:18:24 +01:00
b3b80b72e7 Merge pull request #36517 from jim-minter/missing_closewrite
ensure hijackedConn implements CloseWrite function
Upstream-commit: 518d028baab8a7d96ce59851d6fbbafcb9521c73
Component: engine
2018-03-15 00:05:54 +01:00
9c4442b73b Update libnetwork to fix stale HNS endpoints on Windows
Update libnetwork to 1b91bc94094ecfdae41daa465cc0c8df37dfb3dd to bring in a fix
for stale HNS endpoints on Windows:

When Windows Server 2016 is restarted with the Docker service running, it is
possible for endpoints to be deleted from the libnetwork store without being
deleted from HNS. This does not occur if the Docker service is stopped cleanly
first, or forcibly terminated (since the endpoints still exist in both). This
change works around the issue by removing any stale HNS endpoints for a network
when creating it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: fb364f07468e94226250a1e77579ee6117c64be2
Component: engine
2018-03-14 23:45:58 +01:00
e1d37225cd Merge pull request #36589 from thaJeztah/fix-duplicate-ip-issues
Update libnetwork with fixes for duplicate IP addresses
Upstream-commit: bc0b0f11f3a75a4a8f058d9ceb3d098cf39a091e
Component: engine
2018-03-14 15:04:41 -07:00
32e93cd766 Add some tests to the volume store
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Upstream-commit: 834d0e262ac248191c09bcdb2b86ee92edb6aaf0
Component: engine
2018-03-14 17:17:44 -04:00
8024288396 Merge component 'engine' from git@github.com:moby/moby master 2018-03-14 17:06:05 +00:00
fb08bdcb4b Small content trust enhancement
- `replaceDockerfileForContentTrust` is only used when content trust is
  enabled, so remove the boolean.
- rename `isContentTrustEnabled` to `contentTrustEnabled`

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: 63ebcae382
Component: cli
2018-03-14 17:55:19 +01:00
440327d92f Merge component 'cli' from git@github.com:docker/cli master 2018-03-14 16:41:41 +00:00
4a96b47716 Update libnetwork with fixes for duplicate IP addresses
This updates libnetwork to 8892d7537c67232591f1f3af60587e3e77e61d41 to bring in
IPAM fixes for duplicate IP addresses.

- IPAM tests (libnetwork PR 2104) (no changes in vendored files)
- Fix for Duplicate IP issues  (libnetwork PR 2105)

Also bump golang/x/sync to match libnetwork (no code-changes, other
than the README being updated)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: 55e0fe24db68b16edccb2fa49c3b1b9d3a9ce58c
Component: engine
2018-03-14 16:31:27 +01:00
f42054fc2d Ensure a hijacked connection implements CloseWrite whenever its underlying
connection does.  If this isn't done, then a container listening on stdin won't
receive an EOF when the client closes the stream at their end.

Signed-off-by: Jim Minter <jminter@redhat.com>
Upstream-commit: 37983921c90b468cafd3ba2ca2574fb81cafe5a7
Component: engine
2018-03-14 09:07:55 -06:00
6d58bd7ffc Merge pull request #36571 from kolyshkin/t-win-fail
integration-cli/TestSlowStdinClosing: increase timeout
Upstream-commit: 592a15b7a9a52529429cb81cee0c14983cb1cd95
Component: engine
2018-03-14 12:06:32 +01:00
4be327090a Fix docker stack services command on Port output when kubernetes service is a LoadBalancer or a NodePort
* added tests on Kubernetes service conversion to swarm service

Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
Upstream-commit: b816bde6cc
Component: cli
2018-03-14 11:33:42 +01:00
9c4b5f4db9 Merge pull request #944 from thaJeztah/update-completion-scripts
Bash: update trust completions
Upstream-commit: 6d7c23a6b4
Component: cli
2018-03-14 08:42:40 +01:00
f655d600ba container.BaseFS: check for nil before deref
Commit 7a7357dae1bccc ("LCOW: Implemented support for docker cp + build")
changed `container.BaseFS` from being a string (that could be empty but
can't lead to nil pointer dereference) to containerfs.ContainerFS,
which could be be `nil` and so nil dereference is at least theoretically
possible, which leads to panic (i.e. engine crashes).

Such a panic can be avoided by carefully analysing the source code in all
the places that dereference a variable, to make the variable can't be nil.
Practically, this analisys are impossible as code is constantly
evolving.

Still, we need to avoid panics and crashes. A good way to do so is to
explicitly check that a variable is non-nil, returning an error
otherwise. Even in case such a check looks absolutely redundant,
further changes to the code might make it useful, and having an
extra check is not a big price to pay to avoid a panic.

This commit adds such checks for all the places where it is not obvious
that container.BaseFS is not nil (which in this case means we do not
call daemon.Mount() a few lines earlier).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Upstream-commit: d6ea46cedaca0098c15843c5254a337d087f5cd6
Component: engine
2018-03-13 21:24:48 -07:00
db4a8d6dcb daemon.ContainerExport(): do not panic
In case ContainerExport() is called for an unmounted container, it leads
to a daemon panic as container.BaseFS, which is dereferenced here, is
nil.

To fix, do not rely on container.BaseFS; use the one returned from
rwlayer.Mount().

Fixes: 7a7357dae1bccc ("LCOW: Implemented support for docker cp + build")
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Upstream-commit: 81f6307eda44ab3a91de6e29304810a976161d74
Component: engine
2018-03-13 21:24:43 -07:00
065614040d Bash: update trust completions
The `docker trust` commands were moved out of experimental,
and the `docker trust view` command was changed to
`docker trust inspect --pretty`.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: 2a6808db87
Component: cli
2018-03-14 01:21:33 +01:00
0607bea593 Merge pull request #935 from n4ss/trust-out-of-experimental2
Move Docker Trust out of experimental
Upstream-commit: 176aa4865c
Component: cli
2018-03-13 16:59:50 -07:00
b97b29bfcb update doc
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
Upstream-commit: 09ec6d4ad9
Component: cli
2018-03-13 16:50:56 -07:00
04f51ce3f0 Merge pull request #36577 from cpuguy83/info_tweaks
Minor optimizations
Upstream-commit: 9e1c4f9906176ee120398d1568e8ff395382d675
Component: engine
2018-03-13 16:48:45 -04:00
951f082fa9 Merge pull request #36538 from ctelfer/ingress-fix
Fix automatic removal of ingress sandbox when last service leaves
Upstream-commit: 514fb6cf859f5d40e4100920b0da1410e51f23bd
Component: engine
2018-03-13 20:56:03 +01:00
2c6fe9c524 Change containerd monitor ticker to sleep
With the ticker this could end up just doing back-to-back checks, which
isn't really what we want here.
Instead use a sleep to ensure we actually sleep for the desired
interval.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Upstream-commit: 04a0d6b863ed50cfffa79936cf9cdab7a3a9e7df
Component: engine
2018-03-13 13:20:19 -04:00
6e4307b92b Merge component 'engine' from git@github.com:moby/moby master 2018-03-13 17:14:47 +00:00
d15385dab8 Add Len() to image store for info endpoint
In info, we only need the number of images, but `CountImages` was
getting the whole map of images and then grabbing the length from that.
This causes a lot of unnecessary CPU usage and memory allocations, which
increases with O(n) on the number of images.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Upstream-commit: f6a7763b6f3256bed9a7352021745189d0ca8dc9
Component: engine
2018-03-13 11:58:05 -04:00
59feac96fd Merge pull request #36569 from kolyshkin/t-etc-hosts
TestLinksEtcHostsContentMatch: use container.Exec()
Upstream-commit: fb95dc7eac3ae177d61f7bd67aea5ddeb94454b8
Component: engine
2018-03-13 15:12:59 +01:00
2dcdb5d404 Merge pull request #36567 from kolyshkin/t-parallel
integration/TestContainerShmNoLeak: use --iptables=false
Upstream-commit: 4a65cd4d6d845e895c7c8061080210d74ae5a19b
Component: engine
2018-03-13 08:36:20 -04:00
496c3cdf9d integration-cli/TestSlowStdinClosing: increase timeout
I noticed this test failed on Windows:

> 17:46:24 docker_cli_run_test.go:4361:
> 17:46:24 c.Fatal("running container timed out") // cleanup in teardown

I also noticed that in general tests are running slower on Windows,
for example TestStartAttachSilent (which runs a container with
`busybox echo test` and then starts it again) took 29.763s.
This means a simple container start can easily take 15s, which
explains the above failure.

Double the timeout from 15s to 30s.

Fixes: 4e262f6387 ("Fix race on sending stdin close event")
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Upstream-commit: 5043639645123f2728c81c9a55fea525475ec324
Component: engine
2018-03-12 20:35:28 -07:00
2052fc8774 TestLinksEtcHostsContentMatch: use container.Exec()
I am not quite sure why but this test is sometimes failing like this:

> 15:21:41 --- FAIL: TestLinksEtcHostsContentMatch (0.53s)
> 15:21:41 	assertions.go:226:
>
> 	Error Trace:	links_linux_test.go:46
> 15:21:41
> 	Error:      	Not equal:
> 15:21:41
> 	            	expected: "127.0.0.1\tlocalhost\n::1\tlocalhost
> ip6-localhost
> ip6-loopback\nfe00::0\tip6-localnet\nff00::0\tip6-mcastprefix\nff02::1\tip6-allnodes\nff02::2\tip6-allrouters\n172.17.0.2\tf53feb6df161\n"
> 15:21:41
> 	            	received: ""

To eliminate some possible failures (like ignoring stderr from `cat` or
its exit code), let's use container.Exec() to read a file from a container.

Fixes: e6bd20edcbf ("Migrate some integration-cli test to api tests")
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Upstream-commit: ad2f88d8ccbd9dd0a8d9c4f96ece3956f60489df
Component: engine
2018-03-12 18:15:16 -07:00
6623004cd4 integration/TestContainerShmNoLeak: use --iptables=false
As mentioned in commit 9e31938, test cases that use t.Parallel()
and start a docker daemon might step on each other toes as they
try to configure iptables during startup, resulting in flaky tests.

To avoid this, --iptables=false should be used while starting daemon.

Fixes: eaa5192856c1 ("Make container resource mounts unbindable")
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Upstream-commit: c125e10a0486623ba3badebf974ea6e582373151
Component: engine
2018-03-12 14:49:15 -07:00
f1846c5ab0 Add e2e test for stack deploy
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: fcffd67028
Component: cli
2018-03-12 16:24:30 -04:00
48cfa9f758 Delete the load balancer endpoint in Ingress nets
Ingress networks will no longer automatically remove their
load-balancing endpoint (and sandbox) automatically when the network is
otherwise upopulated.   This is to prevent automatic removal of the
ingress networks when all the containers leave them.  Therefore
explicit removal of an ingress network also requires explicit removal
of its load-balancing endpoint.

Signed-off-by: Chris Telfer <ctelfer@docker.com>
Upstream-commit: 3da4ebf355d3494d1403b2878a1ae6958b2724e9
Component: engine
2018-03-12 15:19:08 -04:00
06f61ef263 Update vendoring for libnetwork PR #2097
This PR prevents automatic removal of the load balancing sandbox
endpoint when the endpoint is the last one in the network but
the network is marked as ingress.

Signed-off-by: Chris Telfer <ctelfer@docker.com>
Upstream-commit: bebad150c9c3bc6eb63758c10ef24b9298ecf6e2
Component: engine
2018-03-12 15:19:08 -04:00
7b6b17fc7d Add test for ingress removal on service removal
The commit https://github.com/moby/moby/pull/35422 had the result of
accidentally causing the removal of the ingress network when the
last member of a service left the network.  This did not appear
in swarm instances because the swarm manager would still maintain
and return cluster state about the network even though it had
removed its sandbox and endpoint.  This test verifies that after a
service gets added and removed that the ingress sandbox remains
in a functional state.

Signed-off-by: Chris Telfer <ctelfer@docker.com>
Upstream-commit: 805b6a7f749a6c7cbb237e21ee7260d536621808
Component: engine
2018-03-12 15:19:02 -04:00
940ab0afd2 Fix named network in compose file
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: b4c108a385
Component: cli
2018-03-12 15:15:27 -04:00
de500b1b76 update vendor, add cmpopts
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: ca88e5e9df
Component: cli
2018-03-12 15:15:23 -04:00
01364ce230 Merge component 'engine' from git@github.com:moby/moby master 2018-03-12 17:09:46 +00:00
09262890a9 Merge pull request #36523 from yolken-stripe/36521-configurable-logfile-perms
Make LogFile perms configurable
Upstream-commit: 241c904e6f5fff020890a7641558e83a209c0bbd
Component: engine
2018-03-12 15:07:23 +01:00
4afacfb791 Merge pull request #36489 from thaJeztah/fix-errdef-is
Change return for errdefs.getImplementer()
Upstream-commit: c74cd60473479bc4b857a1b97e4116fd5f0bfdb0
Component: engine
2018-03-12 10:04:41 -04:00
3179450003 Merge pull request #36546 from arm64b/multi-arch-support4Dockerfiles
Unify arch-specific Dockerfiles into multi-arch one
Upstream-commit: 1790ce52e96fd66621b5d8eb2e203203874a7921
Component: engine
2018-03-12 12:36:58 +01:00
d24c1e8528 Remove arch-suffix detection of Dockerfile
Since now we have only one Dockerfile, so the arch-specific suffix
of the Dockerfile is not needed anymore.

Signed-off-by: Dennis Chen <dennis.chen@arm.com>
Upstream-commit: 8eb7ed673b687ae17e2c7df5dd40f8081c299bc2
Component: engine
2018-03-12 02:05:37 +00:00
e19b73b949 Arch-specific Dockerfile removal
Removing all the existing arch-specific Dockerfiles since we already
have a new multi-arch supported one as the replacement.

Signed-off-by: Dennis Chen <dennis.chen@arm.com>
Upstream-commit: 162f9aee476bd204c2b0146c0128949182e8bd5e
Component: engine
2018-03-12 02:05:37 +00:00
56843d4319 Multiarch support for Dockerfile
This PR consolidates the existing arch-specific Dockerfiles into only
one file `Dockefile` to ease the code maintenance effort.

Signed-off-by: Dennis Chen <dennis.chen@arm.com>
Upstream-commit: f1701a741d77a92d28138944193e23aabfc74abe
Component: engine
2018-03-12 02:05:01 +00:00
ea206204a6 Merge component 'engine' from git@github.com:moby/moby master 2018-03-11 17:06:14 +00:00
de73b08b59 Merge pull request #36550 from dnephin/fix-diff-tests
Remove unnecessary diff tests
Upstream-commit: a575b0b1384b2ba89b79cbd7e770fbeb616758b3
Component: engine
2018-03-11 11:26:50 +09:00
02493cad47 Merge pull request #36526 from kolyshkin/ipc-ro
daemon/setMounts(): do not make /dev/shm ro
Upstream-commit: cda90892aaa03aab59848a79a701fd09b663c3cc
Component: engine
2018-03-10 10:30:22 -08:00
0b63fed158 Merge component 'engine' from git@github.com:moby/moby master 2018-03-10 17:26:08 +00:00
827dc14c2b Merge component 'cli' from git@github.com:docker/cli master 2018-03-10 17:00:57 +00:00
ef5c3d2c0a Merge pull request #36504 from dmcgowan/layer-store-remove-metastore-interface
layer: remove metadata store interface
Upstream-commit: b9cc5cba6964b565e8b2cf1ff50c3e946a924fc8
Component: engine
2018-03-10 12:22:08 +01:00
e11a0c3a06 Merge pull request #36519 from stevvooe/resilient-cpu-sampling
daemon/stats: more resilient cpu sampling
Upstream-commit: 623b1a5c3c7d6b4d6d5943b64bd9ae6a7813786e
Component: engine
2018-03-09 14:34:45 -08:00
3d40163b5c Move Docker Trust out of experimental
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
Upstream-commit: ac35e851e8
Component: cli
2018-03-09 13:29:14 -08:00
84628fc361 Merge pull request #934 from n4ss/refactor-trust-inspect
Refactor trust view command into a --pretty flag on trust inspect
Upstream-commit: 2731c71c99
Component: cli
2018-03-09 13:25:01 -08:00
56c837b651 Fix comment and misc code issues
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
Upstream-commit: 8c3d0b93d6
Component: cli
2018-03-09 20:46:37 +01:00
bb8f7ed84c Refactor trust view command into a --pretty flag on trust inspect
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
Upstream-commit: c5554f811b
Component: cli
2018-03-09 19:12:11 +01:00
1eac9f0c3c Remove unnecessary diff tests
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 038f3add5191240058c7a4154556553c5493ea44
Component: engine
2018-03-09 12:32:50 -05:00
387b9cc196 Merge component 'engine' from git@github.com:moby/moby master 2018-03-09 17:05:19 +00:00
35ab02988e Merge component 'cli' from git@github.com:docker/cli master 2018-03-09 16:41:36 +00:00
cb331ab272 Merge pull request #929 from vdemeester/trust-no-global-var
Refactor content_trust cli/flags handling
Upstream-commit: 240c03a7f8
Component: cli
2018-03-09 11:04:09 +01:00
0d25ace2cb Merge pull request #36539 from tophj-ibm/skip-oom-tests-ppc64le
[integration] skip ppc64le oom tests temporarily
Upstream-commit: c8f9e14b500b1b2e23e79c52ded0aee05579d9bc
Component: engine
2018-03-09 09:53:00 +01:00
e31b1923c7 Merge pull request #36506 from kolyshkin/pkg-mount-slice
pkg/mount: use sort.Slice
Upstream-commit: a21d5bf669571ffc7ad31b8df3c0a632dc207b78
Component: engine
2018-03-09 09:46:53 +01:00
671826c75d [integration] skip ppc64le oom tests for now
These tests were enabled by changing a config option on the ci
machines, instead of from a patch, so let me disable them
for now on ppc64le and open up another patch to enable them, where I can find
out what the issues are with them.

Signed-off-by: Christopher Jones <tophj@linux.vnet.ibm.com>
Upstream-commit: 620ddc78a1437feaa42f40853ef586d268991620
Component: engine
2018-03-08 17:51:37 -06:00
d6bf3cca5c Merge component 'packaging' from git@github.com:docker/docker-ce-packaging master 2018-03-08 22:22:13 +00:00
11d01cef44 daemon/setMounts(): do not make /dev/shm ro
It has been pointed out that if --read-only flag is given, /dev/shm
also becomes read-only in case of --ipc private.

This happens because in this case the mount comes from OCI spec
(since commit 7120976d74195), and is a regression caused by that
commit.

The meaning of --read-only flag is to only have a "main" container
filesystem read-only, not the auxiliary stuff (that includes /dev/shm,
other mounts and volumes, --tmpfs, /proc, /dev and so on).

So, let's make sure /dev/shm that comes from OCI spec is not made
read-only.

Fixes: 7120976d74195 ("Implement none, private, and shareable ipc modes")

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Upstream-commit: cad74056c09f6276b0f4a996a1511553177cd3d7
Component: engine
2018-03-08 14:04:03 -08:00
d36dd1e792 daemon/oci_linux_test: add TestIpcPrivateVsReadonly
The test case checks that in case of IpcMode: private and
ReadonlyRootfs: true (as in "docker run --ipc private --read-only")
the resulting /dev/shm mount is NOT made read-only.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Upstream-commit: 33dd562e3acff71ee18a2543d14fcbecf9bf0e62
Component: engine
2018-03-08 14:04:03 -08:00
34b45355cc Merge component 'cli' from git@github.com:docker/cli master 2018-03-08 21:57:36 +00:00
a895fe3327 Only read trust setting from options
Rename IsTrusted to ContentTrustEnabled

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: feae0e9756
Component: cli
2018-03-08 16:46:30 -05:00
5e391186a8 Refactor content_trust cli/flags handling
Remove the global variable used. Allows easier unit testing.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: 6e21829af4
Component: cli
2018-03-08 15:00:43 -05:00
925dbcac37 Merge pull request #925 from dnephin/add-build-test-symlink
Add a build unit test for symlinked context
Upstream-commit: 82f325ed81
Component: cli
2018-03-08 18:52:43 +01:00
e5ebdf8a68 Merge pull request #90 from seemethere/fix_dynamic
Use new 'dynamic' args in install.sh
Upstream-commit: 5019e235eb123aba7469b0b91c8b6c1dba3feccf
Component: packaging
2018-03-08 09:34:18 -08:00
342df2dbd8 Merge component 'engine' from git@github.com:moby/moby master 2018-03-08 17:07:06 +00:00
d578d1c1c6 Merge component 'cli' from git@github.com:docker/cli master 2018-03-08 16:41:49 +00:00
d56f856549 Merge pull request #36518 from seemethere/fix_static_builds
Build containerd, runc, and proxy statically
Upstream-commit: 0c01629e17752749b32422e327d47764ce23baac
Component: engine
2018-03-08 13:59:34 +01:00
62cc4eebd1 Merge pull request #905 from vdemeester/appveyor-setup
Add appveyor setup to build and unit test
Upstream-commit: 310127a7d0
Component: cli
2018-03-08 09:50:41 +01:00
7856345e7b Merge pull request #36505 from kolyshkin/pkg-mount-tests
pkg/mount unit tests: skip some test under non-root
Upstream-commit: 4a1d35c546c4a5df3353f5984d86671f702a315a
Component: engine
2018-03-08 17:27:31 +09:00
445c3dadbe Use new 'dynamic' args in install.sh
Scripts were changed around to do static by default, this changes so
that we have "dynamic" inserted where it needs to be inserted

Signed-off-by: Eli Uriegas <eli.uriegas@docker.com>
Upstream-commit: 130f74155e39ddc36b59d7c47867230284739710
Component: packaging
2018-03-08 00:20:10 +00:00
882fe67e01 Make logfile perms configurable
Signed-off-by: Benjamin Yolken <yolken@stripe.com>
Upstream-commit: d0c1287a8d3aa0391b4e8bfbe867ec8f0e639a51
Component: engine
2018-03-07 15:18:51 -08:00
3398cf7be9 buildmod => buildmode
There was a typo with the buildmode flag for containerd

Signed-off-by: Eli Uriegas <eli.uriegas@docker.com>
Upstream-commit: 5e4885b9afb1de30133627ce751af2c0e7b72a4e
Component: engine
2018-03-07 21:36:23 +00:00
b6d64a77d2 Build containerd, runc, and proxy statically
These were originally static binaries in the first place, this changes
them back to that.

Signed-off-by: Eli Uriegas <eli.uriegas@docker.com>
Upstream-commit: 63c7bb24637fdbfd905096ecc75b435ecefd31e9
Component: engine
2018-03-07 21:29:10 +00:00
aa0ca25049 daemon/stats: more resilient cpu sampling
To avoid noise in sampling CPU usage metrics, we now sample the system
usage closer to the actual response from the underlying runtime. Because
the response from the runtime may be delayed, this makes the sampling
more resilient in loaded conditions. In addition to this, we also
replace the tick with a sleep to avoid situations where ticks can backup
under loaded conditions.

The trade off here is slightly more load reading the system CPU usage
for each container. There may be an optimization required for large
amounts of containers but the cost is on the order of 15 ms per 1000
containers. If this becomes a problem, we can time slot the sampling,
but the complexity may not be worth it unless we can test further.

Unfortunately, there aren't really any good tests for this condition.
Triggering this behavior is highly system dependent. As a matter of
course, we should qualify the fix with the users that are affected.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
Upstream-commit: fd0e24b7189374e0fe7c55b6d26ee916d3ee1655
Component: engine
2018-03-07 13:20:21 -08:00
1158d96fc9 Merge pull request #36307 from kolyshkin/dm-misc
devmapper cleanup improvements
Upstream-commit: bc7424b4434443b036604277bfcdee3fa34a268a
Component: engine
2018-03-07 12:57:21 -08:00
5b9b83cf96 Add a build unit test for symlinked context
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 00b803b2d8
Component: cli
2018-03-07 13:04:33 -05:00
3d323d03af Remove unused powershell function
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: 10baa756b2
Component: cli
2018-03-07 18:18:14 +01:00
39e1627a66 Fixes some unit tests to be able to run them on windows
Some of them are skipped for now (because the feature is not supported
or needs more work), some of them are fixed.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: 0cf2e6353a
Component: cli
2018-03-07 18:18:13 +01:00
22b79a8c67 Add appveyor setup to build and unit test
Adds a `make.ps1` powershell script to make it easy to compile and test.

```
.\scripts\make.ps1 -Binary
INFO: make.ps1 starting at 03/01/2018 14:37:28
INFO: Building...

 ________   ____  __.
 \_____  \ |    |/ _|
 /   |   \|      <
 /    |    \    |  \
 \_______  /____|__ \
         \/        \/

INFO: make.ps1 ended at 03/01/2018 14:37:30

.\scripts\make.ps1 -TestUnit
```

The next step is to run e2e tests on windows too.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: facb22573d
Component: cli
2018-03-07 18:14:10 +01:00
7ad6c1ceaa Merge component 'engine' from git@github.com:moby/moby master 2018-03-07 17:05:36 +00:00
bd1a3c6e68 Merge pull request #921 from dnephin/use-canonical-imports
testing: Use canonical asserts
Upstream-commit: 0e3677ead5
Component: cli
2018-03-07 12:00:34 -05:00
6f963bee65 Merge component 'cli' from git@github.com:docker/cli master 2018-03-07 16:41:39 +00:00
2c2dcf7989 Merge pull request #36451 from Microsoft/jjh/ubr
Windows: Report Version and UBR
Upstream-commit: 8cf8fe9cf80a07d4e68829f619ea2c71fbb5af0c
Component: engine
2018-03-07 06:27:01 -08:00
17282c064a Merge pull request #920 from dnephin/fix-image-build-github
Don't prompt for github creds in unit test
Upstream-commit: 485a01fb53
Component: cli
2018-03-07 14:22:52 +01:00
ac93c97ba9 Merge pull request #914 from justincormack/notaryup
Update Notary vendor to 0.6.0 release
Upstream-commit: f351f00f9e
Component: cli
2018-03-07 10:38:53 +01:00
9e6eb16d6f Merge pull request #36502 from thaJeztah/remove-duplicate-test
Remove duplicate TestServiceUpdatePort
Upstream-commit: f3a3778808dae0da82f2acf300875b5da931c000
Component: engine
2018-03-06 15:18:30 -08:00
ef941c7ad3 Convert assert.Check(t, is.Error()) to assert.Error
git grep -l -P '^\s+assert\.Check\(t, is\.Error\(' | \
    xargs perl -pi -e 's/^(\s+assert\.)Check\(t, is\.Error\((.*)\)$/\1Error(t, \2/'

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: e15b208e96
Component: cli
2018-03-06 16:00:28 -05:00
0d96772294 manual clean of asserts
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: f21276575f
Component: cli
2018-03-06 15:49:00 -05:00
c617524866 pkg/mount: use sort.Slice
Sorting by mount point length can be implemented in a more
straightforward fashion since Go 1.8 introduced sort.Slice()
with an ability to provide a less() function in place.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Upstream-commit: a00310b54c0cdcafb402aeea92feca865da9fdf3
Component: engine
2018-03-06 12:46:58 -08:00
b52b42c8db Convert assert.Check with
git grep -l -P '^\s+assert\.Check\(t, ' | \
    xargs perl -pi -e 's/^(\s+assert)\.Check(\(t, (?!is).*(\.Execute\(|\.Set\(|\.Write\(|\.Close\(|\.Untar\(|\.WriteFile\(|Validate\().*\)$)/\1.NilError\2/'

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 078cbc9c4b
Component: cli
2018-03-06 15:43:53 -05:00
db90a864e8 pkg/mount unit tests: skip some test under non-root
This makes `go test .` to pass if run as non-root user, skipping
those tests that require superuser privileges (for `mount`).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Upstream-commit: 4aae77602a7540b4f977572f3fbdc0891ac57cab
Component: engine
2018-03-06 12:37:27 -08:00
dd7eb35a89 Convert to assert.NilError
Using:

  git grep -l '^\s\+assert\.Check(t, err)$' | \
    xargs sed -i -e 's/^\(\s\+assert\)\.Check(t, err)$/\1.NilError(t, err)/'

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: baf65a5502
Component: cli
2018-03-06 15:27:34 -05:00
dcb7fd9dc1 dont prompt for github creds in unit test
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 0f11a310fd
Component: cli
2018-03-06 15:27:09 -05:00
95d1804c11 Merge pull request #918 from dnephin/remove-testutil
Remove testutil
Upstream-commit: 0c75f522b6
Component: cli
2018-03-06 21:19:26 +01:00
18ad0fab61 Merge pull request #36494 from stevvooe/remove-unnecessary-types-file
daemon/stats: remove obnoxious types file
Upstream-commit: 4db41f1a69fc38337baaee9edb763a3672fa047c
Component: engine
2018-03-06 11:52:56 -08:00
6dbf483853 Remove testutil
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 681c921528
Component: cli
2018-03-06 14:38:35 -05:00
1e7a21de7c Merge pull request #917 from dnephin/cleanup-test-configfile
Don't set a default filename for ConfigFile
Upstream-commit: c969e1e0b3
Component: cli
2018-03-06 14:37:28 -05:00
2625498b94 Cleanup config load error handling
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 789acb526c
Component: cli
2018-03-06 13:44:06 -05:00
b6580d6c65 Remove metadata store interface
Layer metadata storage has not been implemented outside of the layer
store and will be deprecated by containerd metadata storage. To prepare
for this and freeze the current metadata storage, remove the exported
interface and make it internal to the layer store.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
Upstream-commit: 0aebcbc32dc6a7b35982a2bfc44335562cbb68ec
Component: engine
2018-03-06 10:42:00 -08:00
a6a881dbc7 Don't set a default filename for ConfigFile
With a default filename tests will leave a file in the working directory
that is never cleaned up.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 7c8b5708eb
Component: cli
2018-03-06 13:32:50 -05:00
7d173fd392 Merge component 'engine' from git@github.com:moby/moby master 2018-03-06 17:08:52 +00:00
3258000bfc Merge component 'cli' from git@github.com:docker/cli master 2018-03-06 16:41:54 +00:00
e38d9c1064 Merge pull request #879 from dnephin/update-assertions
Replace testify assertions with gotestyourself/assert
Upstream-commit: a0b19f0ec2
Component: cli
2018-03-06 17:19:51 +01:00
f51e800a06 Remove duplicate TestServiceUpdatePort
The TestAPIServiceUpdatePort test performs exactly
the same steps.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: 36e1646e4f010ea033643c6df3d9c3dccc166ed2
Component: engine
2018-03-06 16:17:13 +01:00
bccba2fc33 Merge pull request #916 from dnephin/use-client-with-ops
Use new APIClient interface
Upstream-commit: fe067a0877
Component: cli
2018-03-06 15:01:42 +01:00
0aaffbe844 Merge pull request #36417 from NobodyOnSE/patch-2
Whitelist statx syscall
Upstream-commit: f0694e968fe600efdf24ab0d3a1b0e887267aea2
Component: engine
2018-03-06 14:33:56 +01:00
062463b48b Merge pull request #36316 from selansen/36247
Fix to address regression caused by PR 30897
Upstream-commit: 0b0af855ae28698f8e3dc97cdc2a46e714ce6b6a
Component: engine
2018-03-06 13:40:29 +01:00
46b936e807 Merge pull request #36493 from cpuguy83/add_plugin_timeout_test
Adds a unit test for plugin request timeout
Upstream-commit: 390b74cb6376e70f9376b96a8a82557124e67a9b
Component: engine
2018-03-06 12:45:17 +01:00
c527ffbfcc Whitelist statx syscall for libseccomp-2.3.3 onward
Older seccomp versions will ignore this.

Signed-off-by: NobodyOnSE <ich@sektor.selfip.com>
Upstream-commit: b2a907c8cab64830c9e424eb1ec71e0429d326ff
Component: engine
2018-03-06 08:42:12 +01:00
cb84ae24c4 Merge pull request #36444 from yongtang/02142018-events-tests
Migrate events tests to api tests
Upstream-commit: 2f7a76a6a0959109e4438952c88c824078cea074
Component: engine
2018-03-06 08:36:30 +01:00
847ef0d3fb Merge pull request #36490 from yongtang/03052018-expected-actual
Address `expected` vs `actual` in integration tests
Upstream-commit: e02fa4a679c670d0745a1f828274297feb5a193c
Component: engine
2018-03-05 19:40:53 -08:00
ca48b9593b Merge pull request #36437 from kolyshkin/dm-unused
devmapper.Mounted: remove
Upstream-commit: a6b1d2ea297827d763de9e4b1940434e00a37883
Component: engine
2018-03-05 18:14:36 -08:00
0faba84bd7 Merge pull request #36474 from yongtang/03022018-rm-test
Migrate docker rm tests to api tests
Upstream-commit: da559d01d140978123c37f0f359c4aa5b022adb4
Component: engine
2018-03-05 17:15:26 -08:00
146b9fed38 Post migration fixes
Fix tests that failed when using cmp.Compare()
internal/test/testutil/assert
InDelta
Fix DeepEqual with kube metav1.Time
Convert some ErrorContains to assert

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 5155cda716
Component: cli
2018-03-05 19:41:17 -05:00
ad1a2c9e1d Automated migration
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 39c2ca57c1
Component: cli
2018-03-05 19:41:17 -05:00
40f9f0a5c0 Replace testify vendor with updated gotestyourself
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 5ef8835f23
Component: cli
2018-03-05 19:41:14 -05:00
483e590861 Fix to address regression caused by PR 30897
With the inclusion of PR 30897, creating service for host network
    fails in 18.02. Modified IsPreDefinedNetwork check and return
    NetworkNameError instead of errdefs.Forbidden to address this issue

Signed-off-by: selansen <elango.siva@docker.com>
Upstream-commit: 7cf8b20762cc9491f52ff3f3d94c880378183696
Component: engine
2018-03-05 19:10:39 -05:00
804775ddc9 daemon/stats: remove obnoxious types file
While a `types.go` file is handly when there are a lot of record types,
it is completely obnoxious when used for concrete, utility types with a
struct, new function and method set in the same file. This change
removes the `types.go` file in favor of the simpler approach.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
Upstream-commit: 244e59e94f153af82e6c3bd8a6c200a48d3cea60
Component: engine
2018-03-05 15:59:04 -08:00
666369f138 Merge pull request #36327 from Microsoft/jjh/block-pulling-uplevel
Windows: Block pulling uplevel images
Upstream-commit: 3e1505e3e671d35636f7818dc1f41e4a4d429620
Component: engine
2018-03-05 15:12:52 -08:00
04d932c6ce Fix definition of ErrSystem type
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: d48392a35b157612d28c48eb8e4fad1272fa1442
Component: engine
2018-03-05 23:42:23 +01:00
a83b855a07 Change return for errdefs.getImplementer()
The types defined in the errdefs package do not
satisfy the `error` interface, because they do not
implement `Error()`.

Instead of returning the matched interface, return
the original error.

When matching _multiple_ interfaces/types, Golang doesn't complain:

    func getImplementer(err error) error {
        switch e := err.(type) {
        case
            ErrNotFound,
            ErrInvalidParameter:
            return e
        default:
            return err
        }
    }

But matching a single interface/type:

    func getImplementer(err error) error {
        switch e := err.(type) {
        case
            ErrNotFound:
            return e
        default:
            return err
        }
    }

Produces an error:

    cannot use e (type ErrNotFound) as type error in return argument: ErrNotFound does not implement error (missing Error method)

Return the original `err` instead of the matched interface/type instead.

Also added some additional tests

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: 59854e407d1541d644a7d814e8e0096dc477dd82
Component: engine
2018-03-05 23:41:58 +01:00
9ccbb57610 Update some assertions.
and fix some tests

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 93615dd967
Component: cli
2018-03-05 17:15:24 -05:00
d8679c544e Use new APIClient interface
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: cff874122c
Component: cli
2018-03-05 16:34:22 -05:00
391894bb6c Address expected vs actual in integration tests
This fix addresses `expected` vs `actual` in integration tests
so that they match `assert.Equal(t, expected, actual)`

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Upstream-commit: 8a854e933b3dbb26cfce28b920cff61909412c6f
Component: engine
2018-03-05 20:39:42 +00:00
61babf754e Adds a unit test for plugin request timeout
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Upstream-commit: 7ca971fb495e4de4aa4455964625974464d86920
Component: engine
2018-03-05 15:38:56 -05:00
02ba73152d Migrate docker rm tests to api tests
This fix migrates docker rm test in integration-cli
to api tests.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Upstream-commit: ed58ba99fb28ceac56063b7f003f38b597ddef80
Component: engine
2018-03-05 20:35:14 +00:00
fd6608a9da Merge pull request #36468 from vdemeester/e2e-container-run
Fixes some integration/container tests to run on remote daemon
Upstream-commit: 4b2fb7e394e8ee631394d6c12f8267065f39766b
Component: engine
2018-03-05 12:23:24 -08:00
8b5e7a334b devmapper.shutdown: optimize
Move the "unmount and deactivate" code into a separate method, and
optimize it a bit:

1. Do not use filepath.Walk() as there's no requirement to recursively
   go into every directory under home/mnt; a list of directories in mnt
   is sufficient. With filepath.Walk(), in case some container will fail
   to unmount, it'll go through the whole container filesystem which is
   excessive and useless.

2. Do not use GetMounts() and check if a directory is mounted; just
   unmount it and ignore "not mounted" error. Note the same error
   is returned in case of wrong flags set, but as flags are hardcoded
   we can safely ignore such case.

While at it, promote "can't unmount" log level from debug to warning.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Upstream-commit: f1a459229724f5e8e440b49f058167c2eeeb2dc6
Component: engine
2018-03-05 10:08:56 -08:00
8f7dd9a1c4 devmapper cleanup: improve error msg
1. Make sure it's clear the error is from unmount.

2. Simplify the code a bit to make it more readable.

[v2: use errors.Wrap]
[v3: use errors.Wrapf]
[v4: lowercase the error message]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Upstream-commit: 9d00aedebc25507042c5afd4ab8fc6b333ca7c53
Component: engine
2018-03-05 10:08:56 -08:00
e5ed7f4225 Merge component 'engine' from git@github.com:moby/moby master 2018-03-05 17:39:27 +00:00
dec1b3c995 Merge pull request #36407 from agawish/36395-mount-print
36395 mount print
Upstream-commit: 8830ef804fec52f3087d9c24a8583ca9954e0967
Component: engine
2018-03-06 02:31:21 +09:00
b917c45482 Merge pull request #36471 from yongtang/03022018-improvement
Improvement in integration tests
Upstream-commit: 3af9b1d395615882dc64df68878139fd5e68712c
Component: engine
2018-03-05 17:54:09 +01:00
12ab7bd4cb Merge component 'engine' from git@github.com:moby/moby master 2018-03-05 16:41:15 +00:00
8a42f40f5e Windows: Report Version and UBR
Signed-off-by: John Howard <jhoward@microsoft.com>
Upstream-commit: 6de9f90417f1295fcdc2f1c977178bff7a735f99
Component: engine
2018-03-05 08:20:45 -08:00
bcdb133cb4 Migrate events tests to api tests
This fix migrates events tests in integration-cli to api tests.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Upstream-commit: 3a749157d2c2b320fea49f7aa4d4eb634f52662f
Component: engine
2018-03-05 16:13:48 +00:00
85d9dcf398 Fixes some integration/container test to run on remote daemon
```
docker build -f Dockerfile.e2e -t moby-e2e .
docker run -v /var/run/docker.sock:/var/run/docker.sock \
           -e TEST_INTEGRATION_DIR=/tests/integration/container \
           -e DOCKER_API_VERSION=1.36 moby-e2e
```

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: 18dd1d9aba3c79d355abaa7f498b88ad816f7d04
Component: engine
2018-03-05 14:24:01 +01:00
bc39105891 Merge pull request #36449 from thaJeztah/bump-runc-1.0-rc5
Bump Runc to 1.0.0-rc5
Upstream-commit: 61cb026e7eba8ecd720b752244e14ce142b0c288
Component: engine
2018-03-05 11:44:21 +01:00
b0676c2968 Merge pull request #36476 from yongtang/03022018-kill_test
Remove unnecessary container.WithName in kill test
Upstream-commit: e3814ece2147b4a6c7f01e6611aa7c886ce26fed
Component: engine
2018-03-05 11:42:30 +01:00
0265691c4b Merge component 'engine' from git@github.com:moby/moby master 2018-03-04 16:41:54 +00:00
e10e8cecdc Merge pull request #36475 from IRCody/logdriver-errors
daemon/logger/ring.go: log error not instance
Upstream-commit: 954e55b3745fe764df54e8fc19039b49bcd2f1a3
Component: engine
2018-03-03 15:51:35 -08:00
0fb17d706d Merge component 'engine' from git@github.com:moby/moby master 2018-03-03 16:40:29 +00:00
530cbde3fb daemon/logger/ring.go: log error not instance
Log the error returned from logdriver.Log() instead of the logdriver
itself.

Signed-off-by: Cody Roseborough <crrosebo@amazon.com>
Upstream-commit: a1956b5623fad186ad39ae8aca998284003b0cd3
Component: engine
2018-03-03 16:29:57 +00:00
c04142001c Merge pull request #36438 from kolyshkin/dm-rm
devmapper/Remove(): use Rmdir, ignore errors
Upstream-commit: 6fe8384939b867409a5021d97afe5d2a606d0f0c
Component: engine
2018-03-03 15:10:08 +01:00
ff4f20efc2 Merge pull request #36459 from yongtang/02282018-export-test
Migrate export tests to api tests
Upstream-commit: e734e8f51597bba3d7c097144d981b85b30dde99
Component: engine
2018-03-03 12:29:53 +09:00
ce4da0689b devmapper/Remove(): use Rmdir, ignore errors
1. Replace EnsureRemoveAll() with Rmdir(), as here we are removing
   the container's mount point, which is already properly unmounted
   and is therefore an empty directory.

2. Ignore the Rmdir() error (but log it unless it's ENOENT). This
   is a mount point, currently unmounted (i.e. an empty directory),
   and an older kernel can return EBUSY if e.g. the mount was
   leaked to other mount namespaces.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Upstream-commit: 732dd9b848bec70a2ecb5b4998918886a0cec497
Component: engine
2018-03-02 18:10:57 -08:00
9781623852 Remove unnecessary container.WithName in kill test
This fix removes several unnecessary `container.WithName`
usage in docker kill integration test.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Upstream-commit: 1778719d6ac166250acfaebe5dd99b5e9d151c3e
Component: engine
2018-03-03 01:06:49 +00:00
49ec29b887 Improvement in integration tests
This fix adds several improvement:
1. No need for explicit ContainerRemove as it has been handled in setupTest()
2. Added `container.WithImage` helper function and used it in commit tests.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Upstream-commit: 6ab465804b0b8cec6c5ac278a21151d49e34885d
Component: engine
2018-03-02 19:03:59 +00:00
2b42807dc0 Merge component 'engine' from git@github.com:moby/moby master 2018-03-02 16:41:20 +00:00
17f0eebf06 Update Notary vendor to 0.6.0 release
We were on a slightly earlier random commit.

We should try to stay on releases where possible...

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
Upstream-commit: 9da428da2e
Component: cli
2018-03-02 14:56:12 +00:00
be632872ec Fix AppArmor not being applied to Exec processes
Exec processes do not automatically inherit AppArmor
profiles from the container.

This patch sets the AppArmor profile for the exec
process.

Before this change:

    apparmor_parser -q -r <<EOF
    #include <tunables/global>
    profile deny-write flags=(attach_disconnected) {
      #include <abstractions/base>
      file,
      network,
      deny /tmp/** w,
      capability,
    }
    EOF

    docker run -dit --security-opt "apparmor=deny-write" --name aa busybox

    docker exec aa sh -c 'mkdir /tmp/test'
    (no error)

With this change applied:

    docker exec aa sh -c 'mkdir /tmp/test'
    mkdir: can't create directory '/tmp/test': Permission denied

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: 8f3308ae10ec9ad0dd4edfb46fde53a0e1e19b34
Component: engine
2018-03-02 14:05:36 +01:00
8d8ee52c02 Merge pull request #36460 from yongtang/03012018-import
Add missing canonical import comment to files in integration tests
Upstream-commit: 135f815fb4b1c362c0b212e9f3dd3b0cea81616b
Component: engine
2018-03-02 09:37:58 +01:00
f51e63d406 Migrate export tests to api tests
This fix migrates export tests in integration-cli to api tests.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Upstream-commit: 4e702cf70d50ee5b0737270f27d9973fd3084c66
Component: engine
2018-03-02 00:44:03 +00:00
59d8a525c8 Add missing canonical import comment to files in integration tests
The  canonical import comment was added some time ago, though several
newly added files do not have the comment. This fix adds the missing
canonical import comment to files in integration tests

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Upstream-commit: 9045406144413920da49629a181bb787c670197e
Component: engine
2018-03-01 22:51:11 +00:00
c17eb54e99 Merge pull request #36455 from thaJeztah/flip-asserts
Fix "expected" and "actual" being reversed
Upstream-commit: 7459e4cd4fc71dec134e0a90bb317142dcd4270d
Component: engine
2018-03-01 21:31:46 +01:00
f7a26ee523 Merge pull request #36445 from yongtang/02282018-secret-inspect
Remove docker_cli_secret_inspect_test.go
Upstream-commit: 9276750543074a36422b391008e00a7e45a9c991
Component: engine
2018-03-01 09:40:45 -08:00
969c8724a0 Merge component 'engine' from git@github.com:moby/moby master 2018-03-01 16:40:13 +00:00
32f6a89499 Merge pull request #36450 from yongtang/02282018-enhancement
Enhancement of replacing ContainerCreate with helper funcs in tests
Upstream-commit: fa018b433a4baa552ffbeb5d53d5674c6467b8e5
Component: engine
2018-03-01 16:47:49 +01:00
82ee559ff8 Fix "expected" and "actual" being reversed
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: a2517cbf62d75c48861337182aa841c5089f8ac4
Component: engine
2018-03-01 14:16:19 +01:00
da1e08d484 Merge component 'engine' from git@github.com:moby/moby master 2018-03-01 01:35:10 +00:00
bc59bfb890 Merge component 'cli' from git@github.com:docker/cli master 2018-03-01 01:11:14 +00:00
9361078009 Merge pull request #448 from seemethere/cherry_pick_cli_version
[master] Bump CLI VERSION to 18.04.0-dev
2018-02-28 17:08:42 -08:00
17a2a3b279 Bump VERSION to 18.04.0-dev
The Docker 18.03 branch was cut from

CLI:    84c7dd6057
Engine: fb005971c2bd82de482d1cfe924f2f4ec60c60ae

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 06dd62ab1e)
Signed-off-by: Eli Uriegas <eli.uriegas@docker.com>
2018-02-28 22:30:57 +00:00
dd065f4320 Merge pull request #36425 from vdemeester/dockerfile-adjusts
Follow-up fixes on multi-stage moby's Dockerfile
Upstream-commit: 78efc2f38362b60d4e66a142c0c3cbadc7e89ae3
Component: engine
2018-02-28 23:07:27 +01:00
fb7feb1626 Enhancement of replacing ContainerCreate with helper funcs in tests
This fix is a minor enhancement to replace several ContainerCreate with
helper funcs of `container.Create` in tests.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Upstream-commit: 6ad4720c78d6ac61a60a3e7ed1d0c0119c5d103e
Component: engine
2018-02-28 21:35:56 +00:00
8ab6373d15 bump containerd/console to 2748ece16665b45a47f884001d5831ec79703880
Fix runc exec on big-endian, causing:

    container_linux.go:265: starting container process caused "open /dev/pts/4294967296: no such file or directory"

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: aab5eaddccb8cb196fdb1e285890dfa94a071b14
Component: engine
2018-02-28 21:43:20 +01:00
6261d99318 Bump Runc to 1.0.0-rc5 / 4fc53a81fb7c994640722ac585fa9ca548971871
Release notes: https://github.com/opencontainers/runc/releases/tag/v1.0.0-rc5

Possibly relevant changes included:

- chroot when no mount namespaces is provided
- fix systemd slice expansion so that it could be consumed by cAdvisor
- libcontainer/capabilities_linux: Drop os.Getpid() call
- Update console dependency to fix runc exec on BE (causing: `container_linux.go:265: starting container process caused "open /dev/pts/4294967296: no such file or directory"`)
- libcontainer: setupUserNamespace is always called (fixes: Devices are mounted with wrong uid/gid)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: a2f5a1a5b2d77d694c5bd47798be15b3c0bcdf70
Component: engine
2018-02-28 21:39:59 +01:00
3521e40e1a Remove docker_cli_secret_inspect_test.go
as the test (TestSecretInspectMultiple) seems to have been covered pretty well in cli:
https://github.com/docker/cli/blob/master/cli/command/secret/inspect_test.go

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Upstream-commit: 3d38adb20c619b87edab72e51ff0fd1cf6e08691
Component: engine
2018-02-28 17:16:47 +00:00
060165553c Merge pull request #911 from vdemeester/update-gotestyourself
Update gotestyourself dependency
Upstream-commit: c26f37c0cc
Component: cli
2018-02-28 18:07:37 +01:00
c2ab7d89c3 Merge pull request #912 from kkirsche/patch-1
Fix grammar typo in comment
Upstream-commit: 60dcc4cdfb
Component: cli
2018-02-28 11:58:01 -05:00
e11e04d02b Fix grammar typo in comment
Overriding is the incorrect part of speech for this sentence. It is more common to state that the values are overridden instead.

Other options would include:

```golang
// ldflags is overriding these values
```

```golang
// These values will be overridden by ldflags
```

etc.

Signed-off-by: Kevin Kirsche <kevin.kirsche@verizon.com>
Upstream-commit: 0e2fdc92ce
Component: cli
2018-02-28 11:29:40 -05:00
919ca49c30 Update gotestyourself dependency
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: 98ba439f67
Component: cli
2018-02-28 16:11:02 +01:00
7c89f9b56b Merge pull request #909 from LydellManganti/LydellManganti-patch-1
Update run.md --restart to include unless-stopped
Upstream-commit: c19b272c09
Component: cli
2018-02-28 14:53:49 +01:00
5ea7143788 Merge pull request #36434 from dnephin/fix-cp-cli-tests
Migrate some container copy tests to integration
Upstream-commit: 75377ec12c44fed7d5dcb131438ae88d9fe7df84
Component: engine
2018-02-28 12:28:18 +01:00
04c0eb713d Merge pull request #36429 from mnussbaum/cleanup_container_unit_test_temp_dir
Clean up a temp dir created in container unit test
Upstream-commit: 7c7dfce37f629d44eb6f86bd960643fc5b2c8252
Component: engine
2018-02-28 12:28:01 +01:00
63f4daf361 Update run.md --restart to include unless-stopped
Update --restart option to include unless-stopped to be consistent with https://docs.docker.com/config/containers/start-containers-automatically/#use-a-restart-policy

Signed-off-by: Lydell Manganti <lydell.manganti@gmail.com>
Upstream-commit: d281b72a98
Component: cli
2018-02-28 21:05:30 +10:00
c453879121 Merge pull request #36430 from yongtang/02262018-config-test
Migrate config inspect test to api test
Upstream-commit: 973cf656ddb75656fd3225854be13a911377eda6
Component: engine
2018-02-28 11:50:52 +01:00
1d9d1d8c5e Merge pull request #907 from dnephin/add-more-container-copy-tests
Add more container cp tests
Upstream-commit: c9303404d4
Component: cli
2018-02-28 11:12:56 +01:00
2c1f22484b Merge pull request #36375 from arm64b/frozen-busybox-latest-glibc
Frozen busybox latest glibc
Upstream-commit: 3e0299f58c580dd356163cce0d9ca2e686ff1d15
Component: engine
2018-02-28 10:55:08 +01:00
64a7496544 Merge pull request #36293 from yongtang/02122018-rm-tests
Migrate several docker rm tests to api tests
Upstream-commit: 8fe1589615318c4761b314a18fdb0de2fb5e0d56
Component: engine
2018-02-28 09:25:49 +01:00
6150221be3 Use golang official image instead debian stretch
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: 572cb664621ca08e912a006c5c9cf2fb568ce757
Component: engine
2018-02-28 09:04:48 +01:00
35e67f98e4 Merge pull request #36427 from vdemeester/micro-clean-docker-cli-build-test
Clean some docker_cli_build_tests that are cli-only
Upstream-commit: f571eb1720de2bca5875b6a107f543249858b688
Component: engine
2018-02-28 08:20:51 +01:00
1a6f7f8e03 devmapper.Mounted: remove
It looks like no one uses this function.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Upstream-commit: 0450f61cb995c8fc2f41a6909526be6ed4093565
Component: engine
2018-02-27 19:13:46 -08:00
3711359ab5 Clean-up after container unit test
Remove temp directories and close file loggers in container unit tests.

Signed-off-by: mnussbaum <michael.nussbaum@getbraintree.com>
Upstream-commit: 07d5446fe27cb92d881df48be6e8a6510d9608b0
Component: engine
2018-02-28 01:15:15 +00:00
f4c3a36fa1 Merge pull request #36267 from Microsoft/jjh/removeservicing
Windows: Remove servicing mode
Upstream-commit: 1346a2c89a11f2d111ff20f46d557f1f9ccbbeb7
Component: engine
2018-02-28 01:15:03 +01:00
6f429fb8a3 Migrate config inspect test to api test
This fix migrates config inspect test in integration-cli
to api test.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Upstream-commit: 4b99d782079dc390c2d8fb78f6973bbeee7d8a47
Component: engine
2018-02-27 23:25:07 +00:00
1f17074f8a Print which path failed when the mount source doesn't exist.
Changes Details:
--------------
Fixes: #36395

Refactoring the code to do the following:
1. Add the method `errBindSourceDoesNotExist` inside `validate.go` to be in-line with the rest of error message
2. Utilised the new method inside `linux_parser.go`, `windows_parser.go` and `validate_test.go`
3. Change the format from `bind mount source path: '%s' does not exist` to `bind mount source path does not exist: %s`
4. Reflected the format change into the 2 unit tests, namely: `volume_test.go` and `validate_test.go`
5. Reflected the format change into `docker_api_containers_test.go` integration test

Signed-off-by: Amr Gawish <amr.gawish@gmail.com>
Upstream-commit: df6af282b9048dfedcd7b7a9a89126aca887f4e1
Component: engine
2018-02-27 23:19:46 +00:00
599e1c79a6 Merge pull request #36240 from dnephin/investigate-image-component
Extract ImageService from Daemon
Upstream-commit: 6cb75dd5b61f438b026572aca0c191c7d2fb7694
Component: engine
2018-02-27 14:35:01 -08:00
3b71e84103 Migrate some copy tests to integration
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 00d409f03ed825f623b6ef8ec5a3a91cd26194c2
Component: engine
2018-02-27 16:48:35 -05:00
697a64b33e Add more container cp tests
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 07cb69e9bc
Component: cli
2018-02-27 16:38:02 -05:00
bedfb491b4 Migrate several docker rm tests to api tests
This fix migrates several docker rm tests to api tests

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Upstream-commit: 6bd4f4801b244555213f0040b9885033e99d4ae8
Component: engine
2018-02-27 19:20:01 +00:00
be84720c48 Merge pull request #139 from shhsu/v3_credhelper
Silent login: use credentials from cred store to login
Upstream-commit: 2cc6ff131d
Component: cli
2018-02-27 19:08:53 +01:00
afdaedaad3 Merge pull request #904 from vdemeester/fix-run-label-flag-behavior
Fix `--label` behavior on run
Upstream-commit: a9c6c52dc0
Component: cli
2018-02-27 19:07:24 +01:00
a0d675b388 Windows: Remove servicing mode
Signed-off-by: John Howard <jhoward@microsoft.com>
Upstream-commit: d4f37c08858b90e8603741ba92de8e0d39b88eb3
Component: engine
2018-02-27 08:48:31 -08:00
bed6817329 Merge pull request #36272 from mnussbaum/36255-fix_log_path
Fix empty LogPath with non-blocking logging mode
Upstream-commit: a1afe38e5225b12d91e66ca4d89ac378c2df0a29
Component: engine
2018-02-27 11:25:39 -05:00
37ba7892be Merge pull request #898 from silvin-lubecki/add-stack-to-version-command
Print Stack API and Kubernetes versions in version command
Upstream-commit: 2851c007fe
Component: cli
2018-02-27 17:14:55 +01:00
c2447aef7c Merge pull request #36391 from vdemeester/update-e2e-script
Update e2e run script
Upstream-commit: 3cb8635001ee4723e08e6e4175e50494c72bf120
Component: engine
2018-02-27 16:23:36 +01:00
1988af7bf7 Clean some docker_cli_build_tests that are cli-only
Remove TestBuildRenamedDockerfile and TestBuildDockerfileOutsideContext
that are cli-only tests (and already tested in the docker/cli
repository).

Also adds some comments on few tests that could be migrate to
docker/cli.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: 894c213b3bd6f4d8f344837b5b5084360a013680
Component: engine
2018-02-27 13:42:29 +01:00
2e25fe581a Merge pull request #36292 from yongtang/0212-2018-volumes-tests
Migrate volumes tests in integration-cli to api tests
Upstream-commit: 407e122ac3dc29a739fa99e0684b45f7e52fa71e
Component: engine
2018-02-27 13:06:06 +01:00
70e2992847 Fix --label behavior on run
Commit 2b17f4c8a8 fixed the way empty labels
are taken into account (i.e. not interpolated from environment variable),
but it created a regression.

`ValidateLabel` functions doesn't allow empty label value, but it has
always been possible to pass an empty label via the cli (`docker run --label foo`).

This fixes that by not validating the label flag.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: 31dc5c0a9a
Component: cli
2018-02-27 12:14:07 +01:00
b1748ad25c Merge pull request #893 from adshmh/add-support-for-mandatory-variables-syntax-to-stack-deploy
add support for mandatory variables to stack deploy
Upstream-commit: 750b038707
Component: cli
2018-02-27 10:25:22 +01:00
5889969510 Merge pull request #36424 from liubin/fix-typo
Fix typos in builder and client
Upstream-commit: 5b124d7422c723ae8e403d24afc9e78dc06bbefe
Component: engine
2018-02-27 10:24:20 +01:00
f7442fe6a7 Merge pull request #36406 from yongtang/02222018-secret-create-with-labels
Migrate some config secret tests to api test
Upstream-commit: 2c24bfd07069f8d3c292ff2ce5ac32e3d762a5b3
Component: engine
2018-02-27 10:01:39 +01:00
1269ee770f Do not copy golang in itself
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: 30498c7c5f2e63a48fa285d117b4388d2a4961e6
Component: engine
2018-02-27 09:16:13 +01:00
37a473147f Network testing with busybox:glibc
Using the `busybox:glibc` instead of `busybox:latest` to the
network related test cases (`ping` issue).

Signed-off-by: Dennis Chen <dennis.chen@arm.com>
Upstream-commit: 0d31dee5ec724731607e277a415b1ca4ecb7b2c4
Component: engine
2018-02-27 06:53:00 +00:00
55e0468775 Add busybox:latest into the frozen images
Adding `busybox:latest` and `busybox:glibc` as the frozen images

Signed-off-by: Dennis Chen <dennis.chen@arm.com>
Upstream-commit: 3ae45c5f173d88ba621116f9e1b5611fe687e050
Component: engine
2018-02-27 06:28:29 +00:00
6aa61cd683 Migrate volumes tests in integration-cli to api tests
This fix migrates volumes tests in integration-cli to api tests
in integration/

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Upstream-commit: d896f87c0595134fa2f0787dad30b237815f233f
Component: engine
2018-02-27 05:18:31 +00:00
103568711d Remove unnecessary GetImageIDAndOS use GetImage
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: c10e6a4d15b907da22ab508770d67e1447a8d0bd
Component: engine
2018-02-26 16:49:37 -05:00
fa6faa5087 Move ImageService to new package
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 2b1a2b10afce6ba251d096cfdbd642fc436120ef
Component: engine
2018-02-26 16:49:37 -05:00
7df5ef918e Move all daemon image methods into imageService
imageService provides the backend for the image API and handles the
imageStore, and referenceStore.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 0dab53ff3cb0aae91aae068a3f1f2fd32339e23b
Component: engine
2018-02-26 16:48:29 -05:00
6534f3d45e Merge pull request #36338 from tonistiigi/fix-copy-leak
builder: fix layer lifecycle leak
Upstream-commit: 600475715eb93fa402d1642a3586421c7182d63b
Component: engine
2018-02-26 22:36:40 +01:00
f717509b83 Windows: Block pulling uplevel images
Signed-off-by: John Howard <jhoward@microsoft.com>
Upstream-commit: 83908836d35b9f85a94489854d7eefd7dce785f8
Component: engine
2018-02-26 12:33:54 -08:00
38e7824f05 fix the error message in Substitute function
Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
Upstream-commit: 5d8ce59a25
Component: cli
2018-02-26 15:29:17 -05:00
bb11b4e9b1 Added error message check to TestMandatoryVariableErrors test
Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
Upstream-commit: e33bc48752
Component: cli
2018-02-26 15:29:17 -05:00
41c5444dac Refactor substitute to reduce cyclo complexity
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: ce544823b6
Component: cli
2018-02-26 15:29:17 -05:00
99c3d5bb04 added support for mandatory variables to cli/compose
Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
Upstream-commit: 99ecf57c6c
Component: cli
2018-02-26 15:29:17 -05:00
c67f00aca0 Update e2e script
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: 4bb0f24716f45ac520e73a52d7d7ca2752cabd31
Component: engine
2018-02-26 14:32:41 +01:00
7c3a542167 Merge pull request #35100 from cpuguy83/multistage_dockerfile
Updates the Dockerfile to use multi-stage
Upstream-commit: 00c1c604d08bbceb73a680d37d7428e6a4e986af
Component: engine
2018-02-26 14:05:21 +01:00
8fee7710b7 Merge pull request #900 from AkihiroSuda/sctp-doc
docs: mention sctp
Upstream-commit: 2813fae8f9
Component: cli
2018-02-26 11:28:44 +01:00
f49d1f63d7 Merge pull request #901 from thaJeztah/bump-version-to-v18.04-dev
Bump VERSION to 18.04.0-dev
Upstream-commit: 71039d0486
Component: cli
2018-02-26 11:25:43 +01:00
9f5c7766d0 Bump VERSION to 18.04.0-dev
The Docker 18.03 branch was cut from

CLI:    84c7dd6057
Engine: fb005971c2bd82de482d1cfe924f2f4ec60c60ae

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: 06dd62ab1e
Component: cli
2018-02-26 11:06:07 +01:00
e4ccd4c846 Updates the Dockerfile to use multi-stage
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: d539038d9712daa44254412c6fcc6d78a14da691
Component: engine
2018-02-26 09:10:17 +01:00
faa59fb288 docs: mention sctp
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
Upstream-commit: b85d87b8ab
Component: cli
2018-02-26 15:27:11 +09:00
d3e338ece5 Print Stack API version in version command
* Resolve Stack API using Kubernetes discovering API
* Refactor Kubernetes flags parsing

Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
Upstream-commit: 854aad8927
Component: cli
2018-02-26 01:16:49 +01:00
55a9ea06ee Migrate some config secret tests to api test
This fix migrates some secret create tests to api tests,
and remove redundant TestConfigCreate.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Upstream-commit: 99e28188507bbcb925b0c09df6b53cdd882d24c5
Component: engine
2018-02-25 23:58:04 +00:00
778e918eef Merge component 'engine' from git@github.com:moby/moby master 2018-02-25 17:06:31 +00:00
d2354e66ce Merge pull request #36393 from yongtang/02222018-containerIsStopped
Move containerIsStopped/containerIsInState to integration/internal/container
Upstream-commit: 5a7bbd6dba252d0935bb2505b725041b6d4eeeea
Component: engine
2018-02-25 16:02:12 +01:00
55fe35908b Merge pull request #36384 from yongtang/02222018-docker-py
Update docker-py
Upstream-commit: 64eae3752bd8ec62c3081b0947d701ec8224ae13
Component: engine
2018-02-25 12:42:16 +01:00
38dfebce07 Merge pull request #36164 from emil2k/gzip-archive
Content encoding negotiation added to archive request.
Upstream-commit: 20c4efee7b886c8b29f35595ebe5f21dc01c75ce
Component: engine
2018-02-24 14:06:06 -08:00
91066ac9d1 Merge component 'engine' from git@github.com:moby/moby master 2018-02-24 17:06:03 +00:00
71ca3e138f Content encoding negotiation added to archive request.
Signed-off-by: Emil Davtyan <emil2k@gmail.com>
Upstream-commit: 117cd7ff640d5e58229eb7f6588d01b928a30607
Component: engine
2018-02-24 06:41:45 +01:00
44fafead08 Merge pull request #36392 from yongtang/02232018-golint
Golint fix up
Upstream-commit: 4d9beb4607404e4d756052aca7041517788f7e75
Component: engine
2018-02-24 00:50:04 +01:00
a52b825c7e Update docker-py
This fix update docker-py so that containers from the tests run
could be cleaned up during teardown:
```diff
-ENV DOCKER_PY_COMMIT 5e28dcaace5f7b70cbe44c313b7a3b288fa38916
+ENV DOCKER_PY_COMMIT 8b246db271a85d6541dc458838627e89c683e42f
```

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Upstream-commit: 66935a0f64f0a72162fb3919c759f4f500b6c372
Component: engine
2018-02-23 22:24:47 +00:00
f620082c7f Merge component 'packaging' from git@github.com:docker/docker-ce-packaging master 2018-02-23 22:02:41 +00:00
2c12cc5798 Move containerIsStopped/containerIsInState to integration/internal/container
This fix moves helper functions containerIsStopped and
containerIsInState to integration/internal/container,
so that they could be used outside of integration/container.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Upstream-commit: eda311c18f388ed4541dc44dcfba08cd4347a685
Component: engine
2018-02-23 21:23:05 +00:00
52b3ec446a Merge pull request #88 from seemethere/fix_binary_installation
Fixes binary installation
Upstream-commit: 98f4889e6aadb750b8bfa1e7da7d9770ea21669f
Component: packaging
2018-02-23 11:53:26 -08:00
ce470fab4f Fixes binary installation
Binary installation was broken after the
hack/dockerfile/install-binaries script was removed.

This remedies that.

Signed-off-by: Eli Uriegas <eli.uriegas@docker.com>
Upstream-commit: 59164bedeab571029805a107e8e5a32fc9cd56b3
Component: packaging
2018-02-23 19:40:35 +00:00
db9462548a Merge component 'engine' from git@github.com:moby/moby master 2018-02-23 17:05:27 +00:00
50ae06e05c Golint fix up
This fix fixes a golint issue.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Upstream-commit: 742d4506bd5aa6f686070d0d5e984a8b9ee2cda6
Component: engine
2018-02-23 16:40:37 +00:00
ab9415b4ec Merge pull request #36387 from arm64b/teardown-cleanup4network
Clean the teardown process of network test
Upstream-commit: 219582bba6a316673fddeca50585f5c655041acb
Component: engine
2018-02-23 15:14:50 +01:00
c82f8abc80 Clean the teardown process of network test
We need to clean the resources created in some test cases, else
in some cases we'll get below error for other tests:

> FAIL: docker_experimental_network_test.go:37: DockerNetworkSuite.TestDockerNetworkMacvlanPersistance
>  docker_experimental_network_test.go:44:
> ...
> Command:  ip link add dm-dummy0 type dummy
> ExitCode: 2
> Error:    exit status 2
> Stdout:
> Stderr:   RTNETLINK answers: File exists
> ...

Logically, each test case should be independent, the failure of previous
test case should not have side-effect for the test cases followed.

Signed-off-by: Dennis Chen <dennis.chen@arm.com>
Upstream-commit: 57d85e7e54f7d074af8c496cba43ee18d3815207
Component: engine
2018-02-23 08:54:52 +00:00
196d64b294 Merge pull request #35967 from Microsoft/jjh/32838-pass-container-shutdown-error-back
Windows: Pass back system errors on container exit
Upstream-commit: 66e6beeb249948634e2815ef5cac97984d5c0d56
Component: engine
2018-02-22 19:12:10 -08:00
d662aea133 Merge pull request #36376 from vdemeester/fix-e2e-dockerfile
Fix Dockerfile.e2e build
Upstream-commit: 8b8a0e2c523eb886094fad7e5342d93407a19c8e
Component: engine
2018-02-22 13:17:22 -05:00
1b83ee58c9 Silent login: if user did not provide -u and -p flag for login command but both username and password are retrieved in cred store, docker will automatically use the credentials found in the cred store to log in
Signed-off-by: shhsu@microsoft.com <shhsu@microsoft.com>
Signed-off-by: Peter Hsu <shhsu@microsoft.com>
Signed-off-by: shhsu <shhsu@microsoft.com>
Signed-off-by: Peter Hsu <shhsu@microsoft.com>
Upstream-commit: 8883cd636a
Component: cli
2018-02-22 09:14:51 -08:00
c679327e80 Merge component 'engine' from git@github.com:moby/moby master 2018-02-22 17:06:34 +00:00
96898bda21 Windows: Pass back system errors on container exit
Signed-off-by: John Howard <jhoward@microsoft.com>

While debugging #32838, it was found (https://github.com/moby/moby/issues/32838#issuecomment-356005845) that the utility VM in some circumstances was crashing. Unfortunately, this was silently thrown away, and as far as the build step (also applies to docker run) was concerned, the exit code was zero and the error was thrown away. Windows containers operate differently to containers on Linux, and there can be legitimate system errors during container shutdown after the init process exits. This PR handles this and passes the error all the way back to the client, and correctly causes a build step running a container which hits a system error to fail, rather than blindly trying to keep going, assuming all is good, and get a subsequent failure on a commit.

With this change, assuming an error occurs, here's an example of a failure which previous was reported as a commit error:

```
The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; Install-WindowsFeature -Name Web-App-Dev ;   Install-WindowsFeature -Name ADLDS;   Install-WindowsFeature -Name Web-Mgmt-Compat;   Install-WindowsFeature -Name Web-Mgmt-Service;   Install-WindowsFeature -Name Web-Metabase;   Install-WindowsFeature -Name Web-Lgcy-Scripting;   Install-WindowsFeature -Name Web-WMI;   Install-WindowsFeature -Name Web-WHC;   Install-WindowsFeature -Name Web-Scripting-Tools;   Install-WindowsFeature -Name Web-Net-Ext45;   Install-WindowsFeature -Name Web-ASP;   Install-WindowsFeature -Name Web-ISAPI-Ext;   Install-WindowsFeature -Name Web-ISAPI-Filter;   Install-WindowsFeature -Name Web-Default-Doc;   Install-WindowsFeature -Name Web-Dir-Browsing;   Install-WindowsFeature -Name Web-Http-Errors;   Install-WindowsFeature -Name Web-Static-Content;   Install-WindowsFeature -Name Web-Http-Redirect;   Install-WindowsFeature -Name Web-DAV-Publishing;   Install-WindowsFeature -Name Web-Health;   Install-WindowsFeature -Name Web-Http-Logging;   Install-WindowsFeature -Name Web-Custom-Logging;   Install-WindowsFeature -Name Web-Log-Libraries;   Install-WindowsFeature -Name Web-Request-Monitor;   Install-WindowsFeature -Name Web-Http-Tracing;   Install-WindowsFeature -Name Web-Stat-Compression;   Install-WindowsFeature -Name Web-Dyn-Compression;   Install-WindowsFeature -Name Web-Security;   Install-WindowsFeature -Name Web-Windows-Auth;   Install-WindowsFeature -Name Web-Basic-Auth;   Install-WindowsFeature -Name Web-Url-Auth;   Install-WindowsFeature -Name Web-WebSockets;   Install-WindowsFeature -Name Web-AppInit;   Install-WindowsFeature -Name NET-WCF-HTTP-Activation45;   Install-WindowsFeature -Name NET-WCF-Pipe-Activation45;   Install-WindowsFeature -Name NET-WCF-TCP-Activation45;' returned a non-zero code: 4294967295: container shutdown failed: container ba9c65054d42d4830fb25ef55e4ab3287550345aa1a2bb265df4e5bfcd79c78a encountered an error during WaitTimeout: failure in a Windows system call: The compute system exited unexpectedly. (0xc0370106)
```

Without this change, it would be incorrectly reported such as in this comment: https://github.com/moby/moby/issues/32838#issuecomment-309621097

```
Step 3/8 : ADD buildtools C:/buildtools
re-exec error: exit status 1: output: time="2017-06-20T11:37:38+10:00" level=error msg="hcsshim::ImportLayer failed in Win32: The system cannot find the path specified. (0x3) layerId=\\\\?\\C:\\ProgramData\\docker\\windowsfilter\\b41d28c95f98368b73fc192cb9205700e21
6691495c1f9ac79b9b04ec4923ea2 flavour=1 folder=C:\\Windows\\TEMP\\hcs232661915"
hcsshim::ImportLayer failed in Win32: The system cannot find the path specified. (0x3) layerId=\\?\C:\ProgramData\docker\windowsfilter\b41d28c95f98368b73fc192cb9205700e216691495c1f9ac79b9b04ec4923ea2 flavour=1 folder=C:\Windows\TEMP\hcs232661915
```
Upstream-commit: 8c52560ea4593935322c1d056124be44e234b934
Component: engine
2018-02-22 08:53:43 -08:00
502470a3d8 Merge component 'cli' from git@github.com:docker/cli master 2018-02-22 16:42:28 +00:00
34d6002b9b Merge pull request #36373 from dnephin/prepare-for-image-service
Move daemon image code in preparation for ImageService
Upstream-commit: 867a10aadeb56a508fb7ceeee21ab1ef45a506a6
Component: engine
2018-02-22 17:32:43 +01:00
79cad3892d Merge pull request #36363 from dnephin/fix-attach-detach-test
Fix TestAttachAfterDetach to work with latest client
Upstream-commit: c6513bd05170ad3b77def3ae50541ef50d2ad27d
Component: engine
2018-02-22 11:25:02 -05:00
118b6d65e2 Merge pull request #36371 from cpuguy83/bump_swarmkit
Bump swarmkit
Upstream-commit: ffbb130873ad1aba579de7817b348b0ceacc31c2
Component: engine
2018-02-22 12:20:42 +01:00
2c4f0e56a8 Fix Dockerfile.e2e build
This images is used to run integration and integration-cli tests on
anything that implements the docker api :). The image wasn't building
anywore :D

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: 9c46b587eec84f6d9b525ecca1d8b66a51055c12
Component: engine
2018-02-22 11:30:47 +01:00
9963a034b3 Merge pull request #896 from thaJeztah/templated-configs-secrets
Add --template-driver option for secrets/configs
Upstream-commit: ef7d8be86c
Component: cli
2018-02-22 09:44:16 +01:00
e6062e18f5 Merge pull request #36336 from cpuguy83/split_installers
Split binary installers/commit scripts
Upstream-commit: 49ad3d69a7780e54ace50290d0a1a55c1182a947
Component: engine
2018-02-21 19:20:29 -08:00
4b9c2900d6 Bump version to 18.04.0-ce-dev
Signed-off-by: GordonTheTurtle <engine-team@docker.com>
2018-02-21 23:59:05 +00:00
112db723e1 Image commit
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: bad33bbd02b9f2754d3a8c64648d46baba509680
Component: engine
2018-02-21 18:26:16 -05:00
718daa9c98 Image events
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 0ac4ad0580c48749fb7d07f60a77a0014b1c3a99
Component: engine
2018-02-21 18:26:16 -05:00
192d8829e0 GetLayerFolders
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: f6639cb46d83cb9bb92a30578c10fdb372a58f04
Component: engine
2018-02-21 18:26:16 -05:00
4811cada93 Move ImagePrune
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 9c25df0fa201279f78d555c91ae000cc4f9b3036
Component: engine
2018-02-21 18:26:16 -05:00
3b6356337c Add --template-driver option for secrets/configs
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: d11b5ccdfa
Component: cli
2018-02-21 23:22:32 +01:00
c5a1aa150e Bump swarmkit
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Upstream-commit: be713ec486090db312f9a83481a2c4663d473f71
Component: engine
2018-02-21 16:08:32 -05:00
f11213a800 Split binary installers/commit scripts
Originally I worked on this for the multi-stage build Dockerfile
changes. Decided to split this out as we are still waiting for
multi-stage to be available on CI and rebasing these is pretty annoying.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Upstream-commit: b529d1b0936b90ae14d584c73f7332919f8d76b7
Component: engine
2018-02-21 15:39:24 -05:00
94dbb42ee9 Fix empty LogPath with non-blocking logging mode
This fixes an issue where the container LogPath was empty when the
non-blocking logging mode was enabled. This change sets the LogPath on
the container as soon as the path is generated, instead of setting the
LogPath on a logger struct and then attempting to pull it off that
logger at a later point. That attempt to pull the LogPath off the logger
was error prone since it assumed that the logger would only ever be a
single type.

Prior to this change docker inspect returned an empty string for
LogPath. This caused issues with tools that rely on docker inspect
output to discover container logs, e.g. Kubernetes.

This commit also removes some LogPath methods that are now unnecessary
and are never invoked.

Signed-off-by: junzhe and mnussbaum <code@getbraintree.com>
Upstream-commit: 20ca612a59c45c0bd58c71c199a7ebd2a6bf1a9e
Component: engine
2018-02-20 23:12:34 -08:00
143dde6783 Fix TestAttachAfterDetach to work with latest client
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 847b610620a8b8294d61c717d3c4aa13cb7a8b33
Component: engine
2018-02-20 18:34:25 -05:00
692e4bf089 builder: fix layer lifecycle leak
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Upstream-commit: 7ad41d53df94c4277574d14809211b42dca2becc
Component: engine
2018-02-20 11:14:53 -08:00
4f8240aeab Fix typos in builder and client
Signed-off-by: bin liu <liubin0329@gmail.com>
Upstream-commit: ce0993270436c16a17e0afb08b9130556346b983
Component: engine
2018-02-10 19:39:26 +08:00
c052f895a8 image/spec: add historical information about v1 spec
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
Upstream-commit: 1d17542f80d1a961224c762cec7628293f81465e
Component: engine
2017-11-13 06:34:28 +00:00
815 changed files with 22510 additions and 20340 deletions

View File

@ -1,120 +1,85 @@
# Changelog
For more information on the list of deprecated flags and APIs please have a look at
https://docs.docker.com/engine/deprecated/ where you can find the target removal dates
# Changelog
## 18.03.0-ce (2018-03-21)
For more information on the list of deprecated flags and APIs, have a look at
https://docs.docker.com/engine/deprecated/ where you can find the target removal dates
## 18.04.0-ce (2018-04-10)
### Builder
* Switch to -buildmode=pie [moby/moby#34369](https://github.com/moby/moby/pull/34369)
* Allow Dockerfile to be outside of build-context [docker/cli#886](https://github.com/docker/cli/pull/886)
* Builder: fix wrong cache hits building from tars [moby/moby#36329](https://github.com/moby/moby/pull/36329)
- Fixes files leaking to other images in a multi-stage build [moby/moby#36338](https://github.com/moby/moby/pull/36338)
- Fix typos in builder and client. [moby/moby#36424](https://github.com/moby/moby/pull/36424)
### Client
* Simplify the marshaling of compose types.Config [docker/cli#895](https://github.com/docker/cli/pull/895)
+ Add support for multiple composefile when deploying [docker/cli#569](https://github.com/docker/cli/pull/569)
- Fix broken Kubernetes stack flags [docker/cli#831](https://github.com/docker/cli/pull/831)
- Fix stack marshaling for Kubernetes [docker/cli#890](https://github.com/docker/cli/pull/890)
- Fix and simplify bash completion for service env, mounts and labels [docker/cli#682](https://github.com/docker/cli/pull/682)
- Fix `before` and `since` filter for `docker ps` [moby/moby#35938](https://github.com/moby/moby/pull/35938)
- Fix `--label-file` weird behavior [docker/cli#838](https://github.com/docker/cli/pull/838)
- Fix compilation of defaultCredentialStore() on unsupported platforms [docker/cli#872](https://github.com/docker/cli/pull/872)
* Improve and fix bash completion for images [docker/cli#717](https://github.com/docker/cli/pull/717)
+ Added check for empty source in bind mount [docker/cli#824](https://github.com/docker/cli/pull/824)
- Fix TLS from environment variables in client [moby/moby#36270](https://github.com/moby/moby/pull/36270)
* docker build now runs faster when registry-specific credential helper(s) are configured [docker/cli#840](https://github.com/docker/cli/pull/840)
* Update event filter zsh completion with `disable`, `enable`, `install` and `remove` [docker/cli#372](https://github.com/docker/cli/pull/372)
* Produce errors when empty ids are passed into inspect calls [moby/moby#36144](https://github.com/moby/moby/pull/36144)
* Marshall version for the k8s controller [docker/cli#891](https://github.com/docker/cli/pull/891)
* Set a non-zero timeout for HTTP client communication with plugin backend [docker/cli#883](https://github.com/docker/cli/pull/883)
+ Add DOCKER_TLS environment variable for --tls option [docker/cli#863](https://github.com/docker/cli/pull/863)
+ Add --template-driver option for secrets/configs [docker/cli#896](https://github.com/docker/cli/pull/896)
+ Move `docker trust` commands out of experimental [docker/cli#934](https://github.com/docker/cli/pull/934) [docker/cli#935](https://github.com/docker/cli/pull/935) [docker/cli#944](https://github.com/docker/cli/pull/944)
* Print Stack API and Kubernetes versions in version command. [docker/cli#898](https://github.com/docker/cli/pull/898)
- Fix Kubernetes duplication in version command. [docker/cli#953](https://github.com/docker/cli/pull/953)
* Use HasAvailableFlags instead of HasFlags for Options in help. [docker/cli#959](https://github.com/docker/cli/pull/959)
+ Add support for mandatory variables to stack deploy. [docker/cli#893](https://github.com/docker/cli/pull/893)
- Fix docker stack services command Port output. [docker/cli#943](https://github.com/docker/cli/pull/943)
* Deprecate unencrypted storage. [docker/cli#561](https://github.com/docker/cli/pull/561)
* Don't set a default filename for ConfigFile. [docker/cli#917](https://github.com/docker/cli/pull/917)
- Fix compose network name. [docker/cli#941](https://github.com/docker/cli/pull/941)
### Logging
* AWS logs - don't add new lines to maximum sized events [moby/moby#36078](https://github.com/moby/moby/pull/36078)
* Move log validator logic after plugins are loaded [moby/moby#36306](https://github.com/moby/moby/pull/36306)
* Support a proxy in Splunk log driver [moby/moby#36220](https://github.com/moby/moby/pull/36220)
- Fix log tail with empty logs [moby/moby#36305](https://github.com/moby/moby/pull/36305)
* Silent login: use credentials from cred store to login. [docker/cli#139](https://github.com/docker/cli/pull/139)
+ Add support for compressibility of log file. [moby/moby#29932](https://github.com/moby/moby/pull/29932)
- Fix empty LogPath with non-blocking logging mode. [moby/moby#36272](https://github.com/moby/moby/pull/36272)
### Networking
* Libnetwork revendoring [moby/moby#36137](https://github.com/moby/moby/pull/36137)
- Fix for deadlock on exit with Memberlist revendor [docker/libnetwork#2040](https://github.com/docker/libnetwork/pull/2040)
* Fix user specified ndots option [docker/libnetwork#2065](https://github.com/docker/libnetwork/pull/2065)
- Fix to use ContainerID for Windows instead of SandboxID [docker/libnetwork#2010](https://github.com/docker/libnetwork/pull/2010)
* Verify NetworkingConfig to make sure EndpointSettings is not nil [moby/moby#36077](https://github.com/moby/moby/pull/36077)
- Fix `DockerNetworkInternalMode` issue [moby/moby#36298](https://github.com/moby/moby/pull/36298)
- Fix race in attachable network attachment [moby/moby#36191](https://github.com/moby/moby/pull/36191)
- Fix timeout issue of `InspectNetwork` on AArch64 [moby/moby#36257](https://github.com/moby/moby/pull/36257)
* Verbose info is missing for partial overlay ID [moby/moby#35989](https://github.com/moby/moby/pull/35989)
* Update `FindNetwork` to address network name duplications [moby/moby#30897](https://github.com/moby/moby/pull/30897)
* Disallow attaching ingress network [docker/swarmkit#2523](https://github.com/docker/swarmkit/pull/2523)
- Prevent implicit removal of the ingress network [moby/moby#36538](https://github.com/moby/moby/pull/36538)
- Fix stale HNS endpoints on Windows [moby/moby#36603](https://github.com/moby/moby/pull/36603)
- IPAM fixes for duplicate IP addresses [docker/libnetwork#2104](https://github.com/docker/libnetwork/pull/2104) [docker/libnetwork#2105](https://github.com/docker/libnetwork/pull/2105)
- Prevent explicit removal of ingress network. [moby/moby#36538](https://github.com/moby/moby/pull/36538)
### Runtime
* Enable HotAdd for Windows [moby/moby#35414](https://github.com/moby/moby/pull/35414)
* LCOW: Graphdriver fix deadlock in hotRemoveVHDs [moby/moby#36114](https://github.com/moby/moby/pull/36114)
* LCOW: Regular mount if only one layer [moby/moby#36052](https://github.com/moby/moby/pull/36052)
* Remove interim env var LCOW_API_PLATFORM_IF_OMITTED [moby/moby#36269](https://github.com/moby/moby/pull/36269)
* Revendor Microsoft/opengcs @ v0.3.6 [moby/moby#36108](https://github.com/moby/moby/pull/36108)
- Fix issue of ExitCode and PID not show up in Task.Status.ContainerStatus [moby/moby#36150](https://github.com/moby/moby/pull/36150)
- Fix issue with plugin scanner going too deep [moby/moby#36119](https://github.com/moby/moby/pull/36119)
* Do not make graphdriver homes private mounts [moby/moby#36047](https://github.com/moby/moby/pull/36047)
* Do not recursive unmount on cleanup of zfs/btrfs [moby/moby#36237](https://github.com/moby/moby/pull/36237)
* Don't restore image if layer does not exist [moby/moby#36304](https://github.com/moby/moby/pull/36304)
* Adjust minimum API version for templated configs/secrets [moby/moby#36366](https://github.com/moby/moby/pull/36366)
* Bump containerd to 1.0.2 (cfd04396dc68220d1cecbe686a6cc3aa5ce3667c) [moby/moby#36308](https://github.com/moby/moby/pull/36308)
* Bump Golang to 1.9.4 [moby/moby#36243](https://github.com/moby/moby/pull/36243)
* Ensure daemon root is unmounted on shutdown [moby/moby#36107](https://github.com/moby/moby/pull/36107)
* Update runc to 6c55f98695e902427906eed2c799e566e3d3dfb5 [moby/moby#36222](https://github.com/moby/moby/pull/36222)
- Fix container cleanup on daemon restart [moby/moby#36249](https://github.com/moby/moby/pull/36249)
* Support SCTP port mapping (bump up API to v1.37) [moby/moby#33922](https://github.com/moby/moby/pull/33922)
* Support SCTP port mapping [docker/cli#278](https://github.com/docker/cli/pull/278)
- Fix Volumes property definition in ContainerConfig [moby/moby#35946](https://github.com/moby/moby/pull/35946)
* Bump moby and dependencies [docker/cli#829](https://github.com/docker/cli/pull/829)
* C.RWLayer: check for nil before use [moby/moby#36242](https://github.com/moby/moby/pull/36242)
+ Add `REMOVE` and `ORPHANED` to TaskState [moby/moby#36146](https://github.com/moby/moby/pull/36146)
- Fixed error detection using `IsErrNotFound` and `IsErrNotImplemented` for `ContainerStatPath`, `CopyFromContainer`, and `CopyToContainer` methods [moby/moby#35979](https://github.com/moby/moby/pull/35979)
+ Add an integration/internal/container helper package [moby/moby#36266](https://github.com/moby/moby/pull/36266)
+ Add canonical import path [moby/moby#36194](https://github.com/moby/moby/pull/36194)
+ Add/use container.Exec() to integration [moby/moby#36326](https://github.com/moby/moby/pull/36326)
- Fix "--node-generic-resource" singular/plural [moby/moby#36125](https://github.com/moby/moby/pull/36125)
* Daemon.cleanupContainer: nullify container RWLayer upon release [moby/moby#36160](https://github.com/moby/moby/pull/36160)
* Daemon: passdown the `--oom-kill-disable` option to containerd [moby/moby#36201](https://github.com/moby/moby/pull/36201)
* Display a warn message when there is binding ports and net mode is host [moby/moby#35510](https://github.com/moby/moby/pull/35510)
* Refresh containerd remotes on containerd restarted [moby/moby#36173](https://github.com/moby/moby/pull/36173)
* Set daemon root to use shared propagation [moby/moby#36096](https://github.com/moby/moby/pull/36096)
* Optimizations for recursive unmount [moby/moby#34379](https://github.com/moby/moby/pull/34379)
* Perform plugin mounts in the runtime [moby/moby#35829](https://github.com/moby/moby/pull/35829)
* Graphdriver: Fix RefCounter memory leak [moby/moby#36256](https://github.com/moby/moby/pull/36256)
* Use continuity fs package for volume copy [moby/moby#36290](https://github.com/moby/moby/pull/36290)
* Use proc/exe for reexec [moby/moby#36124](https://github.com/moby/moby/pull/36124)
+ Add API support for templated secrets and configs [moby/moby#33702](https://github.com/moby/moby/pull/33702) and [moby/moby#36366](https://github.com/moby/moby/pull/36366)
* Use rslave propagation for mounts from daemon root [moby/moby#36055](https://github.com/moby/moby/pull/36055)
+ Add /proc/keys to masked paths [moby/moby#36368](https://github.com/moby/moby/pull/36368)
* Bump Runc to 1.0.0-rc5 [moby/moby#36449](https://github.com/moby/moby/pull/36449)
- Fixes `runc exec` on big-endian architectures [moby/moby#36449](https://github.com/moby/moby/pull/36449)
* Use chroot when mount namespaces aren't provided [moby/moby#36449](https://github.com/moby/moby/pull/36449)
- Fix systemd slice expansion so that it could be consumed by cAdvisor [moby/moby#36449](https://github.com/moby/moby/pull/36449)
- Fix devices mounted with wrong uid/gid [moby/moby#36449](https://github.com/moby/moby/pull/36449)
- Fix read-only containers with IPC private mounts `/dev/shm` read-only [moby/moby#36526](https://github.com/moby/moby/pull/36526)
* Devmapper cleanup improvements. [moby/moby#36307](https://github.com/moby/moby/pull/36307)
* Devmapper.Mounted: remove. [moby/moby#36437](https://github.com/moby/moby/pull/36437)
* Devmapper/Remove(): use Rmdir, ignore errors. [moby/moby#36438](https://github.com/moby/moby/pull/36438)
* LCOW - Change platform parser directive to FROM statement flag. [moby/moby#35089](https://github.com/moby/moby/pull/35089)
* Split daemon service code to windows file. [moby/moby#36653](https://github.com/moby/moby/pull/36653)
* Windows: Block pulling uplevel images. [moby/moby#36327](https://github.com/moby/moby/pull/36327)
* Windows: Hyper-V containers are broken after 36586 was merged. [moby/moby#36610](https://github.com/moby/moby/pull/36610)
* Windows: Move kernel_windows to use golang registry functions. [moby/moby#36617](https://github.com/moby/moby/pull/36617)
* Windows: Pass back system errors on container exit. [moby/moby#35967](https://github.com/moby/moby/pull/35967)
* Windows: Remove servicing mode. [moby/moby#36267](https://github.com/moby/moby/pull/36267)
* Windows: Report Version and UBR. [moby/moby#36451](https://github.com/moby/moby/pull/36451)
* Bump Runc to 1.0.0-rc5. [moby/moby#36449](https://github.com/moby/moby/pull/36449)
* Mount failure indicates the path that failed. [moby/moby#36407](https://github.com/moby/moby/pull/36407)
* Change return for errdefs.getImplementer(). [moby/moby#36489](https://github.com/moby/moby/pull/36489)
* Client: fix hijackedconn reading from buffer. [moby/moby#36663](https://github.com/moby/moby/pull/36663)
* Content encoding negotiation added to archive request. [moby/moby#36164](https://github.com/moby/moby/pull/36164)
* Daemon/stats: more resilient cpu sampling. [moby/moby#36519](https://github.com/moby/moby/pull/36519)
* Daemon/stats: remove obnoxious types file. [moby/moby#36494](https://github.com/moby/moby/pull/36494)
* Daemon: use context error rather than inventing new one. [moby/moby#36670](https://github.com/moby/moby/pull/36670)
* Enable CRIU on non-amd64 architectures (v2). [moby/moby#36676](https://github.com/moby/moby/pull/36676)
- Fixes intermittent client hang after closing stdin to attached container [moby/moby#36517](https://github.com/moby/moby/pull/36517)
- Fix daemon panic on container export after restart [moby/moby#36586](https://github.com/moby/moby/pull/36586)
- Follow-up fixes on multi-stage moby's Dockerfile. [moby/moby#36425](https://github.com/moby/moby/pull/36425)
* Freeze busybox and latest glibc in Docker image. [moby/moby#36375](https://github.com/moby/moby/pull/36375)
* If container will run as non root user, drop permitted, effective caps early. [moby/moby#36587](https://github.com/moby/moby/pull/36587)
* Layer: remove metadata store interface. [moby/moby#36504](https://github.com/moby/moby/pull/36504)
* Minor optimizations to dockerd. [moby/moby#36577](https://github.com/moby/moby/pull/36577)
* Whitelist statx syscall. [moby/moby#36417](https://github.com/moby/moby/pull/36417)
+ Add missing error return for plugin creation. [moby/moby#36646](https://github.com/moby/moby/pull/36646)
- Fix AppArmor not being applied to Exec processes. [moby/moby#36466](https://github.com/moby/moby/pull/36466)
* Daemon/logger/ring.go: log error not instance. [moby/moby#36475](https://github.com/moby/moby/pull/36475)
- Fix stats collector spinning CPU if no stats are collected. [moby/moby#36609](https://github.com/moby/moby/pull/36609)
- Fix(distribution): digest cache should not be moved if it was an auth. [moby/moby#36509](https://github.com/moby/moby/pull/36509)
- Make sure plugin container is removed on failure. [moby/moby#36715](https://github.com/moby/moby/pull/36715)
* Bump to containerd 1.0.3. [moby/moby#36749](https://github.com/moby/moby/pull/36749)
* Don't sort plugin mount slice. [moby/moby#36711](https://github.com/moby/moby/pull/36711)
### Swarm Mode
* Replace EC Private Key with PKCS#8 PEMs [docker/swarmkit#2246](https://github.com/docker/swarmkit/pull/2246)
* Fix IP overlap with empty EndpointSpec [docker/swarmkit #2505](https://github.com/docker/swarmkit/pull/2505)
* Add support for Support SCTP port mapping [docker/swarmkit#2298](https://github.com/docker/swarmkit/pull/2298)
* Do not reschedule tasks if only placement constraints change and are satisfied by the assigned node [docker/swarmkit#2496](https://github.com/docker/swarmkit/pull/2496)
* Ensure task reaper stopChan is closed no more than once [docker/swarmkit #2491](https://github.com/docker/swarmkit/pull/2491)
* Synchronization fixes [docker/swarmkit#2495](https://github.com/docker/swarmkit/pull/2495)
* Add log message to indicate message send retry if streaming unimplemented [docker/swarmkit#2483](https://github.com/docker/swarmkit/pull/2483)
* Debug logs for session, node events on dispatcher, heartbeats [docker/swarmkit#2486](https://github.com/docker/swarmkit/pull/2486)
+ Add swarm types to bash completion event type filter [docker/cli#888](https://github.com/docker/cli/pull/888)
- Fix issue where network inspect does not show Created time for networks in swarm scope [moby/moby#36095](https://github.com/moby/moby/pull/36095)
* Fixes for synchronizing the dispatcher shutdown with in-progress rpcs. [moby/moby#36371](https://github.com/moby/moby/pull/36371)
* Increase raft ElectionTick to 10xHeartbeatTick. [moby/moby#36672](https://github.com/moby/moby/pull/36672)
* Make Swarm manager Raft quorum parameters configurable in daemon config. [moby/moby#36726](https://github.com/moby/moby/pull/36726)
* Ingress network should not be attachable. [docker/swarmkit#2523](https://github.com/docker/swarmkit/pull/2523)
* [manager/state] Add fernet as an option for raft encryption. [docker/swarmkit#2535](https://github.com/docker/swarmkit/pull/2535)
* Log GRPC server errors. [docker/swarmkit#2541](https://github.com/docker/swarmkit/pull/2541)
* Log leadership changes at the manager level. [docker/swarmkit#2542](https://github.com/docker/swarmkit/pull/2542)
* Remove the containerd executor. [docker/swarmkit#2568](https://github.com/docker/swarmkit/pull/2568)
* Agent: backoff session when no remotes are available. [docker/swarmkit#2570](https://github.com/docker/swarmkit/pull/2570)
* [ca/manager] Remove root CA key encryption support entirely. [docker/swarmkit#2573](https://github.com/docker/swarmkit/pull/2573)
- Fix agent logging race. [docker/swarmkit#2578](https://github.com/docker/swarmkit/pull/2578)
* Adding logic to restore networks in order. [docker/swarmkit#2571](https://github.com/docker/swarmkit/pull/2571)

View File

@ -1 +1 @@
18.03.0-ce
18.04.0-ce

View File

@ -1 +1 @@
18.03.0-ce
18.04.0-ce

View File

@ -0,0 +1,23 @@
version: "{build}"
clone_folder: c:\gopath\src\github.com\docker\cli
environment:
GOPATH: c:\gopath
GOVERSION: 1.10
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

View File

@ -128,7 +128,7 @@ Examples:
{{ .Example }}
{{- end}}
{{- if .HasFlags}}
{{- if .HasAvailableFlags}}
Options:
{{ wrappedFlagUsages . | trimRightSpace}}

View File

@ -5,7 +5,8 @@ import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestLoadFileV01Success(t *testing.T) {
@ -25,9 +26,9 @@ func TestLoadFileV01Success(t *testing.T) {
}`)
bundle, err := LoadFile(reader)
assert.NoError(t, err)
assert.Equal(t, "0.1", bundle.Version)
assert.Len(t, bundle.Services, 2)
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) {
@ -37,7 +38,7 @@ func TestLoadFileSyntaxError(t *testing.T) {
}`)
_, err := LoadFile(reader)
assert.EqualError(t, err, "JSON syntax error at byte 37: invalid character 'u' looking for beginning of value")
assert.Error(t, err, "JSON syntax error at byte 37: invalid character 'u' looking for beginning of value")
}
func TestLoadFileTypeError(t *testing.T) {
@ -52,7 +53,7 @@ func TestLoadFileTypeError(t *testing.T) {
}`)
_, err := LoadFile(reader)
assert.EqualError(t, err, "Unexpected type at byte 94. Expected []string but received string.")
assert.Error(t, err, "Unexpected type at byte 94. Expected []string but received string.")
}
func TestPrint(t *testing.T) {
@ -66,12 +67,12 @@ func TestPrint(t *testing.T) {
},
},
}
assert.NoError(t, Print(&buffer, bundle))
assert.Check(t, Print(&buffer, bundle))
output := buffer.String()
assert.Contains(t, output, "\"Image\": \"image\"")
assert.Contains(t, output,
assert.Check(t, is.Contains(output, "\"Image\": \"image\""))
assert.Check(t, is.Contains(output,
`"Command": [
"echo",
"something"
]`)
]`))
}

View File

@ -6,10 +6,10 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
func TestCheckpointCreateErrors(t *testing.T) {
@ -42,7 +42,7 @@ func TestCheckpointCreateErrors(t *testing.T) {
cmd := newCreateCommand(cli)
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -63,10 +63,10 @@ func TestCheckpointCreateWithOptions(t *testing.T) {
cmd.SetArgs([]string{"container-foo", checkpoint})
cmd.Flags().Set("leave-running", "true")
cmd.Flags().Set("checkpoint-dir", "/dir/foo")
assert.NoError(t, cmd.Execute())
assert.Equal(t, "container-foo", containerID)
assert.Equal(t, checkpoint, checkpointID)
assert.Equal(t, "/dir/foo", checkpointDir)
assert.Equal(t, false, exit)
assert.Equal(t, checkpoint, strings.TrimSpace(cli.OutBuffer().String()))
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())))
}

View File

@ -5,11 +5,11 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
func TestCheckpointListErrors(t *testing.T) {
@ -42,7 +42,7 @@ func TestCheckpointListErrors(t *testing.T) {
cmd := newListCommand(cli)
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -60,8 +60,8 @@ func TestCheckpointListWithOptions(t *testing.T) {
cmd := newListCommand(cli)
cmd.SetArgs([]string{"container-foo"})
cmd.Flags().Set("checkpoint-dir", "/dir/foo")
assert.NoError(t, cmd.Execute())
assert.Equal(t, "container-foo", containerID)
assert.Equal(t, "/dir/foo", checkpointDir)
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")
}

View File

@ -5,10 +5,10 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
func TestCheckpointRemoveErrors(t *testing.T) {
@ -41,7 +41,7 @@ func TestCheckpointRemoveErrors(t *testing.T) {
cmd := newRemoveCommand(cli)
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -58,8 +58,8 @@ func TestCheckpointRemoveWithOptions(t *testing.T) {
cmd := newRemoveCommand(cli)
cmd.SetArgs([]string{"container-foo", "checkpoint-bar"})
cmd.Flags().Set("checkpoint-dir", "/dir/foo")
assert.NoError(t, cmd.Execute())
assert.Equal(t, "container-foo", containerID)
assert.Equal(t, "checkpoint-bar", checkpointID)
assert.Equal(t, "/dir/foo", checkpointDir)
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))
}

View File

@ -22,7 +22,6 @@ import (
"github.com/docker/docker/api/types"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/client"
"github.com/docker/go-connections/sockets"
"github.com/docker/go-connections/tlsconfig"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@ -53,18 +52,20 @@ type Cli interface {
DefaultVersion() string
ManifestStore() manifeststore.Store
RegistryClient(bool) registryclient.RegistryClient
ContentTrustEnabled() bool
}
// DockerCli is an instance the docker command line client.
// Instances of the client can be returned from NewDockerCli.
type DockerCli struct {
configFile *configfile.ConfigFile
in *InStream
out *OutStream
err io.Writer
client client.APIClient
serverInfo ServerInfo
clientInfo ClientInfo
configFile *configfile.ConfigFile
in *InStream
out *OutStream
err io.Writer
client client.APIClient
serverInfo ServerInfo
clientInfo ClientInfo
contentTrust bool
}
// DefaultVersion returns api.defaultVersion or DOCKER_API_VERSION if specified.
@ -122,6 +123,12 @@ func (cli *DockerCli) ClientInfo() ClientInfo {
return cli.clientInfo
}
// ContentTrustEnabled returns whether content trust has been enabled by an
// environment variable.
func (cli *DockerCli) ContentTrustEnabled() bool {
return cli.contentTrust
}
// ManifestStore returns a store for local manifests
func (cli *DockerCli) ManifestStore() manifeststore.Store {
// TODO: support override default location from config file
@ -238,8 +245,8 @@ func (c ClientInfo) HasKubernetes() bool {
}
// NewDockerCli returns a DockerCli instance with IO output and error streams set by in, out and err.
func NewDockerCli(in io.ReadCloser, out, err io.Writer) *DockerCli {
return &DockerCli{in: NewInStream(in), out: NewOutStream(out), err: err}
func NewDockerCli(in io.ReadCloser, out, err io.Writer, isTrusted bool) *DockerCli {
return &DockerCli{in: NewInStream(in), out: NewOutStream(out), err: err, contentTrust: isTrusted}
}
// NewAPIClientFromFlags creates a new APIClient from command line flags
@ -260,12 +267,12 @@ func NewAPIClientFromFlags(opts *cliflags.CommonOptions, configFile *configfile.
verStr = tmpStr
}
httpClient, err := newHTTPClient(host, opts.TLSOptions)
if err != nil {
return &client.Client{}, err
}
return client.NewClient(host, verStr, httpClient, customHeaders)
return client.NewClientWithOpts(
withHTTPClient(opts.TLSOptions),
client.WithHTTPHeaders(customHeaders),
client.WithVersion(verStr),
client.WithHost(host),
)
}
func getServerHost(hosts []string, tlsOptions *tlsconfig.Options) (string, error) {
@ -282,35 +289,32 @@ func getServerHost(hosts []string, tlsOptions *tlsconfig.Options) (string, error
return dopts.ParseHost(tlsOptions != nil, host)
}
func newHTTPClient(host string, tlsOptions *tlsconfig.Options) (*http.Client, error) {
if tlsOptions == nil {
// let the api client configure the default transport.
return nil, nil
}
opts := *tlsOptions
opts.ExclusiveRootPools = true
config, err := tlsconfig.Client(opts)
if err != nil {
return nil, err
}
tr := &http.Transport{
TLSClientConfig: config,
DialContext: (&net.Dialer{
KeepAlive: 30 * time.Second,
Timeout: 30 * time.Second,
}).DialContext,
}
hostURL, err := client.ParseHostURL(host)
if err != nil {
return nil, err
}
func withHTTPClient(tlsOpts *tlsconfig.Options) func(*client.Client) error {
return func(c *client.Client) error {
if tlsOpts == nil {
// Use the default HTTPClient
return nil
}
sockets.ConfigureTransport(tr, hostURL.Scheme, hostURL.Host)
opts := *tlsOpts
opts.ExclusiveRootPools = true
tlsConfig, err := tlsconfig.Client(opts)
if err != nil {
return err
}
return &http.Client{
Transport: tr,
CheckRedirect: client.CheckRedirect,
}, nil
httpClient := &http.Client{
Transport: &http.Transport{
TLSClientConfig: tlsConfig,
DialContext: (&net.Dialer{
KeepAlive: 30 * time.Second,
Timeout: 30 * time.Second,
}).DialContext,
},
CheckRedirect: client.CheckRedirect,
}
return client.WithHTTPClient(httpClient)(c)
}
}
// UserAgent returns the user agent string used for making API requests

View File

@ -3,24 +3,27 @@ package command
import (
"crypto/x509"
"os"
"runtime"
"testing"
cliconfig "github.com/docker/cli/cli/config"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/flags"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/fs"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/context"
)
func TestNewAPIClientFromFlags(t *testing.T) {
host := "unix://path"
if runtime.GOOS == "windows" {
host = "npipe://./"
}
opts := &flags.CommonOptions{Hosts: []string{host}}
configFile := &configfile.ConfigFile{
HTTPHeaders: map[string]string{
@ -28,15 +31,15 @@ func TestNewAPIClientFromFlags(t *testing.T) {
},
}
apiclient, err := NewAPIClientFromFlags(opts, configFile)
require.NoError(t, err)
assert.Equal(t, host, apiclient.DaemonHost())
assert.NilError(t, err)
assert.Check(t, is.Equal(host, apiclient.DaemonHost()))
expectedHeaders := map[string]string{
"My-Header": "Custom-Value",
"User-Agent": UserAgent(),
}
assert.Equal(t, expectedHeaders, apiclient.(*client.Client).CustomHTTPHeaders())
assert.Equal(t, api.DefaultVersion, apiclient.ClientVersion())
assert.Check(t, is.DeepEqual(expectedHeaders, apiclient.(*client.Client).CustomHTTPHeaders()))
assert.Check(t, is.Equal(api.DefaultVersion, apiclient.ClientVersion()))
}
func TestNewAPIClientFromFlagsWithAPIVersionFromEnv(t *testing.T) {
@ -46,20 +49,20 @@ func TestNewAPIClientFromFlagsWithAPIVersionFromEnv(t *testing.T) {
opts := &flags.CommonOptions{}
configFile := &configfile.ConfigFile{}
apiclient, err := NewAPIClientFromFlags(opts, configFile)
require.NoError(t, err)
assert.Equal(t, customVersion, apiclient.ClientVersion())
assert.NilError(t, err)
assert.Check(t, is.Equal(customVersion, apiclient.ClientVersion()))
}
// TODO: use gotestyourself/env.Patch
func patchEnvVariable(t *testing.T, key, value string) func() {
oldValue, ok := os.LookupEnv(key)
require.NoError(t, os.Setenv(key, value))
assert.NilError(t, os.Setenv(key, value))
return func() {
if !ok {
require.NoError(t, os.Unsetenv(key))
assert.NilError(t, os.Unsetenv(key))
return
}
require.NoError(t, os.Setenv(key, oldValue))
assert.NilError(t, os.Setenv(key, oldValue))
}
}
@ -125,8 +128,8 @@ func TestInitializeFromClient(t *testing.T) {
cli := &DockerCli{client: apiclient}
cli.initializeFromClient()
assert.Equal(t, testcase.expectedServer, cli.serverInfo)
assert.Equal(t, testcase.negotiated, apiclient.negotiated)
assert.Check(t, is.DeepEqual(testcase.expectedServer, cli.serverInfo))
assert.Check(t, is.Equal(testcase.negotiated, apiclient.negotiated))
})
}
}
@ -164,8 +167,8 @@ func TestExperimentalCLI(t *testing.T) {
cli := &DockerCli{client: apiclient, err: os.Stderr}
cliconfig.SetDir(dir.Path())
err := cli.Initialize(flags.NewClientOptions())
assert.NoError(t, err)
assert.Equal(t, testcase.expectedExperimentalCLI, cli.ClientInfo().HasExperimental)
assert.NilError(t, err)
assert.Check(t, is.Equal(testcase.expectedExperimentalCLI, cli.ClientInfo().HasExperimental))
})
}
}
@ -267,9 +270,9 @@ func TestOrchestratorSwitch(t *testing.T) {
options.Common.Orchestrator = testcase.flagOrchestrator
}
err := cli.Initialize(options)
assert.NoError(t, err)
assert.Equal(t, testcase.expectedKubernetes, cli.ClientInfo().HasKubernetes())
assert.Equal(t, testcase.expectedOrchestrator, string(cli.ClientInfo().Orchestrator))
assert.NilError(t, err)
assert.Check(t, is.Equal(testcase.expectedKubernetes, cli.ClientInfo().HasKubernetes()))
assert.Check(t, is.Equal(testcase.expectedOrchestrator, string(cli.ClientInfo().Orchestrator)))
})
}
}
@ -331,11 +334,11 @@ func TestGetClientWithPassword(t *testing.T) {
_, err := getClientWithPassword(passRetriever, newClient)
if testcase.expectedErr != "" {
testutil.ErrorContains(t, err, testcase.expectedErr)
assert.ErrorContains(t, err, testcase.expectedErr)
return
}
assert.NoError(t, err)
assert.NilError(t, err)
})
}
}

View File

@ -8,12 +8,12 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
const configDataFile = "config-create-with-name.golden"
@ -47,7 +47,7 @@ func TestConfigCreateErrors(t *testing.T) {
)
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -70,9 +70,9 @@ func TestConfigCreateWithName(t *testing.T) {
cmd := newConfigCreateCommand(cli)
cmd.SetArgs([]string{name, filepath.Join("testdata", configDataFile)})
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, string(actual), configDataFile)
assert.Equal(t, "ID-"+name, strings.TrimSpace(cli.OutBuffer().String()))
assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
}
func TestConfigCreateWithLabels(t *testing.T) {
@ -83,7 +83,7 @@ func TestConfigCreateWithLabels(t *testing.T) {
name := "foo"
data, err := ioutil.ReadFile(filepath.Join("testdata", configDataFile))
assert.NoError(t, err)
assert.NilError(t, err)
expected := swarm.ConfigSpec{
Annotations: swarm.Annotations{
@ -109,8 +109,8 @@ func TestConfigCreateWithLabels(t *testing.T) {
cmd.SetArgs([]string{name, filepath.Join("testdata", configDataFile)})
cmd.Flags().Set("label", "lbl1=Label-foo")
cmd.Flags().Set("label", "lbl2=Label-bar")
assert.NoError(t, cmd.Execute())
assert.Equal(t, "ID-"+name, strings.TrimSpace(cli.OutBuffer().String()))
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
}
func TestConfigCreateWithTemplatingDriver(t *testing.T) {
@ -138,6 +138,6 @@ func TestConfigCreateWithTemplatingDriver(t *testing.T) {
cmd := newConfigCreateCommand(cli)
cmd.SetArgs([]string{name, filepath.Join("testdata", configDataFile)})
cmd.Flags().Set("template-driver", expectedDriver.Name)
assert.NoError(t, cmd.Execute())
assert.Equal(t, "ID-"+name, strings.TrimSpace(cli.OutBuffer().String()))
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
}

View File

@ -11,9 +11,8 @@ import (
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/cli/internal/test/testutil"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
)
func TestConfigInspectErrors(t *testing.T) {
@ -62,7 +61,7 @@ func TestConfigInspectErrors(t *testing.T) {
cmd.Flags().Set(key, value)
}
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -96,7 +95,7 @@ func TestConfigInspectWithoutFormat(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{configInspectFunc: tc.configInspectFunc})
cmd := newConfigInspectCommand(cli)
cmd.SetArgs(tc.args)
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("config-inspect-without-format.%s.golden", tc.name))
}
}
@ -133,7 +132,7 @@ func TestConfigInspectWithFormat(t *testing.T) {
cmd := newConfigInspectCommand(cli)
cmd.SetArgs(tc.args)
cmd.Flags().Set("format", tc.format)
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("config-inspect-with-format.%s.golden", tc.name))
}
}
@ -167,7 +166,7 @@ func TestConfigInspectPretty(t *testing.T) {
cmd.SetArgs([]string{"configID"})
cmd.Flags().Set("pretty", "true")
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("config-inspect-pretty.%s.golden", tc.name))
}
}

View File

@ -12,9 +12,9 @@ import (
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/cli/internal/test/testutil"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
)
func TestConfigListErrors(t *testing.T) {
@ -42,7 +42,7 @@ func TestConfigListErrors(t *testing.T) {
)
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -72,7 +72,7 @@ func TestConfigList(t *testing.T) {
},
})
cmd := newConfigListCommand(cli)
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "config-list-sort.golden")
}
@ -89,7 +89,7 @@ func TestConfigListWithQuietOption(t *testing.T) {
})
cmd := newConfigListCommand(cli)
cmd.Flags().Set("quiet", "true")
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "config-list-with-quiet-option.golden")
}
@ -108,7 +108,7 @@ func TestConfigListWithConfigFormat(t *testing.T) {
ConfigFormat: "{{ .Name }} {{ .Labels }}",
})
cmd := newConfigListCommand(cli)
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "config-list-with-config-format.golden")
}
@ -125,15 +125,15 @@ func TestConfigListWithFormat(t *testing.T) {
})
cmd := newConfigListCommand(cli)
cmd.Flags().Set("format", "{{ .Name }} {{ .Labels }}")
assert.NoError(t, cmd.Execute())
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.Equal(t, "foo", options.Filters.Get("name")[0])
assert.Equal(t, "lbl1=Label-bar", options.Filters.Get("label")[0])
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"),
@ -153,6 +153,6 @@ func TestConfigListWithFilter(t *testing.T) {
cmd := newConfigListCommand(cli)
cmd.Flags().Set("filter", "name=foo")
cmd.Flags().Set("filter", "label=lbl1=Label-bar")
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "config-list-with-filter.golden")
}

View File

@ -6,9 +6,9 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
func TestConfigRemoveErrors(t *testing.T) {
@ -37,7 +37,7 @@ func TestConfigRemoveErrors(t *testing.T) {
)
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -52,9 +52,9 @@ func TestConfigRemoveWithName(t *testing.T) {
})
cmd := newConfigRemoveCommand(cli)
cmd.SetArgs(names)
assert.NoError(t, cmd.Execute())
assert.Equal(t, names, strings.Split(strings.TrimSpace(cli.OutBuffer().String()), "\n"))
assert.Equal(t, names, removedConfigs)
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) {
@ -74,6 +74,6 @@ func TestConfigRemoveContinueAfterError(t *testing.T) {
cmd := newConfigRemoveCommand(cli)
cmd.SetArgs(names)
cmd.SetOutput(ioutil.Discard)
assert.EqualError(t, cmd.Execute(), "error removing config: foo")
assert.Equal(t, names, removedConfigs)
assert.Error(t, cmd.Execute(), "error removing config: foo")
assert.Check(t, is.DeepEqual(names, removedConfigs))
}

View File

@ -7,11 +7,10 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
func TestNewAttachCommandErrors(t *testing.T) {
@ -74,7 +73,7 @@ func TestNewAttachCommandErrors(t *testing.T) {
cmd := NewAttachCommand(test.NewFakeCli(&fakeClient{inspectFunc: tc.containerInspectFunc}))
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -101,9 +100,7 @@ func TestGetExitStatus(t *testing.T) {
},
{
result: &container.ContainerWaitOKBody{
Error: &container.ContainerWaitOKBodyError{
expectedErr.Error(),
},
Error: &container.ContainerWaitOKBodyError{expectedErr.Error()},
},
expectedError: expectedErr,
},
@ -123,6 +120,10 @@ func TestGetExitStatus(t *testing.T) {
resultC <- *testcase.result
}
err := getExitStatus(errC, resultC)
assert.Equal(t, testcase.expectedError, err)
if testcase.expectedError == nil {
assert.NilError(t, err)
} else {
assert.Error(t, err, testcase.expectedError.Error())
}
}
}

View File

@ -9,13 +9,12 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/archive"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/fs"
"github.com/gotestyourself/gotestyourself/skip"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestRunCopyWithInvalidArguments(t *testing.T) {
@ -44,7 +43,7 @@ func TestRunCopyWithInvalidArguments(t *testing.T) {
for _, testcase := range testcases {
t.Run(testcase.doc, func(t *testing.T) {
err := runCopy(test.NewFakeCli(nil), testcase.options)
assert.EqualError(t, err, testcase.expectedErr)
assert.Error(t, err, testcase.expectedErr)
})
}
}
@ -54,16 +53,16 @@ func TestRunCopyFromContainerToStdout(t *testing.T) {
fakeClient := &fakeClient{
containerCopyFromFunc: func(container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) {
assert.Equal(t, "container", container)
assert.Check(t, is.Equal("container", container))
return ioutil.NopCloser(strings.NewReader(tarContent)), types.ContainerPathStat{}, nil
},
}
options := copyOptions{source: "container:/path", destination: "-"}
cli := test.NewFakeCli(fakeClient)
err := runCopy(cli, options)
require.NoError(t, err)
assert.Equal(t, tarContent, cli.OutBuffer().String())
assert.Equal(t, "", cli.ErrBuffer().String())
assert.NilError(t, err)
assert.Check(t, is.Equal(tarContent, cli.OutBuffer().String()))
assert.Check(t, is.Equal("", cli.ErrBuffer().String()))
}
func TestRunCopyFromContainerToFilesystem(t *testing.T) {
@ -73,7 +72,7 @@ func TestRunCopyFromContainerToFilesystem(t *testing.T) {
fakeClient := &fakeClient{
containerCopyFromFunc: func(container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) {
assert.Equal(t, "container", container)
assert.Check(t, is.Equal("container", container))
readCloser, err := archive.TarWithOptions(destDir.Path(), &archive.TarOptions{})
return readCloser, types.ContainerPathStat{}, err
},
@ -81,13 +80,13 @@ func TestRunCopyFromContainerToFilesystem(t *testing.T) {
options := copyOptions{source: "container:/path", destination: destDir.Path()}
cli := test.NewFakeCli(fakeClient)
err := runCopy(cli, options)
require.NoError(t, err)
assert.Equal(t, "", cli.OutBuffer().String())
assert.Equal(t, "", cli.ErrBuffer().String())
assert.NilError(t, err)
assert.Check(t, is.Equal("", cli.OutBuffer().String()))
assert.Check(t, is.Equal("", cli.ErrBuffer().String()))
content, err := ioutil.ReadFile(destDir.Join("file1"))
require.NoError(t, err)
assert.Equal(t, "content\n", string(content))
assert.NilError(t, err)
assert.Check(t, is.Equal("content\n", string(content)))
}
func TestRunCopyFromContainerToFilesystemMissingDestinationDirectory(t *testing.T) {
@ -97,7 +96,7 @@ func TestRunCopyFromContainerToFilesystemMissingDestinationDirectory(t *testing.
fakeClient := &fakeClient{
containerCopyFromFunc: func(container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) {
assert.Equal(t, "container", container)
assert.Check(t, is.Equal("container", container))
readCloser, err := archive.TarWithOptions(destDir.Path(), &archive.TarOptions{})
return readCloser, types.ContainerPathStat{}, err
},
@ -109,7 +108,7 @@ func TestRunCopyFromContainerToFilesystemMissingDestinationDirectory(t *testing.
}
cli := test.NewFakeCli(fakeClient)
err := runCopy(cli, options)
testutil.ErrorContains(t, err, destDir.Join("missing"))
assert.ErrorContains(t, err, destDir.Join("missing"))
}
func TestRunCopyToContainerFromFileWithTrailingSlash(t *testing.T) {
@ -122,7 +121,12 @@ func TestRunCopyToContainerFromFileWithTrailingSlash(t *testing.T) {
}
cli := test.NewFakeCli(&fakeClient{})
err := runCopy(cli, options)
testutil.ErrorContains(t, err, "not a directory")
expectedError := "not a directory"
if runtime.GOOS == "windows" {
expectedError = "The filename, directory name, or volume label syntax is incorrect"
}
assert.ErrorContains(t, err, expectedError)
}
func TestRunCopyToContainerSourceDoesNotExist(t *testing.T) {
@ -136,7 +140,7 @@ func TestRunCopyToContainerSourceDoesNotExist(t *testing.T) {
if runtime.GOOS == "windows" {
expected = "cannot find the file specified"
}
testutil.ErrorContains(t, err, expected)
assert.ErrorContains(t, err, expected)
}
func TestSplitCpArg(t *testing.T) {
@ -181,8 +185,8 @@ func TestSplitCpArg(t *testing.T) {
skip.IfCondition(t, testcase.os != "" && testcase.os != runtime.GOOS)
container, path := splitCpArg(testcase.path)
assert.Equal(t, testcase.expectedContainer, container)
assert.Equal(t, testcase.expectedPath, path)
assert.Check(t, is.Equal(testcase.expectedContainer, container))
assert.Check(t, is.Equal(testcase.expectedPath, path))
})
}
}

View File

@ -21,8 +21,9 @@ import (
)
type createOptions struct {
name string
platform string
name string
platform string
untrusted bool
}
// NewCreateCommand creates a new cobra.Command for `docker create`
@ -53,7 +54,7 @@ func NewCreateCommand(dockerCli command.Cli) *cobra.Command {
flags.Bool("help", false, "Print usage")
command.AddPlatformFlag(flags, &opts.platform)
command.AddTrustVerificationFlags(flags)
command.AddTrustVerificationFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled())
copts = addFlags(flags)
return cmd
}
@ -64,7 +65,7 @@ func runCreate(dockerCli command.Cli, flags *pflag.FlagSet, opts *createOptions,
reportError(dockerCli.Err(), "create", err.Error(), true)
return cli.StatusError{StatusCode: 125}
}
response, err := createContainer(context.Background(), dockerCli, containerConfig, opts.name, opts.platform)
response, err := createContainer(context.Background(), dockerCli, containerConfig, opts)
if err != nil {
return err
}
@ -158,7 +159,7 @@ func newCIDFile(path string) (*cidFile, error) {
return &cidFile{path: path, file: f}, nil
}
func createContainer(ctx context.Context, dockerCli command.Cli, containerConfig *containerConfig, name string, platform string) (*container.ContainerCreateCreatedBody, error) {
func createContainer(ctx context.Context, dockerCli command.Cli, containerConfig *containerConfig, opts *createOptions) (*container.ContainerCreateCreatedBody, error) {
config := containerConfig.Config
hostConfig := containerConfig.HostConfig
networkingConfig := containerConfig.NetworkingConfig
@ -182,7 +183,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerConfig
if named, ok := ref.(reference.Named); ok {
namedRef = reference.TagNameOnly(named)
if taggedRef, ok := namedRef.(reference.NamedTagged); ok && command.IsTrusted() {
if taggedRef, ok := namedRef.(reference.NamedTagged); ok && !opts.untrusted {
var err error
trustedRef, err = image.TrustedReference(ctx, dockerCli, taggedRef, nil)
if err != nil {
@ -193,7 +194,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerConfig
}
//create the container
response, err := dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, name)
response, err := dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, opts.name)
//if image not found try to pull it
if err != nil {
@ -201,7 +202,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerConfig
fmt.Fprintf(stderr, "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef))
// we don't want to write to stdout anything apart from container.ID
if err := pullImage(ctx, dockerCli, config.Image, platform, stderr); err != nil {
if err := pullImage(ctx, dockerCli, config.Image, opts.platform, stderr); err != nil {
return nil, err
}
if taggedRef, ok := namedRef.(reference.NamedTagged); ok && trustedRef != nil {
@ -211,7 +212,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerConfig
}
// Retry
var retryErr error
response, retryErr = dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, name)
response, retryErr = dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, opts.name)
if retryErr != nil {
return nil, retryErr
}

View File

@ -2,6 +2,7 @@ package container
import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
@ -10,23 +11,24 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/cli/internal/test/notary"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/google/go-cmp/cmp"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/fs"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCIDFileNoOPWithNoFilename(t *testing.T) {
file, err := newCIDFile("")
require.NoError(t, err)
assert.Equal(t, &cidFile{}, file)
assert.NilError(t, err)
assert.DeepEqual(t, &cidFile{}, file, cmp.AllowUnexported(cidFile{}))
assert.NoError(t, file.Write("id"))
assert.NoError(t, file.Close())
assert.NilError(t, file.Write("id"))
assert.NilError(t, file.Close())
}
func TestNewCIDFileWhenFileAlreadyExists(t *testing.T) {
@ -34,7 +36,7 @@ func TestNewCIDFileWhenFileAlreadyExists(t *testing.T) {
defer tempfile.Remove()
_, err := newCIDFile(tempfile.Path())
testutil.ErrorContains(t, err, "Container ID file found")
assert.ErrorContains(t, err, "Container ID file found")
}
func TestCIDFileCloseWithNoWrite(t *testing.T) {
@ -43,12 +45,12 @@ func TestCIDFileCloseWithNoWrite(t *testing.T) {
path := tempdir.Join("cidfile")
file, err := newCIDFile(path)
require.NoError(t, err)
assert.Equal(t, file.path, path)
assert.NilError(t, err)
assert.Check(t, is.Equal(file.path, path))
assert.NoError(t, file.Close())
assert.NilError(t, file.Close())
_, err = os.Stat(path)
assert.True(t, os.IsNotExist(err))
assert.Check(t, os.IsNotExist(err))
}
func TestCIDFileCloseWithWrite(t *testing.T) {
@ -57,18 +59,18 @@ func TestCIDFileCloseWithWrite(t *testing.T) {
path := tempdir.Join("cidfile")
file, err := newCIDFile(path)
require.NoError(t, err)
assert.NilError(t, err)
content := "id"
assert.NoError(t, file.Write(content))
assert.NilError(t, file.Write(content))
actual, err := ioutil.ReadFile(path)
require.NoError(t, err)
assert.Equal(t, content, string(actual))
assert.NilError(t, err)
assert.Check(t, is.Equal(content, string(actual)))
assert.NoError(t, file.Close())
assert.NilError(t, file.Close())
_, err = os.Stat(path)
require.NoError(t, err)
assert.NilError(t, err)
}
func TestCreateContainerPullsImageIfMissing(t *testing.T) {
@ -107,12 +109,61 @@ func TestCreateContainerPullsImageIfMissing(t *testing.T) {
},
HostConfig: &container.HostConfig{},
}
body, err := createContainer(context.Background(), cli, config, "name", runtime.GOOS)
require.NoError(t, err)
body, err := createContainer(context.Background(), cli, config, &createOptions{
name: "name",
platform: runtime.GOOS,
untrusted: true,
})
assert.NilError(t, err)
expected := container.ContainerCreateCreatedBody{ID: containerID}
assert.Equal(t, expected, *body)
assert.Check(t, is.DeepEqual(expected, *body))
stderr := cli.ErrBuffer().String()
assert.Contains(t, stderr, "Unable to find image 'does-not-exist-locally:latest' locally")
assert.Check(t, is.Contains(stderr, "Unable to find image 'does-not-exist-locally:latest' locally"))
}
func TestNewCreateCommandWithContentTrustErrors(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 := NewCreateCommand(cli)
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
err := cmd.Execute()
assert.ErrorContains(t, err, tc.expectedError)
}
}
type fakeNotFound struct{}

View File

@ -7,11 +7,11 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
@ -106,7 +106,7 @@ func TestParseExec(t *testing.T) {
for _, testcase := range testcases {
execConfig := parseExec(testcase.options, &testcase.configFile)
assert.Equal(t, testcase.expected, *execConfig)
assert.Check(t, is.DeepEqual(testcase.expected, *execConfig))
}
}
@ -150,14 +150,14 @@ func TestRunExec(t *testing.T) {
err := runExec(cli, testcase.options)
if testcase.expectedError != "" {
testutil.ErrorContains(t, err, testcase.expectedError)
assert.ErrorContains(t, err, testcase.expectedError)
} else {
if !assert.NoError(t, err) {
if !assert.Check(t, err) {
return
}
}
assert.Equal(t, testcase.expectedOut, cli.OutBuffer().String())
assert.Equal(t, testcase.expectedErr, cli.ErrBuffer().String())
assert.Check(t, is.Equal(testcase.expectedOut, cli.OutBuffer().String()))
assert.Check(t, is.Equal(testcase.expectedErr, cli.ErrBuffer().String()))
})
}
}
@ -192,12 +192,12 @@ func TestGetExecExitStatus(t *testing.T) {
for _, testcase := range testcases {
client := &fakeClient{
execInspectFunc: func(id string) (types.ContainerExecInspect, error) {
assert.Equal(t, execID, id)
assert.Check(t, is.Equal(execID, id))
return types.ContainerExecInspect{ExitCode: testcase.exitCode}, testcase.inspectError
},
}
err := getExecExitStatus(context.Background(), client, execID)
assert.Equal(t, testcase.expectedError, err)
assert.Check(t, is.Equal(testcase.expectedError, err))
}
}
@ -222,6 +222,6 @@ func TestNewExecCommandErrors(t *testing.T) {
cmd := NewExecCommand(cli)
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}

View File

@ -7,11 +7,10 @@ import (
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/stretchr/testify/assert"
// Import builders to get the builder function as package function
. "github.com/docker/cli/internal/test/builders"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/golden"
)
@ -52,7 +51,7 @@ func TestContainerListErrors(t *testing.T) {
cmd.Flags().Set(key, value)
}
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -69,7 +68,7 @@ func TestContainerListWithoutFormat(t *testing.T) {
},
})
cmd := newListCommand(cli)
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "container-list-without-format.golden")
}
@ -84,7 +83,7 @@ func TestContainerListNoTrunc(t *testing.T) {
})
cmd := newListCommand(cli)
cmd.Flags().Set("no-trunc", "true")
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "container-list-without-format-no-trunc.golden")
}
@ -100,7 +99,7 @@ func TestContainerListNamesMultipleTime(t *testing.T) {
})
cmd := newListCommand(cli)
cmd.Flags().Set("format", "{{.Names}} {{.Names}}")
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "container-list-format-name-name.golden")
}
@ -116,20 +115,20 @@ func TestContainerListFormatTemplateWithArg(t *testing.T) {
})
cmd := newListCommand(cli)
cmd.Flags().Set("format", `{{.Names}} {{.Label "some.label"}}`)
assert.NoError(t, cmd.Execute())
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.True(t, options.Size)
assert.Check(t, options.Size)
return []types.Container{}, nil
},
})
cmd := newListCommand(cli)
cmd.Flags().Set("format", `{{.Size}}`)
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}
func TestContainerListWithConfigFormat(t *testing.T) {
@ -145,7 +144,7 @@ func TestContainerListWithConfigFormat(t *testing.T) {
PsFormat: "{{ .Names }} {{ .Image }} {{ .Labels }}",
})
cmd := newListCommand(cli)
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "container-list-with-config-format.golden")
}
@ -160,6 +159,6 @@ func TestContainerListWithFormat(t *testing.T) {
})
cmd := newListCommand(cli)
cmd.Flags().Set("format", "{{ .Names }} {{ .Image }} {{ .Labels }}")
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "container-list-with-format.golden")
}

View File

@ -7,10 +7,10 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
var logFn = func(expectedOut string) func(string, types.ContainerLogsOptions) (io.ReadCloser, error) {
@ -49,14 +49,14 @@ func TestRunLogs(t *testing.T) {
err := runLogs(cli, testcase.options)
if testcase.expectedError != "" {
testutil.ErrorContains(t, err, testcase.expectedError)
assert.ErrorContains(t, err, testcase.expectedError)
} else {
if !assert.NoError(t, err) {
if !assert.Check(t, err) {
return
}
}
assert.Equal(t, testcase.expectedOut, cli.OutBuffer().String())
assert.Equal(t, testcase.expectedErr, cli.ErrBuffer().String())
assert.Check(t, is.Equal(testcase.expectedOut, cli.OutBuffer().String()))
assert.Check(t, is.Equal(testcase.expectedErr, cli.ErrBuffer().String()))
})
}
}

View File

@ -9,14 +9,13 @@ import (
"testing"
"time"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types/container"
networktypes "github.com/docker/docker/api/types/network"
"github.com/docker/go-connections/nat"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors"
"github.com/spf13/pflag"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestValidateAttach(t *testing.T) {
@ -67,12 +66,12 @@ func setupRunFlags() (*pflag.FlagSet, *containerOptions) {
func parseMustError(t *testing.T, args string) {
_, _, _, err := parseRun(strings.Split(args+" ubuntu bash", " "))
assert.Error(t, err, args)
assert.ErrorContains(t, err, "", args)
}
func mustParse(t *testing.T, args string) (*container.Config, *container.HostConfig) {
config, hostConfig, _, err := parseRun(append(strings.Split(args, " "), "ubuntu", "bash"))
assert.NoError(t, err)
assert.NilError(t, err)
return config, hostConfig
}
@ -236,23 +235,23 @@ func TestRunFlagsParseWithMemory(t *testing.T) {
flags, _ := setupRunFlags()
args := []string{"--memory=invalid", "img", "cmd"}
err := flags.Parse(args)
testutil.ErrorContains(t, err, `invalid argument "invalid" for "-m, --memory" flag`)
assert.ErrorContains(t, err, `invalid argument "invalid" for "-m, --memory" flag`)
_, hostconfig := mustParse(t, "--memory=1G")
assert.Equal(t, int64(1073741824), hostconfig.Memory)
assert.Check(t, is.Equal(int64(1073741824), hostconfig.Memory))
}
func TestParseWithMemorySwap(t *testing.T) {
flags, _ := setupRunFlags()
args := []string{"--memory-swap=invalid", "img", "cmd"}
err := flags.Parse(args)
testutil.ErrorContains(t, err, `invalid argument "invalid" for "--memory-swap" flag`)
assert.ErrorContains(t, err, `invalid argument "invalid" for "--memory-swap" flag`)
_, hostconfig := mustParse(t, "--memory-swap=1G")
assert.Equal(t, int64(1073741824), hostconfig.MemorySwap)
assert.Check(t, is.Equal(int64(1073741824), hostconfig.MemorySwap))
_, hostconfig = mustParse(t, "--memory-swap=-1")
assert.Equal(t, int64(-1), hostconfig.MemorySwap)
assert.Check(t, is.Equal(int64(-1), hostconfig.MemorySwap))
}
func TestParseHostname(t *testing.T) {
@ -373,24 +372,24 @@ func TestParseModes(t *testing.T) {
// pid ko
flags, copts := setupRunFlags()
args := []string{"--pid=container:", "img", "cmd"}
require.NoError(t, flags.Parse(args))
assert.NilError(t, flags.Parse(args))
_, err := parse(flags, copts)
testutil.ErrorContains(t, err, "--pid: invalid PID mode")
assert.ErrorContains(t, err, "--pid: invalid PID mode")
// pid ok
_, hostconfig, _, err := parseRun([]string{"--pid=host", "img", "cmd"})
require.NoError(t, err)
assert.NilError(t, err)
if !hostconfig.PidMode.Valid() {
t.Fatalf("Expected a valid PidMode, got %v", hostconfig.PidMode)
}
// uts ko
_, _, _, err = parseRun([]string{"--uts=container:", "img", "cmd"})
testutil.ErrorContains(t, err, "--uts: invalid UTS mode")
assert.ErrorContains(t, err, "--uts: invalid UTS mode")
// uts ok
_, hostconfig, _, err = parseRun([]string{"--uts=host", "img", "cmd"})
require.NoError(t, err)
assert.NilError(t, err)
if !hostconfig.UTSMode.Valid() {
t.Fatalf("Expected a valid UTSMode, got %v", hostconfig.UTSMode)
}
@ -402,11 +401,11 @@ func TestRunFlagsParseShmSize(t *testing.T) {
args := []string{"--shm-size=a128m", "img", "cmd"}
expectedErr := `invalid argument "a128m" for "--shm-size" flag: invalid size: 'a128m'`
err := flags.Parse(args)
testutil.ErrorContains(t, err, expectedErr)
assert.ErrorContains(t, err, expectedErr)
// shm-size ok
_, hostconfig, _, err := parseRun([]string{"--shm-size=128m", "img", "cmd"})
require.NoError(t, err)
assert.NilError(t, err)
if hostconfig.ShmSize != 134217728 {
t.Fatalf("Expected a valid ShmSize, got %d", hostconfig.ShmSize)
}

View File

@ -4,13 +4,14 @@ import (
"testing"
"github.com/docker/cli/opts"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestBuildContainerListOptions(t *testing.T) {
filters := opts.NewFilterOpt()
assert.NoError(t, filters.Set("foo=bar"))
assert.NoError(t, filters.Set("baz=foo"))
assert.NilError(t, filters.Set("foo=bar"))
assert.NilError(t, filters.Set("baz=foo"))
contexts := []struct {
psOpts *psOptions
@ -101,12 +102,12 @@ func TestBuildContainerListOptions(t *testing.T) {
for _, c := range contexts {
options, err := buildContainerListOptions(c.psOpts)
assert.NoError(t, err)
assert.NilError(t, err)
assert.Equal(t, c.expectedAll, options.All)
assert.Equal(t, c.expectedSize, options.Size)
assert.Equal(t, c.expectedLimit, options.Limit)
assert.Equal(t, len(c.expectedFilters), options.Filters.Len())
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

View File

@ -25,11 +25,10 @@ import (
)
type runOptions struct {
createOptions
detach bool
sigProxy bool
name string
detachKeys string
platform string
}
// NewRunCommand create a new `docker run` command
@ -64,7 +63,7 @@ func NewRunCommand(dockerCli command.Cli) *cobra.Command {
flags.Bool("help", false, "Print usage")
command.AddPlatformFlag(flags, &opts.platform)
command.AddTrustVerificationFlags(flags)
command.AddTrustVerificationFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled())
copts = addFlags(flags)
return cmd
}
@ -162,7 +161,7 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio
ctx, cancelFun := context.WithCancel(context.Background())
createResponse, err := createContainer(ctx, dockerCli, containerConfig, opts.name, opts.platform)
createResponse, err := createContainer(ctx, dockerCli, containerConfig, &opts.createOptions)
if err != nil {
reportError(stderr, cmdPath, err.Error(), true)
return runStartContainerErr(err)

View File

@ -1,12 +1,15 @@
package container
import (
"fmt"
"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"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestRunLabel(t *testing.T) {
@ -21,5 +24,50 @@ func TestRunLabel(t *testing.T) {
cmd := NewRunCommand(cli)
cmd.Flags().Set("detach", "true")
cmd.SetArgs([]string{"--label", "foo", "busybox"})
assert.NoError(t, cmd.Execute())
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)
err := cmd.Execute()
assert.Assert(t, err != nil)
assert.Assert(t, is.Contains(cli.ErrBuffer().String(), tc.expectedError))
}
}

View File

@ -1,10 +1,11 @@
package container
import (
"fmt"
"testing"
"github.com/docker/docker/api/types"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
)
func TestCalculateMemUsageUnixNoCache(t *testing.T) {
@ -15,7 +16,7 @@ func TestCalculateMemUsageUnixNoCache(t *testing.T) {
result := calculateMemUsageUnixNoCache(stats)
// Then
assert.InDelta(t, 100.0, result, 1e-6)
assert.Assert(t, inDelta(100.0, result, 1e-6))
}
func TestCalculateMemPercentUnixNoCache(t *testing.T) {
@ -27,10 +28,20 @@ func TestCalculateMemPercentUnixNoCache(t *testing.T) {
// When and Then
t.Run("Limit is set", func(t *testing.T) {
result := calculateMemPercentUnixNoCache(someLimit, used)
assert.InDelta(t, 70.0, result, 1e-6)
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.InDelta(t, 0.0, result, 1e-6)
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, ""
}
}

View File

@ -7,8 +7,9 @@ import (
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api"
"github.com/docker/docker/api/types/container"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
@ -64,6 +65,6 @@ func TestWaitExitOrRemoved(t *testing.T) {
for _, testcase := range testcases {
statusC := waitExitOrRemoved(context.Background(), client, testcase.cid, true)
exitCode := <-statusC
assert.Equal(t, testcase.exitCode, exitCode)
assert.Check(t, is.Equal(testcase.exitCode, exitCode))
}
}

View File

@ -5,7 +5,7 @@ import (
"testing"
"github.com/docker/docker/api/types"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
)
func TestCheckpointContextFormatWrite(t *testing.T) {
@ -46,10 +46,7 @@ checkpoint-3:
out := bytes.NewBufferString("")
testcase.context.Output = out
err := CheckpointWrite(testcase.context, checkpoints)
if err != nil {
assert.Error(t, err, testcase.expected)
} else {
assert.Equal(t, out.String(), testcase.expected)
}
assert.NilError(t, err)
assert.Equal(t, out.String(), testcase.expected)
}
}

View File

@ -6,7 +6,8 @@ import (
"time"
"github.com/docker/docker/api/types/swarm"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestConfigContextFormatWrite(t *testing.T) {
@ -55,9 +56,9 @@ id_rsa
out := bytes.NewBufferString("")
testcase.context.Output = out
if err := ConfigWrite(testcase.context, configs); err != nil {
assert.Error(t, err, testcase.expected)
assert.ErrorContains(t, err, testcase.expected)
} else {
assert.Equal(t, out.String(), testcase.expected)
assert.Check(t, is.Equal(out.String(), testcase.expected))
}
}
}

View File

@ -10,9 +10,9 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/stringid"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestContainerPsContext(t *testing.T) {
@ -244,9 +244,9 @@ size: 0B
testcase.context.Output = out
err := ContainerWrite(testcase.context, containers)
if err != nil {
assert.EqualError(t, err, testcase.expected)
assert.Error(t, err, testcase.expected)
} else {
assert.Equal(t, testcase.expected, out.String())
assert.Check(t, is.Equal(testcase.expected, out.String()))
}
}
}
@ -305,7 +305,7 @@ func TestContainerContextWriteWithNoContainers(t *testing.T) {
for _, context := range contexts {
ContainerWrite(context.context, containers)
assert.Equal(t, context.expected, out.String())
assert.Check(t, is.Equal(context.expected, out.String()))
// Clean buffer
out.Reset()
}
@ -359,8 +359,8 @@ func TestContainerContextWriteJSON(t *testing.T) {
msg := fmt.Sprintf("Output: line %d: %s", i, line)
var m map[string]interface{}
err := json.Unmarshal([]byte(line), &m)
require.NoError(t, err, msg)
assert.Equal(t, expectedJSONs[i], m, msg)
assert.NilError(t, err, msg)
assert.Check(t, is.DeepEqual(expectedJSONs[i], m), msg)
}
}
@ -378,8 +378,8 @@ func TestContainerContextWriteJSONField(t *testing.T) {
msg := fmt.Sprintf("Output: line %d: %s", i, line)
var s string
err := json.Unmarshal([]byte(line), &s)
require.NoError(t, err, msg)
assert.Equal(t, containers[i].ID, s, msg)
assert.NilError(t, err, msg)
assert.Check(t, is.Equal(containers[i].ID, s), msg)
}
}
@ -653,6 +653,6 @@ func TestDisplayablePorts(t *testing.T) {
for _, port := range cases {
actual := DisplayablePorts(port.ports)
assert.Equal(t, port.expected, actual)
assert.Check(t, is.Equal(port.expected, actual))
}
}

View File

@ -4,7 +4,8 @@ import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func compareMultipleValues(t *testing.T, value, expected string) {
@ -23,5 +24,5 @@ func compareMultipleValues(t *testing.T, value, expected string) {
keyval := strings.Split(expected, "=")
expMap[keyval[0]] = keyval[1]
}
assert.Equal(t, expMap, entriesMap)
assert.Check(t, is.DeepEqual(expMap, entriesMap))
}

View File

@ -6,7 +6,8 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/pkg/archive"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestDiffContextFormatWrite(t *testing.T) {
@ -51,9 +52,9 @@ D: /usr/app/old_app.js
testcase.context.Output = out
err := DiffWrite(testcase.context, diffs)
if err != nil {
assert.EqualError(t, err, testcase.expected)
assert.Error(t, err, testcase.expected)
} else {
assert.Equal(t, testcase.expected, out.String())
assert.Check(t, is.Equal(testcase.expected, out.String()))
}
}
}

View File

@ -4,8 +4,9 @@ import (
"bytes"
"testing"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
)
func TestDiskUsageContextFormatWrite(t *testing.T) {
@ -101,9 +102,9 @@ Build Cache 0B
out := bytes.NewBufferString("")
testcase.context.Output = out
if err := testcase.context.Write(); err != nil {
assert.Equal(t, testcase.expected, err.Error())
assert.Check(t, is.Equal(testcase.expected, err.Error()))
} else {
assert.Equal(t, testcase.expected, out.String())
assert.Check(t, is.Equal(testcase.expected, out.String()))
}
}
}

View File

@ -3,7 +3,8 @@ package formatter
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestEllipsis(t *testing.T) {
@ -25,6 +26,6 @@ func TestEllipsis(t *testing.T) {
}
for _, testcase := range testcases {
assert.Equal(t, testcase.expected, Ellipsis(testcase.source, testcase.width))
assert.Check(t, is.Equal(testcase.expected, Ellipsis(testcase.source, testcase.width)))
}
}

View File

@ -1,16 +1,16 @@
package formatter
import (
"bytes"
"strconv"
"strings"
"testing"
"time"
"bytes"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/pkg/stringid"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
type historyCase struct {
@ -50,6 +50,7 @@ func TestHistoryContext_ID(t *testing.T) {
}
func TestHistoryContext_CreatedSince(t *testing.T) {
dateStr := "2009-11-10T23:00:00Z"
var ctx historyContext
cases := []historyCase{
{
@ -64,7 +65,7 @@ func TestHistoryContext_CreatedSince(t *testing.T) {
h: image.HistoryResponseItem{Created: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()},
trunc: false,
human: false,
}, "2009-11-10T23:00:00Z", ctx.CreatedSince,
}, dateStr, ctx.CreatedSince,
},
}
@ -218,7 +219,7 @@ imageID4 24 hours ago /bin/bash grep
for _, context := range contexts {
HistoryWrite(context.context, true, histories)
assert.Equal(t, context.expected, out.String())
assert.Check(t, is.Equal(context.expected, out.String()))
// Clean buffer
out.Reset()
}

View File

@ -9,7 +9,8 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/stringid"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestImageContext(t *testing.T) {
@ -83,7 +84,7 @@ func TestImageContext(t *testing.T) {
if strings.Contains(v, ",") {
compareMultipleValues(t, v, c.expValue)
} else {
assert.Equal(t, c.expValue, v)
assert.Check(t, is.Equal(c.expValue, v))
}
}
}
@ -293,9 +294,9 @@ image_id: imageID3
testcase.context.Output = out
err := ImageWrite(testcase.context, images)
if err != nil {
assert.EqualError(t, err, testcase.expected)
assert.Error(t, err, testcase.expected)
} else {
assert.Equal(t, testcase.expected, out.String())
assert.Check(t, is.Equal(testcase.expected, out.String()))
}
}
}
@ -348,7 +349,7 @@ func TestImageContextWriteWithNoImage(t *testing.T) {
for _, context := range contexts {
ImageWrite(context.context, images)
assert.Equal(t, context.expected, out.String())
assert.Check(t, is.Equal(context.expected, out.String()))
// Clean buffer
out.Reset()
}

View File

@ -10,8 +10,8 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/stringid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestNetworkContext(t *testing.T) {
@ -162,9 +162,9 @@ foobar_bar 2017-01-01 00:00:00 +0000 UTC
testcase.context.Output = out
err := NetworkWrite(testcase.context, networks)
if err != nil {
assert.EqualError(t, err, testcase.expected)
assert.Error(t, err, testcase.expected)
} else {
assert.Equal(t, testcase.expected, out.String())
assert.Check(t, is.Equal(testcase.expected, out.String()))
}
}
}
@ -188,8 +188,8 @@ func TestNetworkContextWriteJSON(t *testing.T) {
msg := fmt.Sprintf("Output: line %d: %s", i, line)
var m map[string]interface{}
err := json.Unmarshal([]byte(line), &m)
require.NoError(t, err, msg)
assert.Equal(t, expectedJSONs[i], m, msg)
assert.NilError(t, err, msg)
assert.Check(t, is.DeepEqual(expectedJSONs[i], m), msg)
}
}
@ -207,7 +207,7 @@ func TestNetworkContextWriteJSONField(t *testing.T) {
msg := fmt.Sprintf("Output: line %d: %s", i, line)
var s string
err := json.Unmarshal([]byte(line), &s)
require.NoError(t, err, msg)
assert.Equal(t, networks[i].ID, s, msg)
assert.NilError(t, err, msg)
assert.Check(t, is.Equal(networks[i].ID, s), msg)
}
}

View File

@ -10,8 +10,8 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/pkg/stringid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestNodeContext(t *testing.T) {
@ -203,9 +203,9 @@ foobar_boo Unknown
testcase.context.Output = out
err := NodeWrite(testcase.context, nodes, types.Info{Swarm: swarm.Info{Cluster: &testcase.clusterInfo}})
if err != nil {
assert.EqualError(t, err, testcase.expected)
assert.Error(t, err, testcase.expected)
} else {
assert.Equal(t, testcase.expected, out.String())
assert.Check(t, is.Equal(testcase.expected, out.String()))
}
}
}
@ -255,8 +255,8 @@ func TestNodeContextWriteJSON(t *testing.T) {
msg := fmt.Sprintf("Output: line %d: %s", i, line)
var m map[string]interface{}
err := json.Unmarshal([]byte(line), &m)
require.NoError(t, err, msg)
assert.Equal(t, testcase.expected[i], m, msg)
assert.NilError(t, err, msg)
assert.Check(t, is.DeepEqual(testcase.expected[i], m), msg)
}
}
}
@ -275,8 +275,8 @@ func TestNodeContextWriteJSONField(t *testing.T) {
msg := fmt.Sprintf("Output: line %d: %s", i, line)
var s string
err := json.Unmarshal([]byte(line), &s)
require.NoError(t, err, msg)
assert.Equal(t, nodes[i].ID, s, msg)
assert.NilError(t, err, msg)
assert.Check(t, is.Equal(nodes[i].ID, s), msg)
}
}
@ -344,5 +344,5 @@ data
Issuer Subject: c3ViamVjdA==
Issuer Public Key: cHViS2V5
`
assert.Equal(t, expected, out.String())
assert.Check(t, is.Equal(expected, out.String()))
}

View File

@ -8,7 +8,8 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/stringid"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestPluginContext(t *testing.T) {
@ -131,9 +132,9 @@ foobar_bar
testcase.context.Output = out
err := PluginWrite(testcase.context, plugins)
if err != nil {
assert.EqualError(t, err, testcase.expected)
assert.Error(t, err, testcase.expected)
} else {
assert.Equal(t, testcase.expected, out.String())
assert.Check(t, is.Equal(testcase.expected, out.String()))
}
}
}
@ -158,7 +159,7 @@ func TestPluginContextWriteJSON(t *testing.T) {
if err := json.Unmarshal([]byte(line), &m); err != nil {
t.Fatal(err)
}
assert.Equal(t, expectedJSONs[i], m)
assert.Check(t, is.DeepEqual(expectedJSONs[i], m))
}
}
@ -177,6 +178,6 @@ func TestPluginContextWriteJSONField(t *testing.T) {
if err := json.Unmarshal([]byte(line), &s); err != nil {
t.Fatal(err)
}
assert.Equal(t, plugins[i].ID, s)
assert.Check(t, is.Equal(plugins[i].ID, s))
}
}

View File

@ -7,8 +7,9 @@ import (
"testing"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
)
func TestSearchContext(t *testing.T) {
@ -154,9 +155,9 @@ result2 5
testcase.context.Output = out
err := SearchWrite(testcase.context, results, false, 0)
if err != nil {
assert.Error(t, err, testcase.expected)
assert.Check(t, is.ErrorContains(err, testcase.expected))
} else {
assert.Equal(t, out.String(), testcase.expected)
assert.Check(t, is.Equal(out.String(), testcase.expected))
}
}
}
@ -191,9 +192,9 @@ result2
testcase.context.Output = out
err := SearchWrite(testcase.context, results, true, 0)
if err != nil {
assert.Error(t, err, testcase.expected)
assert.Check(t, is.ErrorContains(err, testcase.expected))
} else {
assert.Equal(t, out.String(), testcase.expected)
assert.Check(t, is.Equal(out.String(), testcase.expected))
}
}
}
@ -226,9 +227,9 @@ result1
testcase.context.Output = out
err := SearchWrite(testcase.context, results, false, 6)
if err != nil {
assert.Error(t, err, testcase.expected)
assert.Check(t, is.ErrorContains(err, testcase.expected))
} else {
assert.Equal(t, out.String(), testcase.expected)
assert.Check(t, is.Equal(out.String(), testcase.expected))
}
}
}
@ -254,7 +255,7 @@ func TestSearchContextWriteJSON(t *testing.T) {
if err := json.Unmarshal([]byte(line), &m); err != nil {
t.Fatal(err)
}
assert.Equal(t, m, expectedJSONs[i])
assert.Check(t, is.DeepEqual(m, expectedJSONs[i]))
}
}
@ -274,6 +275,6 @@ func TestSearchContextWriteJSONField(t *testing.T) {
if err := json.Unmarshal([]byte(line), &s); err != nil {
t.Fatal(err)
}
assert.Equal(t, s, results[i].Name)
assert.Check(t, is.Equal(s, results[i].Name))
}
}

View File

@ -6,7 +6,8 @@ import (
"time"
"github.com/docker/docker/api/types/swarm"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestSecretContextFormatWrite(t *testing.T) {
@ -55,9 +56,9 @@ id_rsa
out := bytes.NewBufferString("")
testcase.context.Output = out
if err := SecretWrite(testcase.context, secrets); err != nil {
assert.EqualError(t, err, testcase.expected)
assert.Error(t, err, testcase.expected)
} else {
assert.Equal(t, testcase.expected, out.String())
assert.Check(t, is.Equal(testcase.expected, out.String()))
}
}
}

View File

@ -8,9 +8,9 @@ import (
"testing"
"github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestServiceContextWrite(t *testing.T) {
@ -126,9 +126,9 @@ bar
testcase.context.Output = out
err := ServiceListWrite(testcase.context, services, info)
if err != nil {
assert.EqualError(t, err, testcase.expected)
assert.Error(t, err, testcase.expected)
} else {
assert.Equal(t, testcase.expected, out.String())
assert.Check(t, is.Equal(testcase.expected, out.String()))
}
}
}
@ -192,8 +192,8 @@ func TestServiceContextWriteJSON(t *testing.T) {
msg := fmt.Sprintf("Output: line %d: %s", i, line)
var m map[string]interface{}
err := json.Unmarshal([]byte(line), &m)
require.NoError(t, err, msg)
assert.Equal(t, expectedJSONs[i], m, msg)
assert.NilError(t, err, msg)
assert.Check(t, is.DeepEqual(expectedJSONs[i], m), msg)
}
}
func TestServiceContextWriteJSONField(t *testing.T) {
@ -220,8 +220,8 @@ func TestServiceContextWriteJSONField(t *testing.T) {
msg := fmt.Sprintf("Output: line %d: %s", i, line)
var s string
err := json.Unmarshal([]byte(line), &s)
require.NoError(t, err, msg)
assert.Equal(t, services[i].Spec.Name, s, msg)
assert.NilError(t, err, msg)
assert.Check(t, is.Equal(services[i].Spec.Name, s), msg)
}
}
@ -355,5 +355,5 @@ func TestServiceContext_Ports(t *testing.T) {
},
}
assert.Equal(t, "*:97-98->97-98/sctp, *:60-61->60-61/tcp, *:62->61/tcp, *:80-81->80/tcp, *:90-95->90-95/tcp, *:90-96->90-96/udp", c.Ports())
assert.Check(t, is.Equal("*:97-98->97-98/sctp, *:60-61->60-61/tcp, *:62->61/tcp, *:80-81->80/tcp, *:90-95->90-95/tcp, *:90-96->90-96/udp", c.Ports()))
}

View File

@ -4,7 +4,8 @@ import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestStackContextWrite(t *testing.T) {
@ -56,9 +57,9 @@ bar
testcase.context.Output = out
err := StackWrite(testcase.context, stacks)
if err != nil {
assert.Error(t, err, testcase.expected)
assert.Check(t, is.ErrorContains(err, testcase.expected))
} else {
assert.Equal(t, out.String(), testcase.expected)
assert.Check(t, is.Equal(out.String(), testcase.expected))
}
}
}

View File

@ -5,7 +5,8 @@ import (
"testing"
"github.com/docker/docker/pkg/stringid"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestContainerStatsContext(t *testing.T) {
@ -116,9 +117,9 @@ container2 --
te.context.Output = &out
err := ContainerStatsWrite(te.context, stats, "linux", false)
if err != nil {
assert.EqualError(t, err, te.expected)
assert.Error(t, err, te.expected)
} else {
assert.Equal(t, te.expected, out.String())
assert.Check(t, is.Equal(te.expected, out.String()))
}
}
}
@ -182,9 +183,9 @@ container2 -- --
te.context.Output = &out
err := ContainerStatsWrite(te.context, stats, "windows", false)
if err != nil {
assert.EqualError(t, err, te.expected)
assert.Error(t, err, te.expected)
} else {
assert.Equal(t, te.expected, out.String())
assert.Check(t, is.Equal(te.expected, out.String()))
}
}
}
@ -221,7 +222,7 @@ func TestContainerStatsContextWriteWithNoStats(t *testing.T) {
for _, context := range contexts {
ContainerStatsWrite(context.context, []StatsEntry{}, "linux", false)
assert.Equal(t, context.expected, out.String())
assert.Check(t, is.Equal(context.expected, out.String()))
// Clean buffer
out.Reset()
}
@ -259,7 +260,7 @@ func TestContainerStatsContextWriteWithNoStatsWindows(t *testing.T) {
for _, context := range contexts {
ContainerStatsWrite(context.context, []StatsEntry{}, "windows", false)
assert.Equal(t, context.expected, out.String())
assert.Check(t, is.Equal(context.expected, out.String()))
// Clean buffer
out.Reset()
}
@ -293,7 +294,7 @@ func TestContainerStatsContextWriteTrunc(t *testing.T) {
for _, context := range contexts {
ContainerStatsWrite(context.context, []StatsEntry{{ID: "b95a83497c9161c9b444e3d70e1a9dfba0c1840d41720e146a95a08ebf938afc"}}, "linux", context.trunc)
assert.Equal(t, context.expected, out.String())
assert.Check(t, is.Equal(context.expected, out.String()))
// Clean buffer
out.Reset()
}

View File

@ -7,8 +7,9 @@ import (
"testing"
"github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
)
func TestTaskContextWrite(t *testing.T) {
@ -74,9 +75,9 @@ foobar_bar foo2
testcase.context.Output = out
err := TaskWrite(testcase.context, tasks, names, nodes)
if err != nil {
assert.EqualError(t, err, testcase.expected)
assert.Error(t, err, testcase.expected)
} else {
assert.Equal(t, testcase.expected, out.String())
assert.Check(t, is.Equal(testcase.expected, out.String()))
}
}
}
@ -100,6 +101,6 @@ func TestTaskContextWriteJSONField(t *testing.T) {
if err := json.Unmarshal([]byte(line), &s); err != nil {
t.Fatal(err)
}
assert.Equal(t, tasks[i].ID, s)
assert.Check(t, is.Equal(tasks[i].ID, s))
}
}

View File

@ -5,7 +5,8 @@ import (
"testing"
"github.com/docker/docker/pkg/stringid"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestTrustTag(t *testing.T) {
@ -126,9 +127,9 @@ tag3 bbbbbbbb
testcase.context.Output = out
err := TrustTagWrite(testcase.context, signedTags)
if err != nil {
assert.EqualError(t, err, testcase.expected)
assert.Error(t, err, testcase.expected)
} else {
assert.Equal(t, testcase.expected, out.String())
assert.Check(t, is.Equal(testcase.expected, out.String()))
}
}
}
@ -152,8 +153,8 @@ func TestTrustTagContextEmptyWrite(t *testing.T) {
out := bytes.NewBufferString("")
emptyCase.context.Output = out
err := TrustTagWrite(emptyCase.context, emptySignedTags)
assert.NoError(t, err)
assert.Equal(t, emptyCase.expected, out.String())
assert.NilError(t, err)
assert.Check(t, is.Equal(emptyCase.expected, out.String()))
}
func TestSignerInfoContextEmptyWrite(t *testing.T) {
@ -171,8 +172,8 @@ func TestSignerInfoContextEmptyWrite(t *testing.T) {
out := bytes.NewBufferString("")
emptyCase.context.Output = out
err := SignerInfoWrite(emptyCase.context, emptySignerInfo)
assert.NoError(t, err)
assert.Equal(t, emptyCase.expected, out.String())
assert.NilError(t, err)
assert.Check(t, is.Equal(emptyCase.expected, out.String()))
}
func TestSignerInfoContextWrite(t *testing.T) {
@ -230,9 +231,9 @@ eve foobarbazquxquux, key31, key32
testcase.context.Output = out
err := SignerInfoWrite(testcase.context, signerInfo)
if err != nil {
assert.EqualError(t, err, testcase.expected)
assert.Error(t, err, testcase.expected)
} else {
assert.Equal(t, testcase.expected, out.String())
assert.Check(t, is.Equal(testcase.expected, out.String()))
}
}
}

View File

@ -9,8 +9,8 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/stringid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestVolumeContext(t *testing.T) {
@ -133,9 +133,9 @@ foobar_bar
testcase.context.Output = out
err := VolumeWrite(testcase.context, volumes)
if err != nil {
assert.EqualError(t, err, testcase.expected)
assert.Error(t, err, testcase.expected)
} else {
assert.Equal(t, testcase.expected, out.String())
assert.Check(t, is.Equal(testcase.expected, out.String()))
}
}
}
@ -158,8 +158,8 @@ func TestVolumeContextWriteJSON(t *testing.T) {
msg := fmt.Sprintf("Output: line %d: %s", i, line)
var m map[string]interface{}
err := json.Unmarshal([]byte(line), &m)
require.NoError(t, err, msg)
assert.Equal(t, expectedJSONs[i], m, msg)
assert.NilError(t, err, msg)
assert.Check(t, is.DeepEqual(expectedJSONs[i], m), msg)
}
}
@ -177,7 +177,7 @@ func TestVolumeContextWriteJSONField(t *testing.T) {
msg := fmt.Sprintf("Output: line %d: %s", i, line)
var s string
err := json.Unmarshal([]byte(line), &s)
require.NoError(t, err, msg)
assert.Equal(t, volumes[i].Name, s, msg)
assert.NilError(t, err, msg)
assert.Check(t, is.Equal(volumes[i].Name, s), msg)
}
}

View File

@ -4,10 +4,11 @@ import (
"testing"
"github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
// Import builders to get the builder function as package function
. "github.com/docker/cli/internal/test/builders"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
@ -21,7 +22,7 @@ func TestResolveError(t *testing.T) {
idResolver := New(cli, false)
_, err := idResolver.Resolve(context.Background(), struct{}{}, "nodeID")
assert.EqualError(t, err, "unsupported type")
assert.Error(t, err, "unsupported type")
}
func TestResolveWithNoResolveOption(t *testing.T) {
@ -40,9 +41,9 @@ func TestResolveWithNoResolveOption(t *testing.T) {
idResolver := New(cli, true)
id, err := idResolver.Resolve(context.Background(), swarm.Node{}, "nodeID")
assert.NoError(t, err)
assert.Equal(t, "nodeID", id)
assert.False(t, resolved)
assert.NilError(t, err)
assert.Check(t, is.Equal("nodeID", id))
assert.Check(t, !resolved)
}
func TestResolveWithCache(t *testing.T) {
@ -59,11 +60,11 @@ func TestResolveWithCache(t *testing.T) {
ctx := context.Background()
for i := 0; i < 2; i++ {
id, err := idResolver.Resolve(ctx, swarm.Node{}, "nodeID")
assert.NoError(t, err)
assert.Equal(t, "node-foo", id)
assert.NilError(t, err)
assert.Check(t, is.Equal("node-foo", id))
}
assert.Equal(t, 1, inspectCounter)
assert.Check(t, is.Equal(1, inspectCounter))
}
func TestResolveNode(t *testing.T) {
@ -103,8 +104,8 @@ func TestResolveNode(t *testing.T) {
idResolver := New(cli, false)
id, err := idResolver.Resolve(ctx, swarm.Node{}, tc.nodeID)
assert.NoError(t, err)
assert.Equal(t, tc.expectedID, id)
assert.NilError(t, err)
assert.Check(t, is.Equal(tc.expectedID, id))
}
}
@ -138,7 +139,7 @@ func TestResolveService(t *testing.T) {
idResolver := New(cli, false)
id, err := idResolver.Resolve(ctx, swarm.Service{}, tc.serviceID)
assert.NoError(t, err)
assert.Equal(t, tc.expectedID, id)
assert.NilError(t, err)
assert.Check(t, is.Equal(tc.expectedID, id))
}
}

View File

@ -67,6 +67,7 @@ type buildOptions struct {
imageIDFile string
stream bool
platform string
untrusted bool
}
// dockerfileFromStdin returns true when the user specified that the Dockerfile
@ -137,7 +138,7 @@ func NewBuildCommand(dockerCli command.Cli) *cobra.Command {
flags.StringVar(&options.target, "target", "", "Set the target build stage to build.")
flags.StringVar(&options.imageIDFile, "iidfile", "", "Write the image ID to the file")
command.AddTrustVerificationFlags(flags)
command.AddTrustVerificationFlags(flags, &options.untrusted, dockerCli.ContentTrustEnabled())
command.AddPlatformFlag(flags, &options.platform)
flags.BoolVar(&options.squash, "squash", false, "Squash newly built layers into a single new layer")
@ -285,7 +286,7 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
defer cancel()
var resolvedTags []*resolvedTag
if command.IsTrusted() {
if !options.untrusted {
translator := func(ctx context.Context, ref reference.NamedTagged) (reference.Canonical, error) {
return TrustedReference(ctx, dockerCli, ref, nil)
}
@ -293,10 +294,10 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
if buildCtx != nil {
// Wrap the tar archive to replace the Dockerfile entry with the rewritten
// Dockerfile which uses trusted pulls.
buildCtx = replaceDockerfileTarWrapper(ctx, buildCtx, relDockerfile, translator, &resolvedTags)
buildCtx = replaceDockerfileForContentTrust(ctx, buildCtx, relDockerfile, translator, &resolvedTags)
} else if dockerfileCtx != nil {
// if there was not archive context still do the possible replacements in Dockerfile
newDockerfile, _, err := rewriteDockerfileFrom(ctx, dockerfileCtx, translator)
newDockerfile, _, err := rewriteDockerfileFromForContentTrust(ctx, dockerfileCtx, translator)
if err != nil {
return err
}
@ -460,7 +461,7 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
return err
}
}
if command.IsTrusted() {
if !options.untrusted {
// Since the build was successful, now we must tag any of the resolved
// images from the above Dockerfile rewrite.
for _, resolved := range resolvedTags {
@ -499,11 +500,12 @@ type resolvedTag struct {
tagRef reference.NamedTagged
}
// rewriteDockerfileFrom rewrites the given Dockerfile by resolving images in
// rewriteDockerfileFromForContentTrust rewrites the given Dockerfile by resolving images in
// "FROM <image>" instructions to a digest reference. `translator` is a
// function that takes a repository name and tag reference and returns a
// trusted digest reference.
func rewriteDockerfileFrom(ctx context.Context, dockerfile io.Reader, translator translatorFunc) (newDockerfile []byte, resolvedTags []*resolvedTag, err error) {
// This should be called *only* when content trust is enabled
func rewriteDockerfileFromForContentTrust(ctx context.Context, dockerfile io.Reader, translator translatorFunc) (newDockerfile []byte, resolvedTags []*resolvedTag, err error) {
scanner := bufio.NewScanner(dockerfile)
buf := bytes.NewBuffer(nil)
@ -520,7 +522,7 @@ func rewriteDockerfileFrom(ctx context.Context, dockerfile io.Reader, translator
return nil, nil, err
}
ref = reference.TagNameOnly(ref)
if ref, ok := ref.(reference.NamedTagged); ok && command.IsTrusted() {
if ref, ok := ref.(reference.NamedTagged); ok {
trustedRef, err := translator(ctx, ref)
if err != nil {
return nil, nil, err
@ -543,11 +545,10 @@ func rewriteDockerfileFrom(ctx context.Context, dockerfile io.Reader, translator
return buf.Bytes(), resolvedTags, scanner.Err()
}
// replaceDockerfileTarWrapper wraps the given input tar archive stream and
// replaces the entry with the given Dockerfile name with the contents of the
// new Dockerfile. Returns a new tar archive stream with the replaced
// Dockerfile.
func replaceDockerfileTarWrapper(ctx context.Context, inputTarStream io.ReadCloser, dockerfileName string, translator translatorFunc, resolvedTags *[]*resolvedTag) io.ReadCloser {
// replaceDockerfileForContentTrust wraps the given input tar archive stream and
// uses the translator to replace the Dockerfile which uses a trusted reference.
// Returns a new tar archive stream with the replaced Dockerfile.
func replaceDockerfileForContentTrust(ctx context.Context, inputTarStream io.ReadCloser, dockerfileName string, translator translatorFunc, resolvedTags *[]*resolvedTag) io.ReadCloser {
pipeReader, pipeWriter := io.Pipe()
go func() {
tarReader := tar.NewReader(inputTarStream)
@ -574,7 +575,7 @@ func replaceDockerfileTarWrapper(ctx context.Context, inputTarStream io.ReadClos
// generated from a directory on the local filesystem, the
// Dockerfile will only appear once in the archive.
var newDockerfile []byte
newDockerfile, *resolvedTags, err = rewriteDockerfileFrom(ctx, content, translator)
newDockerfile, *resolvedTags, err = rewriteDockerfileFromForContentTrust(ctx, content, translator)
if err != nil {
pipeWriter.CloseWithError(err)
return

View File

@ -11,10 +11,9 @@ import (
"strings"
"testing"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/pkg/archive"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
const dockerfileContents = "FROM busybox"
@ -38,7 +37,7 @@ func testValidateContextDirectory(t *testing.T, prepare func(t *testing.T) (stri
defer cleanup()
err := ValidateContextDirectory(contextDir, excludes)
require.NoError(t, err)
assert.NilError(t, err)
}
func TestGetContextFromLocalDirNoDockerfile(t *testing.T) {
@ -46,7 +45,7 @@ func TestGetContextFromLocalDirNoDockerfile(t *testing.T) {
defer cleanup()
_, _, err := GetContextFromLocalDir(contextDir, "")
testutil.ErrorContains(t, err, "Dockerfile")
assert.ErrorContains(t, err, "Dockerfile")
}
func TestGetContextFromLocalDirNotExistingDir(t *testing.T) {
@ -56,7 +55,7 @@ func TestGetContextFromLocalDirNotExistingDir(t *testing.T) {
fakePath := filepath.Join(contextDir, "fake")
_, _, err := GetContextFromLocalDir(fakePath, "")
testutil.ErrorContains(t, err, "fake")
assert.ErrorContains(t, err, "fake")
}
func TestGetContextFromLocalDirNotExistingDockerfile(t *testing.T) {
@ -66,7 +65,7 @@ func TestGetContextFromLocalDirNotExistingDockerfile(t *testing.T) {
fakePath := filepath.Join(contextDir, "fake")
_, _, err := GetContextFromLocalDir(contextDir, fakePath)
testutil.ErrorContains(t, err, "fake")
assert.ErrorContains(t, err, "fake")
}
func TestGetContextFromLocalDirWithNoDirectory(t *testing.T) {
@ -79,10 +78,10 @@ func TestGetContextFromLocalDirWithNoDirectory(t *testing.T) {
defer chdirCleanup()
absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, "")
require.NoError(t, err)
assert.NilError(t, err)
assert.Equal(t, contextDir, absContextDir)
assert.Equal(t, DefaultDockerfileName, relDockerfile)
assert.Check(t, is.Equal(contextDir, absContextDir))
assert.Check(t, is.Equal(DefaultDockerfileName, relDockerfile))
}
func TestGetContextFromLocalDirWithDockerfile(t *testing.T) {
@ -92,10 +91,10 @@ func TestGetContextFromLocalDirWithDockerfile(t *testing.T) {
createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777)
absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, "")
require.NoError(t, err)
assert.NilError(t, err)
assert.Equal(t, contextDir, absContextDir)
assert.Equal(t, DefaultDockerfileName, relDockerfile)
assert.Check(t, is.Equal(contextDir, absContextDir))
assert.Check(t, is.Equal(DefaultDockerfileName, relDockerfile))
}
func TestGetContextFromLocalDirLocalFile(t *testing.T) {
@ -130,10 +129,10 @@ func TestGetContextFromLocalDirWithCustomDockerfile(t *testing.T) {
createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777)
absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, DefaultDockerfileName)
require.NoError(t, err)
assert.NilError(t, err)
assert.Equal(t, contextDir, absContextDir)
assert.Equal(t, DefaultDockerfileName, relDockerfile)
assert.Check(t, is.Equal(contextDir, absContextDir))
assert.Check(t, is.Equal(DefaultDockerfileName, relDockerfile))
}
func TestGetContextFromReaderString(t *testing.T) {
@ -161,7 +160,7 @@ func TestGetContextFromReaderString(t *testing.T) {
t.Fatalf("Tar stream too long: %s", err)
}
require.NoError(t, tarArchive.Close())
assert.NilError(t, tarArchive.Close())
if dockerfileContents != contents {
t.Fatalf("Uncompressed tar archive does not equal: %s, got: %s", dockerfileContents, contents)
@ -179,15 +178,15 @@ func TestGetContextFromReaderTar(t *testing.T) {
createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777)
tarStream, err := archive.Tar(contextDir, archive.Uncompressed)
require.NoError(t, err)
assert.NilError(t, err)
tarArchive, relDockerfile, err := GetContextFromReader(tarStream, DefaultDockerfileName)
require.NoError(t, err)
assert.NilError(t, err)
tarReader := tar.NewReader(tarArchive)
header, err := tarReader.Next()
require.NoError(t, err)
assert.NilError(t, err)
if header.Name != DefaultDockerfileName {
t.Fatalf("Dockerfile name should be: %s, got: %s", DefaultDockerfileName, header.Name)
@ -203,7 +202,7 @@ func TestGetContextFromReaderTar(t *testing.T) {
t.Fatalf("Tar stream too long: %s", err)
}
require.NoError(t, tarArchive.Close())
assert.NilError(t, tarArchive.Close())
if dockerfileContents != contents {
t.Fatalf("Uncompressed tar archive does not equal: %s, got: %s", dockerfileContents, contents)
@ -243,8 +242,8 @@ func TestValidateContextDirectoryWithOneFileExcludes(t *testing.T) {
// When an error occurs, it terminates the test.
func createTestTempDir(t *testing.T, dir, prefix string) (string, func()) {
path, err := ioutil.TempDir(dir, prefix)
require.NoError(t, err)
return path, func() { require.NoError(t, os.RemoveAll(path)) }
assert.NilError(t, err)
return path, func() { assert.NilError(t, os.RemoveAll(path)) }
}
// createTestTempFile creates a temporary file within dir with specific contents and permissions.
@ -252,7 +251,7 @@ func createTestTempDir(t *testing.T, dir, prefix string) (string, func()) {
func createTestTempFile(t *testing.T, dir, filename, contents string, perm os.FileMode) string {
filePath := filepath.Join(dir, filename)
err := ioutil.WriteFile(filePath, []byte(contents), perm)
require.NoError(t, err)
assert.NilError(t, err)
return filePath
}
@ -262,9 +261,9 @@ func createTestTempFile(t *testing.T, dir, filename, contents string, perm os.Fi
// When an error occurs, it terminates the test.
func chdir(t *testing.T, dir string) func() {
workingDirectory, err := os.Getwd()
require.NoError(t, err)
require.NoError(t, os.Chdir(dir))
return func() { require.NoError(t, os.Chdir(workingDirectory)) }
assert.NilError(t, err)
assert.NilError(t, os.Chdir(dir))
return func() { assert.NilError(t, os.Chdir(workingDirectory)) }
}
func TestIsArchive(t *testing.T) {
@ -295,6 +294,6 @@ func TestIsArchive(t *testing.T) {
},
}
for _, testcase := range testcases {
assert.Equal(t, testcase.expected, IsArchive(testcase.header), testcase.doc)
assert.Check(t, is.Equal(testcase.expected, IsArchive(testcase.header)), testcase.doc)
}
}

View File

@ -1,39 +1,66 @@
package image
import (
"archive/tar"
"bytes"
"compress/gzip"
"io"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"sort"
"syscall"
"testing"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/archive"
"github.com/google/go-cmp/cmp"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/fs"
"github.com/gotestyourself/gotestyourself/skip"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/context"
)
func TestRunBuildResetsUidAndGidInContext(t *testing.T) {
skip.IfCondition(t, runtime.GOOS == "windows", "uid and gid not relevant on windows")
dest := fs.NewDir(t, "test-build-context-dest")
defer dest.Remove()
fakeImageBuild := func(_ context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) {
assert.NoError(t, archive.Untar(context, dest.Path(), nil))
body := new(bytes.Buffer)
return types.ImageBuildResponse{Body: ioutil.NopCloser(body)}, nil
func TestRunBuildDockerfileFromStdinWithCompress(t *testing.T) {
buffer := new(bytes.Buffer)
fakeBuild := newFakeBuild()
fakeImageBuild := func(ctx context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) {
tee := io.TeeReader(context, buffer)
gzipReader, err := gzip.NewReader(tee)
assert.NilError(t, err)
return fakeBuild.build(ctx, gzipReader, options)
}
cli := test.NewFakeCli(&fakeClient{imageBuildFunc: fakeImageBuild})
dockerfile := bytes.NewBufferString(`
FROM alpine:3.6
COPY foo /
`)
cli.SetIn(command.NewInStream(ioutil.NopCloser(dockerfile)))
dir := fs.NewDir(t, t.Name(),
fs.WithFile("foo", "some content"))
defer dir.Remove()
options := newBuildOptions()
options.compress = true
options.dockerfileName = "-"
options.context = dir.Path()
options.untrusted = true
assert.NilError(t, runBuild(cli, options))
expected := []string{fakeBuild.options.Dockerfile, ".dockerignore", "foo"}
assert.DeepEqual(t, expected, fakeBuild.filenames(t))
header := buffer.Bytes()[:10]
assert.Equal(t, archive.Gzip, archive.DetectCompression(header))
}
func TestRunBuildResetsUidAndGidInContext(t *testing.T) {
skip.If(t, os.Getuid() != 0, "root is required to chown files")
fakeBuild := newFakeBuild()
cli := test.NewFakeCli(&fakeClient{imageBuildFunc: fakeBuild.build})
dir := fs.NewDir(t, "test-build-context",
fs.WithFile("foo", "some content", fs.AsUser(65534, 65534)),
@ -46,72 +73,23 @@ func TestRunBuildResetsUidAndGidInContext(t *testing.T) {
options := newBuildOptions()
options.context = dir.Path()
options.untrusted = true
assert.NilError(t, runBuild(cli, options))
err := runBuild(cli, options)
require.NoError(t, err)
files, err := ioutil.ReadDir(dest.Path())
require.NoError(t, err)
for _, fileInfo := range files {
assert.Equal(t, uint32(0), fileInfo.Sys().(*syscall.Stat_t).Uid)
assert.Equal(t, uint32(0), fileInfo.Sys().(*syscall.Stat_t).Gid)
headers := fakeBuild.headers(t)
expected := []*tar.Header{
{Name: "Dockerfile"},
{Name: "foo"},
}
}
func TestRunBuildDockerfileFromStdinWithCompress(t *testing.T) {
dest, err := ioutil.TempDir("", "test-build-compress-dest")
require.NoError(t, err)
defer os.RemoveAll(dest)
var dockerfileName string
fakeImageBuild := func(_ context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) {
buffer := new(bytes.Buffer)
tee := io.TeeReader(context, buffer)
assert.NoError(t, archive.Untar(tee, dest, nil))
dockerfileName = options.Dockerfile
header := buffer.Bytes()[:10]
assert.Equal(t, archive.Gzip, archive.DetectCompression(header))
body := new(bytes.Buffer)
return types.ImageBuildResponse{Body: ioutil.NopCloser(body)}, nil
}
cli := test.NewFakeCli(&fakeClient{imageBuildFunc: fakeImageBuild})
dockerfile := bytes.NewBufferString(`
FROM alpine:3.6
COPY foo /
`)
cli.SetIn(command.NewInStream(ioutil.NopCloser(dockerfile)))
dir, err := ioutil.TempDir("", "test-build-compress")
require.NoError(t, err)
defer os.RemoveAll(dir)
ioutil.WriteFile(filepath.Join(dir, "foo"), []byte("some content"), 0644)
options := newBuildOptions()
options.compress = true
options.dockerfileName = "-"
options.context = dir
err = runBuild(cli, options)
require.NoError(t, err)
files, err := ioutil.ReadDir(dest)
require.NoError(t, err)
actual := []string{}
for _, fileInfo := range files {
actual = append(actual, fileInfo.Name())
}
sort.Strings(actual)
assert.Equal(t, []string{dockerfileName, ".dockerignore", "foo"}, actual)
var cmpTarHeaderNameAndOwner = cmp.Comparer(func(x, y tar.Header) bool {
return x.Name == y.Name && x.Uid == y.Uid && x.Gid == y.Gid
})
assert.DeepEqual(t, expected, headers, cmpTarHeaderNameAndOwner)
}
func TestRunBuildDockerfileOutsideContext(t *testing.T) {
dir := fs.NewDir(t, t.Name(),
fs.WithFile("data", "data file"),
)
fs.WithFile("data", "data file"))
defer dir.Remove()
// Dockerfile outside of build-context
@ -123,51 +101,32 @@ COPY data /data
)
defer df.Remove()
dest, err := ioutil.TempDir("", t.Name())
require.NoError(t, err)
defer os.RemoveAll(dest)
var dockerfileName string
fakeImageBuild := func(_ context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) {
buffer := new(bytes.Buffer)
tee := io.TeeReader(context, buffer)
assert.NoError(t, archive.Untar(tee, dest, nil))
dockerfileName = options.Dockerfile
body := new(bytes.Buffer)
return types.ImageBuildResponse{Body: ioutil.NopCloser(body)}, nil
}
cli := test.NewFakeCli(&fakeClient{imageBuildFunc: fakeImageBuild})
fakeBuild := newFakeBuild()
cli := test.NewFakeCli(&fakeClient{imageBuildFunc: fakeBuild.build})
options := newBuildOptions()
options.context = dir.Path()
options.dockerfileName = df.Path()
options.untrusted = true
assert.NilError(t, runBuild(cli, options))
err = runBuild(cli, options)
require.NoError(t, err)
files, err := ioutil.ReadDir(dest)
require.NoError(t, err)
var actual []string
for _, fileInfo := range files {
actual = append(actual, fileInfo.Name())
}
sort.Strings(actual)
assert.Equal(t, []string{dockerfileName, ".dockerignore", "data"}, actual)
expected := []string{fakeBuild.options.Dockerfile, ".dockerignore", "data"}
assert.DeepEqual(t, expected, fakeBuild.filenames(t))
}
// TestRunBuildFromLocalGitHubDirNonExistingRepo tests that build contexts
// starting with `github.com/` are special-cased, and the build command attempts
// to clone the remote repo.
// TODO: test "context selection" logic directly when runBuild is refactored
// to support testing (ex: docker/cli#294)
func TestRunBuildFromGitHubSpecialCase(t *testing.T) {
cmd := NewBuildCommand(test.NewFakeCli(nil))
cmd.SetArgs([]string{"github.com/docker/no-such-repository"})
// Clone a small repo that exists so git doesn't prompt for credentials
cmd.SetArgs([]string{"github.com/docker/for-win"})
cmd.SetOutput(ioutil.Discard)
err := cmd.Execute()
assert.Error(t, err)
assert.Contains(t, err.Error(), "unable to prepare context: unable to 'git clone'")
assert.ErrorContains(t, err, "unable to prepare context")
assert.ErrorContains(t, err, "docker-build-git")
}
// TestRunBuildFromLocalGitHubDirNonExistingRepo tests that a local directory
@ -175,19 +134,83 @@ func TestRunBuildFromGitHubSpecialCase(t *testing.T) {
// case.
func TestRunBuildFromLocalGitHubDir(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "docker-build-from-local-dir-")
require.NoError(t, err)
assert.NilError(t, err)
defer os.RemoveAll(tmpDir)
buildDir := filepath.Join(tmpDir, "github.com", "docker", "no-such-repository")
err = os.MkdirAll(buildDir, 0777)
require.NoError(t, err)
assert.NilError(t, err)
err = ioutil.WriteFile(filepath.Join(buildDir, "Dockerfile"), []byte("FROM busybox\n"), 0644)
require.NoError(t, err)
assert.NilError(t, err)
client := test.NewFakeCli(&fakeClient{})
cmd := NewBuildCommand(client)
cmd.SetArgs([]string{buildDir})
cmd.SetOutput(ioutil.Discard)
err = cmd.Execute()
require.NoError(t, err)
assert.NilError(t, err)
}
func TestRunBuildWithSymlinkedContext(t *testing.T) {
dockerfile := `
FROM alpine:3.6
RUN echo hello world
`
tmpDir := fs.NewDir(t, t.Name(),
fs.WithDir("context",
fs.WithFile("Dockerfile", dockerfile)),
fs.WithSymlink("context-link", "context"))
defer tmpDir.Remove()
fakeBuild := newFakeBuild()
cli := test.NewFakeCli(&fakeClient{imageBuildFunc: fakeBuild.build})
options := newBuildOptions()
options.context = tmpDir.Join("context-link")
options.untrusted = true
assert.NilError(t, runBuild(cli, options))
assert.DeepEqual(t, fakeBuild.filenames(t), []string{"Dockerfile"})
}
type fakeBuild struct {
context *tar.Reader
options types.ImageBuildOptions
}
func newFakeBuild() *fakeBuild {
return &fakeBuild{}
}
func (f *fakeBuild) build(_ context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) {
f.context = tar.NewReader(context)
f.options = options
body := new(bytes.Buffer)
return types.ImageBuildResponse{Body: ioutil.NopCloser(body)}, nil
}
func (f *fakeBuild) headers(t *testing.T) []*tar.Header {
t.Helper()
headers := []*tar.Header{}
for {
hdr, err := f.context.Next()
switch err {
case io.EOF:
return headers
case nil:
headers = append(headers, hdr)
default:
assert.NilError(t, err)
}
}
}
func (f *fakeBuild) filenames(t *testing.T) []string {
t.Helper()
names := []string{}
for _, header := range f.headers(t) {
names = append(names, header.Name)
}
sort.Strings(names)
return names
}

View File

@ -7,11 +7,11 @@ import (
"time"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types/image"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/gotestyourself/gotestyourself/skip"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
func TestNewHistoryCommandErrors(t *testing.T) {
@ -39,15 +39,20 @@ func TestNewHistoryCommandErrors(t *testing.T) {
cmd := NewHistoryCommand(test.NewFakeCli(&fakeClient{imageHistoryFunc: tc.imageHistoryFunc}))
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
func notUTCTimezone() bool {
now := time.Now()
return now != now.UTC()
}
func TestNewHistoryCommandSuccess(t *testing.T) {
skip.If(t, notUTCTimezone, "expected output requires UTC timezone")
testCases := []struct {
name string
args []string
outputRegex string
imageHistoryFunc func(img string) ([]image.HistoryResponseItem, error)
}{
{
@ -64,16 +69,17 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
name: "quiet",
args: []string{"--quiet", "image:tag"},
},
// TODO: This test is failing since the output does not contain an RFC3339 date
//{
// name: "non-human",
// args: []string{"--human=false", "image:tag"},
// outputRegex: "\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}", // RFC3339 date format match
//},
{
name: "non-human-header",
args: []string{"--human=false", "image:tag"},
outputRegex: "CREATED\\sAT",
name: "non-human",
args: []string{"--human=false", "image:tag"},
imageHistoryFunc: func(img string) ([]image.HistoryResponseItem, error) {
return []image.HistoryResponseItem{{
ID: "abcdef",
Created: time.Date(2017, 1, 1, 12, 0, 3, 0, time.UTC).Unix(),
CreatedBy: "rose",
Comment: "new history item!",
}}, nil
},
},
{
name: "quiet-no-trunc",
@ -92,12 +98,8 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
err := cmd.Execute()
assert.NoError(t, err)
assert.NilError(t, err)
actual := cli.OutBuffer().String()
if tc.outputRegex == "" {
golden.Assert(t, actual, fmt.Sprintf("history-command-success.%s.golden", tc.name))
} else {
assert.Regexp(t, tc.outputRegex, actual)
}
golden.Assert(t, actual, fmt.Sprintf("history-command-success.%s.golden", tc.name))
}
}

View File

@ -7,10 +7,10 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
func TestNewImportCommandErrors(t *testing.T) {
@ -38,7 +38,7 @@ func TestNewImportCommandErrors(t *testing.T) {
cmd := NewImportCommand(test.NewFakeCli(&fakeClient{imageImportFunc: tc.imageImportFunc}))
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -46,7 +46,7 @@ func TestNewImportCommandInvalidFile(t *testing.T) {
cmd := NewImportCommand(test.NewFakeCli(&fakeClient{}))
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs([]string{"testdata/import-command-success.unexistent-file"})
testutil.ErrorContains(t, cmd.Execute(), "testdata/import-command-success.unexistent-file")
assert.ErrorContains(t, cmd.Execute(), "testdata/import-command-success.unexistent-file")
}
func TestNewImportCommandSuccess(t *testing.T) {
@ -67,7 +67,7 @@ func TestNewImportCommandSuccess(t *testing.T) {
name: "double",
args: []string{"-", "image:local"},
imageImportFunc: func(source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) {
assert.Equal(t, "image:local", ref)
assert.Check(t, is.Equal("image:local", ref))
return ioutil.NopCloser(strings.NewReader("")), nil
},
},
@ -75,7 +75,7 @@ func TestNewImportCommandSuccess(t *testing.T) {
name: "message",
args: []string{"--message", "test message", "-"},
imageImportFunc: func(source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) {
assert.Equal(t, "test message", options.Message)
assert.Check(t, is.Equal("test message", options.Message))
return ioutil.NopCloser(strings.NewReader("")), nil
},
},
@ -83,7 +83,7 @@ func TestNewImportCommandSuccess(t *testing.T) {
name: "change",
args: []string{"--change", "ENV DEBUG true", "-"},
imageImportFunc: func(source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) {
assert.Equal(t, "ENV DEBUG true", options.Changes[0])
assert.Check(t, is.Equal("ENV DEBUG true", options.Changes[0]))
return ioutil.NopCloser(strings.NewReader("")), nil
},
},
@ -92,6 +92,6 @@ func TestNewImportCommandSuccess(t *testing.T) {
cmd := NewImportCommand(test.NewFakeCli(&fakeClient{imageImportFunc: tc.imageImportFunc}))
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}
}

View File

@ -6,10 +6,10 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
)
func TestNewInspectCommandErrors(t *testing.T) {
@ -28,7 +28,7 @@ func TestNewInspectCommandErrors(t *testing.T) {
cmd := newInspectCommand(test.NewFakeCli(&fakeClient{}))
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -46,7 +46,7 @@ func TestNewInspectCommandSuccess(t *testing.T) {
imageCount: 1,
imageInspectFunc: func(image string) (types.ImageInspect, []byte, error) {
imageInspectInvocationCount++
assert.Equal(t, "image", image)
assert.Check(t, is.Equal("image", image))
return types.ImageInspect{}, nil, nil
},
},
@ -66,9 +66,9 @@ func TestNewInspectCommandSuccess(t *testing.T) {
imageInspectFunc: func(image string) (types.ImageInspect, []byte, error) {
imageInspectInvocationCount++
if imageInspectInvocationCount == 1 {
assert.Equal(t, "image1", image)
assert.Check(t, is.Equal("image1", image))
} else {
assert.Equal(t, "image2", image)
assert.Check(t, is.Equal("image2", image))
}
return types.ImageInspect{}, nil, nil
},
@ -81,8 +81,8 @@ func TestNewInspectCommandSuccess(t *testing.T) {
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
err := cmd.Execute()
assert.NoError(t, err)
assert.NilError(t, err)
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("inspect-command-success.%s.golden", tc.name))
assert.Equal(t, imageInspectInvocationCount, tc.imageCount)
assert.Check(t, is.Equal(imageInspectInvocationCount, tc.imageCount))
}
}

View File

@ -7,11 +7,11 @@ import (
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
func TestNewImagesCommandErrors(t *testing.T) {
@ -38,7 +38,7 @@ func TestNewImagesCommandErrors(t *testing.T) {
cmd := NewImagesCommand(test.NewFakeCli(&fakeClient{imageListFunc: tc.imageListFunc}))
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -65,7 +65,7 @@ func TestNewImagesCommandSuccess(t *testing.T) {
name: "match-name",
args: []string{"image"},
imageListFunc: func(options types.ImageListOptions) ([]types.ImageSummary, error) {
assert.Equal(t, "image", options.Filters.Get("reference")[0])
assert.Check(t, is.Equal("image", options.Filters.Get("reference")[0]))
return []types.ImageSummary{{}}, nil
},
},
@ -73,7 +73,7 @@ func TestNewImagesCommandSuccess(t *testing.T) {
name: "filters",
args: []string{"--filter", "name=value"},
imageListFunc: func(options types.ImageListOptions) ([]types.ImageSummary, error) {
assert.Equal(t, "value", options.Filters.Get("name")[0])
assert.Check(t, is.Equal("value", options.Filters.Get("name")[0]))
return []types.ImageSummary{{}}, nil
},
},
@ -85,14 +85,14 @@ func TestNewImagesCommandSuccess(t *testing.T) {
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
err := cmd.Execute()
assert.NoError(t, err)
assert.NilError(t, err)
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("list-command-success.%s.golden", tc.name))
}
}
func TestNewListCommandAlias(t *testing.T) {
cmd := newListCommand(test.NewFakeCli(&fakeClient{}))
assert.True(t, cmd.HasAlias("images"))
assert.True(t, cmd.HasAlias("list"))
assert.False(t, cmd.HasAlias("other"))
assert.Check(t, cmd.HasAlias("images"))
assert.Check(t, cmd.HasAlias("list"))
assert.Check(t, !cmd.HasAlias("other"))
}

View File

@ -8,11 +8,10 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
func TestNewLoadCommandErrors(t *testing.T) {
@ -47,7 +46,7 @@ func TestNewLoadCommandErrors(t *testing.T) {
cmd := NewLoadCommand(cli)
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -57,7 +56,7 @@ func TestNewLoadCommandInvalidInput(t *testing.T) {
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs([]string{"--input", "*"})
err := cmd.Execute()
testutil.ErrorContains(t, err, expectedError)
assert.ErrorContains(t, err, expectedError)
}
func TestNewLoadCommandSuccess(t *testing.T) {
@ -96,7 +95,7 @@ func TestNewLoadCommandSuccess(t *testing.T) {
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
err := cmd.Execute()
assert.NoError(t, err)
assert.NilError(t, err)
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("load-command-success.%s.golden", tc.name))
}
}

View File

@ -6,12 +6,12 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
func TestNewPruneCommandErrors(t *testing.T) {
@ -41,7 +41,7 @@ func TestNewPruneCommandErrors(t *testing.T) {
}))
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -55,7 +55,7 @@ func TestNewPruneCommandSuccess(t *testing.T) {
name: "all",
args: []string{"--all"},
imagesPruneFunc: func(pruneFilter filters.Args) (types.ImagesPruneReport, error) {
assert.Equal(t, "false", pruneFilter.Get("dangling")[0])
assert.Check(t, is.Equal("false", pruneFilter.Get("dangling")[0]))
return types.ImagesPruneReport{}, nil
},
},
@ -63,7 +63,7 @@ func TestNewPruneCommandSuccess(t *testing.T) {
name: "force-deleted",
args: []string{"--force"},
imagesPruneFunc: func(pruneFilter filters.Args) (types.ImagesPruneReport, error) {
assert.Equal(t, "true", pruneFilter.Get("dangling")[0])
assert.Check(t, is.Equal("true", pruneFilter.Get("dangling")[0]))
return types.ImagesPruneReport{
ImagesDeleted: []types.ImageDeleteResponseItem{{Deleted: "image1"}},
SpaceReclaimed: 1,
@ -74,7 +74,7 @@ func TestNewPruneCommandSuccess(t *testing.T) {
name: "force-untagged",
args: []string{"--force"},
imagesPruneFunc: func(pruneFilter filters.Args) (types.ImagesPruneReport, error) {
assert.Equal(t, "true", pruneFilter.Get("dangling")[0])
assert.Check(t, is.Equal("true", pruneFilter.Get("dangling")[0]))
return types.ImagesPruneReport{
ImagesDeleted: []types.ImageDeleteResponseItem{{Untagged: "image1"}},
SpaceReclaimed: 2,
@ -88,7 +88,7 @@ func TestNewPruneCommandSuccess(t *testing.T) {
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
err := cmd.Execute()
assert.NoError(t, err)
assert.NilError(t, err)
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("prune-command-success.%s.golden", tc.name))
}
}

View File

@ -14,9 +14,10 @@ import (
)
type pullOptions struct {
remote string
all bool
platform string
remote string
all bool
platform string
untrusted bool
}
// NewPullCommand creates a new `docker pull` command
@ -38,7 +39,7 @@ func NewPullCommand(dockerCli command.Cli) *cobra.Command {
flags.BoolVarP(&opts.all, "all-tags", "a", false, "Download all tagged images in the repository")
command.AddPlatformFlag(flags, &opts.platform)
command.AddTrustVerificationFlags(flags)
command.AddTrustVerificationFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled())
return cmd
}
@ -58,14 +59,14 @@ func runPull(cli command.Cli, opts pullOptions) error {
}
ctx := context.Background()
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, AuthResolver(cli), distributionRef.String())
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, nil, AuthResolver(cli), distributionRef.String())
if err != nil {
return err
}
// Check if reference has a digest
_, isCanonical := distributionRef.(reference.Canonical)
if command.IsTrusted() && !isCanonical {
if !opts.untrusted && !isCanonical {
err = trustedPull(ctx, cli, imgRefAndAuth, opts.platform)
} else {
err = imagePullPrivileged(ctx, cli, imgRefAndAuth, opts.all, opts.platform)

View File

@ -8,10 +8,11 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/cli/internal/test/notary"
"github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
)
func TestNewPullCommandErrors(t *testing.T) {
@ -41,7 +42,7 @@ func TestNewPullCommandErrors(t *testing.T) {
cmd := NewPullCommand(cli)
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -65,7 +66,7 @@ func TestNewPullCommandSuccess(t *testing.T) {
for _, tc := range testCases {
cli := test.NewFakeCli(&fakeClient{
imagePullFunc: func(ref string, options types.ImagePullOptions) (io.ReadCloser, error) {
assert.Equal(t, tc.expectedTag, ref, tc.name)
assert.Check(t, is.Equal(tc.expectedTag, ref), tc.name)
return ioutil.NopCloser(strings.NewReader("")), nil
},
})
@ -73,7 +74,48 @@ func TestNewPullCommandSuccess(t *testing.T) {
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
err := cmd.Execute()
assert.NoError(t, err)
assert.NilError(t, err)
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("pull-command-success.%s.golden", tc.name))
}
}
func TestNewPullCommandWithContentTrustErrors(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{
imagePullFunc: func(ref string, options types.ImagePullOptions) (io.ReadCloser, error) {
return ioutil.NopCloser(strings.NewReader("")), fmt.Errorf("shouldn't try to pull image")
},
}, test.EnableContentTrust)
cli.SetNotaryClient(tc.notaryFunc)
cmd := NewPullCommand(cli)
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
err := cmd.Execute()
assert.ErrorContains(t, err, tc.expectedError)
}
}

View File

@ -11,26 +11,34 @@ import (
"github.com/spf13/cobra"
)
type pushOptions struct {
remote string
untrusted bool
}
// NewPushCommand creates a new `docker push` command
func NewPushCommand(dockerCli command.Cli) *cobra.Command {
var opts pushOptions
cmd := &cobra.Command{
Use: "push [OPTIONS] NAME[:TAG]",
Short: "Push an image or a repository to a registry",
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return runPush(dockerCli, args[0])
opts.remote = args[0]
return runPush(dockerCli, opts)
},
}
flags := cmd.Flags()
command.AddTrustSigningFlags(flags)
command.AddTrustSigningFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled())
return cmd
}
func runPush(dockerCli command.Cli, remote string) error {
ref, err := reference.ParseNormalizedNamed(remote)
func runPush(dockerCli command.Cli, opts pushOptions) error {
ref, err := reference.ParseNormalizedNamed(opts.remote)
if err != nil {
return err
}
@ -47,7 +55,7 @@ func runPush(dockerCli command.Cli, remote string) error {
authConfig := command.ResolveAuthConfig(ctx, dockerCli, repoInfo.Index)
requestPrivilege := command.RegistryAuthenticationPrivilegedFunc(dockerCli, repoInfo.Index, "push")
if command.IsTrusted() {
if !opts.untrusted {
return TrustedPush(ctx, dockerCli, repoInfo, ref, authConfig, requestPrivilege)
}

View File

@ -7,10 +7,9 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
func TestNewPushCommandErrors(t *testing.T) {
@ -38,18 +37,13 @@ func TestNewPushCommandErrors(t *testing.T) {
return ioutil.NopCloser(strings.NewReader("")), errors.Errorf("Failed to push")
},
},
{
name: "trust-error",
args: []string{"--disable-content-trust=false", "image:repo"},
expectedError: "you are not authorized to perform this operation: server returned 401.",
},
}
for _, tc := range testCases {
cli := test.NewFakeCli(&fakeClient{imagePushFunc: tc.imagePushFunc})
cmd := NewPushCommand(cli)
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -72,6 +66,6 @@ func TestNewPushCommandSuccess(t *testing.T) {
cmd := NewPushCommand(cli)
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}
}

View File

@ -6,11 +6,11 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
type notFound struct {
@ -27,9 +27,9 @@ func (n notFound) NotFound() bool {
func TestNewRemoveCommandAlias(t *testing.T) {
cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}))
assert.True(t, cmd.HasAlias("rmi"))
assert.True(t, cmd.HasAlias("remove"))
assert.False(t, cmd.HasAlias("other"))
assert.Check(t, cmd.HasAlias("rmi"))
assert.Check(t, cmd.HasAlias("remove"))
assert.Check(t, !cmd.HasAlias("other"))
}
func TestNewRemoveCommandErrors(t *testing.T) {
@ -48,7 +48,7 @@ func TestNewRemoveCommandErrors(t *testing.T) {
args: []string{"-f", "image1"},
expectedError: "error removing image",
imageRemoveFunc: func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
assert.Equal(t, "image1", image)
assert.Check(t, is.Equal("image1", image))
return []types.ImageDeleteResponseItem{}, errors.Errorf("error removing image")
},
},
@ -57,8 +57,8 @@ func TestNewRemoveCommandErrors(t *testing.T) {
args: []string{"arg1"},
expectedError: "error removing image",
imageRemoveFunc: func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
assert.False(t, options.Force)
assert.True(t, options.PruneChildren)
assert.Check(t, !options.Force)
assert.Check(t, options.PruneChildren)
return []types.ImageDeleteResponseItem{}, errors.Errorf("error removing image")
},
},
@ -70,7 +70,7 @@ func TestNewRemoveCommandErrors(t *testing.T) {
}))
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
})
}
}
@ -86,7 +86,7 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
name: "Image Deleted",
args: []string{"image1"},
imageRemoveFunc: func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
assert.Equal(t, "image1", image)
assert.Check(t, is.Equal("image1", image))
return []types.ImageDeleteResponseItem{{Deleted: image}}, nil
},
},
@ -94,8 +94,8 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
name: "Image not found with force option",
args: []string{"-f", "image1"},
imageRemoveFunc: func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
assert.Equal(t, "image1", image)
assert.Equal(t, true, options.Force)
assert.Check(t, is.Equal("image1", image))
assert.Check(t, is.Equal(true, options.Force))
return []types.ImageDeleteResponseItem{}, notFound{"image1"}
},
expectedStderr: "Error: No such image: image1\n",
@ -105,7 +105,7 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
name: "Image Untagged",
args: []string{"image1"},
imageRemoveFunc: func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
assert.Equal(t, "image1", image)
assert.Check(t, is.Equal("image1", image))
return []types.ImageDeleteResponseItem{{Untagged: image}}, nil
},
},
@ -126,8 +126,8 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
cmd := NewRemoveCommand(cli)
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
assert.NoError(t, cmd.Execute())
assert.Equal(t, tc.expectedStderr, cli.ErrBuffer().String())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal(tc.expectedStderr, cli.ErrBuffer().String()))
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("remove-command-success.%s.golden", tc.name))
})
}

View File

@ -8,10 +8,9 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewSaveCommandErrors(t *testing.T) {
@ -54,7 +53,7 @@ func TestNewSaveCommandErrors(t *testing.T) {
cmd := NewSaveCommand(cli)
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -69,8 +68,8 @@ func TestNewSaveCommandSuccess(t *testing.T) {
args: []string{"-o", "save_tmp_file", "arg1"},
isTerminal: true,
imageSaveFunc: func(images []string) (io.ReadCloser, error) {
require.Len(t, images, 1)
assert.Equal(t, "arg1", images[0])
assert.Assert(t, is.Len(images, 1))
assert.Check(t, is.Equal("arg1", images[0]))
return ioutil.NopCloser(strings.NewReader("")), nil
},
deferredFunc: func() {
@ -81,9 +80,9 @@ func TestNewSaveCommandSuccess(t *testing.T) {
args: []string{"arg1", "arg2"},
isTerminal: false,
imageSaveFunc: func(images []string) (io.ReadCloser, error) {
require.Len(t, images, 2)
assert.Equal(t, "arg1", images[0])
assert.Equal(t, "arg2", images[1])
assert.Assert(t, is.Len(images, 2))
assert.Check(t, is.Equal("arg1", images[0]))
assert.Check(t, is.Equal("arg2", images[1]))
return ioutil.NopCloser(strings.NewReader("")), nil
},
},
@ -96,7 +95,7 @@ func TestNewSaveCommandSuccess(t *testing.T) {
}))
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
if tc.deferredFunc != nil {
tc.deferredFunc()
}

View File

@ -5,8 +5,8 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestCliNewTagCommandErrors(t *testing.T) {
@ -20,7 +20,7 @@ func TestCliNewTagCommandErrors(t *testing.T) {
cmd := NewTagCommand(test.NewFakeCli(&fakeClient{}))
cmd.SetArgs(args)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), expectedError)
assert.ErrorContains(t, cmd.Execute(), expectedError)
}
}
@ -28,14 +28,14 @@ func TestCliNewTagCommand(t *testing.T) {
cmd := NewTagCommand(
test.NewFakeCli(&fakeClient{
imageTagFunc: func(image string, ref string) error {
assert.Equal(t, "image1", image)
assert.Equal(t, "image2", ref)
assert.Check(t, is.Equal("image1", image))
assert.Check(t, is.Equal("image2", ref))
return nil
},
}))
cmd.SetArgs([]string{"image1", "image2"})
cmd.SetOutput(ioutil.Discard)
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
value, _ := cmd.Flags().GetBool("interspersed")
assert.False(t, value)
assert.Check(t, !value)
}

View File

@ -0,0 +1,2 @@
IMAGE CREATED AT CREATED BY SIZE COMMENT
abcdef 2017-01-01T12:00:03Z rose 0 new history item!

View File

@ -198,7 +198,7 @@ func trustedPull(ctx context.Context, cli command.Cli, imgRefAndAuth trust.Image
if err != nil {
return err
}
updatedImgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, AuthResolver(cli), trustedRef.String())
updatedImgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, nil, AuthResolver(cli), trustedRef.String())
if err != nil {
return err
}
@ -293,35 +293,24 @@ func imagePullPrivileged(ctx context.Context, cli command.Cli, imgRefAndAuth tru
// TrustedReference returns the canonical trusted reference for an image reference
func TrustedReference(ctx context.Context, cli command.Cli, ref reference.NamedTagged, rs registry.Service) (reference.Canonical, error) {
var (
repoInfo *registry.RepositoryInfo
err error
)
if rs != nil {
repoInfo, err = rs.ResolveRepository(ref)
} else {
repoInfo, err = registry.ParseRepositoryInfo(ref)
}
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, rs, AuthResolver(cli), ref.String())
if err != nil {
return nil, err
}
// Resolve the Auth config relevant for this server
authConfig := command.ResolveAuthConfig(ctx, cli, repoInfo.Index)
notaryRepo, err := trust.GetNotaryRepository(cli.In(), cli.Out(), command.UserAgent(), repoInfo, &authConfig, "pull")
notaryRepo, err := cli.NotaryClient(imgRefAndAuth, []string{"pull"})
if err != nil {
return nil, errors.Wrap(err, "error establishing connection to trust repository")
}
t, err := notaryRepo.GetTargetByName(ref.Tag(), trust.ReleasesRole, data.CanonicalTargetsRole)
if err != nil {
return nil, trust.NotaryError(repoInfo.Name.Name(), err)
return nil, trust.NotaryError(imgRefAndAuth.RepoInfo().Name.Name(), err)
}
// Only list tags in the top level targets role or the releases delegation role - ignore
// all other delegation roles
if t.Role != trust.ReleasesRole && t.Role != data.CanonicalTargetsRole {
return nil, trust.NotaryError(repoInfo.Name.Name(), client.ErrNoSuchTarget(ref.Tag()))
return nil, trust.NotaryError(imgRefAndAuth.RepoInfo().Name.Name(), client.ErrNoSuchTarget(ref.Tag()))
}
r, err := convertTarget(t.Target)
if err != nil {

View File

@ -7,9 +7,7 @@ import (
"github.com/docker/cli/cli/trust"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/registry"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/theupdateframework/notary/client"
"github.com/theupdateframework/notary/passphrase"
"github.com/theupdateframework/notary/trustpinning"
@ -48,8 +46,8 @@ func TestHTTPENVTrustServer(t *testing.T) {
func TestOfficialTrustServer(t *testing.T) {
indexInfo := &registrytypes.IndexInfo{Name: "testserver", Official: true}
output, err := trust.Server(indexInfo)
if err != nil || output != registry.NotaryServer {
t.Fatalf("Expected server to be %s, got %s", registry.NotaryServer, output)
if err != nil || output != trust.NotaryServer {
t.Fatalf("Expected server to be %s, got %s", trust.NotaryServer, output)
}
}
@ -64,12 +62,12 @@ func TestNonOfficialTrustServer(t *testing.T) {
func TestAddTargetToAllSignableRolesError(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "notary-test-")
assert.NoError(t, err)
assert.NilError(t, err)
defer os.RemoveAll(tmpDir)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{})
require.NoError(t, err)
assert.NilError(t, err)
target := client.Target{}
err = AddTargetToAllSignableRoles(notaryRepo, &target)
assert.EqualError(t, err, "client is offline")
assert.Error(t, err, "client is offline")
}

View File

@ -6,8 +6,8 @@ import (
"testing"
"github.com/docker/cli/templates"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
type testElement struct {
@ -243,17 +243,17 @@ func TestTemplateInspectorRawFallbackNumber(t *testing.T) {
}
b := new(bytes.Buffer)
tmpl, err := templates.Parse("{{.Size}} {{.Id}}")
require.NoError(t, err)
assert.NilError(t, err)
i := NewTemplateInspector(b, tmpl)
for _, tc := range testcases {
err = i.Inspect(typedElem, tc.raw)
require.NoError(t, err)
assert.NilError(t, err)
err = i.Flush()
require.NoError(t, err)
assert.NilError(t, err)
assert.Equal(t, tc.exp, b.String())
assert.Check(t, is.Equal(tc.exp, b.String()))
b.Reset()
}
}

View File

@ -5,10 +5,9 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestManifestAnnotateError(t *testing.T) {
@ -35,7 +34,7 @@ func TestManifestAnnotateError(t *testing.T) {
cmd := newAnnotateCommand(cli)
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -48,13 +47,13 @@ func TestManifestAnnotate(t *testing.T) {
namedRef := ref(t, "alpine:3.0")
imageManifest := fullImageManifest(t, namedRef)
err := store.Save(ref(t, "list:v1"), namedRef, imageManifest)
require.NoError(t, err)
assert.NilError(t, err)
cmd := newAnnotateCommand(cli)
cmd.SetArgs([]string{"example.com/list:v1", "example.com/fake:0.0"})
cmd.SetOutput(ioutil.Discard)
expectedError := "manifest for image example.com/fake:0.0 does not exist"
testutil.ErrorContains(t, cmd.Execute(), expectedError)
assert.ErrorContains(t, cmd.Execute(), expectedError)
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
cmd.Flags().Set("os", "freebsd")
@ -62,17 +61,17 @@ func TestManifestAnnotate(t *testing.T) {
cmd.Flags().Set("os-features", "feature1")
cmd.Flags().Set("variant", "v7")
expectedError = "manifest entry for image has unsupported os/arch combination"
testutil.ErrorContains(t, cmd.Execute(), expectedError)
assert.ErrorContains(t, cmd.Execute(), expectedError)
cmd.Flags().Set("arch", "arm")
require.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
cmd = newInspectCommand(cli)
err = cmd.Flags().Set("verbose", "true")
require.NoError(t, err)
assert.NilError(t, err)
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
require.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
actual := cli.OutBuffer()
expected := golden.Get(t, "inspect-annotate.golden")
assert.Equal(t, string(expected), actual.String())
assert.Check(t, is.Equal(string(expected), actual.String()))
}

View File

@ -10,7 +10,6 @@ import (
)
type fakeRegistryClient struct {
client.RegistryClient
getManifestFunc func(ctx context.Context, ref reference.Named) (manifesttypes.ImageManifest, error)
getManifestListFunc func(ctx context.Context, ref reference.Named) ([]manifesttypes.ImageManifest, error)
mountBlobFunc func(ctx context.Context, source reference.Canonical, target reference.Named) error
@ -44,3 +43,5 @@ func (c *fakeRegistryClient) PutManifest(ctx context.Context, ref reference.Name
}
return digest.Digest(""), nil
}
var _ client.RegistryClient = &fakeRegistryClient{}

View File

@ -6,12 +6,11 @@ import (
manifesttypes "github.com/docker/cli/cli/manifest/types"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/distribution/reference"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/context"
)
@ -35,7 +34,7 @@ func TestManifestCreateErrors(t *testing.T) {
cmd := newCreateListCommand(cli)
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -50,28 +49,28 @@ func TestManifestCreateAmend(t *testing.T) {
namedRef := ref(t, "alpine:3.0")
imageManifest := fullImageManifest(t, namedRef)
err := store.Save(ref(t, "list:v1"), namedRef, imageManifest)
require.NoError(t, err)
assert.NilError(t, err)
namedRef = ref(t, "alpine:3.1")
imageManifest = fullImageManifest(t, namedRef)
err = store.Save(ref(t, "list:v1"), namedRef, imageManifest)
require.NoError(t, err)
assert.NilError(t, err)
cmd := newCreateListCommand(cli)
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.1"})
cmd.Flags().Set("amend", "true")
cmd.SetOutput(ioutil.Discard)
err = cmd.Execute()
require.NoError(t, err)
assert.NilError(t, err)
// make a new cli to clear the buffers
cli = test.NewFakeCli(nil)
cli.SetManifestStore(store)
inspectCmd := newInspectCommand(cli)
inspectCmd.SetArgs([]string{"example.com/list:v1"})
require.NoError(t, inspectCmd.Execute())
assert.NilError(t, inspectCmd.Execute())
actual := cli.OutBuffer()
expected := golden.Get(t, "inspect-manifest-list.golden")
assert.Equal(t, string(expected), actual.String())
assert.Check(t, is.Equal(string(expected), actual.String()))
}
// attempt to overwrite a saved manifest and get refused
@ -84,13 +83,13 @@ func TestManifestCreateRefuseAmend(t *testing.T) {
namedRef := ref(t, "alpine:3.0")
imageManifest := fullImageManifest(t, namedRef)
err := store.Save(ref(t, "list:v1"), namedRef, imageManifest)
require.NoError(t, err)
assert.NilError(t, err)
cmd := newCreateListCommand(cli)
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
cmd.SetOutput(ioutil.Discard)
err = cmd.Execute()
assert.EqualError(t, err, "refusing to amend an existing manifest list with no --amend flag")
assert.Error(t, err, "refusing to amend an existing manifest list with no --amend flag")
}
// attempt to make a manifest list without valid images
@ -113,5 +112,5 @@ func TestManifestCreateNoManifest(t *testing.T) {
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
cmd.SetOutput(ioutil.Discard)
err := cmd.Execute()
assert.EqualError(t, err, "No such image: example.com/alpine:3.0")
assert.Error(t, err, "No such image: example.com/alpine:3.0")
}

View File

@ -12,24 +12,24 @@ import (
"github.com/docker/distribution"
"github.com/docker/distribution/manifest/schema2"
"github.com/docker/distribution/reference"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/opencontainers/go-digest"
digest "github.com/opencontainers/go-digest"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/context"
)
func newTempManifestStore(t *testing.T) (store.Store, func()) {
tmpdir, err := ioutil.TempDir("", "test-manifest-storage")
require.NoError(t, err)
assert.NilError(t, err)
return store.NewStore(tmpdir), func() { os.RemoveAll(tmpdir) }
}
func ref(t *testing.T, name string) reference.Named {
named, err := reference.ParseNamed("example.com/" + name)
require.NoError(t, err)
assert.NilError(t, err)
return named
}
@ -49,7 +49,7 @@ func fullImageManifest(t *testing.T, ref reference.Named) types.ImageManifest {
},
},
})
require.NoError(t, err)
assert.NilError(t, err)
// TODO: include image data for verbose inspect
return types.NewImageManifest(ref, digest.Digest("sha256:7328f6f8b41890597575cbaadc884e7386ae0acc53b747401ebce5cf0d62abcd"), types.Image{OS: "linux", Architecture: "amd64"}, man)
}
@ -65,7 +65,7 @@ func TestInspectCommandLocalManifestNotFound(t *testing.T) {
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
err := cmd.Execute()
assert.EqualError(t, err, "No such manifest: example.com/alpine:3.0")
assert.Error(t, err, "No such manifest: example.com/alpine:3.0")
}
func TestInspectCommandNotFound(t *testing.T) {
@ -87,7 +87,7 @@ func TestInspectCommandNotFound(t *testing.T) {
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs([]string{"example.com/alpine:3.0"})
err := cmd.Execute()
assert.EqualError(t, err, "No such manifest: example.com/alpine:3.0")
assert.Error(t, err, "No such manifest: example.com/alpine:3.0")
}
func TestInspectCommandLocalManifest(t *testing.T) {
@ -99,14 +99,14 @@ func TestInspectCommandLocalManifest(t *testing.T) {
namedRef := ref(t, "alpine:3.0")
imageManifest := fullImageManifest(t, namedRef)
err := store.Save(ref(t, "list:v1"), namedRef, imageManifest)
require.NoError(t, err)
assert.NilError(t, err)
cmd := newInspectCommand(cli)
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
require.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
actual := cli.OutBuffer()
expected := golden.Get(t, "inspect-manifest.golden")
assert.Equal(t, string(expected), actual.String())
assert.Check(t, is.Equal(string(expected), actual.String()))
}
func TestInspectcommandRemoteManifest(t *testing.T) {
@ -124,8 +124,8 @@ func TestInspectcommandRemoteManifest(t *testing.T) {
cmd := newInspectCommand(cli)
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs([]string{"example.com/alpine:3.0"})
require.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
actual := cli.OutBuffer()
expected := golden.Get(t, "inspect-manifest.golden")
assert.Equal(t, string(expected), actual.String())
assert.Check(t, is.Equal(string(expected), actual.String()))
}

View File

@ -6,16 +6,13 @@ import (
manifesttypes "github.com/docker/cli/cli/manifest/types"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/distribution/reference"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
"golang.org/x/net/context"
)
func newFakeRegistryClient(t *testing.T) *fakeRegistryClient {
require.NoError(t, nil)
func newFakeRegistryClient() *fakeRegistryClient {
return &fakeRegistryClient{
getManifestFunc: func(_ context.Context, _ reference.Named) (manifesttypes.ImageManifest, error) {
return manifesttypes.ImageManifest{}, errors.New("")
@ -46,16 +43,15 @@ func TestManifestPushErrors(t *testing.T) {
cmd := newPushListCommand(cli)
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
// store a one-image manifest list and puah it
func TestManifestPush(t *testing.T) {
store, sCleanup := newTempManifestStore(t)
defer sCleanup()
registry := newFakeRegistryClient(t)
registry := newFakeRegistryClient()
cli := test.NewFakeCli(nil)
cli.SetManifestStore(store)
@ -64,10 +60,10 @@ func TestManifestPush(t *testing.T) {
namedRef := ref(t, "alpine:3.0")
imageManifest := fullImageManifest(t, namedRef)
err := store.Save(ref(t, "list:v1"), namedRef, imageManifest)
require.NoError(t, err)
assert.NilError(t, err)
cmd := newPushListCommand(cli)
cmd.SetArgs([]string{"example.com/list:v1"})
err = cmd.Execute()
require.NoError(t, err)
assert.NilError(t, err)
}

View File

@ -5,10 +5,10 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types/network"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
@ -38,7 +38,7 @@ func TestNetworkConnectErrors(t *testing.T) {
)
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -54,7 +54,7 @@ func TestNetworkConnectWithFlags(t *testing.T) {
}
cli := test.NewFakeCli(&fakeClient{
networkConnectFunc: func(ctx context.Context, networkID, container string, config *network.EndpointSettings) error {
assert.Equal(t, expectedOpts, config.IPAMConfig, "not expected driver error")
assert.Check(t, is.DeepEqual(expectedOpts, config.IPAMConfig), "not expected driver error")
return nil
},
})
@ -66,5 +66,5 @@ func TestNetworkConnectWithFlags(t *testing.T) {
cmd.Flags().Set("ip-range", "192.168.4.0/24")
cmd.Flags().Set("gateway", "192.168.4.1/24")
cmd.Flags().Set("subnet", "192.168.4.0/24")
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}

View File

@ -6,12 +6,11 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/network"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/context"
)
@ -136,10 +135,10 @@ func TestNetworkCreateErrors(t *testing.T) {
)
cmd.SetArgs(tc.args)
for key, value := range tc.flags {
require.NoError(t, cmd.Flags().Set(key, value))
assert.NilError(t, cmd.Flags().Set(key, value))
}
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -155,8 +154,8 @@ func TestNetworkCreateWithFlags(t *testing.T) {
}
cli := test.NewFakeCli(&fakeClient{
networkCreateFunc: func(ctx context.Context, name string, createBody types.NetworkCreate) (types.NetworkCreateResponse, error) {
assert.Equal(t, expectedDriver, createBody.Driver, "not expected driver error")
assert.Equal(t, expectedOpts, createBody.IPAM.Config, "not expected driver error")
assert.Check(t, is.Equal(expectedDriver, createBody.Driver), "not expected driver error")
assert.Check(t, is.DeepEqual(expectedOpts, createBody.IPAM.Config), "not expected driver error")
return types.NetworkCreateResponse{
ID: name,
}, nil
@ -170,6 +169,6 @@ func TestNetworkCreateWithFlags(t *testing.T) {
cmd.Flags().Set("ip-range", "192.168.4.0/24")
cmd.Flags().Set("gateway", "192.168.4.1/24")
cmd.Flags().Set("subnet", "192.168.4.0/24")
assert.NoError(t, cmd.Execute())
assert.Equal(t, "banana", strings.TrimSpace(cli.OutBuffer().String()))
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("banana", strings.TrimSpace(cli.OutBuffer().String())))
}

View File

@ -5,7 +5,7 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/pkg/errors"
"golang.org/x/net/context"
)
@ -36,6 +36,6 @@ func TestNetworkDisconnectErrors(t *testing.T) {
)
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}

View File

@ -1,20 +1,19 @@
package network
import (
"testing"
"io/ioutil"
"strings"
"testing"
"github.com/docker/cli/internal/test"
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/google/go-cmp/cmp"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
@ -38,23 +37,18 @@ func TestNetworkListErrors(t *testing.T) {
}),
)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
func TestNetworkListWithFlags(t *testing.T) {
filterArgs := filters.NewArgs()
filterArgs.Add("image.name", "ubuntu")
expectedOpts := types.NetworkListOptions{
Filters: filterArgs,
Filters: filters.NewArgs(filters.Arg("image.name", "ubuntu")),
}
cli := test.NewFakeCli(&fakeClient{
networkListFunc: func(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) {
assert.Equal(t, expectedOpts, options, "not expected options error")
assert.Check(t, is.DeepEqual(expectedOpts, options, cmp.AllowUnexported(filters.Args{})))
return []types.NetworkResource{*NetworkResource(NetworkResourceID("123454321"),
NetworkResourceName("network_1"),
NetworkResourceDriver("09.7.01"),
@ -64,6 +58,6 @@ func TestNetworkListWithFlags(t *testing.T) {
cmd := newListCommand(cli)
cmd.Flags().Set("filter", "image.name=ubuntu")
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, strings.TrimSpace(cli.OutBuffer().String()), "network-list.golden")
}

View File

@ -6,11 +6,10 @@ import (
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/cli/internal/test/testutil"
"github.com/stretchr/testify/assert"
)
func TestNodeDemoteErrors(t *testing.T) {
@ -46,7 +45,7 @@ func TestNodeDemoteErrors(t *testing.T) {
}))
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -64,7 +63,7 @@ func TestNodeDemoteNoChange(t *testing.T) {
},
}))
cmd.SetArgs([]string{"nodeID"})
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}
func TestNodeDemoteMultipleNode(t *testing.T) {
@ -81,5 +80,5 @@ func TestNodeDemoteMultipleNode(t *testing.T) {
},
}))
cmd.SetArgs([]string{"nodeID1", "nodeID2"})
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}

View File

@ -11,9 +11,8 @@ import (
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/cli/internal/test/testutil"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
)
func TestNodeInspectErrors(t *testing.T) {
@ -76,7 +75,7 @@ func TestNodeInspectErrors(t *testing.T) {
cmd.Flags().Set(key, value)
}
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -113,7 +112,7 @@ func TestNodeInspectPretty(t *testing.T) {
cmd := newInspectCommand(cli)
cmd.SetArgs([]string{"nodeID"})
cmd.Flags().Set("pretty", "true")
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("node-inspect-pretty.%s.golden", tc.name))
}
}

View File

@ -8,11 +8,12 @@ import (
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/internal/test/builders"
"github.com/stretchr/testify/assert"
)
func TestNodeListErrorOnAPIFailure(t *testing.T) {
@ -48,7 +49,7 @@ func TestNodeListErrorOnAPIFailure(t *testing.T) {
})
cmd := newListCommand(cli)
cmd.SetOutput(ioutil.Discard)
assert.EqualError(t, cmd.Execute(), tc.expectedError)
assert.Error(t, cmd.Execute(), tc.expectedError)
}
}
@ -71,7 +72,7 @@ func TestNodeList(t *testing.T) {
})
cmd := newListCommand(cli)
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "node-list-sort.golden")
}
@ -85,8 +86,8 @@ func TestNodeListQuietShouldOnlyPrintIDs(t *testing.T) {
})
cmd := newListCommand(cli)
cmd.Flags().Set("quiet", "true")
assert.NoError(t, cmd.Execute())
assert.Equal(t, cli.OutBuffer().String(), "nodeID1\n")
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal(cli.OutBuffer().String(), "nodeID1\n"))
}
func TestNodeListDefaultFormatFromConfig(t *testing.T) {
@ -110,7 +111,7 @@ func TestNodeListDefaultFormatFromConfig(t *testing.T) {
NodesFormat: "{{.ID}}: {{.Hostname}} {{.Status}}/{{.ManagerStatus}}",
})
cmd := newListCommand(cli)
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "node-list-format-from-config.golden")
}
@ -135,6 +136,6 @@ func TestNodeListFormat(t *testing.T) {
})
cmd := newListCommand(cli)
cmd.Flags().Set("format", "{{.Hostname}}: {{.ManagerStatus}}")
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "node-list-format-flag.golden")
}

View File

@ -6,11 +6,10 @@ import (
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/cli/internal/test/testutil"
"github.com/stretchr/testify/assert"
)
func TestNodePromoteErrors(t *testing.T) {
@ -46,7 +45,7 @@ func TestNodePromoteErrors(t *testing.T) {
}))
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -64,7 +63,7 @@ func TestNodePromoteNoChange(t *testing.T) {
},
}))
cmd.SetArgs([]string{"nodeID"})
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}
func TestNodePromoteMultipleNode(t *testing.T) {
@ -81,5 +80,5 @@ func TestNodePromoteMultipleNode(t *testing.T) {
},
}))
cmd.SetArgs([]string{"nodeID1", "nodeID2"})
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}

View File

@ -12,8 +12,8 @@ import (
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/internal/test/builders"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
)
func TestNodePsErrors(t *testing.T) {
@ -60,7 +60,7 @@ func TestNodePsErrors(t *testing.T) {
cmd.Flags().Set(key, value)
}
cmd.SetOutput(ioutil.Discard)
assert.EqualError(t, cmd.Execute(), tc.expectedError)
assert.Error(t, cmd.Execute(), tc.expectedError)
}
}
@ -122,7 +122,7 @@ func TestNodePs(t *testing.T) {
for key, value := range tc.flags {
cmd.Flags().Set(key, value)
}
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("node-ps.%s.golden", tc.name))
}
}

View File

@ -5,9 +5,8 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
func TestNodeRemoveErrors(t *testing.T) {
@ -34,12 +33,12 @@ func TestNodeRemoveErrors(t *testing.T) {
}))
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
func TestNodeRemoveMultiple(t *testing.T) {
cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}))
cmd.SetArgs([]string{"nodeID1", "nodeID2"})
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}

View File

@ -6,11 +6,10 @@ import (
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/cli/internal/test/testutil"
"github.com/stretchr/testify/assert"
)
func TestNodeUpdateErrors(t *testing.T) {
@ -66,7 +65,7 @@ func TestNodeUpdateErrors(t *testing.T) {
cmd.Flags().Set(key, value)
}
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -165,6 +164,6 @@ func TestNodeUpdate(t *testing.T) {
for key, value := range tc.flags {
cmd.Flags().Set(key, value)
}
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}
}

View File

@ -4,17 +4,21 @@ import (
"fmt"
"io"
"io/ioutil"
"runtime"
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/fs"
"github.com/stretchr/testify/assert"
)
func TestCreateErrors(t *testing.T) {
noSuchFile := "no such file or directory"
if runtime.GOOS == "windows" {
noSuchFile = "The system cannot find the file specified."
}
testCases := []struct {
args []string
expectedError string
@ -29,7 +33,7 @@ func TestCreateErrors(t *testing.T) {
},
{
args: []string{"plugin-foo", "nonexistent_context_dir"},
expectedError: "no such file or directory",
expectedError: noSuchFile,
},
}
@ -38,7 +42,7 @@ func TestCreateErrors(t *testing.T) {
cmd := newCreateCommand(cli)
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -50,7 +54,7 @@ func TestCreateErrorOnFileAsContextDir(t *testing.T) {
cmd := newCreateCommand(cli)
cmd.SetArgs([]string{"plugin-foo", tmpFile.Path()})
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), "context must be a directory")
assert.ErrorContains(t, cmd.Execute(), "context must be a directory")
}
func TestCreateErrorOnContextDirWithoutConfig(t *testing.T) {
@ -61,7 +65,12 @@ func TestCreateErrorOnContextDirWithoutConfig(t *testing.T) {
cmd := newCreateCommand(cli)
cmd.SetArgs([]string{"plugin-foo", tmpDir.Path()})
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), "config.json: no such file or directory")
expectedErr := "config.json: no such file or directory"
if runtime.GOOS == "windows" {
expectedErr = "config.json: The system cannot find the file specified."
}
assert.ErrorContains(t, cmd.Execute(), expectedErr)
}
func TestCreateErrorOnInvalidConfig(t *testing.T) {
@ -74,7 +83,7 @@ func TestCreateErrorOnInvalidConfig(t *testing.T) {
cmd := newCreateCommand(cli)
cmd.SetArgs([]string{"plugin-foo", tmpDir.Path()})
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), "invalid")
assert.ErrorContains(t, cmd.Execute(), "invalid")
}
func TestCreateErrorFromDaemon(t *testing.T) {
@ -92,7 +101,7 @@ func TestCreateErrorFromDaemon(t *testing.T) {
cmd := newCreateCommand(cli)
cmd.SetArgs([]string{"plugin-foo", tmpDir.Path()})
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), "Error creating plugin")
assert.ErrorContains(t, cmd.Execute(), "Error creating plugin")
}
func TestCreatePlugin(t *testing.T) {
@ -109,6 +118,6 @@ func TestCreatePlugin(t *testing.T) {
cmd := newCreateCommand(cli)
cmd.SetArgs([]string{"plugin-foo", tmpDir.Path()})
assert.NoError(t, cmd.Execute())
assert.Equal(t, "plugin-foo\n", cli.OutBuffer().String())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
}

View File

@ -6,9 +6,9 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestPluginDisableErrors(t *testing.T) {
@ -41,7 +41,7 @@ func TestPluginDisableErrors(t *testing.T) {
}))
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -53,6 +53,6 @@ func TestPluginDisable(t *testing.T) {
})
cmd := newDisableCommand(cli)
cmd.SetArgs([]string{"plugin-foo"})
assert.NoError(t, cmd.Execute())
assert.Equal(t, "plugin-foo\n", cli.OutBuffer().String())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
}

View File

@ -6,9 +6,9 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestPluginEnableErrors(t *testing.T) {
@ -52,7 +52,7 @@ func TestPluginEnableErrors(t *testing.T) {
cmd.Flags().Set(key, value)
}
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -65,6 +65,6 @@ func TestPluginEnable(t *testing.T) {
cmd := newEnableCommand(cli)
cmd.SetArgs([]string{"plugin-foo"})
assert.NoError(t, cmd.Execute())
assert.Equal(t, "plugin-foo\n", cli.OutBuffer().String())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
}

View File

@ -24,11 +24,12 @@ type pluginOptions struct {
disable bool
args []string
skipRemoteCheck bool
untrusted bool
}
func loadPullFlags(opts *pluginOptions, flags *pflag.FlagSet) {
func loadPullFlags(dockerCli command.Cli, opts *pluginOptions, flags *pflag.FlagSet) {
flags.BoolVar(&opts.grantPerms, "grant-all-permissions", false, "Grant all permissions necessary to run the plugin")
command.AddTrustVerificationFlags(flags)
command.AddTrustVerificationFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled())
}
func newInstallCommand(dockerCli command.Cli) *cobra.Command {
@ -47,7 +48,7 @@ func newInstallCommand(dockerCli command.Cli) *cobra.Command {
}
flags := cmd.Flags()
loadPullFlags(&options, flags)
loadPullFlags(dockerCli, &options, flags)
flags.BoolVar(&options.disable, "disable", false, "Do not enable the plugin on install")
flags.StringVar(&options.localName, "alias", "", "Local name for plugin")
return cmd
@ -90,7 +91,7 @@ func buildPullConfig(ctx context.Context, dockerCli command.Cli, opts pluginOpti
remote := ref.String()
_, isCanonical := ref.(reference.Canonical)
if command.IsTrusted() && !isCanonical {
if !opts.untrusted && !isCanonical {
ref = reference.TagNameOnly(ref)
nt, ok := ref.(reference.NamedTagged)
if !ok {

View File

@ -13,30 +13,37 @@ import (
"github.com/spf13/cobra"
)
type pushOptions struct {
name string
untrusted bool
}
func newPushCommand(dockerCli command.Cli) *cobra.Command {
var opts pushOptions
cmd := &cobra.Command{
Use: "push [OPTIONS] PLUGIN[:TAG]",
Short: "Push a plugin to a registry",
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return runPush(dockerCli, args[0])
opts.name = args[0]
return runPush(dockerCli, opts)
},
}
flags := cmd.Flags()
command.AddTrustSigningFlags(flags)
command.AddTrustSigningFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled())
return cmd
}
func runPush(dockerCli command.Cli, name string) error {
named, err := reference.ParseNormalizedNamed(name)
func runPush(dockerCli command.Cli, opts pushOptions) error {
named, err := reference.ParseNormalizedNamed(opts.name)
if err != nil {
return err
}
if _, ok := named.(reference.Canonical); ok {
return errors.Errorf("invalid name: %s", name)
return errors.Errorf("invalid name: %s", opts.name)
}
named = reference.TagNameOnly(named)
@ -60,7 +67,7 @@ func runPush(dockerCli command.Cli, name string) error {
}
defer responseBody.Close()
if command.IsTrusted() {
if !opts.untrusted {
repoInfo.Class = "plugin"
return image.PushTrustedReference(dockerCli, repoInfo, named, authConfig, responseBody)
}

View File

@ -6,9 +6,9 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/stretchr/testify/assert"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestRemoveErrors(t *testing.T) {
@ -38,7 +38,7 @@ func TestRemoveErrors(t *testing.T) {
cmd := newRemoveCommand(cli)
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -50,8 +50,8 @@ func TestRemove(t *testing.T) {
})
cmd := newRemoveCommand(cli)
cmd.SetArgs([]string{"plugin-foo"})
assert.NoError(t, cmd.Execute())
assert.Equal(t, "plugin-foo\n", cli.OutBuffer().String())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
}
func TestRemoveWithForceOption(t *testing.T) {
@ -65,7 +65,7 @@ func TestRemoveWithForceOption(t *testing.T) {
cmd := newRemoveCommand(cli)
cmd.SetArgs([]string{"plugin-foo"})
cmd.Flags().Set("force", "true")
assert.NoError(t, cmd.Execute())
assert.True(t, force)
assert.Equal(t, "plugin-foo\n", cli.OutBuffer().String())
assert.NilError(t, cmd.Execute())
assert.Check(t, force)
assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
}

View File

@ -30,7 +30,7 @@ func newUpgradeCommand(dockerCli command.Cli) *cobra.Command {
}
flags := cmd.Flags()
loadPullFlags(&options, flags)
loadPullFlags(dockerCli, &options, flags)
flags.BoolVar(&options.skipRemoteCheck, "skip-remote-check", false, "Do not check if specified remote plugin matches existing plugin image")
return cmd
}

View File

@ -52,11 +52,15 @@ func RegistryAuthenticationPrivilegedFunc(cli Cli, index *registrytypes.IndexInf
fmt.Fprintf(cli.Out(), "\nPlease login prior to %s:\n", cmdName)
indexServer := registry.GetAuthConfigKey(index)
isDefaultRegistry := indexServer == ElectAuthServer(context.Background(), cli)
authConfig, err := ConfigureAuth(cli, "", "", indexServer, isDefaultRegistry)
authConfig, err := GetDefaultAuthConfig(cli, true, indexServer, isDefaultRegistry)
if err != nil {
fmt.Fprintf(cli.Err(), "Unable to retrieve stored credentials for %s, error: %s.\n", indexServer, err)
}
err = ConfigureAuth(cli, "", "", authConfig, isDefaultRegistry)
if err != nil {
return "", err
}
return EncodeAuthToBase64(authConfig)
return EncodeAuthToBase64(*authConfig)
}
}
@ -73,20 +77,29 @@ func ResolveAuthConfig(ctx context.Context, cli Cli, index *registrytypes.IndexI
return a
}
// ConfigureAuth returns an AuthConfig from the specified user, password and server.
func ConfigureAuth(cli Cli, flUser, flPassword, serverAddress string, isDefaultRegistry bool) (types.AuthConfig, error) {
// On Windows, force the use of the regular OS stdin stream. Fixes #14336/#14210
if runtime.GOOS == "windows" {
cli.SetIn(NewInStream(os.Stdin))
}
// GetDefaultAuthConfig gets the default auth config given a serverAddress
// If credentials for given serverAddress exists in the credential store, the configuration will be populated with values in it
func GetDefaultAuthConfig(cli Cli, checkCredStore bool, serverAddress string, isDefaultRegistry bool) (*types.AuthConfig, error) {
if !isDefaultRegistry {
serverAddress = registry.ConvertToHostname(serverAddress)
}
var authconfig types.AuthConfig
var err error
if checkCredStore {
authconfig, err = cli.ConfigFile().GetAuthConfig(serverAddress)
} else {
authconfig = types.AuthConfig{}
}
authconfig.ServerAddress = serverAddress
authconfig.IdentityToken = ""
return &authconfig, err
}
authconfig, err := cli.ConfigFile().GetAuthConfig(serverAddress)
if err != nil {
return authconfig, err
// ConfigureAuth handles prompting of user's username and password if needed
func ConfigureAuth(cli Cli, flUser, flPassword string, authconfig *types.AuthConfig, isDefaultRegistry bool) error {
// On Windows, force the use of the regular OS stdin stream. Fixes #14336/#14210
if runtime.GOOS == "windows" {
cli.SetIn(NewInStream(os.Stdin))
}
// Some links documenting this:
@ -97,7 +110,7 @@ func ConfigureAuth(cli Cli, flUser, flPassword, serverAddress string, isDefaultR
// will hit this if you attempt docker login from mintty where stdin
// is a pipe, not a character based console.
if flPassword == "" && !cli.In().IsTerminal() {
return authconfig, errors.Errorf("Error: Cannot perform an interactive login from a non TTY device")
return errors.Errorf("Error: Cannot perform an interactive login from a non TTY device")
}
authconfig.Username = strings.TrimSpace(authconfig.Username)
@ -115,12 +128,12 @@ func ConfigureAuth(cli Cli, flUser, flPassword, serverAddress string, isDefaultR
}
}
if flUser == "" {
return authconfig, errors.Errorf("Error: Non-null Username Required")
return errors.Errorf("Error: Non-null Username Required")
}
if flPassword == "" {
oldState, err := term.SaveState(cli.In().FD())
if err != nil {
return authconfig, err
return err
}
fmt.Fprintf(cli.Out(), "Password: ")
term.DisableEcho(cli.In().FD(), oldState)
@ -130,16 +143,14 @@ func ConfigureAuth(cli Cli, flUser, flPassword, serverAddress string, isDefaultR
term.RestoreTerminal(cli.In().FD(), oldState)
if flPassword == "" {
return authconfig, errors.Errorf("Error: Password Required")
return errors.Errorf("Error: Password Required")
}
}
authconfig.Username = flUser
authconfig.Password = flPassword
authconfig.ServerAddress = serverAddress
authconfig.IdentityToken = ""
return authconfig, nil
return nil
}
func readInput(in io.Reader, out io.Writer) string {

View File

@ -9,11 +9,19 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/docker/api/types"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/client"
"github.com/docker/docker/registry"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
const unencryptedWarning = `WARNING! Your password will be stored unencrypted in %s.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
`
type loginOptions struct {
serverAddress string
user string
@ -47,10 +55,30 @@ func NewLoginCommand(dockerCli command.Cli) *cobra.Command {
return cmd
}
func runLogin(dockerCli command.Cli, opts loginOptions) error {
ctx := context.Background()
clnt := dockerCli.Client()
// unencryptedPrompt prompts the user to find out whether they want to continue
// with insecure credential storage. If stdin is not a terminal, we assume they
// want it (sadly), because people may have been scripting insecure logins and
// we don't want to break them. Maybe they'll see the warning in their logs and
// fix things.
func unencryptedPrompt(dockerCli command.Streams, filename string) error {
fmt.Fprintln(dockerCli.Err(), fmt.Sprintf(unencryptedWarning, filename))
if dockerCli.In().IsTerminal() {
if command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), "") {
return nil
}
return errors.Errorf("User refused unencrypted credentials storage.")
}
return nil
}
type isFileStore interface {
IsFileStore() bool
GetFilename() string
}
func verifyloginOptions(dockerCli command.Cli, opts *loginOptions) error {
if opts.password != "" {
fmt.Fprintln(dockerCli.Err(), "WARNING! Using --password via the CLI is insecure. Use --password-stdin.")
if opts.passwordStdin {
@ -71,7 +99,15 @@ func runLogin(dockerCli command.Cli, opts loginOptions) error {
opts.password = strings.TrimSuffix(string(contents), "\n")
opts.password = strings.TrimSuffix(opts.password, "\r")
}
return nil
}
func runLogin(dockerCli command.Cli, opts loginOptions) error { //nolint: gocyclo
ctx := context.Background()
clnt := dockerCli.Client()
if err := verifyloginOptions(dockerCli, &opts); err != nil {
return err
}
var (
serverAddress string
authServer = command.ElectAuthServer(ctx, dockerCli)
@ -82,21 +118,41 @@ func runLogin(dockerCli command.Cli, opts loginOptions) error {
serverAddress = authServer
}
var err error
var authConfig *types.AuthConfig
var response registrytypes.AuthenticateOKBody
isDefaultRegistry := serverAddress == authServer
authConfig, err := command.ConfigureAuth(dockerCli, opts.user, opts.password, serverAddress, isDefaultRegistry)
if err != nil {
return err
authConfig, err = command.GetDefaultAuthConfig(dockerCli, opts.user == "" && opts.password == "", serverAddress, isDefaultRegistry)
if err == nil && authConfig.Username != "" && authConfig.Password != "" {
response, err = loginWithCredStoreCreds(ctx, dockerCli, authConfig)
}
response, err := clnt.RegistryLogin(ctx, authConfig)
if err != nil {
return err
if err != nil || authConfig.Username == "" || authConfig.Password == "" {
err = command.ConfigureAuth(dockerCli, opts.user, opts.password, authConfig, isDefaultRegistry)
if err != nil {
return err
}
response, err = clnt.RegistryLogin(ctx, *authConfig)
if err != nil {
return err
}
}
if response.IdentityToken != "" {
authConfig.Password = ""
authConfig.IdentityToken = response.IdentityToken
}
if err := dockerCli.ConfigFile().GetCredentialsStore(serverAddress).Store(authConfig); err != nil {
creds := dockerCli.ConfigFile().GetCredentialsStore(serverAddress)
store, isDefault := creds.(isFileStore)
if isDefault {
err = unencryptedPrompt(dockerCli, store.GetFilename())
if err != nil {
return err
}
}
if err := creds.Store(*authConfig); err != nil {
return errors.Errorf("Error saving credentials: %v", err)
}
@ -105,3 +161,17 @@ func runLogin(dockerCli command.Cli, opts loginOptions) error {
}
return nil
}
func loginWithCredStoreCreds(ctx context.Context, dockerCli command.Cli, authConfig *types.AuthConfig) (registrytypes.AuthenticateOKBody, error) {
fmt.Fprintf(dockerCli.Out(), "Authenticating with existing credentials...\n")
cliClient := dockerCli.Client()
response, err := cliClient.RegistryLogin(ctx, *authConfig)
if err != nil {
if client.IsErrUnauthorized(err) {
fmt.Fprintf(dockerCli.Err(), "Stored credentials invalid or expired\n")
} else {
fmt.Fprintf(dockerCli.Err(), "Login did not succeed, error: %s\n", err)
}
}
return response, err
}

View File

@ -0,0 +1,157 @@
package registry
import (
"bytes"
"fmt"
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/client"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/fs"
"golang.org/x/net/context"
)
const userErr = "userunknownError"
const testAuthErrMsg = "UNKNOWN_ERR"
var testAuthErrors = map[string]error{
userErr: fmt.Errorf(testAuthErrMsg),
}
var expiredPassword = "I_M_EXPIRED"
type fakeClient struct {
client.Client
}
// nolint: unparam
func (c fakeClient) RegistryLogin(ctx context.Context, auth types.AuthConfig) (registrytypes.AuthenticateOKBody, error) {
if auth.Password == expiredPassword {
return registrytypes.AuthenticateOKBody{}, fmt.Errorf("Invalid Username or Password")
}
err := testAuthErrors[auth.Username]
return registrytypes.AuthenticateOKBody{}, err
}
func TestLoginWithCredStoreCreds(t *testing.T) {
testCases := []struct {
inputAuthConfig types.AuthConfig
expectedMsg string
expectedErr string
}{
{
inputAuthConfig: types.AuthConfig{},
expectedMsg: "Authenticating with existing credentials...\n",
},
{
inputAuthConfig: types.AuthConfig{
Username: userErr,
},
expectedMsg: "Authenticating with existing credentials...\n",
expectedErr: fmt.Sprintf("Login did not succeed, error: %s\n", testAuthErrMsg),
},
// can't easily test the 401 case because client.IsErrUnauthorized(err) involving
// creating an error of a private type
}
ctx := context.Background()
for _, tc := range testCases {
cli := (*test.FakeCli)(test.NewFakeCli(&fakeClient{}))
errBuf := new(bytes.Buffer)
cli.SetErr(errBuf)
loginWithCredStoreCreds(ctx, cli, &tc.inputAuthConfig)
outputString := cli.OutBuffer().String()
assert.Check(t, is.Equal(tc.expectedMsg, outputString))
errorString := errBuf.String()
assert.Check(t, is.Equal(tc.expectedErr, errorString))
}
}
func TestRunLogin(t *testing.T) {
const storedServerAddress = "reg1"
const validUsername = "u1"
const validPassword = "p1"
const validPassword2 = "p2"
validAuthConfig := types.AuthConfig{
ServerAddress: storedServerAddress,
Username: validUsername,
Password: validPassword,
}
expiredAuthConfig := types.AuthConfig{
ServerAddress: storedServerAddress,
Username: validUsername,
Password: expiredPassword,
}
testCases := []struct {
inputLoginOption loginOptions
inputStoredCred *types.AuthConfig
expectedErr string
expectedSavedCred types.AuthConfig
}{
{
inputLoginOption: loginOptions{
serverAddress: storedServerAddress,
},
inputStoredCred: &validAuthConfig,
expectedErr: "",
expectedSavedCred: validAuthConfig,
},
{
inputLoginOption: loginOptions{
serverAddress: storedServerAddress,
},
inputStoredCred: &expiredAuthConfig,
expectedErr: "Error: Cannot perform an interactive login from a non TTY device",
},
{
inputLoginOption: loginOptions{
serverAddress: storedServerAddress,
user: validUsername,
password: validPassword2,
},
inputStoredCred: &validAuthConfig,
expectedErr: "",
expectedSavedCred: types.AuthConfig{
ServerAddress: storedServerAddress,
Username: validUsername,
Password: validPassword2,
},
},
{
inputLoginOption: loginOptions{
serverAddress: storedServerAddress,
user: userErr,
password: validPassword,
},
inputStoredCred: &validAuthConfig,
expectedErr: testAuthErrMsg,
},
}
for i, tc := range testCases {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
tmpFile := fs.NewFile(t, "test-run-login")
defer tmpFile.Remove()
cli := test.NewFakeCli(&fakeClient{})
configfile := cli.ConfigFile()
configfile.Filename = tmpFile.Path()
if tc.inputStoredCred != nil {
cred := *tc.inputStoredCred
configfile.GetCredentialsStore(cred.ServerAddress).Store(cred)
}
loginErr := runLogin(cli, tc.inputLoginOption)
if tc.expectedErr != "" {
assert.Error(t, loginErr, tc.expectedErr)
return
}
assert.NilError(t, loginErr)
savedCred, credStoreErr := configfile.GetCredentialsStore(tc.inputStoredCred.ServerAddress).Get(tc.inputStoredCred.ServerAddress)
assert.Check(t, credStoreErr)
assert.DeepEqual(t, tc.expectedSavedCred, savedCred)
})
}
}

View File

@ -1,13 +1,17 @@
package command_test
import (
"bytes"
"fmt"
"testing"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
// Prevents a circular import with "github.com/docker/cli/internal/test"
. "github.com/docker/cli/cli/command"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
@ -19,6 +23,19 @@ type fakeClient struct {
infoFunc func() (types.Info, error)
}
var testAuthConfigs = []types.AuthConfig{
{
ServerAddress: "https://index.docker.io/v1/",
Username: "u0",
Password: "p0",
},
{
ServerAddress: "server1.io",
Username: "u1",
Password: "p1",
},
}
func (cli *fakeClient) Info(_ context.Context) (types.Info, error) {
if cli.infoFunc != nil {
return cli.infoFunc()
@ -64,12 +81,67 @@ func TestElectAuthServer(t *testing.T) {
for _, tc := range testCases {
cli := test.NewFakeCli(&fakeClient{infoFunc: tc.infoFunc})
server := ElectAuthServer(context.Background(), cli)
assert.Equal(t, tc.expectedAuthServer, server)
assert.Check(t, is.Equal(tc.expectedAuthServer, server))
actual := cli.ErrBuffer().String()
if tc.expectedWarning == "" {
assert.Empty(t, actual)
assert.Check(t, is.Len(actual, 0))
} else {
assert.Contains(t, actual, tc.expectedWarning)
assert.Check(t, is.Contains(actual, tc.expectedWarning))
}
}
}
func TestGetDefaultAuthConfig(t *testing.T) {
testCases := []struct {
checkCredStore bool
inputServerAddress string
expectedErr string
expectedAuthConfig types.AuthConfig
}{
{
checkCredStore: false,
inputServerAddress: "",
expectedErr: "",
expectedAuthConfig: types.AuthConfig{
ServerAddress: "",
Username: "",
Password: "",
},
},
{
checkCredStore: true,
inputServerAddress: testAuthConfigs[0].ServerAddress,
expectedErr: "",
expectedAuthConfig: testAuthConfigs[0],
},
{
checkCredStore: true,
inputServerAddress: testAuthConfigs[1].ServerAddress,
expectedErr: "",
expectedAuthConfig: testAuthConfigs[1],
},
{
checkCredStore: true,
inputServerAddress: fmt.Sprintf("https://%s", testAuthConfigs[1].ServerAddress),
expectedErr: "",
expectedAuthConfig: testAuthConfigs[1],
},
}
cli := test.NewFakeCli(&fakeClient{})
errBuf := new(bytes.Buffer)
cli.SetErr(errBuf)
for _, authconfig := range testAuthConfigs {
cli.ConfigFile().GetCredentialsStore(authconfig.ServerAddress).Store(authconfig)
}
for _, tc := range testCases {
serverAddress := tc.inputServerAddress
authconfig, err := GetDefaultAuthConfig(cli, tc.checkCredStore, serverAddress, serverAddress == "https://index.docker.io/v1/")
if tc.expectedErr != "" {
assert.Check(t, err != nil)
assert.Check(t, is.Equal(tc.expectedErr, err.Error()))
} else {
assert.NilError(t, err)
assert.Check(t, is.DeepEqual(tc.expectedAuthConfig, *authconfig))
}
}
}

View File

@ -8,11 +8,11 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
const secretDataFile = "secret-create-with-name.golden"
@ -45,14 +45,14 @@ func TestSecretCreateErrors(t *testing.T) {
)
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
func TestSecretCreateWithName(t *testing.T) {
name := "foo"
data, err := ioutil.ReadFile(filepath.Join("testdata", secretDataFile))
assert.NoError(t, err)
assert.NilError(t, err)
expected := swarm.SecretSpec{
Annotations: swarm.Annotations{
@ -75,8 +75,8 @@ func TestSecretCreateWithName(t *testing.T) {
cmd := newSecretCreateCommand(cli)
cmd.SetArgs([]string{name, filepath.Join("testdata", secretDataFile)})
assert.NoError(t, cmd.Execute())
assert.Equal(t, "ID-"+name, strings.TrimSpace(cli.OutBuffer().String()))
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
}
func TestSecretCreateWithDriver(t *testing.T) {
@ -104,8 +104,8 @@ func TestSecretCreateWithDriver(t *testing.T) {
cmd := newSecretCreateCommand(cli)
cmd.SetArgs([]string{name})
cmd.Flags().Set("driver", expectedDriver.Name)
assert.NoError(t, cmd.Execute())
assert.Equal(t, "ID-"+name, strings.TrimSpace(cli.OutBuffer().String()))
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
}
func TestSecretCreateWithTemplatingDriver(t *testing.T) {
@ -133,8 +133,8 @@ func TestSecretCreateWithTemplatingDriver(t *testing.T) {
cmd := newSecretCreateCommand(cli)
cmd.SetArgs([]string{name})
cmd.Flags().Set("template-driver", expectedDriver.Name)
assert.NoError(t, cmd.Execute())
assert.Equal(t, "ID-"+name, strings.TrimSpace(cli.OutBuffer().String()))
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
}
func TestSecretCreateWithLabels(t *testing.T) {
@ -164,6 +164,6 @@ func TestSecretCreateWithLabels(t *testing.T) {
cmd.SetArgs([]string{name, filepath.Join("testdata", secretDataFile)})
cmd.Flags().Set("label", "lbl1=Label-foo")
cmd.Flags().Set("label", "lbl2=Label-bar")
assert.NoError(t, cmd.Execute())
assert.Equal(t, "ID-"+name, strings.TrimSpace(cli.OutBuffer().String()))
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
}

View File

@ -11,9 +11,8 @@ import (
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/cli/internal/test/testutil"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
)
func TestSecretInspectErrors(t *testing.T) {
@ -62,7 +61,7 @@ func TestSecretInspectErrors(t *testing.T) {
cmd.Flags().Set(key, value)
}
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -98,7 +97,7 @@ func TestSecretInspectWithoutFormat(t *testing.T) {
})
cmd := newSecretInspectCommand(cli)
cmd.SetArgs(tc.args)
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("secret-inspect-without-format.%s.golden", tc.name))
}
}
@ -135,7 +134,7 @@ func TestSecretInspectWithFormat(t *testing.T) {
cmd := newSecretInspectCommand(cli)
cmd.SetArgs(tc.args)
cmd.Flags().Set("format", tc.format)
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("secret-inspect-with-format.%s.golden", tc.name))
}
}
@ -168,7 +167,7 @@ func TestSecretInspectPretty(t *testing.T) {
cmd := newSecretInspectCommand(cli)
cmd.SetArgs([]string{"secretID"})
cmd.Flags().Set("pretty", "true")
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("secret-inspect-pretty.%s.golden", tc.name))
}
}

View File

@ -12,9 +12,9 @@ import (
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/cli/internal/test/testutil"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
)
func TestSecretListErrors(t *testing.T) {
@ -42,7 +42,7 @@ func TestSecretListErrors(t *testing.T) {
)
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -74,7 +74,7 @@ func TestSecretList(t *testing.T) {
},
})
cmd := newSecretListCommand(cli)
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "secret-list-sort.golden")
}
@ -91,7 +91,7 @@ func TestSecretListWithQuietOption(t *testing.T) {
})
cmd := newSecretListCommand(cli)
cmd.Flags().Set("quiet", "true")
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "secret-list-with-quiet-option.golden")
}
@ -110,7 +110,7 @@ func TestSecretListWithConfigFormat(t *testing.T) {
SecretFormat: "{{ .Name }} {{ .Labels }}",
})
cmd := newSecretListCommand(cli)
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "secret-list-with-config-format.golden")
}
@ -127,15 +127,15 @@ func TestSecretListWithFormat(t *testing.T) {
})
cmd := newSecretListCommand(cli)
cmd.Flags().Set("format", "{{ .Name }} {{ .Labels }}")
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "secret-list-with-format.golden")
}
func TestSecretListWithFilter(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
secretListFunc: func(options types.SecretListOptions) ([]swarm.Secret, error) {
assert.Equal(t, "foo", options.Filters.Get("name")[0], "foo")
assert.Equal(t, "lbl1=Label-bar", options.Filters.Get("label")[0])
assert.Check(t, is.Equal("foo", options.Filters.Get("name")[0]), "foo")
assert.Check(t, is.Equal("lbl1=Label-bar", options.Filters.Get("label")[0]))
return []swarm.Secret{
*Secret(SecretID("ID-foo"),
SecretName("foo"),
@ -155,6 +155,6 @@ func TestSecretListWithFilter(t *testing.T) {
cmd := newSecretListCommand(cli)
cmd.Flags().Set("filter", "name=foo")
cmd.Flags().Set("filter", "label=lbl1=Label-bar")
assert.NoError(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "secret-list-with-filter.golden")
}

View File

@ -6,9 +6,9 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
func TestSecretRemoveErrors(t *testing.T) {
@ -37,7 +37,7 @@ func TestSecretRemoveErrors(t *testing.T) {
)
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
@ -52,9 +52,9 @@ func TestSecretRemoveWithName(t *testing.T) {
})
cmd := newSecretRemoveCommand(cli)
cmd.SetArgs(names)
assert.NoError(t, cmd.Execute())
assert.Equal(t, names, strings.Split(strings.TrimSpace(cli.OutBuffer().String()), "\n"))
assert.Equal(t, names, removedSecrets)
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, removedSecrets))
}
func TestSecretRemoveContinueAfterError(t *testing.T) {
@ -74,6 +74,6 @@ func TestSecretRemoveContinueAfterError(t *testing.T) {
cmd := newSecretRemoveCommand(cli)
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(names)
assert.EqualError(t, cmd.Execute(), "error removing secret: foo")
assert.Equal(t, names, removedSecrets)
assert.Error(t, cmd.Execute(), "error removing secret: foo")
assert.Check(t, is.DeepEqual(names, removedSecrets))
}

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