forked from webrecorder/browsertrix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
btrix
executable file
·187 lines (155 loc) · 4.42 KB
/
btrix
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env bash
# ./btrix: Browsertrix Cloud dev environment utility
#
# Note: btrix helper expects a local.yaml file to exist in
# the chart directory alongside values.yaml.
#
# Test commands require installing pytest first, e.g.:
# python3 -m pip install pytest
#
# Usage:
#
# $ ./btrix bootstrap
# Build frontend and backend and upgrade
# Optional args:
# -microk8s: Preface kubectl/helm commands with microk8s
# -wait: Wait until pods are ready
#
# $ ./btrix reset
# Uninstall, delete data, then bootstrap
# Optional args:
# -microk8s: Preface kubectl/helm commands with microk8s
# -wait: Wait until pods are ready
#
# $ ./btrix down
# Uninstall and delete data
# Optional args:
# -microk8s: Preface kubectl/helm commands with microk8s
#
# $ ./btrix test
# Run backend tests
#
# $ ./btrix nightly
# Run nightly backend tests
bootstrap(){
echo "Building backend..."
./scripts/build-backend.sh
echo "Building frontend..."
./scripts/build-frontend.sh
echo "Installing..."
helm upgrade --install -f ./chart/values.yaml -f ./chart/local.yaml btrix ./chart
}
bootstrapMicrok8s(){
echo "Building backend..."
./scripts/build-backend.sh
echo "Building frontend..."
./scripts/build-frontend.sh
echo "Installing..."
microk8s helm3 upgrade --install -f ./chart/values.yaml -f ./chart/local.yaml btrix ./chart
}
waitUntilReady(){
echo "Waiting until ready..."
kubectl wait --for=condition=ready pod --all --timeout=300s
}
waitUntilReadyMicrok8s(){
echo "Waiting until ready..."
microk8s kubectl wait --for=condition=ready pod --all --timeout=300s
}
reset(){
echo "Stopping all crawls & profile browsers"
kubectl delete cjs -n crawlers --all
kubectl delete pjs -n crawlers --all
echo "Uninstalling..."
helm uninstall btrix
echo "Deleting data..."
kubectl delete pvc --all
kubectl delete cronjob -n crawlers --all
kubectl delete configmap -n crawlers -l btrix.crawlconfig
}
resetMicrok8s(){
echo "Stopping all crawls & profile browsers"
microk8s kubectl delete cjs -n crawlers --all
microk8s kubectl delete pjs -n crawlers --all
echo "Uninstalling..."
microk8s helm uninstall btrix
echo "Deleting data..."
microk8s kubectl delete pvc --all
microk8s kubectl delete cronjob -n crawlers --all
microk8s kubectl delete configmap -n crawlers -l btrix.crawlconfig
}
runTests() {
echo "Running backend tests..."
python3 -m pytest backend/test/test_*.py
}
runNightlyTests() {
echo "Running nightly backend tests..."
python3 -m pytest backend/test_nightly/test_*.py
}
CONTEXT=$(cat ~/.kube/config | grep "current-context:" | sed "s/current-context: //")
MICROK8S="-microk8s"
WAIT="-wait"
# bootstrap: build frontend and backend, upgrade and wait until ready
if [[ $1 = "bootstrap" ]]; then
echo "Current context: $CONTEXT"
echo "Are you sure you want to update this context?"
if [[ "$(read -e -p '[y/N] > '; echo $REPLY)" == [Yy]* ]] ; then
echo Continuing
else
echo Stopping
exit 1
fi
if [[ $2 = "$MICROK8S" || $3 = "$MICROK8S" ]] ; then
bootstrapMicrok8s
else
bootstrap
fi
if [[ $2 = "$WAIT" || $3 = "$WAIT" ]]; then
if [[ $2 = "$MICROK8S" || $3 = "$MICROK8S" ]] ; then
waitUntilReadyMicrok8s
else
waitUntilReady
fi
fi
fi
# reset: uninstall, delete data, then bootstrap
if [[ $1 = "reset" ]]; then
echo "Current context: $CONTEXT"
echo "Resetting k8s cluster will delete the database. All running crawls will first be canceled. Are you sure you want to do this?"
if [[ "$(read -e -p '[y/N] > '; echo $REPLY)" == [Yy]* ]] ; then
echo Continuing
else
echo Stopping
exit 1
fi
if [[ $2 = "$MICROK8S" || $3 = "$MICROK8S" ]] ; then
resetMicrok8s
bootstrapMicrok8s
else
reset
bootstrap
fi
if [[ $2 = "$WAIT" || $3 = "$WAIT" ]] ; then
if [[ $2 = "$MICROK8S" || $3 = "$MICROK8S" ]] ; then
waitUntilReadyMicrok8s
else
waitUntilReady
fi
fi
fi
# test: run backend tests
if [[ $1 = "test" ]]; then
runTests
fi
# nightly: run nightly backend tests
if [[ $1 = "nightly" ]]; then
runNightlyTests
fi
# down: stop and uninstall browsertrix cloud
if [[ $1 = "down" ]]; then
if [[ $2 = "$MICROK8S" ]] ; then
resetMicrok8s
else
reset
fi
fi
echo "Done"