forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify-common.sh
129 lines (114 loc) · 2.76 KB
/
verify-common.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash -e
DELAY="${DELAY:-0}"
DOCKER_NO_PULL="${DOCKER_NO_PULL:-}"
MANUAL="${MANUAL:-}"
NAME="${NAME:-}"
PATHS="${PATHS:-.}"
UPARGS="${UPARGS:-}"
run_log () {
echo -e "\n> [${NAME}] ${*}"
}
bring_up_example_stack () {
local args path up_args
args=("${UPARGS[@]}")
path="$1"
read -ra up_args <<< "up --build -d ${args[*]}"
if [[ -z "$DOCKER_NO_PULL" ]]; then
run_log "Pull the images ($path)"
docker-compose pull
echo
fi
run_log "Bring up services ($path)"
docker-compose "${up_args[@]}" || return 1
echo
}
bring_up_example () {
local path paths
read -ra paths <<< "$(echo "$PATHS" | tr ',' ' ')"
for path in "${paths[@]}"; do
pushd "$path" > /dev/null || return 1
bring_up_example_stack "$path" || {
echo "ERROR: starting ${NAME} ${path}" >&2
return 1
}
popd > /dev/null || return 1
done
if [[ "$DELAY" -ne "0" ]]; then
run_log "Snooze for ${DELAY} while ${NAME} gets started"
sleep "$DELAY"
fi
for path in "${paths[@]}"; do
pushd "$path" > /dev/null || return 1
docker-compose ps
docker-compose logs
popd > /dev/null || return 1
done
}
cleanup_stack () {
local path
path="$1"
run_log "Cleanup ($path)"
docker-compose down
docker system prune -f
}
cleanup () {
local path paths
read -ra paths <<< "$(echo "$PATHS" | tr ',' ' ')"
for path in "${paths[@]}"; do
pushd "$path" > /dev/null || return 1
cleanup_stack "$path" || {
echo "ERROR: cleanup ${NAME} ${path}" >&2
return 1
}
popd > /dev/null
done
}
_curl () {
local arg curl_command
curl_command=(curl -s)
if [[ ! "$*" =~ "-X" ]]; then
curl_command+=(-X GET)
fi
for arg in "${@}"; do
curl_command+=("$arg")
done
"${curl_command[@]}" || {
echo "ERROR: curl (${curl_command[*]})" >&2
return 1
}
}
responds_with () {
local expected
expected="$1"
shift
_curl "${@}" | grep "$expected" || {
echo "ERROR: curl expected (${*}): $expected" >&2
return 1
}
}
responds_with_header () {
local expected
expected="$1"
shift
_curl --head "${@}" | grep "$expected" || {
echo "ERROR: curl header (${*}): $expected" >&2
return 1
}
}
responds_without_header () {
local expected
expected="$1"
shift
_curl --head "${@}" | grep "$expected" | [[ "$(wc -l)" -eq 0 ]] || {
echo "ERROR: curl without header (${*}): $expected" >&2
return 1
}
}
trap 'cleanup' EXIT
if [[ -z "$NAME" ]]; then
echo "ERROR: You must set the '$NAME' variable before sourcing this script" >&2
exit 1
fi
if [[ -z "$MANUAL" ]]; then
bring_up_example
fi