-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_local.sh
executable file
·98 lines (79 loc) · 2.08 KB
/
test_local.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
#!/usr/bin/env bash
build-single() {
eval $(minikube docker-env)
if [ -z "$1" ]; then
echo "No service specified"
exit 1
fi
for f in ./infra-local/"$1"*; do
if [ -f "$f" ]; then
kubectl delete --wait -f "$f"
fi
done
local d
if [ "$1" == "ui" ]; then
d=./tripapp-"$1"
minikube image rm fedeztk/"$(basename "$d")":latest
else
d=./tripapp-app/"$1"
minikube image rm fedeztk/tripapp-"$(basename "$d")":latest
fi
if [ "$1" == "ui" ]; then
docker build -t fedeztk/tripapp-ui:latest --build-arg GH_ACTIONS_BACKEND_ENDPOINT=http://mastercc.hpc4ai.unito.it."$(minikube ip)".nip.io:80/api/gateway ./tripapp-ui
else
if [ -d "$d" ]; then
docker build -t fedeztk/tripapp-"$(basename "$d")":latest "$d"
fi
fi
for f in ./infra-local/"$1"*; do
if [ -f "$f" ]; then
kubectl apply -f "$f"
fi
done
eval $(minikube docker-env -u)
}
stop-cluster() {
minikube delete
}
start-cluster() {
stop-cluster
# This script is used to test the local environment
minikube start --container-runtime=docker
minikube addons enable ingress
eval $(minikube docker-env)
update-cluster-ip
build-all-images
k8s-deploy
eval $(minikube docker-env -u)
}
build-all-images() {
# build all images under tripapp-app and load them into minikube in parallel
for d in ./tripapp-app/*; do
if [ -d "$d" ]; then
docker build -t fedeztk/tripapp-"$(basename "$d")":latest "$d" &
fi
done
docker build -t fedeztk/tripapp-ui:latest --build-arg GH_ACTIONS_BACKEND_ENDPOINT=http://mastercc.hpc4ai.unito.it."$(minikube ip)".nip.io:80/api/gateway ./tripapp-ui &
wait
}
k8s-deploy() {
# apply all yaml files under triapp-infra
for f in ./infra-local/*; do
if [ -f "$f" ]; then
kubectl apply -f "$f"
fi
done
}
update-cluster-ip() {
local predefined_ip
predefined_ip="192.168.49.2"
if ! ping -c 1 "$predefined_ip" &>/dev/null; then
find ./infra-local/ -type f -exec sed -i "s/$(predefined_ip)/$(minikube ip)/g" {} \;
fi
}
case "$1" in
-r | --rebuild) shift build-single "$1" ;;
-u | --up) start-cluster ;;
-d | --down) stop-cluster ;;
*) echo "Unrecognized option $1" && exit 1 ;;
esac