Skip to content

Commit 8847344

Browse files
committed
make deploy.sh resilient against failure
1 parent e813bc6 commit 8847344

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

bin/deploy.sh

+23-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1+
#!/usr/bin/bash
2+
3+
# protect ourselves from bash nonsense
4+
set -o errexit # fail the script if any command fails
5+
set -o pipefail # fail if a pipeline fails
6+
set -o nounset # fail if we use an unset variable
7+
18
export RAZZLE_PUBLIC_DIR=/var/app/current/build/public
29
export PORT=8081
310
export RAZZLE_AMPLITUDE_KEY=`eb printenv | grep -Eo "RAZZLE_AMPLITUDE_KEY.=.(.*)" | sed -E "s/RAZZLE_AMPLITUDE_KEY.=.//"`
411
export RAZZLE_CDN_ROOT=https://d24gftfomm9wsp.cloudfront.net
512

6-
git branch | grep "* master" > /dev/null
7-
if [ $? -ne 0 ]
8-
then
9-
echo "Branch is not master, aborting deploy" >&2
13+
function fail() {
14+
echo "${1}" >&2
1015
exit
11-
fi
16+
}
1217

13-
git status | grep "nothing to commit" > /dev/null
14-
if [ $? -ne 0 ]
15-
then
16-
echo "Branch is dirty, aborting deploy" >&2
17-
exit
18-
fi
18+
function cleanup() {
19+
echo "running cleanup..."
20+
# move the real .gitignore back
21+
mv .gitignore.bak .gitignore 2>/dev/null || echo "never created gitignore.bak"
22+
git reset
23+
}
24+
25+
trap cleanup EXIT
26+
27+
# make sure we're on a clean master
28+
git branch | grep "* master" > /dev/null || fail "Branch is not master, aborting deploy"
29+
git status | grep "nothing to commit" > /dev/null || fail "Branch is dirty, aborting deploy"
1930

2031
# take build out of .gitignore for deploy (long story)
2132
git checkout .gitignore
@@ -26,8 +37,4 @@ mv .gitignore.deploy .gitignore
2637
npm run build
2738
git add build
2839
aws s3 sync --size-only --acl public-read build/public/ s3://spaceship-earth/public/
29-
eb deploy Spaceship-$1 --staged
30-
31-
# move the real .gitignore back
32-
mv .gitignore.bak .gitignore
33-
git reset
40+
eb deploy Spaceship-$1 --staged || echo "either EB failed or you CTRL-Ced it!"

0 commit comments

Comments
 (0)