-
Notifications
You must be signed in to change notification settings - Fork 3
/
local-build.sh
executable file
·56 lines (47 loc) · 1.14 KB
/
local-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
#!/bin/bash
#
# Purpose: Publish docker image new tag to docker hub.
#
# Author: Dinesh Alapati, [email protected]
#
# Parameters:
# $1: version
#
set -ex
VERSION=$1
IMAGE_NAME="networknt/light-router"
showHelp() {
echo " "
echo "Error: $1"
echo " "
echo " build.sh [VERSION]"
echo " "
echo " where [VERSION] version of the docker image that you want to publish (example: 0.0.1)"
echo " "
echo " example 1: ./build.sh 0.0.1"
echo " "
}
build() {
echo "Building ..."
mvn clean install
echo "Successfully built!"
}
cleanup() {
if [[ "$(docker images -q $IMAGE_NAME 2> /dev/null)" != "" ]]; then
echo "Removing old $IMAGE_NAME images"
docker images | grep $IMAGE_NAME | awk '{print $3}' | xargs docker rmi -f
echo "Cleanup completed!"
fi
}
publish() {
echo "Building Docker image with version $VERSION"
docker build -t $IMAGE_NAME:$VERSION -t $IMAGE_NAME:latest -f ./docker/Dockerfile . --no-cache=true
echo "Images built with version $VERSION"
}
if [ -z $VERSION ]; then
showHelp "[VERSION] parameter is missing"
exit
fi
build;
cleanup;
publish;