Run weave run with the local docker

We want to be compatible with whatever docker the user has; `weave
run` is the only command that passes on arbitrary args to docker
(i.e., that doesn't have a fixed set of docker features that it
needs).

To make this workable we still need to do some things on the remote
host: the IP attachment and figuring out the DNS settings (since those
may depend on the bridge IP).
This commit is contained in:
Michael Bridgen committed 2015-03-20 14:37:24 +00:00
1 parent 84ce0663f8
commit 93f16d91ce
4 files changed
+72 -29

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
#!/bin/bash
. ./config.sh
start_suite "Run weave with --local"
run_on $HOST1 sudo ./weave --local reset
run_on $HOST1 sudo ./weave --local launch
assert_raises "docker_on $HOST1 ps | grep weave" 0
docker_on $HOST1 rm -f c1 || true
run_on $HOST1 sudo ./weave --local run 10.2.6.5/24 -ti --name=c1 ubuntu
ok=$(docker -H tcp://$HOST1:2375 exec -i c1 sh -c "ifconfig | grep ethwe")
assert "test -n \"$ok\" && echo pass" "pass"
docker_on $HOST1 rm -f c1 || true
end_suite
+1 -1
View File
@@ -6,7 +6,7 @@ ip_prefix = "192.168.48"
ip_suffix_base = 10
def configure_docker(host, hostname, ip)
pkgs = "lxc-docker"
pkgs = "lxc-docker ethtool"
host.vm.box = "phusion/ubuntu-14.04-amd64"
host.vm.box_url = "https://oss-binaries.phusionpassenger.com/vagrant/boxes/latest/ubuntu-14.04-amd64-vbox.box"
+2 -1
View File
@@ -16,6 +16,7 @@ for HOST in $HOSTS; do
docker_on $HOST load -i ../weaveexec.tar
run_on $HOST mkdir -p bin
cat ../bin/docker-ns | run_on $HOST sh -c "cat > $DOCKER_NS"
run_on $HOST chmod a+x $DOCKER_NS
cat ../weave | run_on $HOST sh -c "cat > ./weave"
run_on $HOST chmod a+x $DOCKER_NS ./weave
run_on $HOST sudo service docker restart
done
+50 -27
View File
@@ -62,14 +62,19 @@ exec_remote() {
$EXEC_IMAGE --local "$@"
}
# "run" is a special case because we want to use docker directly,
# rather than the docker in $EXEC_IMAGE remotely. That's because we
# are passing arbitrary arguments on to docker run, and we can't rely
# on our baked-in docker to support those arguments.
if [ "$1" = "--local" ]; then
LOCAL="$1"
shift 1
else
elif [ "$1" != "run" ]; then
exec_remote "$@"
exit $?
fi
[ $(id -u) = 0 ] || {
[ $(id -u) = 0 ] || ([ "$1" = "run" ] && [ -z "$LOCAL" ]) || {
echo "weave must be run as 'root' when run locally" >&2
exit 1
}
@@ -87,6 +92,31 @@ COMMAND=$1
shift 1
dns_args() {
if [ "$1" = "--with-dns" ] ; then
shift 1
if [ \( "$DOCKER_VERSION_MAJOR" -lt 1 \) -o \
\( "$DOCKER_VERSION_MAJOR" -eq 1 -a \
"$DOCKER_VERSION_MINOR" -lt 2 \) ] ; then
echo "ERROR: The '--with-dns' option requires Docker 1.2.0 or later; you are running $DOCKER_VERSION" >&2
exit 1
fi
docker_bridge_ip
DNS_ARG="--dns $DOCKER_BRIDGE_IP"
DNS_SEARCH_ARG="--dns-search=."
for arg in "$@"; do
case $arg in
--dns-search=*)
DNS_SEARCH_ARG=""
;;
*)
;;
esac;
done
fi
DNS_ARGS="$DNS_ARG $DNS_SEARCH_ARG"
}
# utility function to check whether a command can be executed by the shell
# see http://stackoverflow.com/questions/592620/how-to-check-if-a-program-exists-from-a-bash-script
command_exists () {
@@ -598,36 +628,29 @@ case "$COMMAND" in
;;
run)
[ $# -gt 0 ] || usage
if [ "$1" = "--with-dns" ] ; then
shift 1
if [ \( "$DOCKER_VERSION_MAJOR" -lt 1 \) -o \
\( "$DOCKER_VERSION_MAJOR" -eq 1 -a \
"$DOCKER_VERSION_MINOR" -lt 2 \) ] ; then
echo "ERROR: The '--with-dns' option requires Docker 1.2.0 or later; you are running $DOCKER_VERSION" >&2
exit 1
fi
docker_bridge_ip
DNS_ARG="--dns $DOCKER_BRIDGE_IP"
DNS_SEARCH_ARG="--dns-search=."
for arg in "$@"; do
case $arg in
--dns-search=*)
DNS_SEARCH_ARG=""
;;
*)
;;
esac;
done
if [ "$LOCAL" = "--local" ]; then
dns_args "$@"
else
DNS_ARGS=$(exec_remote dns-args "$@")
[ "$1" = "--with-dns" ] && shift 1
fi
CIDR=$1
validate_cidr $CIDR
shift 1
create_bridge
CONTAINER=$(docker run $DNS_ARG $DNS_SEARCH_ARG -d "$@")
with_container_netns $CONTAINER attach $CIDR >/dev/null
tell_dns PUT $CONTAINER $CIDR
validate_cidr $CIDR
CONTAINER=$(docker run $DNS_ARGS -d "$@")
if [ "$LOCAL" = "--local" ]; then
create_bridge
with_container_netns $CONTAINER attach $CIDR >/dev/null
tell_dns PUT $CONTAINER $CIDR
else
exec_remote attach $CIDR $CONTAINER
fi
echo $CONTAINER
;;
dns-args)
dns_args "$@"
echo -n $DNS_ARGS
;;
start)
[ $# -eq 2 ] || usage
CIDR=$1