-
Notifications
You must be signed in to change notification settings - Fork 4
/
ci_build.sh
executable file
·66 lines (55 loc) · 1.49 KB
/
ci_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
63
64
65
66
#!/usr/bin/env bash
set -e
# Config
# ======================================================================
IMAGE="lev-web"
REGISTRY="quay.io/ukhomeofficedigital"
# Misc variables
# ======================================================================
BUILD_HOME_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
# Grep package.json to extract version
PACKAGE_VERSION=$(grep version package.json \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[[:space:]]')
# This will work even when build number set to empty string...
VERSION="v${PACKAGE_VERSION}-${BUILD_NUMBER:-local}-${GIT_COMMIT:-$(git rev-parse HEAD)}"
TAG=${REGISTRY}/${IMAGE}:${VERSION}
# Functions
# ======================================================================
function build_image {
echo "Starting docker image build with params:'$@'..."
docker build -t ${TAG} .
return $?
}
function push_image {
echo "Starting docker image push with params:'$@'..."
docker push ${TAG}
return $?
}
function if_ci_push_image {
if [ "${BUILD_NUMBER}" != "" ]; then
push_image
return $?
else
return 0
fi
}
# Start!
# ======================================================================
# Init
cd ${BUILD_HOME_DIR}
# Build (and test) and push
build_image && if_ci_push_image
ok="$?"
# Report status
if [ ${ok} -ne 0 ]; then
echo "Failed build"
exit 1
else
echo -n "$(git rev-parse HEAD)">artefacts/gitrev
echo -n "${VERSION}">artefacts/lev-web_version
echo "Completed build"
exit 0
fi