mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Cleanup from CR.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
9e7651db4d
commit
c0acfccc7b
7 changed files with 69 additions and 40 deletions
|
@ -1,11 +1,5 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
const daemonBinary = "dockerd"
|
const daemonBinary = "dockerd"
|
||||||
|
|
||||||
// DaemonProxy acts as a cli.Handler to proxy calls to the daemon binary
|
// DaemonProxy acts as a cli.Handler to proxy calls to the daemon binary
|
||||||
|
@ -15,29 +9,3 @@ type DaemonProxy struct{}
|
||||||
func NewDaemonProxy() DaemonProxy {
|
func NewDaemonProxy() DaemonProxy {
|
||||||
return 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
37
client/daemon_unix.go
Normal 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
11
client/daemon_windows.go
Normal 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")
|
||||||
|
}
|
18
client/daemon_windows_test.go
Normal file
18
client/daemon_windows_test.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,16 +9,11 @@ import (
|
||||||
"github.com/docker/docker/cli"
|
"github.com/docker/docker/cli"
|
||||||
"github.com/docker/docker/dockerversion"
|
"github.com/docker/docker/dockerversion"
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
flag "github.com/docker/docker/pkg/mflag"
|
||||||
"github.com/docker/docker/pkg/reexec"
|
|
||||||
"github.com/docker/docker/pkg/term"
|
"github.com/docker/docker/pkg/term"
|
||||||
"github.com/docker/docker/utils"
|
"github.com/docker/docker/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if reexec.Init() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set terminal emulation based on platform as required.
|
// Set terminal emulation based on platform as required.
|
||||||
stdin, stdout, stderr := term.StdStreams()
|
stdin, stdout, stderr := term.StdStreams()
|
||||||
|
|
||||||
|
|
|
@ -188,7 +188,7 @@ if [ $ec -eq 0 ]; then
|
||||||
ec=$?
|
ec=$?
|
||||||
set +x
|
set +x
|
||||||
if [ 0 -ne $ec ]; then
|
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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ if [ $ec -eq 0 ]; then
|
||||||
export TIMEOUT="5m"
|
export TIMEOUT="5m"
|
||||||
export DOCKER_HOST="tcp://$ip:$port_inner"
|
export DOCKER_HOST="tcp://$ip:$port_inner"
|
||||||
export DOCKER_TEST_HOST="tcp://$ip:$port_inner"
|
export DOCKER_TEST_HOST="tcp://$ip:$port_inner"
|
||||||
unset DOCKER_CLIENTONLY
|
unset DOCKER_CLIENTONLY
|
||||||
export DOCKER_REMOTE_DAEMON=1
|
export DOCKER_REMOTE_DAEMON=1
|
||||||
hack/make.sh binary
|
hack/make.sh binary
|
||||||
ec=$?
|
ec=$?
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# This script exists as backwards compatiblity for CI
|
# This script exists as backwards compatibility for CI
|
||||||
(
|
(
|
||||||
DEST="${DEST}-client"
|
DEST="${DEST}-client"
|
||||||
ABS_DEST="${ABS_DEST}-client"
|
ABS_DEST="${ABS_DEST}-client"
|
||||||
|
|
Loading…
Reference in a new issue