-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathbuild.sh
executable file
·285 lines (250 loc) · 10.8 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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#!/bin/bash
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
source .env
MAXIMO_VER="${ENV_MAXIMO_VER:-7.6.1.2}"
FP_VER="${ENV_FP_VER:-2}"
WAS_VER="${ENV_WAS_VER:-20.0.0.3-kernel-java8-ibmjava}"
PROXY_VER="${PROXY_VER:-1.8}"
DEFAULT_BUILD_ARGS=" --build-arg buildver=${MAXIMO_VER} "
DEFAULT_BUILD_ARGS_FILE="build.args"
DOCKER="${DOCKER_CMD:-docker}"
NAME_SPACE="maximo-liberty"
REMOVE=0
SKIP_DB=0
DEPLOY_ON_BUILD=-1
QUIET=-q
PRUNE=0
ADD_LATEST_TAG=1
REMOTE_REGISTRY=""
PRESERVE_IMAGE_CONTAINER=0
INTERMEDIATE_BUILD_IMAGE_ID="ubuntu:18.04"
# Usage: remove "tag name" "version" "product name"
function remove {
image_id=`${DOCKER} images -q --no-trunc ${NAME_SPACE}/${1}:${2}`
if [[ ! -z "${image_id}" ]]; then
echo "${3} image exists. Remove it."
container_ids=`${DOCKER} ps -aq --no-trunc -f ancestor=${image_id}`
if [[ ! -z "${container_ids}" ]]; then
${DOCKER} container rm -f ${container_ids}
fi
${DOCKER} image rm -f "${image_id}"
fi
if [[ -n "${REMOTE_REGISTRY}" ]]; then
${DOCKER} image rm ${REMOTE_REGISTRY}/${NAME_SPACE}/${1}:${2}
fi
}
# Usage: build "tag name" "version" "target directory name" "product name"
function build {
echo "Building ${4} image ..."
if [[ ${ADD_LATEST_TAG} -eq 1 ]]; then
LT="-t ${NAME_SPACE}/${1}:latest"
fi
${DOCKER} build ${QUIET} ${5} ${EXTRA_BUILD_ARGS} ${DEFAULT_BUILD_ARGS} --rm -t ${NAME_SPACE}/${1}:${2} ${LT} ${3} || exit 1
exists=`${DOCKER} images -q --no-trunc ${NAME_SPACE}/${1}:${2}`
if [[ -z "${exists}" ]]; then
echo "Failed to create ${4} image."
exit 2
fi
echo "Completed ${4} image creation."
}
# Usage: push "tag name" "version" "product name"
function push {
if [[ -n "${REMOTE_REGISTRY}" ]]; then
echo "Start to push ${3} image"
${DOCKER} tag ${QUIET} ${NAME_SPACE}/${1}:${2} ${REMOTE_REGISTRY}/${NAME_SPACE}/${1}:${2} || exit 1
${DOCKER} push ${QUIET} ${REMOTE_REGISTRY}/${NAME_SPACE}/${1}:${2} || exit 1
echo "Completed to push the ${3} image."
fi
}
while [[ $# -gt 0 ]]; do
key="${1}"
case "${key}" in
-r | --remove )
REMOVE=1
;;
-R | --remove-only )
REMOVE=1
REMOVE_ONLY=1
;;
-s | --skip-db )
SKIP_DB=1
DEPLOY_ON_BUILD=0
;;
-h | --help )
SHOW_HELP=1
;;
-g )
GEN_PKG_LIST=1
;;
-c | --use-custom-image )
USE_CUSTOM_IMAGE=1
;;
-rt | --remove-latest-tag )
ADD_LATEST_TAG=0
;;
-v | --verbose )
QUIET=""
;;
-p | --prune )
PRUNE=1
;;
--deploy-db-on-runtime )
DEPLOY_ON_BUILD=0
;;
-i | --preserve-image-container )
PRESERVE_IMAGE_CONTAINER=1
;;
"--push-registry="* )
REMOTE_REGISTRY="${key#*=}"
;;
"--namespace="* )
NAME_SPACE="${key#*=}"
DEFAULT_BUILD_ARGS+=" --build-arg namespace=${NAME_SPACE} "
;;
esac
shift
done
if [[ ${SHOW_HELP} -eq 1 ]]; then
cat <<EOF
Usage: build.sh [OPTIONS]
Build Maximo Docker containers.
-r | --remove Remove images when an image exists in repository.
-R | --remove-only Remove images without building when an image exists in repository.
-rt | --remove-latest-tag Do not add the "letest" tag to the built images.
-c | --use-custom-image Build a custom image for Maximo installation container.
-v | --verbose Show detailed output of the docker build.
-p | --prune Remove intermediate multi-stage builds automatically.
-s | --skip-db Skip building and removing a DB image.
-i | --preserve-image-container Do not remove and recreate an installation image container.
--deploy-db-on-runtime Deploy the Maximo database on runtime.
--push-registry=REGISTRY_URL Push the built images to a specified remote Docker registry.
--namespace=NAMESPACE Specify the namespace of the Docker images (default: maximo-liberty).
-h | --help Show this help text.
EOF
exit 1
fi
cd `dirname "${0}"`
if [[ ${REMOVE} -eq 1 ]]; then
echo "Remove old images..."
remove "jmsserver" "${WAS_VER}" "IBM WebSphere Application Server Liberty JMS server"
remove "maximo-ui" "${MAXIMO_VER}" "IBM WebSphere Application Server Liberty for Maximo UI"
remove "maximo-api" "${MAXIMO_VER}" "IBM WebSphere Application Server Liberty for Maximo API"
remove "maximo-cron" "${MAXIMO_VER}" "IBM WebSphere Application Server Liberty for Maximo Crontask"
remove "maximo-report" "${MAXIMO_VER}" "IBM WebSphere Application Server Liberty for Maximo Report Server"
remove "maximo-mea" "${MAXIMO_VER}" "IBM WebSphere Application Server Liberty for Maximo MEA"
remove "maximo-jmsconsumer" "${MAXIMO_VER}" "IBM WebSphere Application Server Liberty for Maximo JMS Consumer"
if [[ ${SKIP_DB} -eq 0 ]]; then
remove "db2" "${MAXIMO_VER}" "IBM Db2 Advanced Workgroup Server Edition"
fi
remove "maximo" "${MAXIMO_VER}" "IBM Maximo Asset Management"
remove "maximo-base" "${MAXIMO_VER}" "IBM Maximo Asset Management base"
if [[ ${SKIP_DB} -eq 0 ]]; then
remove "db2-intermediate" "${MAXIMO_VER}" "IBM Db2 Advanced Workgroup Server Edition - Intermediate Image"
fi
remove "liberty" "${WAS_VER}" "IBM WebSphere Application Server Liberty base"
if [[ ${PRESERVE_IMAGE_CONTAINER} -eq 0 ]]; then
remove "images" "${MAXIMO_VER}" "Maximo Liberty Docker image container"
fi
# remove "frontend-proxy" "${PROXY_VER}" "Frontend Proxy Server"
if [[ ${REMOVE_ONLY} -eq 1 ]]; then
exit
fi
fi
# Construct a default build-args
while IFS='=' read -r key value
do
if [[ "${key}" == "deploy_db_on_build" && ${DEPLOY_ON_BUILD} -eq -1 ]]; then
if [[ "${value}" == "yes" ]]; then
DEPLOY_ON_BUILD=1
else
DEPLOY_ON_BUILD=0
fi
elif [[ "${key}" != "#*" && ! -z "${value}" ]]; then
eval value=${value}
if [[ ! -z "${value}" ]]; then
DEFAULT_BUILD_ARGS+="--build-arg ${key}=${value} "
fi
fi
done < <(sed -e '/^#/d' -e '/^$/d' "${DEFAULT_BUILD_ARGS_FILE}")
if [[ ${DEPLOY_ON_BUILD} -eq -1 ]]; then
DEPLOY_ON_BUILD=1
fi
echo "Start building..."
# Build base image container
image_container_id=`${DOCKER} images -q --no-trunc ${NAME_SPACE}/images:${MAXIMO_VER}`
if [[ ${PRESERVE_IMAGE_CONTAINER} -eq 0 || -z "${image_container_id}" ]]; then
build "images" "${MAXIMO_VER}" "images" "Maximo Liberty Docker image Container"
fi
# Build IBM Db2 Advanced Workgroup Edition image
if [[ ${SKIP_DB} -eq 0 ]]; then
build "db2-intermediate" "${MAXIMO_VER}" "db2" "IBM Db2 Advanced Workgroup Server Edition - Intermediate image"
fi
if [ ${DEPLOY_ON_BUILD} -eq 1 ]; then
INTERMEDIATE_BUILD_IMAGE_ID="${NAME_SPACE}/db2-intermediate:${MAXIMO_VER}"
DEPLOY_ON_BUILD_ARG=" --build-arg deploy_db_on_build=yes "
else
DEPLOY_ON_BUILD_ARG=" --build-arg deploy_db_on_build=no "
fi
if [[ ${USE_CUSTOM_IMAGE} -eq 1 ]]; then
# Build IBM Maximo Asset Management image
build "maximo-base" "${MAXIMO_VER}" "maximo" "IBM Maximo Asset Management" "--build-arg skip_build=yes --build-arg fp=${FP_VER} --build-arg base_maximo_build=${INTERMEDIATE_BUILD_IMAGE_ID} --build-arg deploy_db_on_build=no"
# Build IBM Maximo Asset Management Custom image
build "maximo" "${MAXIMO_VER}" "custom" "IBM Maximo Asset Management Custom" "${DEPLOY_ON_BUILD_ARG}"
else
# Build IBM Maximo Asset Management image
build "maximo" "${MAXIMO_VER}" "maximo" "IBM Maximo Asset Management" "--build-arg fp=${FP_VER} --build-arg base_maximo_build=${INTERMEDIATE_BUILD_IMAGE_ID} ${DEPLOY_ON_BUILD_ARG}"
fi
push "maximo" "${MAXIMO_VER}" "IBM Maximo Asset Management"
# Build IBM Db2 Advanced Workgroup Edition image
if [[ ${SKIP_DB} -eq 0 ]]; then
build "db2" "${MAXIMO_VER}" "maxdb" "IBM Db2 Advanced Workgroup Server Edition"
push "db2" "${MAXIMO_VER}" "IBM Db2 Advanced Workgroup Server Edition"
fi
# Build IBM WebSphere Liberty base image
build "liberty" "${WAS_VER}" "liberty" "IBM WebSphere Application Server Liberty base"
# Build IBM WebSphere Liberty JMS server image
build "jmsserver" "${WAS_VER}" "jmsserver" "IBM WebSphere Application Server Liberty JMS server"
push "jmsserver" "${WAS_VER}" "IBM WebSphere Application Server Liberty JMS server"
# Build IBM WebSphere Liberty for Maximo UI image
build "maximo-ui" "${MAXIMO_VER}" "maxapp" "IBM WebSphere Application Server Liberty for Maximo UI" "--build-arg maximoapp=maximo-ui"
push "maximo-ui" "${MAXIMO_VER}" "IBM WebSphere Application Server Liberty for Maximo UI"
# Build IBM WebSphere Liberty for Maximo Crontask image
build "maximo-cron" "${MAXIMO_VER}" "maxapp" "IBM WebSphere Application Server Liberty for Maximo Crontask" "--build-arg maximoapp=maximo-cron"
push "maximo-cron" "${MAXIMO_VER}" "IBM WebSphere Application Server Liberty for Maximo Crontask"
# Build IBM WebSphere Liberty for Maximo API image
build "maximo-api" "${MAXIMO_VER}" "maxapp" "IBM WebSphere Application Server Liberty for Maximo API" "--build-arg maximoapp=maximo-api"
push "maximo-api" "${MAXIMO_VER}" "IBM WebSphere Application Server Liberty for Maximo API"
# Build IBM WebSphere Liberty for Maximo Report Server image
build "maximo-report" "${MAXIMO_VER}" "maxapp" "IBM WebSphere Application Server Liberty for Maximo Reporting" "--build-arg maximoapp=maximo-report"
push "maximo-report" "${MAXIMO_VER}" "IBM WebSphere Application Server Liberty for Maximo Reporting"
# Build IBM WebSphere Liberty for Maximo MEA image
build "maximo-mea" "${MAXIMO_VER}" "maxapp" "IBM WebSphere Application Server Liberty for Maximo MEA" "--build-arg maximoapp=maximo-mea"
push "maximo-mea" "${MAXIMO_VER}" "IBM WebSphere Application Server Liberty for Maximo MEA"
# Build IBM WebSphere Liberty for JMS Consumer image
build "maximo-jmsconsumer" "${MAXIMO_VER}" "maxapp" "IBM WebSphere Application Server Liberty for Maximo JMS Consumer" "--build-arg maximoapp=maximo-jmsconsumer"
push "maximo-jmsconsumer" "${MAXIMO_VER}" "IBM WebSphere Application Server Liberty for Maximo JMS Consumer"
# Build Frontend Proxy Server
#build "frontend-proxy" "${PROXY_VER}" "frontend-proxy" "Frontend Proxy Server"
# Cleanup Maximo Image build
if [[ ${PRUNE} -eq 1 ]]; then
echo "Cleanup intermediate images."
list=$(docker images -q -f "dangling=true" -f "label=autodelete=true")
if [ -n "${list}" ]; then
docker image rm $list
fi
if [[ ${PRESERVE_IMAGE_CONTAINER} -eq 0 ]]; then
remove "images" "${MAXIMO_VER}" "Maximo Liberty Docker image container"
fi
fi
echo "Done"