-
Notifications
You must be signed in to change notification settings - Fork 95
/
k8s_on_prem.sh
executable file
·110 lines (98 loc) · 2.22 KB
/
k8s_on_prem.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
#!/bin/bash
set -e
function die() {
msg=$1
echo "$msg"
exit 1
}
# args: $1 == message
function confirmOrExit() {
msg=$1
if [ -z "$msg" ]; then
msg="Are you sure?"
fi
read -p "$msg " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
exit 1
fi
}
configMapFile="config/buildbuddy.release.yaml" # Default config file.
useEnterprise="false"
useOutFile="false"
restart="true"
outFile=".buildbuddy.deploy.yaml"
replicas="1"
while test $# -gt 0; do
case "$1" in
-config)
shift
if test $# -gt 0; then
configMapFile=$1
else
die "no config file specified"
fi
shift
;;
-out)
shift
if test $# -gt 0; then
outFile=$1
useOutFile="true"
else
die "no out file specified"
fi
shift
;;
-replicas)
shift
if test $# -gt 0; then
replicas=$1
else
die "no replicas"
fi
shift
;;
-norestart)
restart="false"
shift
;;
-enterprise)
useEnterprise="true"
shift
;;
*)
die "$1 is not a recognized flag!"
;;
esac
done
deploymentFile="deployment/buildbuddy-app.onprem.yaml"
if [ "$useEnterprise" = "true" ]; then
echo "You've selected the enterprise version of BuildBuddy."
echo "Please confirm you've agreed to the BuildBuddy Enterprise Terms at: https://buildbuddy.io/enterprise-terms"
confirmOrExit "Y/n:"
deploymentFile=deployment/buildbuddy-app.enterprise.yaml
fi
[ -f $outFile ] && rm $outFile
touch $outFile
if [ ! -z "$configMapFile" ]; then
kubectl create namespace buildbuddy -o yaml --dry-run=client >> $outFile
echo "---" >> $outFile
kubectl --namespace=buildbuddy create configmap config --save-config --from-file "config.yaml=$configMapFile" -o yaml --dry-run=client >> $outFile
echo "---" >> $outFile
fi
cat $deploymentFile >> $outFile
if [ "$replicas" -gt "1" ]; then
sed -i.bak "s/replicas: 1/replicas: $replicas/g" "$outFile"
rm "$outFile.bak"
fi
if [ "$useOutFile" = "true" ]; then
echo "Configuration written to yaml file: $outFile"
else
kubectl apply -f "$outFile"
rm $outFile
fi
if [ "$restart" = "true" ] && [ "$useOutFile" = "false" ]; then
kubectl rollout restart statefulset buildbuddy-app -n buildbuddy
fi