-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserve.sh
64 lines (49 loc) · 1.45 KB
/
serve.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
#!/bin/bash
set -eo pipefail
#Sanity checks
if [[ -z "${DATA_DIRECTORY}" ]]; then
echo "DATA_DIRECTORY environment variable missing, will not export or import data to firebase"
fi
if [[ -z "${FIREBASE_PROJECT}" ]]; then
echo "FIREBASE_PROJECT environment variable missing"
exit 1
fi
if [[ -z "${EMULATORS_USED}" ]]; then
echo "EMULATORS_USED environment variable missing"
exit 1
fi
dirs=("/usr/src/firebase/functions" "/usr/src/firebase/firestore" "/usr/src/firebase/storage" "/usr/src/firebase")
for i in "${dirs[@]}"
do
if [[ -d "/path/to/dir" ]]
then
cd "$i"
( npm i 2>&1 )
fi
done
if [[ -z "${DATA_DIRECTORY}" ]]; then
( firebase emulators:start --project="$FIREBASE_PROJECT" --only="$EMULATORS_USED" ) &
firebase_pid=$!
else
( firebase emulators:start --project="$FIREBASE_PROJECT" --import="$DATA_DIRECTORY" --export-on-exit="$DATA_DIRECTORY" --only="$EMULATORS_USED" ) &
firebase_pid=$!
fi
# sleep as emulators need to start or the tests crash a bit
sleep 20s
( nginx ) &
nginx_pid=$!
( npm run start 2>&1 ) &
npm_pid=$!
:stop() {
if [[ "${DATA_DIRECTORY}" ]]; then
# remove old firestore data and recreate, export on exit was not working properly nor this without clearing folder first
( rm -rf "$DATA_DIRECTORY" && firebase emulators:export "$DATA_DIRECTORY" )
fi
}
#Execute command
"${@}" &
#Wait
wait $!
# fire stop on container exit
trap :stop INT TERM SIGTERM
wait $firebase_pid $nginx_pid $npm_pid