This repository has been archived by the owner on Aug 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
deploy.sh
executable file
·54 lines (41 loc) · 1.78 KB
/
deploy.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
#!/bin/sh -e
# Deploy the latest commit to AppEngine
: ${PROJECT:=khan-academy}
: ${VERBOSITY:=info}
: ${DOCKER:=}
die() {
echo "FATAL ERROR: $@"
exit 1
}
# Calculate the version name for the latest commit
# Format is: YYMMDD-HHMM-RRRRRRRRRRRR
#
# Keep this in sync with VERSION in set_default.sh
VERSION=`git log -n1 --format="format:%H %ct" | perl -ne '$ENV{TZ} = "US/Pacific"; ($rev, $t) = split; @lt = localtime($t); printf "%02d%02d%02d-%02d%02d-%.12s\n", $lt[5] % 100, $lt[4] + 1, $lt[3], $lt[2], $lt[1], $rev'`
# Ensure the 'secret' file exists (so we can verify /render requests)
[ -s "secret" ] \
|| die "You must create a file called 'secret' with the secret from\n https://phabricator.khanacademy.org/K121"
# Ensure the repository isn't dirty
[ `git status -u -s | wc -c` -eq 0 ] \
|| die "You must commit your changes before deploying."
# Don't deploy if tests fail
npm test
# Use the default value for use_appengine_api. This is configuration set by
# deployment of webapp.
gcloud config set "app/use_appengine_api" "True"
# Yay we're good to go!
if [ -n "$DOCKER" ]; then
echo "Building docker image..."
docker build -f Dockerfile -t react-render-server .
docker tag react-render-server "us.gcr.io/khan-academy/react-render-server-$VERSION"
echo "Pushing docker image..."
gcloud docker -- push "us.gcr.io/khan-academy/react-render-server-$VERSION"
echo "Deploying ${VERSION} via docker..."
gcloud -q --verbosity "${VERBOSITY}" app deploy app-flex.yaml \
--project "$PROJECT" --version "$VERSION" --no-promote \
--image-url=us.gcr.io/khan-academy/react-render-server-$VERSION
else
gcloud -q --verbosity "${VERBOSITY}" app deploy app-standard.yaml \
--project "$PROJECT" --version "$VERSION" --no-promote
fi
echo "DONE"