This repository has been archived by the owner on Jun 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
53 lines (42 loc) · 1.67 KB
/
entrypoint.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
#! /bin/bash
# add rover to PATH
export PATH=$HOME/.rover/bin:$PATH
# record healthcheck start time
STARTTIME=$EPOCHSECONDS
# read hit interval and termination timeout from config
INTERVAL=$(yq e '.interval' config.yml)
TIMEOUT=$(yq e '.timeout' config.yml)
# read services array from config
read -r -a services <<< $(yq e '.services[].url' config.yml | xargs)
# healthcheck services until script times out or everything is up
echo "Waiting for healthcheck to complete..."
healthy=()
until [ $((EPOCHSECONDS-STARTTIME)) -gt $TIMEOUT ] || [ "${#healthy[@]}" -eq "${#services[@]}" ]; do
for i in "${!services[@]}"; do
# check if service has already been marked as healthy
if [[ ! " ${healthy[*]} " =~ " ${i} " ]]; then
# hit the service url to see if it's up
curl -sSf ${services[$i]} -o /dev/null
# if up, add to healthy array
[[ $? -eq 0 ]] && healthy+=($i)
fi
done
# wait before next attempt
sleep $INTERVAL
done
# construct supergraph.yml
echo "Construction supergraph config..."
yq -n e '.federation_version = 2' > /data/supergraph.yml
for i in "${healthy[@]}"; do
service_name=$(yq e ".services[$i].name" config.yml)
service_url=$(yq e ".services[$i].url" config.yml)
yq -i e '.subgraphs.'$service_name'.routing_url = "'$service_url'"' /data/supergraph.yml
yq -i e '.subgraphs.'$service_name'.schema.subgraph_url = "'$service_url'"' /data/supergraph.yml
# log healthy services
echo "HEALTHY: $service_name"
done
# compose supergraph.graphql
echo "Composing supergraph schema..."
rover supergraph compose --config /data/supergraph.yml > /data/supergraph.graphql
# exit
echo "Done."