-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.sh
executable file
·75 lines (66 loc) · 1.91 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
69
70
71
72
73
74
75
#!/bin/bash -Eeu
export ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export SH_DIR="${ROOT_DIR}/sh"
source "${SH_DIR}/build_tagged_images.sh"
source "${SH_DIR}/containers_down.sh"
source "${SH_DIR}/containers_up_healthy_and_clean.sh"
source "${SH_DIR}/echo_versioner_env_vars.sh"
source "${SH_DIR}/lib.sh"
export $(echo_versioner_env_vars)
#- - - - - - - - - - - - - - - - - - - - - - - - - - -
curl_json_body_200()
{
local -r route="${1}" # eg alive
curl \
--data "" \
--fail \
--header 'Content-type: application/json' \
--header 'Accept: application/json' \
--request GET \
--silent \
--verbose \
"http://localhost:$(port)/${route}" \
> "$(log_filename)" 2>&1
grep --quiet 200 "$(log_filename)" # eg HTTP/1.1 200 OK
local -r result=$(tail -n 1 "$(log_filename)" | head -n 1)
echo "$(tab)GET ${route} => 200 ${result}"
}
#- - - - - - - - - - - - - - - - - - - - - - - - - - -
curl_200()
{
local -r route="${1}" # eg group_choose
local -r pattern="${2}" # eg exercise
curl \
--fail \
--request GET \
--silent \
--verbose \
"http://localhost:$(port)/${route}" \
> "$(log_filename)" 2>&1
grep --quiet 200 "$(log_filename)" # eg HTTP/1.1 200 OK
local -r result=$(grep "${pattern}" "$(log_filename)" | head -n 1)
echo "$(tab)GET ${route} => 200 ${result}"
}
#- - - - - - - - - - - - - - - - - - - - - - - - - - -
port() { echo -n "${CYBER_DOJO_SHAS_PORT}"; }
tab() { printf '\t'; }
log_filename() { echo -n /tmp/shas.log ; }
#- - - - - - - - - - - - - - - - - - - - - - - - - - -
build_tagged_images
docker-compose up --detach nginx
server_up_healthy_and_clean
echo
echo API
curl_json_body_200 alive
curl_json_body_200 ready
curl_json_body_200 sha
echo
curl_200 assets/app.css 'Content-Type: text/css'
echo
curl_200 index saver
echo
if [ "${1:-}" == '--no-browser' ]; then
containers_down
else
open "http://localhost:80/shas/index"
fi