-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
executable file
·90 lines (64 loc) · 2.35 KB
/
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
82
83
84
85
86
87
88
89
90
#! /bin/bash
SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd)
pushd $SCRIPT_DIR > /dev/null
MEMORY=4096
CPUS=2
# mode inverse
function mi {
echo -e "\033[7m"
}
# mode restore
function m0 {
echo -e "\033[0m"
}
# check that skaffold is not running already
if ps -ef | grep "[s]kaffold dev" &> /dev/null; then
echo "🚏 $(mi) Competition $(m0) skaffold already seems to be running, right?"
exit
fi
# check requirement and exit this script too if failure
if ! lib/check_requirements.sh; then
exit
fi
# save the current minikube profile to pop back after status call
MINIKUBE_PROFILE=$(lib/mkube.sh profile > /dev/null)
# if there is no current profile selected then switch to minikube
if [ "$MINIKUBE_PROFILE" = "" ]; then
MINIKUBE_PROFILE="minikube"
fi
# check that the profile exists
if ! lib/mkube.sh profile list | grep purrs > /dev/null; then
echo "purrs minikube profile not found, creating..."
lib/mkube.sh profile delete purrs &> /dev/null
lib/mkube.sh profile create purrs --memory=$MEMORY --cpus=$CPUS
else
# check status and restore if possible
lib/mkube.sh profile purrs &> /dev/null
STOPPED=$(bin/minikube status 2> /dev/null | grep 'Stopped' | wc -l)
# if all are stopped try to restart
if [[ $STOPPED -eq 4 ]]; then
echo "purrs minikube profile is stopped, restarting..."
bin/minikube start
fi
RUNNING=$(bin/minikube status 2> /dev/null | grep 'Running' | wc -l)
CONFIGURED=$(bin/minikube status 2> /dev/null | grep 'Configured' | wc -l)
# now check minikube ready
if [[ $RUNNING -ne 3 || $CONFIGURED -ne 1 ]]; then
echo "acluptec minikube profile errors, recreating..."
lib/mkube.sh profile delete purrs
lib/mkube.sh profile create purrs --memory=$MEMORY --cpus=$CPUS
fi
fi
lib/mkube.sh profile $MINIKUBE_PROFILE &> /dev/null
echo
echo "Choose the application to skaffold: "
CHOICES=`find deployment -maxdepth 1 -mindepth 1 -name "[a-z\-]*" -type d | xargs -n1 basename | sort`
SKAFFOLD=$(echo "$CHOICES" | ./lib/shui 2>&1 1>/dev/tty)
OLDPATH="$PATH"
PATH="$SCRIPT_DIR/bin:$OLDPATH"
pushd deployment/$SKAFFOLD > /dev/null
$SCRIPT_DIR/bin/skaffold config set --global collect-metrics false > /dev/null
$SCRIPT_DIR/bin/skaffold dev --port-forward --minikube-profile purrs --profile deployment
PATH="$OLDPATH"
popd > /dev/null
popd > /dev/null