-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbuild.sh
executable file
·59 lines (49 loc) · 1.83 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
#!/bin/bash -eu
# 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
# code will be compiled in this container
BUILDER_IMAGE='ghcr.io/geonet/base-images/go:1.21'
RUNNER_IMAGE='ghcr.io/geonet/base-images/static:latest'
VERSION='git-'$(git rev-parse --short HEAD)
ACCOUNT=$(aws sts get-caller-identity --output text --query 'Account')
for i in "$@"; do
if [[ "${i}" == "fits-api" ]]; then
SOURCEPATH="."
else
SOURCEPATH="./dapper"
fi
mkdir -p "${SOURCEPATH}/cmd/${i}/assets"
dockerfile="Dockerfile"
if test -f "${SOURCEPATH}/cmd/${i}/Dockerfile"; then
dockerfile="${SOURCEPATH}/cmd/${i}/Dockerfile"
else
cat Dockerfile_template > $dockerfile
echo "CMD [\"/${i}\"]" >> $dockerfile
fi
docker build \
--build-arg=BUILD="$i" \
--build-arg=RUNNER_IMAGE="$RUNNER_IMAGE" \
--build-arg=BUILDER_IMAGE="$BUILDER_IMAGE" \
--build-arg=GIT_COMMIT_SHA="$VERSION" \
--build-arg=ASSET_DIR="${SOURCEPATH}/cmd/$i/assets" \
--build-arg=SOURCEPATH="$SOURCEPATH" \
-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
# vim: set ts=4 sw=4 tw=0 et: