forked from topcoder-platform/community-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·62 lines (55 loc) · 2.1 KB
/
build.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
#!/bin/bash
set -eo pipefail
# Builds Docker image of Community App application.
# This script expects a single argument: NODE_ENV, which must be either
# "development" or "production".
NODE_ENV=$1
# Selects proper AWS_ACCOUNT_ID / AWS_REGION for dev / prod builds. Fails
# execution, if NODE_ENV argument is missing or incorrect.
if [ $NODE_ENV == production ]
then
AWS_ACCOUNT_ID=$PROD_AWS_ACCOUNT_ID
AWS_REGION=$PROD_AWS_REGION
FILESTACK_API_KEY=$PROD_FILESTACK_API_KEY
FILESTACK_SUBMISSION_CONTAINER=$PROD_FILESTACK_SUBMISSION_CONTAINER
SEGMENT_IO_API_KEY=$PROD_SEGMENT_IO_API_KEY
elif [ $NODE_ENV == development ]
then
AWS_ACCOUNT_ID=$DEV_AWS_ACCOUNT_ID
AWS_REGION=$DEV_AWS_REGION
FILESTACK_API_KEY=$DEV_FILESTACK_API_KEY
FILESTACK_SUBMISSION_CONTAINER=$DEV_FILESTACK_SUBMISSION_CONTAINER
SEGMENT_IO_API_KEY=$DEV_SEGMENT_IO_API_KEY
else
exit 1
fi
# Builds Docker image of the app.
TAG=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/community-app:$CIRCLE_SHA1
docker build -t $TAG \
--build-arg NODE_ENV=$NODE_ENV \
--build-arg FILESTACK_API_KEY=$FILESTACK_API_KEY \
--build-arg FILESTACK_SUBMISSION_CONTAINER=$FILESTACK_SUBMISSION_CONTAINER \
--build-arg COGNITIVE_NEWSLETTER_SIGNUP_APIKEY=$COGNITIVE_NEWSLETTER_SIGNUP_APIKEY \
--build-arg COGNITIVE_NEWSLETTER_SIGNUP_URL=$COGNITIVE_NEWSLETTER_SIGNUP_URL \
--build-arg SEGMENT_IO_API_KEY=$SEGMENT_IO_API_KEY .
# Copies "node_modules" from the created image, if necessary for caching.
docker create --name app $TAG
if [ -d node_modules ]
then
# If "node_modules" directory already exists, we should compare
# "package-lock.json" from the code and from the container to decide,
# whether we need to re-cache, and thus to copy "node_modules" from
# the Docker container.
mv package-lock.json old-package-lock.json
docker cp app:/opt/app/package-lock.json package-lock.json
set +eo pipefail
UPDATE_CACHE=$(cmp package-lock.json old-package-lock.json)
set -eo pipefail
else
# If "node_modules" does not exist, then cache must be created.
UPDATE_CACHE=1
fi
if [ "$UPDATE_CACHE" == 1 ]
then
docker cp app:/opt/app/node_modules .
fi