-
Notifications
You must be signed in to change notification settings - Fork 7
/
deploy.sh
executable file
·65 lines (52 loc) · 1.75 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
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
set -e
# First parameter should be "development" or "production"
# [optional] Second parameter is the aws region.
MODE="${1}"; shift
if [ "$MODE" != "production" ] && [ "$MODE" != "development" ]; then
echo "First argument must be production or development."
exit 1
fi
if [ -n "${1}" ]; then
export AWS_DEFAULT_REGION="${1}"
shift
fi
#####################
#### Done with parameter parsing.
if [ "${MODE}" = "production" ]; then
EB_ENVNAME='drivevote-prod'
# Allow alternate env var overrides in CI.
if [ -n "$CI" ]; then
if [ -n "${PROD_AWS_ACCESS_KEY_ID}" ]; then
export AWS_ACCESS_KEY_ID="${PROD_AWS_ACCESS_KEY_ID}"
fi
if [ -n "${PROD_AWS_SECRET_ACCESS_KEY}" ]; then
export AWS_SECRET_ACCESS_KEY="${PROD_AWS_SECRET_ACCESS_KEY}"
fi
fi
else
EB_ENVNAME='drivevote-dev'
# Allow alternate env var overrides in CI.
if [ -n "$CI" ]; then
if [ -n "${DEV_AWS_ACCESS_KEY_ID}" ]; then
export AWS_ACCESS_KEY_ID="${DEV_AWS_ACCESS_KEY_ID}"
fi
if [ -n "${DEV_AWS_SECRET_ACCESS_KEY}" ]; then
export AWS_SECRET_ACCESS_KEY="${DEV_AWS_SECRET_ACCESS_KEY}"
fi
fi
fi
# Precompile all assets first so if there are errors, this task bails early.
# This generates files in public/assets and public/webpack.
rm -rf public/webpack
export NODE_ENV='production' # Always build webpack in production mode.
rake assets:precompile
# Snapshot the source code from HEAD into the deploy artifact.
# This will NOT contain the precompiled assets.
ARTIFACT_FILE='tmp/deploy_artifact.zip'
git archive -o "${ARTIFACT_FILE}" HEAD
# Add in the precompiled assets to the deploy file.
zip -ru "${ARTIFACT_FILE}" public/assets
zip -ru "${ARTIFACT_FILE}" public/webpack
eb deploy "${EB_ENVNAME}"
eb deploy "${EB_ENVNAME}"-worker