-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuildDocker.sh
97 lines (84 loc) · 3.63 KB
/
buildDocker.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
################################################################################
# Build docker locally
# Usage:
# bash buildDocker.sh [TAG_NAME]
################################################################################
################################################################################
# Define default values for variables
################################################################################
TAG_NAME=local
################################################################################
# START DECLARATION FUNCTIONS
################################################################################
################################################################################
function usage {
################################################################################
echo "USAGE:"
echo " $0 [TAG_NAME]"
exit 1
}
################################################################################
function printInfo {
################################################################################
echo "---------------------------------------------------------------------------"
echo "$*"
echo "---------------------------------------------------------------------------"
}
################################################################################
# END DECLARATION FUNCTIONS / START OF SCRIPT
################################################################################
################################################################################
# Test for commands used in this script
################################################################################
testForCommands="dirname date docker git"
for command in $testForCommands
do
if ! type "$command" >> /dev/null; then
echo "Error: command '$command' is not installed!"
exit 1
fi
done
################################################################################
# Determine directory of script.
################################################################################
ACTUAL_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
################################################################################
# Determine repo name
################################################################################
REPO_NAME=$("$ACTUAL_DIR"/../gradlew -q printProjectName)
# Use only last line
REPO_NAME=${REPO_NAME##*$'\n'}
################################################################################
# Determine tag
# 1. use tagname given as argument
# 2. determine last tag of git
# a) if no tag defined -> local
# b) concat actual date to tag
################################################################################
if [ "$1" != "" ]; then
TAG_NAME=$1
# Check for invalid flags
if [ "${TAG_NAME:0:1}" = "-" ]; then
usage
fi
else
LAST_TAG=$(git describe --abbrev=0 --tags) >> /dev/null
if [ "$LAST_TAG" = "" ]; then
LAST_TAG=$TAG_NAME
fi
TAG_NAME=$LAST_TAG-$(date -u +%Y-%m-%d)
fi
cd "$ACTUAL_DIR"/.. || { echo "Failure changing to directory $ACTUAL_DIR/.."; exit 1; }
################################################################################
# Build local docker
################################################################################
printInfo Build docker container ghcr.io/kit-data-manager/"$REPO_NAME":"$TAG_NAME"
if ! docker build -t ghcr.io/kit-data-manager/"$REPO_NAME":"$TAG_NAME" .; then
echo .
printInfo "ERROR while building docker container!"
usage
else
echo .
printInfo Now you can create and start the container by calling docker "run -d -p8040:8040 --name metastore4docker ghcr.io/kit-data-manager/$REPO_NAME:$TAG_NAME"
fi