generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 5
/
docker-load-execute.sh
executable file
·112 lines (93 loc) · 3.13 KB
/
docker-load-execute.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
#!/usr/bin/env bash
set -e
local_port=5434
start_api() {
echo 'Starting API'
export DB_URL=postgresql
export DB_PORT=${local_port}
export DB_NAME=intermediary-test
export DB_USER=intermediary
export DB_PASS=changeIT!
export DB_SSL=require
export REPORT_STREAM_URL_PREFIX=
./gradlew shadowJar
docker compose up --build -d
export API_PID="${!}"
echo "API starting at PID ${API_PID}"
}
start_database() {
echo 'Starting database'
docker compose -f docker-compose.postgres-test.yml up -d
sleep 2
echo "Database started"
}
migrate_database() {
echo 'Migrating database'
liquibase update --changelog-file ./etor/databaseMigrations/root.yml --url jdbc:postgresql://localhost:${local_port}/intermediary-test --username intermediary --password 'changeIT!' --label-filter '!azure'
echo "Database migrated"
}
wait_for_api() {
attempt_counter=0
max_attempts=36
until curl --output /dev/null --silent --head --fail http://localhost:8080/health; do
if [ "${attempt_counter}" -eq "${max_attempts}" ];then
echo 'Done waiting for API to respond'
exit 1
fi
attempt_counter=$(($attempt_counter+1))
echo 'Waiting for API to respond'
sleep 5
done
echo 'API is responding'
}
warm_up_api() {
echo 'Warming up API...'
sleep 5
tokenPath=$(pwd)/mock_credentials/trusted-intermediary-valid-token.jwt
token=$(cat "${tokenPath}")
echo ${token}
echo 'Warming up auth...'
tiAuthResponse=$(curl --request POST "http://localhost:8080/v1/auth/token" \
--header "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "scope=trusted-intermediary" \
--data-urlencode "client_assertion=${token}")
echo "$tiAuthResponse"
echo 'Retrieving access token...'
accessToken=$(echo "$tiAuthResponse" | grep -o '"access_token":"[^"]*' | grep -o '[^"]*$')
echo "$accessToken"
echo 'Warming up results...'
resultFile=$(pwd)/examples/Test/e2e/results/001_ORU_R01_short.fhir
curl --silent --request POST "http://localhost:8080/v1/etor/results" \
--header "recordId: 6789" \
--header "Authorization: Bearer ${accessToken}" \
--data-binary "@${resultFile}"
echo 'Warming up orders...'
orderFile=$(pwd)/examples/Test/e2e/orders/002_ORM_O01_short.fhir
curl --silent --request POST "http://localhost:8080/v1/etor/orders" \
--header "recordId: 1234" \
--header "Authorization: Bearer ${accessToken}" \
--data-binary "@${orderFile}"
echo 'Warm up nap time...'
sleep 5
echo 'API is cozy'
}
run_tests() {
echo 'Running the load test'
locust --headless -f ./operations/locustfile.py -H http://localhost:8080 -u 1000 -r 15 -t 5m
}
cleanup() {
echo "Stopping API docker container"
docker compose down
echo "API Docker container stopped"
echo "Stopping and deleting database"
docker compose -f docker-compose.postgres-test.yml down -v
echo "Database stopped and deleted"
}
trap cleanup EXIT # Run the cleanup function on exit
start_database
migrate_database
start_api
wait_for_api
warm_up_api
warm_up_api
run_tests