Merge pull request #689 from thaJeztah/remove-daemon-subcommand

Remove deprecated "daemon" subcommand
This commit is contained in:
Daniel Nephin 2017-11-23 11:10:50 -05:00 committed by GitHub
commit 227dfea9e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 3 additions and 166 deletions

View File

@ -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))
}

View File

@ -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`")
}

View File

@ -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)
}

View File

@ -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
}

View File

@ -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)

View File

@ -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.

View File

@ -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.

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash
set -eu -o pipefail
go test -tags daemon -v "$@"
go test -v "$@"