-
Notifications
You must be signed in to change notification settings - Fork 15
/
build.sh
executable file
·48 lines (40 loc) · 1.46 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
#!/bin/bash -e
# Builds Docker images for the arg list. These must be project directories
# where this script is executed.
#
# Builds a statically linked executable and adds it to the container.
# Adds the assets dir from each project to the container e.g., origin/assets
# It is not an error for the assets dir to not exist.
# Any assets needed by the application should be read from the assets dir
# relative to the executable.
#
# usage: ./build.sh project [project]
if [ $# -eq 0 ]; then
echo Error: please supply a project to build. Usage: ./build.sh project [project]
exit 1
fi
VERSION='git-'$(git rev-parse --short HEAD)
ACCOUNT=$(aws sts get-caller-identity --output text --query 'Account')
# some of the projects don't have asset directory
EMPTY_DIR='empty-dir'
mkdir -p $EMPTY_DIR || :
for i in "$@"; do
mkdir -p cmd/$i/assets
dockerfile="Dockerfile"
if test -f "cmd/${i}/Dockerfile"; then
dockerfile="cmd/${i}/Dockerfile"
else
cat Dockerfile.tmplate > $dockerfile
echo "CMD [\"/${i}\"]" >> $dockerfile
fi
docker build \
--build-arg=BUILD="$i" \
--build-arg=GIT_COMMIT_SHA="$VERSION" \
--build-arg=ASSET_DIR="./cmd/$i/assets" \
-t "${ACCOUNT}.dkr.ecr.ap-southeast-2.amazonaws.com/${i}:$VERSION" \
-f $dockerfile .
# tag latest. Makes it easier to test with compose.
docker tag \
"${ACCOUNT}.dkr.ecr.ap-southeast-2.amazonaws.com/${i}:$VERSION" \
"${ACCOUNT}.dkr.ecr.ap-southeast-2.amazonaws.com/${i}:latest"
done