Merge pull request #1253 from weaveworks/1241-no-command-specified
[proxy] Handle case where no command is specified.
This commit is contained in:
commit
eee13e7dd9
3 files changed
+22
-6
No files matched your search
@@ -7,16 +7,14 @@ import (
|
|||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/weaveworks/weave/net"
|
weavenet "github.com/weaveworks/weave/net"
|
||||||
|
"github.com/weaveworks/weave/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) <= 1 {
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
args := os.Args[1:]
|
args := os.Args[1:]
|
||||||
|
|
||||||
if args[0] == "-s" {
|
if len(args) > 0 && args[0] == "-s" {
|
||||||
args = args[1:]
|
args = args[1:]
|
||||||
} else {
|
} else {
|
||||||
usr2 := make(chan os.Signal)
|
usr2 := make(chan os.Signal)
|
||||||
@@ -24,9 +22,13 @@ func main() {
|
|||||||
<-usr2
|
<-usr2
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := net.EnsureInterface("ethwe", -1)
|
_, err := weavenet.EnsureInterface("ethwe", -1)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
||||||
|
if len(args) == 0 {
|
||||||
|
checkErr(proxy.ErrNoCommandSpecified)
|
||||||
|
}
|
||||||
|
|
||||||
binary, err := exec.LookPath(args[0])
|
binary, err := exec.LookPath(args[0])
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package proxy
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -15,6 +16,10 @@ import (
|
|||||||
|
|
||||||
const MaxDockerHostname = 64
|
const MaxDockerHostname = 64
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrNoCommandSpecified = errors.New("No command specified")
|
||||||
|
)
|
||||||
|
|
||||||
type createContainerInterceptor struct{ proxy *Proxy }
|
type createContainerInterceptor struct{ proxy *Proxy }
|
||||||
|
|
||||||
type createContainerRequestBody struct {
|
type createContainerRequestBody struct {
|
||||||
@@ -105,6 +110,10 @@ func (i *createContainerInterceptor) setWeaveWaitEntrypoint(container *docker.Co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(container.Entrypoint) == 0 && len(container.Cmd) == 0 {
|
||||||
|
return ErrNoCommandSpecified
|
||||||
|
}
|
||||||
|
|
||||||
if len(container.Entrypoint) == 0 || container.Entrypoint[0] != weaveWaitEntrypoint[0] {
|
if len(container.Entrypoint) == 0 || container.Entrypoint[0] != weaveWaitEntrypoint[0] {
|
||||||
container.Entrypoint = append(weaveWaitEntrypoint, container.Entrypoint...)
|
container.Entrypoint = append(weaveWaitEntrypoint, container.Entrypoint...)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,4 +33,9 @@ proxy docker_on $HOST1 create --name c4 -v /tmp/1:/srv1 -v /tmp/2:/srv2 -e 'WEAV
|
|||||||
proxy docker_on $HOST1 start -ai c4
|
proxy docker_on $HOST1 start -ai c4
|
||||||
assert "docker_on $HOST1 inspect --format='{{range \$k, \$v := .Volumes}}{{\$k}} {{end}}' c4" "/srv1 /srv2 /w "
|
assert "docker_on $HOST1 inspect --format='{{range \$k, \$v := .Volumes}}{{\$k}} {{end}}' c4" "/srv1 /srv2 /w "
|
||||||
|
|
||||||
|
# Check errors are returned (when docker returns an error code)
|
||||||
|
assert_raises "docker -H tcp://$HOST1:12375 run -e 'WEAVE_CIDR=10.2.1.3/24' $SMALL_IMAGE foo 2>&1 | grep 'exec: \"foo\": executable file not found in \$PATH'"
|
||||||
|
# Check errors still happen when no command is specified
|
||||||
|
assert_raises "docker -H tcp://$HOST1:12375 run -e 'WEAVE_CIDR=10.2.1.3/24' $SMALL_IMAGE 2>&1 | grep 'Error response from daemon: No command specified'"
|
||||||
|
|
||||||
end_suite
|
end_suite
|
||||||
Reference in new issue
Block a user