-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.sh
executable file
·158 lines (104 loc) · 2.8 KB
/
run.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
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
#!/bin/bash
# throw error if failed
set -o errexit -o nounset
STAGING_APP_ID="[GCLOUD STAGING PROJECT ID]"
PRODUCTION_APP_ID="[GCLOUD PRODUCTION PROJECT ID]"
if [ -f ./build/.env ]; then
export $(echo $(cat ./build/.env | sed 's/#.*//g'| xargs) | envsubst)
fi
case "$1" in
dev)
case "$2" in
local-dev)
echo "running local dev server"
cd development
npm install
npm run dev
;;
static-build)
echo "running static"
rm -rf build/dist
# Build the static site
cd development
# make sure all packages are installed
npm install
rm -rf dist
npm run build
cd ..
cp -R -f development/dist build/
cd build
rm -rf requirements.txt
pip install virtualenv --require-hashes
# prep api dev env
virtualenv env -p python3 && source env/bin/activate && python -m pip install pip-tools && pip install --upgrade pip && pip-compile --allow-unsafe --generate-hashes --resolver=backtracking requirements.in && pip install -r requirements.txt --require-hashes
export GOOGLE_CLOUD_PROJECT=$STAGING_APP_ID
./run.sh
;;
*)
echo 'invalid dev environment (local-dev|static-build)'
exit 1
;;
esac
;;
deploy)
target=""
module=""
APP_ID=""
# shift first args
shift
# get deployment args
while getopts m:t: flag
do
case "${flag}" in
m)
module=${OPTARG}
;;
t)
target=${OPTARG}
;;
esac
done
echo "target deployment: $target"
echo "deployment module: $module"
case "$target" in
production)
APP_ID=$PRODUCTION_APP_ID
;;
staging)
APP_ID=$STAGING_APP_ID
;;
esac
if [ "$APP_ID" = "" ]; then
echo 'invalid target deployment (staging|production)'
exit 1
fi
deployment_version=$(date +%s)
case "$module" in
app)
rm -rf build/dist
# Build the static site
cd development
# make sure all packages are installed
npm install
# remove build folder
rm -rf dist
npm run build
# go back to root folder
cd ..
cp -R -f development/dist build/
cd build
pip install virtualenv --require-hashes
# prep build dev env
virtualenv env -p python3 && source env/bin/activate && pip install -r requirements.txt --require-hashes
# run linting
env/bin/python -m flake8
# Deploy to appengine
gcloud app deploy app.yaml --no-promote --version=$deployment_version --project=$APP_ID --quiet
;;
*)
echo 'invalid module (app)'
exit 1
;;
esac
;;
esac