Cleanup from CR.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2016-04-22 12:37:48 -04:00
parent 9e7651db4d
commit c0acfccc7b
7 changed files with 69 additions and 40 deletions

View file

@ -1,11 +1,5 @@
package main
import (
"os"
"os/exec"
"syscall"
)
const daemonBinary = "dockerd"
// DaemonProxy acts as a cli.Handler to proxy calls to the daemon binary
@ -15,29 +9,3 @@ type DaemonProxy struct{}
func NewDaemonProxy() DaemonProxy {
return DaemonProxy{}
}
// CmdDaemon execs dockerd with the same flags
// TODO: add a deprecation warning?
func (p DaemonProxy) CmdDaemon(args ...string) error {
args = stripDaemonArg(os.Args[1:])
binaryAbsPath, err := exec.LookPath(daemonBinary)
if err != nil {
return err
}
return syscall.Exec(
binaryAbsPath,
append([]string{daemonBinary}, args...),
os.Environ())
}
// 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
}

37
client/daemon_unix.go Normal file
View file

@ -0,0 +1,37 @@
// +build !windows
package main
import (
"os"
"os/exec"
"syscall"
)
// CmdDaemon execs dockerd with the same flags
// TODO: add a deprecation warning?
func (p DaemonProxy) CmdDaemon(args ...string) error {
// Use os.Args[1:] so that "global" args are passed to dockerd
args = stripDaemonArg(os.Args[1:])
// TODO: check dirname args[0] first
binaryAbsPath, err := exec.LookPath(daemonBinary)
if err != nil {
return err
}
return syscall.Exec(
binaryAbsPath,
append([]string{daemonBinary}, args...),
os.Environ())
}
// 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
}

11
client/daemon_windows.go Normal file
View file

@ -0,0 +1,11 @@
package main
import (
"fmt"
)
// CmdDaemon reports on an error on windows, because there is no exec
func (p DaemonProxy) CmdDaemon(args ...string) error {
return fmt.Errorf(
"`docker daemon` does not exist on windows. Please run `dockerd` directly")
}

View file

@ -0,0 +1,18 @@
package main
import (
"strings"
"testing"
)
func TestCmdDaemon(t *testing.T) {
proxy := NewDaemonProxy()
err := proxy.CmdDaemon("--help")
if err == nil {
t.Fatal("Expected CmdDaemon to fail in Windows.")
}
if !strings.Contains(err.Error(), "Please run `dockerd`") {
t.Fatalf("Expected an error about running dockerd, got %s", err)
}
}

View file

@ -9,16 +9,11 @@ import (
"github.com/docker/docker/cli"
"github.com/docker/docker/dockerversion"
flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/pkg/reexec"
"github.com/docker/docker/pkg/term"
"github.com/docker/docker/utils"
)
func main() {
if reexec.Init() {
return
}
// Set terminal emulation based on platform as required.
stdin, stdout, stderr := term.StdStreams()

View file

@ -188,7 +188,7 @@ if [ $ec -eq 0 ]; then
ec=$?
set +x
if [ 0 -ne $ec ]; then
echo "ERROR: Failed to compile and start the linux daemon"
echo "ERROR: Failed to compile and start the linux daemon"
fi
fi
@ -199,7 +199,7 @@ if [ $ec -eq 0 ]; then
export TIMEOUT="5m"
export DOCKER_HOST="tcp://$ip:$port_inner"
export DOCKER_TEST_HOST="tcp://$ip:$port_inner"
unset DOCKER_CLIENTONLY
unset DOCKER_CLIENTONLY
export DOCKER_REMOTE_DAEMON=1
hack/make.sh binary
ec=$?

View file

@ -1,7 +1,7 @@
#!/bin/bash
set -e
# This script exists as backwards compatiblity for CI
# This script exists as backwards compatibility for CI
(
DEST="${DEST}-client"
ABS_DEST="${ABS_DEST}-client"