-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathbuild
executable file
·148 lines (133 loc) · 2.86 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
#
# Author: chris.jenkins@oracle.com
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
# LICENSE UPL 1.0
#
# Copyright (c) 2022 Oracle and/or its affiliates.
#
# Script to build the image.
#
declare -r cfgfilename="container.cfg"
declare -r dflt_registry="container-registry.oracle.com"
declare -r dflt_baseimage="container-registry.oracle.com/timesten/timesten:22.1.1.1.0"
declare -r dflt_imagename="ttimage"
declare -r dflt_containername="ttcontainer"
declare basedir
declare cfgfile
declare -i login=1
usage()
{
echo
echo "Usage:"
echo
echo " build [--login]"
echo
echo "Builds the TimesTen container image. Parameters are:"
echo
echo " --login"
echo " Logs in to the container registry."
echo
exit 100
}
loadConfig()
{
local cfile
if [[ $# -ne 1 ]]
then
return 1
fi
cfile="$1"
if ! source "${cfile}" >& /dev/null
then
echo
echo "error: unable to load configuration from '${cfile}'"
echo
return 1
fi
if [[ "${DOCKER_REGISTRY}" == "" ]]
then
export DOCKER_REGISTRY="${dflt_registry}"
fi
if [[ "${DOCKER_BASEIMAGE}" == "" ]]
then
export DOCKER_BASEIMAGE="${dflt_baseimage}"
fi
if [[ "${DOCKER_TTIMAGE}" == "" ]]
then
export DOCKER_TTIMAGE="${dflt_imagename}"
fi
if [[ "${DOCKER_TTCONTAINER}" == "" ]]
then
export DOCKER_TTCONTAINER="${dflt_containername}"
fi
return 0
}
basedir=$(dirname "$0")
cfgfile="${basedir}/${cfgfilename}"
if ! loadConfig "${cfgfile}"
then
echo "error: ***** build failed *****"
echo
exit 1
fi
while [[ $# -gt 0 ]]
do
case "$1" in
"--login")
if [[ ${login} -eq 0 ]]
then
usage
fi
login=0
;;
*)
usage
;;
esac
shift
done
if ! cd "${basedir}" >& /dev/null
then
echo
echo "error: unable to access '${basedir}'"
echo
echo "error: ***** build failed *****"
echo
exit 2
fi
# login to container registry if requested
if [[ ${login} -eq 0 ]]
then
echo
echo "info: Logging in to container registry '${DOCKER_REGISTRY}'"
echo "info: Please enter your Oracle credentials when prompted"
if ! docker login "${DOCKER_REGISTRY}"
then
echo
echo "error: ***** build failed *****"
echo
exit 3
fi
fi
# cleanup before we start
echo
echo "info: cleaning up ready for build"
docker container rm "${DOCKER_TTCONTAINER}"
docker image rm "${DOCKER_TTIMAGE}"
docker image prune --force
echo
echo "info: building image '${DOCKER_TTIMAGE}'"
if ! docker build --build-arg BASEIMAGE="${DOCKER_BASEIMAGE}" --tag "${DOCKER_TTIMAGE}" .
then
echo
echo "error: ***** build failed *****"
echo
exit 4
fi
echo
echo "info: build successful"
echo
exit 0