-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.sh
executable file
·68 lines (52 loc) · 1.78 KB
/
demo.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
#!/bin/bash
set -o errexit -o nounset -o pipefail
cd -- "$(dirname -- "$0")/.."
declare -r engine="${1-podman}"
declare -r reverse_proxy="${2-caddy}"
"${engine}" network create test-net
case "${reverse_proxy}" in
caddy)
"${engine}" run --detach --name reverse-proxy --network test-net \
--publish 127.0.0.1:8080:8181 \
docker.io/caddy:2 caddy reverse-proxy --from :8181 --to greet:8282
;;
caddy/dynamic | caddy/static)
"${engine}" run --detach --name reverse-proxy --network test-net \
--publish 127.0.0.1:8080:8181 \
--volume "./${reverse_proxy}:/etc/caddy" docker.io/caddy:2
;;
haproxy)
"${engine}" run --detach --name reverse-proxy --network test-net \
--publish 127.0.0.1:8080:8181 \
--volume ./haproxy:/usr/local/etc/haproxy:ro docker.io/haproxy:3.1
;;
nginx)
"${engine}" run --detach --name reverse-proxy --network test-net \
--publish 127.0.0.1:8080:8181 \
--volume ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro docker.io/nginx:1
;;
*)
echo "Unknown reverse proxy: ${reverse_proxy}"
exit 1
;;
esac
"${engine}" run --detach --name hi-0 --network test-net --network-alias greet \
docker.io/hashicorp/http-echo:1.0 -listen=:8282 -text='Hi from A'
sleep 2s
while true; do
curl --fail --max-time 0.2 --silent localhost:8080 || echo "Error $?"
sleep 0.01s
done | tee test.log &
sleep 2s
"${engine}" run --detach --name hi-1 --network test-net --network-alias greet \
docker.io/hashicorp/http-echo:1.0 -listen=:8282 -text='Hi from B'
sleep 2s
"${engine}" stop hi-0
sleep 2s
kill %%
"${engine}" rm --force hi-0 hi-1 reverse-proxy
"${engine}" network rm test-net
grep --quiet '^Hi from A$' test.log
grep --quiet '^Hi from B$' test.log
grep --invert-match --quiet '^Hi from ' test.log && exit 1
: