Fix shfmt issues

This commit is contained in:
Iago López Galeiras
2017-01-12 16:06:47 +01:00
parent 43d9f38c5e
commit 5cb5c7d42e
23 changed files with 212 additions and 216 deletions

View File

@@ -11,9 +11,9 @@ RELEASE_DESCRIPTION=${RELEASE_DESCRIPTION:-"Container Visibility"}
PWD=$(pwd)
infer_release_type() {
if echo "$1" | grep -qE '^v[0-9]+\.[0-9]+\.0+$' ; then
if echo "$1" | grep -qE '^v[0-9]+\.[0-9]+\.0+$'; then
echo MAINLINE
elif echo "$1" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$' ; then
elif echo "$1" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
echo BRANCH
else
echo PRERELEASE
@@ -28,7 +28,7 @@ setup() {
TAG_COUNT=$(echo "$(echo "$HEAD_TAGS" | wc -w)") # mac hack
case $TAG_COUNT in
1)
if [ "$HEAD_TAGS" != "latest_release" ] ; then
if [ "$HEAD_TAGS" != "latest_release" ]; then
LATEST_TAG=$HEAD_TAGS
else
echo "Cannot determine version - latest_release points at HEAD" >&2
@@ -41,7 +41,7 @@ setup() {
;;
*)
echo "Cannot determine version - multiple tags point at HEAD:" >&2
for TAG in $HEAD_TAGS ; do
for TAG in $HEAD_TAGS; do
echo -e "\t$TAG" >&2
done
exit 1
@@ -55,7 +55,7 @@ setup() {
LATEST_TAG_COMMIT_SHA=$(git rev-list -1 "$LATEST_TAG")
LATEST_RELEASE_SHA=$(git rev-parse latest_release)
LATEST_RELEASE_COMMIT_SHA=$(git rev-list -1 latest_release)
if [ "$RELEASE_TYPE" != 'PRERELEASE' ] ; then
if [ "$RELEASE_TYPE" != 'PRERELEASE' ]; then
VERSION=${LATEST_TAG#v}
else
VERSION=${LATEST_TAG}
@@ -80,8 +80,8 @@ build() {
cd "$RELEASE_DIR"
## Check that the top changelog entry is this version
if ! latest_changelog=$(perl -nle'print $& if m{(?<=^## Release ).*}' ./CHANGELOG.md | head -1) || \
! [ "$latest_changelog" = "$VERSION" ]; then
if ! latest_changelog=$(perl -nle'print $& if m{(?<=^## Release ).*}' ./CHANGELOG.md | head -1) \
|| ! [ "$latest_changelog" = "$VERSION" ]; then
echo -e "\u2757 Latest changelog entry \"$latest_changelog\" does not match the release version $VERSION" >&2
exit 1
fi
@@ -141,7 +141,7 @@ draft() {
echo '** Sanity checks OK for publishing tag' "$LATEST_TAG" as "$DOCKERHUB_USER/scope:$VERSION"
RELEASE_ARGS="--draft"
if [ "$RELEASE_TYPE" = 'PRERELEASE' ] ; then
if [ "$RELEASE_TYPE" = 'PRERELEASE' ]; then
RELEASE_ARGS="$RELEASE_ARGS --pre-release"
fi
@@ -168,10 +168,10 @@ publish() {
setup
cd "$PWD"/"$RELEASE_DIR"
if [ "$RELEASE_TYPE" = 'PRERELEASE' ] ; then
if [ "$RELEASE_TYPE" = 'PRERELEASE' ]; then
echo "== Tagging and pushing images on docker hub as user $DOCKERHUB_USER"
$SUDO docker tag -f "$DOCKERHUB_USER"/scope "$DOCKERHUB_USER/scope:$VERSION"
$SUDO docker push "$DOCKERHUB_USER/scope:$VERSION"
$SUDO docker push "$DOCKERHUB_USER/scope:$VERSION"
echo "** Docker images tagged and pushed"
echo "== Publishing pre-release on GitHub"
@@ -185,7 +185,7 @@ publish() {
echo -e "\thttps://github.com/$GITHUB_USER/scope/releases/$LATEST_TAG"
else
echo "== Sanity checks"
if ! [ "$LATEST_TAG_COMMIT_SHA" == "$LATEST_RELEASE_COMMIT_SHA" ] ; then
if ! [ "$LATEST_TAG_COMMIT_SHA" == "$LATEST_RELEASE_COMMIT_SHA" ]; then
echo -e "\u2757 The tag latest_release does not point to the same commit as $LATEST_TAG" >&2
echo "You may need to" >&2
echo -e "\tgit tag -af latest_release $LATEST_TAG" >&2
@@ -204,7 +204,7 @@ publish() {
echo "== Tagging and pushing images on docker hub as user $DOCKERHUB_USER"
$SUDO docker tag -f "$DOCKERHUB_USER"/scope "$DOCKERHUB_USER/scope:$VERSION"
$SUDO docker push "$DOCKERHUB_USER"/scope:$"VERSION"
$SUDO docker push "$DOCKERHUB_USER"/scope:$"VERSION"
echo "** Docker images tagged and pushed"
echo "== Publishing release on GitHub"

View File

@@ -5,10 +5,9 @@ set -eu
# openssl enc -in do-setup-circleci-secrets.orig -out setup-circleci-secrets.orig -e -aes256 -pass stdin
# openssl base64 < setup-circleci-secrets.orig
openssl base64 -d << EOF \
| openssl enc \
openssl base64 -d <<EOF | openssl enc \
-out bin/do-setup-circleci-secrets \
-d -aes256 -pass pass:"$1"
-d -aes256 -pass pass:"$1"
U2FsdGVkX193YHZJXNzxU9GqigQaXWrA0AKd+BIjRcx7bmmKn/zSgOv+FfApRRjn
KGBd2ulZw9CwsftX0HWHzVdtpgqbJUW+FEma8eNldau4/f+T+yWTVpCNQXGc3DvB
cWYhmkoTfGWmI2v/0/Bv2TYkw7MAfjCocdluFAv7sSvYnSgIjoYxD4XXkTjLWy1P

View File

@@ -4,10 +4,10 @@ mkdir -p /var/run/weave
for arg in "$@"; do
case "$arg" in
--no-app|--probe-only|--service-token*|--probe.token*)
--no-app | --probe-only | --service-token* | --probe.token*)
touch /etc/service/app/down
;;
--no-probe|--app-only)
--no-probe | --app-only)
touch /etc/service/probe/down
;;
esac
@@ -16,8 +16,8 @@ done
# shellcheck disable=SC2034
ARGS=("$@")
typeset -p ARGS >/var/run/weave/scope-app.args
declare -p ARGS >/var/run/weave/scope-app.args
# shellcheck disable=SC2034
typeset -p ARGS >/var/run/weave/scope-probe.args
declare -p ARGS >/var/run/weave/scope-probe.args
exec /home/weave/runsvinit

View File

@@ -2,5 +2,5 @@
# shellcheck disable=SC1091
source /var/run/weave/scope-app.args
exec -a scope-app /home/weave/scope --mode app "${ARGS[@]}"

View File

@@ -1,8 +1,8 @@
#!/bin/bash
set -eu
if [ $# -lt 1 ]; then
echo "Usage: $0 <ip:port> [<max_dialer>]" >&2
exit 1
echo "Usage: $0 <ip:port> [<max_dialer>]" >&2
exit 1
fi
readonly addr=$1
@@ -13,15 +13,15 @@ dialer=()
trap 'echo -n "stopping ... "; for c in "${dialer[@]}"; do docker rm -f "$c" >/dev/null; done; echo "done"' EXIT
while true; do
rand=$(( ( RANDOM % max_dialer ) + 1 ))
dialer+=("$(docker run -d dialer /go/bin/dialer connect "$addr" "$rand")")
rand=$(((RANDOM % max_dialer) + 1))
dialer+=("$(docker run -d dialer /go/bin/dialer connect "$addr" "$rand")")
if [ ${#dialer[@]} -gt "$max_dialer" ]; then
container=${dialer[$rand]}
docker rm -f "$container" >/dev/null &
unset dialer[$rand]
dialer=("${dialer[@]}")
fi
if [ ${#dialer[@]} -gt "$max_dialer" ]; then
container=${dialer[$rand]}
docker rm -f "$container" >/dev/null &
unset dialer[$rand]
dialer=("${dialer[@]}")
fi
sleep $(( rand % 3 ))
sleep $((rand % 3))
done

View File

@@ -2,7 +2,7 @@
set -eu
readonly port=${1:-8082}
(
sleep 5 # wait for dialerserver to start
echo "IP addr + port: $(docker inspect -f '{{ .NetworkSettings.IPAddress }}' dialerserver):$port"
sleep 5 # wait for dialerserver to start
echo "IP addr + port: $(docker inspect -f '{{ .NetworkSettings.IPAddress }}' dialerserver):$port"
) &
docker run --rm --name dialerserver dialer /go/bin/dialer listen "$port"

View File

@@ -1,8 +1,8 @@
#!/bin/bash
set -eu
if [ $EUID -ne 0 ]; then
echo "You must be root!" >&2
exit 1
echo "You must be root!" >&2
exit 1
fi
readonly interval_num=${1:-60}
@@ -16,18 +16,18 @@ TIME_K2=0
TIME_T2=0
if [ "$(pidof scope-probe)" == "" ]; then
echo "No scope-probe process running - aborting" >&2
exit 1
echo "No scope-probe process running - aborting" >&2
exit 1
fi
for ((i=0; i<"$interval_num"; i++)); do
sleep "$interval_sleep"
TIME_U1=$TIME_U2
TIME_K1=$TIME_K2
TIME_T1=$TIME_T2
for ((i = 0; i < "$interval_num"; i++)); do
sleep "$interval_sleep"
TIME_U1=$TIME_U2
TIME_K1=$TIME_K2
TIME_T1=$TIME_T2
TIME_U2=$(gawk '{print $14"*10"}'<"/proc/$(pidof scope-probe)/stat" | bc)
TIME_K2=$(gawk '{print $15"*10"}'<"/proc/$(pidof scope-probe)/stat" | bc)
TIME_T2=$(( TIME_U2 + TIME_K2 ))
echo "utime $(( TIME_U2 - TIME_U1)) + stime $(( TIME_K2 - TIME_K1 )) = $(( TIME_T2 - TIME_T1 ))"
TIME_U2=$(gawk '{print $14"*10"}' <"/proc/$(pidof scope-probe)/stat" | bc)
TIME_K2=$(gawk '{print $15"*10"}' <"/proc/$(pidof scope-probe)/stat" | bc)
TIME_T2=$((TIME_U2 + TIME_K2))
echo "utime $((TIME_U2 - TIME_U1)) + stime $((TIME_K2 - TIME_K1)) = $((TIME_T2 - TIME_T1))"
done

View File

@@ -35,4 +35,3 @@ start_container 1 tomwilkie/echo echo
start_container 2 tomwilkie/app app
start_container 2 tomwilkie/frontend frontend --add-host=dns.weave.local:"$(weave docker-bridge-ip)"
start_container 1 tomwilkie/client client

View File

@@ -21,13 +21,13 @@ start_container() {
while [ "$#" -gt 0 ]; do
case "$1" in
--)
shift
break
;;
shift
break
;;
*)
docker_args="${docker_args} $1"
shift
;;
docker_args="${docker_args} $1"
shift
;;
esac
done
local container_args="$*"
@@ -46,4 +46,3 @@ start_container 1 tomwilkie/echo echo
start_container 1 tomwilkie/trace_app app
start_container 1 tomwilkie/client client -- -target app.weave.local \
-concurrency 1 -persist False

View File

@@ -8,11 +8,11 @@
# Depends on:
# - gofmt
function generate_header {
function generate_header() {
local out_file="${1}"
local cmd="${2}"
cat << EOF >"${out_file}"
cat <<EOF >"${out_file}"
// Generated file, do not edit.
// To regenerate, run ${cmd}
@@ -26,7 +26,7 @@ function generate_header {
EOF
}
function generate_latest_map {
function generate_latest_map() {
local out_file="$1"
local data_type="$2"
local uppercase_data_type="${data_type^}"
@@ -43,7 +43,7 @@ function generate_latest_map {
# shellcheck disable=SC2016
local json_value='`json:"value"`'
cat << EOF >>"${out_file}"
cat <<EOF >>"${out_file}"
type ${wire_entry_type} struct {
Timestamp time.Time ${json_timestamp}
Value ${data_type} ${json_value}

View File

@@ -26,7 +26,7 @@ echo Doing "$INPUTS"
for INPUT in $INPUTS; do
START=$(date +%s)
"$COMMAND" "$INPUT"
RUNTIME=$(( $(date +%s) - START ))
RUNTIME=$(($(date +%s) - START))
"../tools/sched" time "$INPUT" "$RUNTIME"
done

View File

@@ -1,7 +1,7 @@
#! /bin/bash
# shellcheck disable=SC1091
./config.sh
./config.sh
start_suite "Launch scope and check it boots"

View File

@@ -12,7 +12,7 @@ scope_on "$HOST1" stop
sleep 5
# Save stdout for debugging output
exec 3>&1
exec 3>&1
assert_raises "docker_on $HOST1 logs weavescope 2>&1 | grep 'app exiting' || (docker_on $HOST1 logs weavescope 2>&3 ; false)"
assert_raises "docker_on $HOST1 logs weavescope 2>&1 | grep 'probe exiting' || (docker_on $HOST1 logs weavescope 2>&3 ; false)"
assert_raises "docker_on $HOST1 inspect --format='{{.State.Running}}' weavescope" "false"

View File

@@ -10,25 +10,25 @@ scope_on "$HOST1" launch
wait_for_containers "$HOST1" 60 weavescope
topology_is_not_empty() {
local host="$1"
local topology="$2"
local timeout="${5:-60}"
local host="$1"
local topology="$2"
local timeout="${5:-60}"
for _ in $(seq "$timeout"); do
local report
local count
report="$(curl -s "http://$host:4040/api/report")"
count=$(echo "$report" | jq -r ".$topology.nodes | length > 0" 2>/dev/null)
for _ in $(seq "$timeout"); do
local report
local count
report="$(curl -s "http://$host:4040/api/report")"
count=$(echo "$report" | jq -r ".$topology.nodes | length > 0" 2>/dev/null)
if [ "$count" = "true" ]; then
assert "curl -s http://$host:4040/api/report | jq -r '.$topology.nodes | length > 0'" true
return
fi
sleep 1
done
if [ "$count" = "true" ]; then
assert "curl -s http://$host:4040/api/report | jq -r '.$topology.nodes | length > 0'" true
return
fi
sleep 1
done
echo "Failed to find any nodes in the $topology topology after $timeout secs"
assert "curl -s http://$host:4040/api/report | jq -r '.$topology.nodes | length > 0'" true
echo "Failed to find any nodes in the $topology topology after $timeout secs"
assert "curl -s http://$host:4040/api/report | jq -r '.$topology.nodes | length > 0'" true
}
topology_is_not_empty "$HOST1" Endpoint

View File

@@ -17,11 +17,11 @@ docker_on "$HOST2" run -dit --name db2 peterbourgon/tns-db
sleep 30 # need to allow the scopes to poll dns, resolve the other app ids, and send them reports
check() {
has_container "$1" weave 2
has_container "$1" weaveproxy 2
has_container "$1" weavescope 2
has_container "$1" db1
has_container "$1" db2
has_container "$1" weave 2
has_container "$1" weaveproxy 2
has_container "$1" weavescope 2
has_container "$1" db1
has_container "$1" db2
}
check "$HOST1"

View File

@@ -14,11 +14,11 @@ docker_on "$HOST2" run -dit --name db2 peterbourgon/tns-db
sleep 30 # need to allow the scopes to poll dns, resolve the other app ids, and send them reports.
check() {
has_container "$1" weave 0
has_container "$1" weaveproxy 0
has_container "$1" weavescope 2
has_container "$1" db1
has_container "$1" db2
has_container "$1" weave 0
has_container "$1" weaveproxy 0
has_container "$1" weavescope 2
has_container "$1" db1
has_container "$1" db2
}
check "$HOST1"

View File

@@ -17,11 +17,11 @@ docker_on "$HOST2" run -dit --name db2 peterbourgon/tns-db
sleep 30 # need to allow the scopes to poll dns, resolve the other app ids, and send them reports
check() {
has_container "$1" weave 2
has_container "$1" weaveproxy 2
has_container "$1" weavescope 2
has_container "$1" db1
has_container "$1" db2
has_container "$1" weave 2
has_container "$1" weaveproxy 2
has_container "$1" weavescope 2
has_container "$1" db1
has_container "$1" db2
}
check "$HOST1"

View File

@@ -6,9 +6,9 @@
start_suite "Test short lived connections from the Internet"
if ! echo "$HOST1" | grep "us-central1-a"; then
echo "Skipping; test needs to be run against VMs on GCE."
scope_end_suite
exit
echo "Skipping; test needs to be run against VMs on GCE."
scope_end_suite
exit
fi
weave_on "$HOST1" launch
@@ -16,12 +16,12 @@ scope_on "$HOST1" launch
docker_on "$HOST1" run -d -p 80:80 --name nginx nginx
do_connections() {
while true; do
curl -s "http://$HOST1:80/" >/dev/null || true
sleep 1
done
while true; do
curl -s "http://$HOST1:80/" >/dev/null || true
sleep 1
done
}
do_connections&
do_connections &
wait_for_containers "$HOST1" 60 nginx "The Internet"

View File

@@ -20,9 +20,9 @@ done"
sleep 30 # need to allow the scopes to poll dns, resolve the other app ids, and send them reports
check() {
has_container "$1" nginx
has_container "$1" client
has_connection containers "$1" client nginx
has_container "$1" nginx
has_container "$1" client
has_connection containers "$1" client nginx
}
check "$HOST1"

View File

@@ -16,7 +16,7 @@ assert "docker_on $HOST1 inspect --format='{{.State.Running}}' alpine" "true"
PROBEID=$(docker_on "$HOST1" logs weavescope 2>&1 | grep "probe starting" | sed -n 's/^.*ID \([0-9a-f]*\)$/\1/p')
# Execute 'echo foo' in a container tty and check its output
PIPEID=$(curl -s -f -X POST "http://$HOST1:4040/api/control/$PROBEID/$CID;<container>/docker_exec_container" | jq -r '.pipe' )
PIPEID=$(curl -s -f -X POST "http://$HOST1:4040/api/control/$PROBEID/$CID;<container>/docker_exec_container" | jq -r '.pipe')
assert "(sleep 1 && echo 'echo foo' && sleep 1) | wscat -b 'ws://$HOST1:4040/api/pipe/$PIPEID' | col -pb" "alpine:/# 6necho foo\nfoo\nalpine:/# 6n"
assert_raises "curl -f -X POST 'http://$HOST1:4040/api/control/$PROBEID/$CID;<container>/docker_stop_container'"

View File

@@ -14,7 +14,7 @@ PROBEID=$(docker_on "$HOST1" logs weavescope 2>&1 | grep "probe starting" | sed
HOSTID=$($SSH "$HOST1" hostname)
# Execute 'echo foo' in the host tty and check its output
PIPEID=$(curl -s -f -X POST "http://$HOST1:4040/api/control/$PROBEID/$HOSTID;<host>/host_exec" | jq -r '.pipe' )
PIPEID=$(curl -s -f -X POST "http://$HOST1:4040/api/control/$PROBEID/$HOSTID;<host>/host_exec" | jq -r '.pipe')
assert "(sleep 1 && echo \"PS1=''; echo foo\" && sleep 1) | wscat -b 'ws://$HOST1:4040/api/pipe/$PIPEID' | col -pb | tail -n 1" "foo\n"
scope_end_suite

View File

@@ -15,45 +15,45 @@ WEAVE="./weave"
SCOPE="../scope"
scope_on() {
local host=$1
shift 1
[ -z "$DEBUG" ] || greyly echo "Scope on $host: $*" >&2
DOCKER_HOST=tcp://$host:$DOCKER_PORT CHECKPOINT_DISABLE=true "$SCOPE" "$@"
local host=$1
shift 1
[ -z "$DEBUG" ] || greyly echo "Scope on $host: $*" >&2
DOCKER_HOST=tcp://$host:$DOCKER_PORT CHECKPOINT_DISABLE=true "$SCOPE" "$@"
}
weave_on() {
local host=$1
shift 1
[ -z "$DEBUG" ] || greyly echo "Weave on $host: $*" >&2
DOCKER_HOST=tcp://$host:$DOCKER_PORT CHECKPOINT_DISABLE=true "$WEAVE" "$@"
local host=$1
shift 1
[ -z "$DEBUG" ] || greyly echo "Weave on $host: $*" >&2
DOCKER_HOST=tcp://$host:$DOCKER_PORT CHECKPOINT_DISABLE=true "$WEAVE" "$@"
}
scope_end_suite() {
end_suite
for host in $HOSTS; do
docker_on "$host" rm -f "$(docker_on "$host" ps -a -q)" 2>/dev/null 1>&2 || true
done
end_suite
for host in $HOSTS; do
docker_on "$host" rm -f "$(docker_on "$host" ps -a -q)" 2>/dev/null 1>&2 || true
done
}
# this checks we have a named node in the given view
has() {
local view=$1
local host=$2
local name=$3
local count=${4:-1}
assert "curl -s http://${host}:4040/api/topology/${view}?system=show | jq -r '[.nodes[] | select(.label == \"${name}\")] | length'" "$count"
local view=$1
local host=$2
local name=$3
local count=${4:-1}
assert "curl -s http://${host}:4040/api/topology/${view}?system=show | jq -r '[.nodes[] | select(.label == \"${name}\")] | length'" "$count"
}
# this checks we have a named container
has_container() {
has containers "$@"
has containers "$@"
}
node_id() {
local view="$1"
local host="$2"
local name="$3"
curl -s "http://${host}:4040/api/topology/${view}?system=show" | jq -r ".nodes[] | select(.label == \"${name}\") | .id"
local host="$2"
local name="$3"
curl -s "http://${host}:4040/api/topology/${view}?system=show" | jq -r ".nodes[] | select(.label == \"${name}\") | .id"
}
container_id() {
@@ -62,74 +62,73 @@ container_id() {
# this checks we have an edge from container 1 to container 2
has_connection_by_id() {
local view="$1"
local host="$2"
local from_id="$3"
local to_id="$4"
local timeout="${5:-60}"
local view="$1"
local host="$2"
local from_id="$3"
local to_id="$4"
local timeout="${5:-60}"
for i in $(seq "$timeout"); do
local nodes
local edge
edge=$(echo "$nodes" | jq -r ".nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])" 2>/dev/null)
nodes="$(curl -s "http://$host:4040/api/topology/${view}?system=show")"
if [ "$edge" = "true" ]; then
echo "Found edge $from -> $to after $i secs"
assert "curl -s http://$host:4040/api/topology/${view}?system=show | jq -r '.nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])'" true
return
fi
sleep 1
done
for i in $(seq "$timeout"); do
local nodes
local edge
edge=$(echo "$nodes" | jq -r ".nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])" 2>/dev/null)
nodes="$(curl -s "http://$host:4040/api/topology/${view}?system=show")"
if [ "$edge" = "true" ]; then
echo "Found edge $from -> $to after $i secs"
assert "curl -s http://$host:4040/api/topology/${view}?system=show | jq -r '.nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])'" true
return
fi
sleep 1
done
echo "Failed to find edge $from -> $to after $timeout secs"
assert "curl -s http://$host:4040/api/topology/${view}?system=show | jq -r '.nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])'" true
echo "Failed to find edge $from -> $to after $timeout secs"
assert "curl -s http://$host:4040/api/topology/${view}?system=show | jq -r '.nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])'" true
}
has_connection() {
local view="$1"
local host="$2"
local from="$3"
local to="$4"
local timeout="${5:-60}"
local from_id
local to_id
local view="$1"
local host="$2"
local from="$3"
local to="$4"
local timeout="${5:-60}"
local from_id
local to_id
from_id="$(node_id "${view}" "${host}" "${from}")"
to_id="$(node_id "${view}" "${host}" "${to}")"
from_id="$(node_id "${view}" "${host}" "${from}")"
to_id="$(node_id "${view}" "${host}" "${to}")"
has_connection_by_id "${view}" "${host}" "${from_id}" "${to_id}" "${timeout}"
has_connection_by_id "${view}" "${host}" "${from_id}" "${to_id}" "${timeout}"
}
wait_for() {
local view="$1"
local host="$2"
local timeout="$3"
shift 3
local view="$1"
local host="$2"
local timeout="$3"
shift 3
for i in $(seq "${timeout}"); do
local nodes
local found=0
nodes="$(curl -s "http://$host:4040/api/topology/${view}?system=show")"
for name in "$@"; do
local count
count=$(echo "${nodes}" | jq -r "[.nodes[] | select(.label == \"${name}\")] | length")
if [ -n "${count}" ] && [ "${count}" -ge 1 ]; then
found=$(( found + 1 ))
fi
done
for i in $(seq "${timeout}"); do
local nodes
local found=0
nodes="$(curl -s "http://$host:4040/api/topology/${view}?system=show")"
for name in "$@"; do
local count
count=$(echo "${nodes}" | jq -r "[.nodes[] | select(.label == \"${name}\")] | length")
if [ -n "${count}" ] && [ "${count}" -ge 1 ]; then
found=$((found + 1))
fi
done
if [ "${found}" -eq $# ]; then
echo "Found ${found} nodes after $i secs"
return
fi
if [ "${found}" -eq $# ]; then
echo "Found ${found} nodes after $i secs"
return
fi
sleep 1
done
sleep 1
done
echo "Failed to find nodes $* after $i secs"
echo "Failed to find nodes $* after $i secs"
}
wait_for_containers() {
wait_for containers "$@"
wait_for containers "$@"
}

74
scope
View File

@@ -4,7 +4,7 @@ set -eu
ARGS="$*"
SCRIPT_VERSION="(unreleased version)"
if [ "$SCRIPT_VERSION" = "(unreleased version)" ] ; then
if [ "$SCRIPT_VERSION" = "(unreleased version)" ]; then
IMAGE_VERSION=latest
else
IMAGE_VERSION="$SCRIPT_VERSION"
@@ -79,8 +79,8 @@ check_docker_access() {
MIN_DOCKER_VERSION=1.6.0
check_docker_version() {
if ! DOCKER_VERSION=$(docker -v | sed -n 's%^Docker version \([0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\).*$%\1%p') ||
[ -z "$DOCKER_VERSION" ] ; then
if ! DOCKER_VERSION=$(docker -v | sed -n 's%^Docker version \([0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\).*$%\1%p') \
|| [ -z "$DOCKER_VERSION" ]; then
echo "ERROR: Unable to parse docker version" >&2
exit 1
fi
@@ -98,22 +98,22 @@ check_docker_version() {
\( "$DOCKER_VERSION_MAJOR" -eq "$MIN_DOCKER_VERSION_MAJOR" -a \
\( "$DOCKER_VERSION_MINOR" -lt "$MIN_DOCKER_VERSION_MINOR" -o \
\( "$DOCKER_VERSION_MINOR" -eq "$MIN_DOCKER_VERSION_MINOR" -a \
\( "$DOCKER_VERSION_PATCH" -lt "$MIN_DOCKER_VERSION_PATCH" \) \) \) \) ] ; then
\( "$DOCKER_VERSION_PATCH" -lt "$MIN_DOCKER_VERSION_PATCH" \) \) \) \) ]; then
echo "ERROR: scope requires Docker version $MIN_DOCKER_VERSION or later; you are running $DOCKER_VERSION" >&2
exit 1
fi
}
check_probe_only() {
echo "${ARGS}" | grep -q -E "\-\-no\-app|\-\-service\-token|\-\-probe\-only"
echo "${ARGS}" | grep -q -E "\-\-no\-app|\-\-service\-token|\-\-probe\-only"
}
check_docker_for_mac() {
[ "$(uname)" = "Darwin" ] \
&& [ -S /var/run/docker.sock ] \
&& [ ! "${DOCKER_HOST+x}" = x ] \
&& [ "${HOME+x}" = x ] \
&& [ -d "${HOME}/Library/Containers/com.docker.docker/Data/database" ]
[ "$(uname)" = "Darwin" ] \
&& [ -S /var/run/docker.sock ] \
&& [ ! "${DOCKER_HOST+x}" = x ] \
&& [ "${HOME+x}" = x ] \
&& [ -d "${HOME}/Library/Containers/com.docker.docker/Data/database" ]
}
# Check that a container named $1 with image $2 is not running
@@ -145,34 +145,34 @@ check_not_running() {
}
create_plugins_dir() {
# Docker for Mac (as of beta18) looks for this path on VM first, and when it doesn't
# find it there, it assumes the user referes to the path on Mac OS. Firstly, in most
# cases user won't have /var/run/scope/plugins on their Mac OS filesystem, and
# secondly Docker for Mac would have to be configured to share this path. The result
# of this "feature" is an error message: "The path /var/run/scope/plugins
# is not shared from OS X and does not belong to the system."
# In any case, creating /var/run/scope/plugins on Mac OS would not work, as domain
# sockets do not cross VM boundaries. We need this directory to exits on the VM.
docker run --rm --entrypoint=/bin/sh \
-v /var/run:/var/run \
"$SCOPE_IMAGE" -c "mkdir -p /var/run/scope/plugins"
# Docker for Mac (as of beta18) looks for this path on VM first, and when it doesn't
# find it there, it assumes the user referes to the path on Mac OS. Firstly, in most
# cases user won't have /var/run/scope/plugins on their Mac OS filesystem, and
# secondly Docker for Mac would have to be configured to share this path. The result
# of this "feature" is an error message: "The path /var/run/scope/plugins
# is not shared from OS X and does not belong to the system."
# In any case, creating /var/run/scope/plugins on Mac OS would not work, as domain
# sockets do not cross VM boundaries. We need this directory to exits on the VM.
docker run --rm --entrypoint=/bin/sh \
-v /var/run:/var/run \
"$SCOPE_IMAGE" -c "mkdir -p /var/run/scope/plugins"
}
launch_command() {
# shellcheck disable=SC2086
echo docker run --privileged -d --name="$SCOPE_CONTAINER_NAME" --net=host --pid=host \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /var/run/scope/plugins:/var/run/scope/plugins \
-e CHECKPOINT_DISABLE \
$WEAVESCOPE_DOCKER_ARGS "$SCOPE_IMAGE" --probe.docker=true
-v /var/run/docker.sock:/var/run/docker.sock \
-v /var/run/scope/plugins:/var/run/scope/plugins \
-e CHECKPOINT_DISABLE \
$WEAVESCOPE_DOCKER_ARGS "$SCOPE_IMAGE" --probe.docker=true
}
launch_docker4mac_app_command() {
# shellcheck disable=SC2086
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
-e CHECKPOINT_DISABLE \
-p 0.0.0.0:4040:4040 \
$WEAVESCOPE_DOCKER_ARGS "$SCOPE_IMAGE" --no-probe
}
launch() {
@@ -213,7 +213,7 @@ case "$COMMAND" in
$WEAVESCOPE_DOCKER_ARGS "$SCOPE_IMAGE" --mode=version
;;
-h|help|-help|--help)
-h | help | -help | --help)
usage
;;
@@ -223,9 +223,9 @@ case "$COMMAND" in
# shellcheck disable=SC2086
docker run --rm -e CHECKPOINT_DISABLE --entrypoint=/home/weave/scope $WEAVESCOPE_DOCKER_ARGS "$SCOPE_IMAGE" --dry-run "$@"
if check_docker_for_mac ; then
if check_docker_for_mac; then
create_plugins_dir
if check_probe_only ; then
if check_probe_only; then
launch "$@"
exit
fi
@@ -248,7 +248,7 @@ case "$COMMAND" in
fi
launch "$@"
if ! check_probe_only ; then
if ! check_probe_only; then
IP_ADDRS=$(docker run --rm --net=host --entrypoint /bin/sh "$SCOPE_IMAGE" -c "$IP_ADDR_CMD")
print_app_endpoints "$IP_ADDRS"
fi
@@ -257,12 +257,12 @@ case "$COMMAND" in
stop)
[ $# -eq 0 ] || usage_and_die
if docker inspect "$SCOPE_CONTAINER_NAME" >/dev/null 2>&1 ; then
docker stop "$SCOPE_CONTAINER_NAME" >/dev/null
if docker inspect "$SCOPE_CONTAINER_NAME" >/dev/null 2>&1; then
docker stop "$SCOPE_CONTAINER_NAME" >/dev/null
fi
if check_docker_for_mac ; then
if docker inspect "$SCOPE_APP_CONTAINER_NAME" >/dev/null 2>&1 ; then
docker stop "$SCOPE_APP_CONTAINER_NAME" >/dev/null
if check_docker_for_mac; then
if docker inspect "$SCOPE_APP_CONTAINER_NAME" >/dev/null 2>&1; then
docker stop "$SCOPE_APP_CONTAINER_NAME" >/dev/null
fi
fi
;;