forked from eclipse-ditto/ditto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-images.sh
executable file
·135 lines (118 loc) · 4.32 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/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=(
"gateway:gateway:org.eclipse.ditto.gateway.service.starter.GatewayService"
"policies:policies:org.eclipse.ditto.policies.service.starter.PoliciesService"
"things:things:org.eclipse.ditto.things.service.starter.ThingsService"
"thingsearch:things-search:org.eclipse.ditto.thingsearch.service.starter.SearchService"
"connectivity:connectivity:org.eclipse.ditto.connectivity.service.ConnectivityService:--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 $4 }')
main_class=$(echo "$1" | awk -F ":" '{ print $3 }')
if [ -n "$NO_DOCKER_CACHE" ]; then
no_cache_option=--no-cache
fi;
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" \
--build-arg MAIN_CLASS="$main_class" \
-t "$image_tag":$IMAGE_VERSION \
$no_cache_option \
"$SCRIPTDIR"
if [[ "$PUSH_CONTAINERS" == "true" ]]; then
$DOCKER_BIN push "$image_tag":$IMAGE_VERSION
fi
}
build_ditto_ui_docker_image() {
image_tag=$(printf "${CONTAINER_REGISTRY}/ditto-ui")
printf "\nBuilding Docker image <%s> for Ditto-UI\n" \
"$image_tag"
$DOCKER_BIN build --pull -f $SCRIPTDIR/ui/Dockerfile \
--build-arg HTTP_PROXY="$HTTP_PROXY_LOCAL" \
--build-arg HTTPS_PROXY="$HTTPS_PROXY_LOCAL" \
-t "$image_tag":$IMAGE_VERSION \
"${SCRIPTDIR}/ui"
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
build_ditto_ui_docker_image
}
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