-
Notifications
You must be signed in to change notification settings - Fork 4
/
build-docker.sh
executable file
·60 lines (42 loc) · 1.17 KB
/
build-docker.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
#!/bin/bash
set -e
PUSH=$1
if [ -z "${DOCKER_REPO_NAME}" ]; then
export DOCKER_REPO_NAME=gulli/cicdw-myip-webui
echo "WARNING: Using default docker repo name $DOCKER_REPO_NAME"
fi
# This is the official version label for this project.
MAJOR_MINOR=0.2
if [ -z "${CIRCLE_BUILD_NUM}" ]; then
export BUILD_NUMBER=localbuild
else
export BUILD_NUMBER=${CIRCLE_BUILD_NUM}
fi
export SEMANTIC_VERSION=${MAJOR_MINOR}-${BUILD_NUMBER}
echo ${SEMANTIC_VERSION} > cicdversion.txt
if [ -z "${DOCKER_IMAGE}" ]; then
export DOCKER_IMAGE=${DOCKER_REPO_NAME}:${SEMANTIC_VERSION}
fi
rm -rf ./.build
mkdir ./.build
mkdir ./.build/metadata
if [ -z "$GIT_COMMIT" ]; then
export GIT_COMMIT=$(git rev-parse HEAD)
export GIT_URL=$(git config --get remote.origin.url)
export BUILD_DATE=$(date)
fi
if [ -z "$BRANCH_NAME" ]; then
export BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
fi
docker build \
-t ${DOCKER_IMAGE} \
-t ${DOCKER_REPO_NAME}:latest \
--cache-from ${DOCKER_REPO_NAME}:latest \
-f Dockerfile .
if [ -d "/caches/" ]; then
docker save -o /caches/layercache.tar ${DOCKER_REPO_NAME}:latest
fi
echo ${DOCKER_IMAGE}
if [ "${PUSH}" = "push" ]; then
docker push ${DOCKER_REPO_NAME}
fi