From c6a319923656a168b0d35921a3451647f2886450 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 13 Nov 2017 01:26:09 +0100 Subject: [PATCH] Remove deprecated "daemon" subcommand The `docker daemon` subcommand was only present for backward compatibility, but deprecated in v1.13, and scheduled for removal in v17.12 Signed-off-by: Sebastiaan van Stijn --- cmd/docker/daemon_none.go | 29 ------------- cmd/docker/daemon_none_test.go | 17 -------- cmd/docker/daemon_unit_test.go | 33 -------------- cmd/docker/daemon_unix.go | 79 ---------------------------------- cmd/docker/docker.go | 5 --- docs/deprecated.md | 2 +- man/src/image/pull.md | 2 +- scripts/test/unit | 2 +- 8 files changed, 3 insertions(+), 166 deletions(-) delete mode 100644 cmd/docker/daemon_none.go delete mode 100644 cmd/docker/daemon_none_test.go delete mode 100644 cmd/docker/daemon_unit_test.go delete mode 100644 cmd/docker/daemon_unix.go diff --git a/cmd/docker/daemon_none.go b/cmd/docker/daemon_none.go deleted file mode 100644 index 6fbd000125..0000000000 --- a/cmd/docker/daemon_none.go +++ /dev/null @@ -1,29 +0,0 @@ -// +build !daemon - -package main - -import ( - "fmt" - "runtime" - "strings" - - "github.com/spf13/cobra" -) - -func newDaemonCommand() *cobra.Command { - return &cobra.Command{ - Use: "daemon", - Hidden: true, - Args: cobra.ArbitraryArgs, - DisableFlagParsing: true, - RunE: func(cmd *cobra.Command, args []string) error { - return runDaemon() - }, - } -} - -func runDaemon() error { - return fmt.Errorf( - "`docker daemon` is not supported on %s. Please run `dockerd` directly", - strings.Title(runtime.GOOS)) -} diff --git a/cmd/docker/daemon_none_test.go b/cmd/docker/daemon_none_test.go deleted file mode 100644 index af0fcfd670..0000000000 --- a/cmd/docker/daemon_none_test.go +++ /dev/null @@ -1,17 +0,0 @@ -// +build !daemon - -package main - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestDaemonCommand(t *testing.T) { - cmd := newDaemonCommand() - cmd.SetArgs([]string{"--version"}) - err := cmd.Execute() - - assert.EqualError(t, err, "Please run `dockerd`") -} diff --git a/cmd/docker/daemon_unit_test.go b/cmd/docker/daemon_unit_test.go deleted file mode 100644 index b7bb441136..0000000000 --- a/cmd/docker/daemon_unit_test.go +++ /dev/null @@ -1,33 +0,0 @@ -// +build daemon - -package main - -import ( - "io/ioutil" - "testing" - - "github.com/spf13/cobra" - "github.com/stretchr/testify/assert" -) - -func stubRun(cmd *cobra.Command, args []string) error { - return nil -} - -func TestDaemonCommandHelp(t *testing.T) { - cmd := newDaemonCommand() - cmd.RunE = stubRun - cmd.SetArgs([]string{"--help"}) - cmd.SetOutput(ioutil.Discard) - err := cmd.Execute() - assert.NoError(t, err) -} - -func TestDaemonCommand(t *testing.T) { - cmd := newDaemonCommand() - cmd.RunE = stubRun - cmd.SetArgs([]string{"--containerd", "/foo"}) - cmd.SetOutput(ioutil.Discard) - err := cmd.Execute() - assert.NoError(t, err) -} diff --git a/cmd/docker/daemon_unix.go b/cmd/docker/daemon_unix.go deleted file mode 100644 index 6ec6b625a1..0000000000 --- a/cmd/docker/daemon_unix.go +++ /dev/null @@ -1,79 +0,0 @@ -// +build daemon - -package main - -import ( - "fmt" - - "os" - "os/exec" - "path/filepath" - "syscall" - - "github.com/spf13/cobra" -) - -const daemonBinary = "dockerd" - -func newDaemonCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "daemon", - Hidden: true, - Args: cobra.ArbitraryArgs, - DisableFlagParsing: true, - RunE: func(cmd *cobra.Command, args []string) error { - return runDaemon() - }, - Deprecated: "and will be removed in Docker 17.12. Please run `dockerd` directly.", - } - cmd.SetHelpFunc(helpFunc) - return cmd -} - -// CmdDaemon execs dockerd with the same flags -func runDaemon() error { - // Use os.Args[1:] so that "global" args are passed to dockerd - return execDaemon(stripDaemonArg(os.Args[1:])) -} - -func execDaemon(args []string) error { - binaryPath, err := findDaemonBinary() - if err != nil { - return err - } - - return syscall.Exec( - binaryPath, - append([]string{daemonBinary}, args...), - os.Environ()) -} - -func helpFunc(cmd *cobra.Command, args []string) { - if err := execDaemon([]string{"--help"}); err != nil { - fmt.Fprintf(os.Stderr, "%s\n", err.Error()) - } -} - -// findDaemonBinary looks for the path to the dockerd binary starting with -// the directory of the current executable (if one exists) and followed by $PATH -func findDaemonBinary() (string, error) { - execDirname := filepath.Dir(os.Args[0]) - if execDirname != "" { - binaryPath := filepath.Join(execDirname, daemonBinary) - if _, err := os.Stat(binaryPath); err == nil { - return binaryPath, nil - } - } - - return exec.LookPath(daemonBinary) -} - -// stripDaemonArg removes the `daemon` argument from the list -func stripDaemonArg(args []string) []string { - for i, arg := range args { - if arg == "daemon" { - return append(args[:i], args[i+1:]...) - } - } - return args -} diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index 2214a13c3c..84e9e2520a 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -39,10 +39,6 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command { return command.ShowHelp(dockerCli.Err())(cmd, args) }, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - // daemon command is special, we redirect directly to another binary - if cmd.Name() == "daemon" { - return nil - } // flags must be the top-level command flags, not cmd.Flags() opts.Common.SetDefaultOptions(flags) dockerPreRun(opts) @@ -64,7 +60,6 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command { setHelpFunc(dockerCli, cmd, flags, opts) cmd.SetOutput(dockerCli.Out()) - cmd.AddCommand(newDaemonCommand()) commands.AddCommands(cmd, dockerCli) setValidateArgs(dockerCli, cmd, flags, opts) diff --git a/docs/deprecated.md b/docs/deprecated.md index 6a728d50dc..7ac8848fea 100644 --- a/docs/deprecated.md +++ b/docs/deprecated.md @@ -81,7 +81,7 @@ The `filter` param to filter the list of image by reference (name or name:tag) i ### `docker daemon` subcommand **Deprecated In Release: [v1.13.0](https://github.com/docker/docker/releases/tag/v1.13.0)** -**Target For Removal In Release: v17.12** +**Removed In Release: v17.12** The daemon is moved to a separate binary (`dockerd`), and should be used instead. diff --git a/man/src/image/pull.md b/man/src/image/pull.md index 0286ef1502..778c7e0bc9 100644 --- a/man/src/image/pull.md +++ b/man/src/image/pull.md @@ -134,7 +134,7 @@ Registry credentials are managed by **docker-login(1)**. Docker uses the `https://` protocol to communicate with a registry, unless the registry is allowed to be accessed over an insecure connection. Refer to the -[insecure registries](https://docs.docker.com/engine/reference/commandline/daemon/#insecure-registries) +[insecure registries](https://docs.docker.com/engine/reference/commandline/dockerd/#insecure-registries) section in the online documentation for more information. diff --git a/scripts/test/unit b/scripts/test/unit index 2a0f02af51..7eb82d0ff0 100755 --- a/scripts/test/unit +++ b/scripts/test/unit @@ -1,4 +1,4 @@ #!/usr/bin/env bash set -eu -o pipefail -go test -tags daemon -v "$@" +go test -v "$@"