-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathdev-start.sh
executable file
·81 lines (65 loc) · 1.98 KB
/
dev-start.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
#!/bin/bash
TIMEOUTMAX=120
# Get host's IP (127.0.0.1 is assumed if $DOCKET_HOST is empty)
IP=$(echo $DOCKER_HOST | cut -d'/' -f3 | cut -d':' -f1)
if [ "$IP" = "" ]; then
IP="127.0.0.1"
fi
export IP
curl --version > /dev/null
if [ $? -ne 0 ];then
echo "Curl not found"
exit 1
fi
# disable cache
sed -i "s,^CACHE_TYPE.*,CACHE_TYPE = 'null'," frontend/flask_settings
## Deploy the application
echo "-> deploying the application..."
docker-compose up -d || exit $?
## Wait for the application to be available
echo "-> waiting for backend..."
TIMEOUT=0
while [ $(curl -s -m 3 -o /dev/null -w "%{http_code}" $IP:8081) -ne 200 ]; do
sleep 1
TIMEOUT=$(($TIMEOUT+1))
if [ $TIMEOUT -ge $TIMEOUTMAX ];then
echo "TIMEOUT!"
exit 1
fi
done
echo "-> waiting for frontend..."
TIMEOUT=0
while [ $(curl -s -m 3 -o /dev/null -w "%{http_code}" $IP:8080) -ne 200 ]; do
sleep 1
TIMEOUT=$(($TIMEOUT+1))
if [ $TIMEOUT -ge $TIMEOUTMAX ];then
echo "TIMEOUT!"
exit 1
fi
done
## Configure the application
echo "-> configuring the application..."
### Get token from backend
echo "-> requesting token from backend..."
TOKEN=""
TIMEOUT=0
while [ "$TOKEN" = "" ];do
TOKEN=$(curl -m 3 -s -X POST -H "Content-Type: application/json" -H "Authorization: MASTER_KEY" -d '{"email": "adm@kernelci.org", "admin": 1}' $IP:8081/token | docker container run --rm -i lucj/jq -r .result[0].token 2>/dev/null)
sleep 1
TIMEOUT=$(($TIMEOUT+1))
if [ $TIMEOUT -ge 60 ];then
echo "TIMEOUT!"
exit 1
fi
done
echo $TOKEN > .kernelci_token
echo "-> token returned: $TOKEN"
### Update frontend with token created
sed -i "s/^BACKEND_TOKEN.*$/BACKEND_TOKEN = \"$TOKEN\"/" frontend/flask_settings
echo "-> wait while frontend is restarted"
docker-compose stop frontend || exit $?
docker-compose start frontend || exit $?
echo "-> application configured"
echo "--> frontend available on port 8080"
echo "--> backend available on port 8081"
echo "--> storage available on port 8082"