Commit Graph

6010 Commits

Author SHA1 Message Date
Jean-Christophe Sirot b3aa17187f Make default context behaves like a real context:
- when using "--context default" parameter
- when printing the list of contexts
- when exporting the default context to a tarball

Signed-off-by: Jean-Christophe Sirot <jean-christophe.sirot@docker.com>
(+1 squashed commit)
Squashed commits:
[20670495] Fix CLI initialization for the `docker stack deploy --help` command and ensure that the dockerCli.CurrentContext() always returns a non empty context name (default as a fallback)
Remove now obsolete code handling empty string context name
Minor code cleanup

Signed-off-by: Jean-Christophe Sirot <jean-christophe.sirot@docker.com>
2019-03-18 11:45:46 +01:00
Sebastiaan van Stijn 86a5a489f7
Merge pull request #1690 from jcsirot/fix-contextstore-for-plugins
Always initialize context store
2019-03-18 11:27:07 +01:00
Silvin Lubecki 33c8c0543b
Merge pull request #1629 from thaJeztah/update_rmi_docs
Improve `docker image rm` reference docs
2019-03-18 10:39:45 +01:00
Silvin Lubecki 651ccc0711
Merge pull request #1713 from thaJeztah/fix_plugin_test
Fix: plugin-tests discarding current environment
2019-03-14 16:22:05 +01:00
Sebastiaan van Stijn 7f1176b8aa
Merge pull request #1737 from ijc/plugins-using-PersistentPreRunE
Fix regression for CLI plugins using PersistentPreRunE
2019-03-14 15:51:13 +01:00
Ian Campbell 3af168c7df Ensure plugins can use PersistentPreRunE again.
I got a bit carried away in d4ced2ef77 ("allow plugins to have argument
which match a top-level flag.") and broke the ability of a plugin to use the
`PersistentPreRun(E)` hook on its top-level command (by unconditionally
overwriting it) and also broke the plugin framework if a plugin's subcommand
used those hooks (because they would shadow the root one). This could result in
either `dockerCli.Client()` returning `nil` or whatever initialisation the
plugin hoped to do not occuring.

This change revert the relevant bits and reinstates the requirement that a
plugin calls `plugin.PersistentPreRunE` if it uses that hook itself.

It is at least a bit nicer now since we avoid the need for the global struct
since the interesting state is now encapsulated in `tcmd` (and the closure).

In principal this could be done even more simply (by calling `tcmd.Initialize`
statically between `tcmd.HandleGlobalFlags` and `cmd.Execute`) however this has
the downside of _always_ initialising the cli (and therefore dialing the
daemon) even for the `docker-cli-plugin-metadata` command but also for the
`help foo` and `foo --help` commands (Cobra short-circuits the hooks in this
case).

Signed-off-by: Ian Campbell <ijc@docker.com>
2019-03-14 14:29:09 +00:00
Ian Campbell 0b794e0620 e2e/cli-plugins: explicitly check that PersistentPreRunE works
I regressed this in d4ced2ef77 ("allow plugins to have argument which match a
top-level flag.") by unconditionally overwriting any `PersistentRunE` that the
user may have supplied.

We need to ensure two things:

1. That the user can use `PersistentRunE` (or `PersistentRun`) for their own
   purposes.
2. That our initialisation always runs, even if the user has used
   `PersistentRun*`, since that will shadow the root.

To do this add a `PersistentRunE` to the helloworld plugin which logs (covers 1
above) and then use it when calling the `apiversion` subcommand (which covers 2
since that uses the client)

Signed-off-by: Ian Campbell <ijc@docker.com>
2019-03-14 14:20:19 +00:00
Tibor Vass c3fc547cc9
Merge pull request #1712 from thaJeztah/fix_test_for_go_1.12
Fix test for Go 1.12.x
2019-03-13 13:38:57 -07:00
Vincent Demeester c748c850f6
Merge pull request #1674 from ericcurtin/patch-1
Add exit status to docker exec manpage
2019-03-13 18:56:48 +01:00
Silvin Lubecki 237bdbf5f6
Merge pull request #1722 from ijc/plugins-global-arg-clash
Allow plugins to have --flags which are the same as the top-level
2019-03-13 15:55:02 +01:00
Jean-Christophe Sirot a1af6e261f Cover the changes with unit test
Signed-off-by: Jean-Christophe Sirot <jean-christophe.sirot@docker.com>
2019-03-13 14:18:41 +01:00
Jean-Christophe Sirot 37fcaf7a29 Resolve the docker Endpoint even if the client already exists. In that case the `TestDialStdio` e2e test had to be modified: the `--tls` option triggers an error since the endpoint resolution tries to read the `${DOCKER_CERT_PATH}/ca.pem` file which does not exist.
Signed-off-by: Jean-Christophe Sirot <jean-christophe.sirot@docker.com>
2019-03-13 14:18:41 +01:00
Jean-Christophe Sirot 3b26cfce8b Always initialize context store
Signed-off-by: Jean-Christophe Sirot <jean-christophe.sirot@docker.com>
2019-03-13 14:18:41 +01:00
Ian Campbell e824bc86f3 Use a copy of root flagset in `HandleGlobalFlags`
This makes things more idempotent, rather than relying on undoing the
interspersed settings.

Note that the underlying `Flag`s remain shared, it's just the `FlagSet` which
is duplicated.

Signed-off-by: Ian Campbell <ijc@docker.com>
2019-03-13 11:28:17 +00:00
Ian Campbell 2c624e8984 Add e2e test for handling of `version`/`-v`/`--version` with plugins
Previous commits fixed the first issue on #1661, this simply adds a test for
it. Note that this is testing the current behaviour, without regard for the
second issue in #1661 which proposes a different behaviour.

Signed-off-by: Ian Campbell <ijc@docker.com>
2019-03-13 11:28:17 +00:00
Ian Campbell d4ced2ef77 allow plugins to have argument which match a top-level flag.
The issue with plugin options clashing with globals is that when cobra is
parsing the command line and it comes across an argument which doesn't start
with a `-` it (in the absence of plugins) distinguishes between "argument to
current command" and "new subcommand" based on the list of registered sub
commands.

Plugins breaks that model. When presented with `docker -D plugin -c foo` cobra
parses up to the `plugin`, sees it isn't a registered sub-command of the
top-level docker (because it isn't, it's a plugin) so it accumulates it as an
argument to the top-level `docker` command. Then it sees the `-c`, and thinks
it is the global `-c` (for AKA `--context`) option and tries to treat it as
that, which fails.

In the specific case of the top-level `docker` subcommand we know that it has
no arguments which aren't `--flags` (or `-f` short flags) and so anything which
doesn't start with a `-` must either be a (known) subcommand or an attempt to
execute a plugin.

We could simply scan for and register all installed plugins at start of day, so
that cobra can do the right thing, but we want to avoid that since it would
involve executing each plugin to fetch the metadata, even if the command wasn't
going to end up hitting a plugin.

Instead we can parse the initial set of global arguments separately before
hitting the main cobra `Execute` path, which works here exactly because we know
that the top-level has no non-flag arguments.

One slight wrinkle is that the top-level `PersistentPreRunE` is no longer
called on the plugins path (since it no longer goes via `Execute`), so we
arrange for the initialisation done there (which has to be done after global
flags are parsed to handle e.g. `--config`) to happen explictly after the
global flags are parsed. Rather than make `newDockerCommand` return the
complicated set of results needed to make this happen, instead return a closure
which achieves this.

The new functionality is introduced via a common `TopLevelCommand` abstraction
which lets us adjust the plugin entrypoint to use the same strategy for parsing
the global arguments. This isn't strictly required (in this case the stuff in
cobra's `Execute` works fine) but doing it this way avoids the possibility of
subtle differences in behaviour.

Fixes #1699, and also, as a side-effect, the first item in #1661.

Signed-off-by: Ian Campbell <ijc@docker.com>
2019-03-13 11:28:17 +00:00
Ian Campbell 8289ae03f8 Add e2e tests for plugin vs global argument issues
These won't pass right now due to https://github.com/docker/cli/issues/1699
("Plugins can't re-use the same flags as cli global flags") and the change in
935d47bbe9 ("Ignore unknown arguments on the top-level command."), but the
intention is to fix them now.

Signed-off-by: Ian Campbell <ijc@docker.com>
2019-03-13 10:54:31 +00:00
Ian Campbell 4e5f0af9cd e2e: start a new file for cli plugins arguments tests
`TestRunGoodArgument` fits here.

Signed-off-by: Ian Campbell <ijc@docker.com>
2019-03-13 10:54:31 +00:00
Sebastiaan van Stijn d6a230606c
Merge pull request #1718 from ijc/dial-stdio-npipe-on-windows
dial-stdio: handle connections which lack CloseRead method.
2019-03-13 11:49:25 +01:00
Tibor Vass 81ac432cc2
Merge pull request #1700 from thaJeztah/update_engine
Update docker/docker 8aca18d, containerd v1.2.4
2019-03-12 10:41:51 -07:00
Ian Campbell 0449ad8d06 Revert "Disable `docker system dial-stdio` on Windows"
This reverts commit c41c23813c.

This case is now handled due to the previous commit.

Signed-off-by: Ian Campbell <ijc@docker.com>
2019-03-12 14:57:52 +00:00
Ian Campbell 186e7456ac dial-stdio: Close the connection
This was leaking the fd.

Signed-off-by: Ian Campbell <ijc@docker.com>
2019-03-12 14:57:40 +00:00
Ian Campbell 8919bbf04d dial-stdio: handle connections which lack CloseRead method.
This happens on Windows when dialing a named pipe (a path which is used by CLI
plugins), in that case some debugging shows:

    DEBU[0000] conn is a *winio.win32MessageBytePipe
    DEBU[0000] conn is a halfReadCloser: false
    DEBU[0000] conn is a halfWriteCloser: true
    the raw stream connection does not implement halfCloser
In such cases we can simply wrap with a nop function since closing for read
isn't too critical.

Signed-off-by: Ian Campbell <ijc@docker.com>
2019-03-12 14:52:42 +00:00
Sebastiaan van Stijn bf4a96e564
Merge pull request #1688 from luoyunpeng/optimize-blockIOTypecheck
use char to check blockIO type
2019-03-12 10:32:31 +01:00
Silvin Lubecki 6d2d597a6d
Merge pull request #1728 from ijc/e2e-handle-alpine-bump
Fixes for e2e testing after Alpine bump
2019-03-11 15:59:17 +01:00
Ian Campbell 0b0c57871a e2e: avoid `usermod -p` by using `useradd`'s `--password` option
Signed-off-by: Ian Campbell <ijc@docker.com>
2019-03-11 14:25:41 +00:00
Ian Campbell e854a9cf96 e2e: Expand `useradd`'s `-m` otion into `--create-home`
... for improved readability

Signed-off-by: Ian Campbell <ijc@docker.com>
2019-03-11 14:25:41 +00:00
Ian Campbell 5de2d9e8a9 e2e Use `useradd`'s `--shell` option
... in preference to `chsh`, since in recent alpine 3.9.2 images that can fail
with:

    Password: chsh: PAM: Authentication token manipulation error

Which seems to relate to the use of `!` as the password for `root` in `/etc/shadow`gq

Signed-off-by: Ian Campbell <ijc@docker.com>
2019-03-11 14:25:19 +00:00
Silvin Lubecki b86bff84b6
Merge pull request #1710 from ijc/no-dial-stdio-on-windows
Disable `docker system dial-stdio` on Windows
2019-03-11 15:14:23 +01:00
Elliot Luo 0bb397f9ef use char to check blockIO type
Signed-off-by: Elliot Luo <956941328@qq.com>
2019-03-11 10:01:22 +08:00
Silvin Lubecki fdb0ef7be0
Merge pull request #1720 from zappy-shu/harden-config-path
hardening config.Path() to disallow directory traversal
2019-03-10 21:04:08 +01:00
Vincent Demeester 89dd14d665
Merge pull request #1693 from thaJeztah/upgrade_shellcheck_0.6.0
Upgrade shellcheck 0.6.0
2019-03-08 20:58:24 +01:00
Nick Adcock ff51b0d77d harden config.Path() to disallow directory traversal
Signed-off-by: Nick Adcock <nick.adcock@docker.com>
2019-03-07 14:40:53 +00:00
Vincent Demeester 39c327ab93
Merge pull request #1717 from ry4nz/export-config
Export cli/command/config
2019-03-07 08:04:33 +01:00
Ryan Zhang f60369dfe6 Export cli/command/config
Signed-off-by: Ryan Zhang <ryan.zhang@docker.com>
2019-03-05 14:26:42 -08:00
Sebastiaan van Stijn 79e1cabf17
Merge pull request #1680 from cquon/plugin_error_handling
Fix issue where plugin command error exit code is printed out
2019-03-05 09:22:47 +01:00
Vincent Demeester 8f68971ede
Merge pull request #1701 from ijc/plugin-build-fixes
Fix cli-plugins build.
2019-03-05 09:10:08 +01:00
Sebastiaan van Stijn d4877fb225
Fix test for Go 1.12.x
After switching to Go 1.12, the format-string causes an error;

```
=== Errors
cli/config/config_test.go:154:3: Fatalf format %q has arg config of wrong type *github.com/docker/cli/cli/config/configfile.ConfigFile
cli/config/config_test.go:217:3: Fatalf format %q has arg config of wrong type *github.com/docker/cli/cli/config/configfile.ConfigFile
cli/config/config_test.go:253:3: Fatalf format %q has arg config of wrong type *github.com/docker/cli/cli/config/configfile.ConfigFile
cli/config/config_test.go:288:3: Fatalf format %q has arg config of wrong type *github.com/docker/cli/cli/config/configfile.ConfigFile
cli/config/config_test.go:435:3: Fatalf format %q has arg config of wrong type *github.com/docker/cli/cli/config/configfile.ConfigFile
cli/config/config_test.go:448:3: Fatalf format %q has arg config of wrong type *github.com/docker/cli/cli/config/configfile.ConfigFile

DONE 1115 tests, 2 skipped, 6 errors in 215.984s
make: *** [Makefile:22: test-coverage] Error 2
Exited with code 2
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-03-04 20:19:14 +01:00
Sebastiaan van Stijn 6c4fbb7738
Fix: plugin-tests discarding current environment
By default, exec uses the environment of the current process, however,
if `exec.Env` is not `nil`, the environment is discarded:

e73f489494/src/os/exec/exec.go (L57-L60)

> If Env is nil, the new process uses the current process's environment.

When adding a new environment variable, prepend the current environment,
to make sure it is not discarded.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-03-04 20:18:24 +01:00
Ian Campbell c41c23813c Disable `docker system dial-stdio` on Windows
The `conn` here is `*winio.win32MessageBytePipe` which does not have a
`CloseRead` method (it does have `CloseWrite`) resulting in:

    docker@WIN-NUC0 C:\Users\docker>.\docker-windows-amd64.exe system dial-stdio
    the raw stream connection does not implement halfCloser

Also disable the path which uses this for cli-plugins on Windows.

Signed-off-by: Ian Campbell <ijc@docker.com>
2019-03-04 17:36:21 +00:00
Ian Campbell 38480d9a96 Use `$(DOCKER_RUN)` for cli plugins build.
Seems I rebased over b039db985a ("Make it possible to override the volume
mounts and shell for the dev container") at some point and failed to notice
that some of the variable names had changed.

In the meantime the underlying issue was fixed in #1698 but here we switch to
using `$(DOCKER_RUN)`. This means that these rules now use
`$(DOCKER_RUN_NAME_OPTION)` and thus obey the `$(DOCKER_CLI_CONTAINER_NAME)`
variable.

Signed-off-by: Ian Campbell <ijc@docker.com>
2019-03-04 10:17:58 +00:00
Sebastiaan van Stijn 8ddde26af6
Merge pull request #1702 from AkihiroSuda/connhelper-export
connhelper: export functions for other projects
2019-03-03 11:40:10 +01:00
Sebastiaan van Stijn 05fd2a87dc
Update containerd 1.2.4 and dependencies
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-03-02 13:44:57 +01:00
Sebastiaan van Stijn 087a7ee712
bump github.com/gorilla/mux v1.7.0
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-03-02 13:42:07 +01:00
Sebastiaan van Stijn 0fc0015173
bump docker/docker to 8aca18d631f3f72d4c6e3dc01b6e5d468ad941b8
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-03-02 13:41:42 +01:00
Akihiro Suda dbe7afbd04 connhelper: export functions for other projects
Exposed functions are planned to be used by `buildctl`:
https://github.com/moby/buildkit/issues/769

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2019-03-02 21:11:49 +09:00
Sebastiaan van Stijn ee94f72e2c
Merge pull request #1698 from silvin-lubecki/fix-cross-dev-mounts
Fix unknown $(MOUNTS) variable in makefile plugins target
2019-03-01 18:48:25 +01:00
Silvin Lubecki 2c6b2ccbdd Fix unknown $(MOUNTS) variable in makefile plugins target
Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
2019-02-28 11:56:13 +01:00
Corey Quon d871451049
Fix issue where plugin command error exit code is printed out
Signed-off-by: Corey Quon <corey.quon@docker.com>
2019-02-26 09:39:07 -08:00
Sebastiaan van Stijn 2178fea84d
Merge pull request #1665 from jcrben/patch-1
Note caveat with detaching using key sequence
2019-02-26 16:56:31 +01:00