Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Docker for Mac (again!) #1448

Merged
merged 2 commits into from
May 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 56 additions & 9 deletions scope
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -eu

ARGS="$@"

usage() {
echo "Usage:"
echo "scope launch [<peer> ...]"
Expand All @@ -22,6 +24,7 @@ IMAGE_VERSION=${VERSION:-$IMAGE_VERSION}
SCOPE_IMAGE_NAME=weaveworks/scope
SCOPE_IMAGE=$SCOPE_IMAGE_NAME:$IMAGE_VERSION
SCOPE_CONTAINER_NAME=weavescope
SCOPE_APP_CONTAINER_NAME=weavescope-app
IP_REGEXP="[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
IP_ADDR_CMD="find /sys/class/net -type l | xargs -n1 basename | grep -vE 'docker|veth|lo' | \
xargs -n1 ip addr show | grep inet | awk '{ print \$2 }' | grep -oE '$IP_REGEXP'"
Expand Down Expand Up @@ -61,6 +64,18 @@ check_docker_version() {
fi
}

check_probe_only() {
echo "${ARGS}" | grep -q -E "\-\-no\-app|\-\-service\-token|\-\-probe\-only"
}

check_docker_for_mac() {
docker_for_mac_network_mode="${HOME}/Library/Containers/com.docker.docker/Data/database/com.docker.driver.amd64-linux/network"
[ "$(uname)" = "Darwin" ] \
&& [ -S /var/run/docker.sock ] \
&& [ ! "${DOCKER_HOST+x}" = x ] \
&& grep -q hybrid $docker_for_mac_network_mode 2>/dev/null
}

# Check that a container named $1 with image $2 is not running
check_not_running() {
case $(docker inspect --format='{{.State.Running}} {{.Config.Image}}' $1 2>/dev/null) in
Expand Down Expand Up @@ -97,6 +112,13 @@ launch_command() {
$WEAVESCOPE_DOCKER_ARGS $SCOPE_IMAGE --probe.docker=true "$@"
}

launch_app_command() {
echo docker run -d --name=$SCOPE_APP_CONTAINER_NAME \
-e CHECKPOINT_DISABLE \
-p 0.0.0.0:4040:4040 \
$WEAVESCOPE_DOCKER_ARGS $SCOPE_IMAGE --no-probe "$@"
}

check_docker_version

case "$COMMAND" in
Expand Down Expand Up @@ -128,18 +150,38 @@ EOF
;;

launch)
check_not_running $SCOPE_CONTAINER_NAME $SCOPE_IMAGE_NAME
docker rm -f $SCOPE_CONTAINER_NAME >/dev/null 2>&1 || true

CONTAINER=$($(launch_command "$@"))
echo $CONTAINER
if ! check_docker_for_mac || check_probe_only ; then
check_not_running $SCOPE_CONTAINER_NAME $SCOPE_IMAGE_NAME
docker rm -f $SCOPE_CONTAINER_NAME >/dev/null 2>&1 || true
CONTAINER=$($(launch_command "$@"))
echo $CONTAINER
elif check_docker_for_mac ; then
# Docker for Mac (as of beta9) does not ship vmnet driver and
# thereby only access container ports via a tunnel, preventing
# access to host ports of the VM.
# - https://github.com/weaveworks/scope/issues/1411
# - https://forums.docker.com/t/ports-in-host-network-namespace-are-not-accessible/10789
check_not_running $SCOPE_APP_CONTAINER_NAME $SCOPE_IMAGE_NAME
docker rm -f $SCOPE_APP_CONTAINER_NAME >/dev/null 2>&1 || true
CONTAINER=$($(launch_app_command "$@"))
echo $CONTAINER
app_ip=$(docker inspect -f '{{.NetworkSettings.IPAddress}}' "${CONTAINER}")
check_not_running $SCOPE_CONTAINER_NAME $SCOPE_IMAGE_NAME
docker rm -f $SCOPE_CONTAINER_NAME >/dev/null 2>&1 || true
CONTAINER=$($(launch_command --no-app "$@" "${app_ip}:4040"))
echo $CONTAINER
fi

if ! echo "$@" | grep -E "\-\-no\-app|\-\-service\-token" 1>/dev/null; then
if ! check_probe_only ; then
IP_ADDRS=$(docker run --rm --net=host --entrypoint /bin/sh $SCOPE_IMAGE -c "$IP_ADDR_CMD")
echo "Weave Scope is reachable at the following URL(s):" >&2
for ip in $IP_ADDRS; do
echo " * http://$ip:4040/" >&2
done
if ! check_docker_for_mac ; then
for ip in $IP_ADDRS; do
echo " * http://$ip:4040/" >&2
done
else
echo " * http://localhost:4040/" >&2
fi
fi
;;

Expand All @@ -148,6 +190,11 @@ EOF
if ! docker stop $SCOPE_CONTAINER_NAME >/dev/null 2>&1 ; then
echo "Weave Scope is not running." >&2
fi
if check_docker_for_mac ; then
if ! docker stop $SCOPE_APP_CONTAINER_NAME >/dev/null 2>&1 ; then
echo "Weave Scope app is not running." >&2
fi
fi
;;

*)
Expand Down