-
Notifications
You must be signed in to change notification settings - Fork 215
/
build-images.sh
executable file
·113 lines (99 loc) · 3.34 KB
/
build-images.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
#!/bin/bash
set -e
# Copyright (c) 2020 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0
#
# SPDX-License-Identifier: EPL-2.0
################################################################################
# This script builds Docker images consisting of the "fat-jars" of the #
# specified services (SERVICES). #
################################################################################
# Directory of the script
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# Array of the services to build Docker images for.
# The pattern is MODULE_NAME:IMAGE_NAME as both can differ from each other.
SERVICES=(
"concierge:concierge"
"gateway:gateway"
"policies:policies"
"things:things"
"thingsearch:things-search"
"connectivity:connectivity:--add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/sun.security.util=ALL-UNNAMED"
)
: "${HTTP_PROXY_LOCAL:=$HTTP_PROXY}"
: "${HTTPS_PROXY_LOCAL:=$HTTPS_PROXY}"
: "${CONTAINER_REGISTRY:=eclipse}"
: "${DOCKER_BIN:=docker}"
: "${DOCKERFILE:="dockerfile-snapshot"}"
: "${SERVICE_VERSION:="0-SNAPSHOT"}"
: "${IMAGE_VERSION:="${SERVICE_VERSION}"}"
print_usage() {
printf "%s [-p HTTP(S) PROXY HOST:PORT]\n" "$1"
}
print_used_proxies() {
printf "Using HTTP_PROXY=%s\n" "$HTTP_PROXY_LOCAL"
printf "Using HTTPS_PROXY=%s\n" "$HTTPS_PROXY_LOCAL"
}
build_docker_image() {
module_name_base=$(echo "$1" | awk -F ":" '{ print $1 }')
module_name=$(printf "ditto-%s" "$module_name_base")
image_tag=$(printf "${CONTAINER_REGISTRY}/ditto-%s" "$(echo "$1" | awk -F ":" '{ print $2 }')")
jvm_args=$(echo "$1" | awk -F ":" '{ print $3 }')
printf "\nBuilding Docker image <%s> for service module <%s> with jvm_args <%s>\n" \
"$image_tag" \
"$module_name" \
"$jvm_args"
$DOCKER_BIN build --pull -f $SCRIPTDIR/$DOCKERFILE \
--build-arg HTTP_PROXY="$HTTP_PROXY_LOCAL" \
--build-arg HTTPS_PROXY="$HTTPS_PROXY_LOCAL" \
--build-arg TARGET_DIR="$module_name_base"/service/target \
--build-arg SERVICE_STARTER="$module_name"-service \
--build-arg SERVICE_VERSION=$SERVICE_VERSION \
--build-arg JVM_CMD_ARGS="$jvm_args" \
-t "$image_tag":$IMAGE_VERSION \
"$SCRIPTDIR"
if [[ "$PUSH_CONTAINERS" == "true" ]]; then
$DOCKER_BIN push "$image_tag":$IMAGE_VERSION
fi
}
build_all_docker_images() {
for i in "${SERVICES[@]}"; do
build_docker_image "$i"
done
}
set_proxies() {
HTTP_PROXY_LOCAL="http://$1"
printf "Set HTTP_PROXY to %s\n" "$HTTP_PROXY_LOCAL"
HTTPS_PROXY_LOCAL="https://$1"
printf "Set HTTPS_PROXY to %s\n" "$HTTPS_PROXY_LOCAL"
}
evaluate_script_arguments() {
while getopts "p:hP" opt; do
case ${opt} in
p)
set_proxies "$OPTARG"
;;
P)
PUSH_CONTAINERS="true"
;;
h | *)
print_usage "$0"
return 1
;;
esac
done
return 0
}
# Here the programme begins
if [ 0 -eq $# ]; then
print_used_proxies
build_all_docker_images
elif evaluate_script_arguments "$@"; then
build_all_docker_images
fi