-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathbuild.sh
executable file
·74 lines (66 loc) · 1.4 KB
/
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
67
68
69
70
71
72
73
74
#!/bin/bash
# Builds a single Open Liberty Docker Image
# dir and tag must be specified, other arguments allow for overrides in development builds.
usage="Usage: build.sh --dir=<Dockerfile directory> --dockerfile --tag=<image tag name> (--tag2=<second image tag name> --tag3=<third image tag name> "
while [ $# -gt 0 ]; do
case "$1" in
--dir=*)
dir="${1#*=}"
;;
--dockerfile=*)
dockerfile="${1#*=}"
;;
--tag=*)
tag="${1#*=}"
;;
--tag2=*)
tag2="${1#*=}"
;;
--tag3=*)
tag3="${1#*=}"
;;
--from=*)
from="${1#*=}"
;;
*)
echo "Error: Invalid argument - $1"
echo "$usage"
exit 1
esac
shift
done
if [ -z "$dir" ] || [ -z "$tag" ]
then
echo "Error: Must specify --dir and --tag args"
echo "$usage"
exit 1
fi
cd $dir
buildCommand="docker build -t $tag -f $dockerfile"
if [ ! -z "$tag2" ]
then
buildCommand="$buildCommand -t $tag2"
fi
if [ ! -z "$tag3" ]
then
buildCommand="$buildCommand -t $tag3"
fi
if [ ! -z "$from" ]
then
buildCommand="$buildCommand --build-arg PARENT_IMAGE=$from"
fi
buildCommand="$buildCommand ."
echo "****"
echo "Building $dir ($tag $tag2 $tag3)"
echo "$buildCommand"
echo "****"
eval $buildCommand
if [ $? = 0 ]
then
echo "****"
echo "Build successful $dir ($tag $tag2 $tag3)"
echo "****"
else
echo "Build failed $dir ($tag $tag2 $tag3), exiting."
exit 1
fi