-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·41 lines (28 loc) · 1.17 KB
/
build
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
#!/usr/bin/env bash
set -Eeuo pipefail
PROGNAME=$(basename $0)
pushd $(cd -P -- "$(dirname -- "$0")" && pwd -P)/..
function clean_before_exit {
popd
}
function error_and_exit {
echo "${PROGNAME}: ${1:-"Unknown error"}" 1>&2
exit 1
}
trap 'error_and_exit "${LINENO}: Unknown error"' ERR
trap clean_before_exit EXIT
[ -z ${DOCKER_REPO-} ] && exit 1
[ -z ${NAME-} ] && exit 1
VERSION=$(if [ -z ${VERSION-} ]; then echo $(if [ -z ${DOCKER_TAG-} ]; then echo latest; else echo $DOCKER_TAG; fi); else echo $VERSION; fi)
VERSION_COMMIT=$(if [ -z ${VERSION_COMMIT-} ]; then echo $(if [ -z ${SOURCE_COMMIT-} ]; then echo `$(which git) rev-parse --short HEAD`; else echo $SOURCE_COMMIT; fi); else echo $VERSION_COMMIT; fi)
VERSION_BUILD_DATE=`$(which date)`
IMAGE_NAME=$(if [ -z ${IMAGE_NAME-} ]; then echo $DOCKER_REPO/$NAME:$VERSION; else echo $IMAGE_NAME; fi)
docker build -t $IMAGE_NAME -f Dockerfile \
--build-arg=NPM_TOKEN=${NPM_TOKEN-} \
--build-arg=NAME=$NAME \
--build-arg=VERSION=$VERSION \
--build-arg=VERSION_COMMIT=$VERSION_COMMIT \
--build-arg=VERSION_BUILD_DATE="$VERSION_BUILD_DATE" \
../..
[ $VERSION != latest ] && docker tag $IMAGE_NAME $DOCKER_REPO/$NAME:latest
exit 0