forked from atlasmap/atlasmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·233 lines (194 loc) · 6.51 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
#!/bin/bash
# Exit if any error occurs
set -e
BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Save global script args
ARGS="$@"
# Display a help message.
function displayHelp() {
echo "This script helps you build the AtlasMap monorepo."
echo "The available options are:"
echo " --docker-user Docker user for Docker Hub."
echo " --docker-password Docker password for Docker Hub."
echo " --skip-tests Skips the test execution."
echo " --skip-image-builds Skips image builds."
echo " --with-image-streams Builds everything using image streams."
echo " --namespace N Specifies the namespace to use."
echo " --resume-from Resume build from module."
echo " --clean Cleans up the projects."
echo " --batch-mode Runs mvn in batch mode."
echo " --release-version Version number to be used for release."
echo " --development-version Version number to be used for next development iteration."
echo " --help Displays this help message."
}
#
# Checks if a flag is present in the arguments.
function hasflag() {
filter=$1
for var in "${@:2}"; do
if [ "$var" = "$filter" ]; then
echo 'true'
break;
fi
done
}
#
# Read the value of an option.
function readopt() {
filter=$1
next=false
for var in "${@:2}"; do
if $next; then
echo $var
break;
fi
if [ "$var" = "$filter" ]; then
next=true
fi
done
}
# ======================================================
# Build functions
function modules_to_build() {
# app needs some love...
# modules="parent runtime camel ui app docs"
modules="parent runtime camel ui docs"
resume_from=$(readopt --resume-from $ARGS 2> /dev/null)
if [ "x${resume_from}" != x ]; then
modules=$(echo $modules | sed -e "s/^.*$resume_from/$resume_from/")
fi
echo $modules
}
function init_options() {
SKIP_TESTS=$(hasflag --skip-tests $ARGS 2> /dev/null)
SKIP_IMAGE_BUILDS=$(hasflag --skip-image-builds $ARGS 2> /dev/null)
CLEAN=$(hasflag --clean $ARGS 2> /dev/null)
WITH_IMAGE_STREAMS=$(hasflag --with-image-streams $ARGS 2> /dev/null)
NAMESPACE=$(readopt --namespace $ARGS 2> /dev/null)
HELP=$(hasflag --help $ARGS 2> /dev/null)
RELEASE_VERSION=$(readopt --release-version $ARGS 2> /dev/null)
DEVELOPMENT_VERSION=$(readopt --development-version $ARGS 2> /dev/null)
DOCKER_USER=$(readopt --docker-user $ARGS 2> /dev/null)
DOCKER_PASSWORD=$(readopt --docker-password $ARGS 2> /dev/null)
# Internal variable default values
OC_OPTS=""
MAVEN_PARAMETERS=""
MAVEN_CLEAN_GOAL="clean"
MAVEN_IMAGE_BUILD_PROFILE="-Pfabric8"
MAVEN_CMD="${MAVEN_CMD:-${BASEDIR}/mvnw}"
# Apply options
if [ -n "$(hasflag --batch-mode $ARGS 2> /dev/null)" ]; then
MAVEN_PARAMETERS="$MAVEN_PARAMETERS --batch-mode"
fi
if [ -n "$SKIP_TESTS" ]; then
echo "Skipping tests ..."
MAVEN_PARAMETERS="$MAVEN_PARAMETERS -DskipTests"
fi
if [ -n "$SKIP_IMAGE_BUILDS" ]; then
echo "Skipping image builds ..."
MAVEN_IMAGE_BUILD_PROFILE=""
fi
if [ -n "$NAMESPACE" ]; then
echo "Namespace: $NAMESPACE"
MAVEN_PARAMETERS="$MAVEN_PARAMETERS -Dfabric8.namespace=$NAMESPACE"
OC_OPTS=" -n $NAMESPACE"
fi
if [ -z "$CLEAN" ];then
MAVEN_CLEAN_GOAL=""
fi
if [ -n "$WITH_IMAGE_STREAMS" ]; then
echo "With image streams ..."
MAVEN_PARAMETERS="$MAVEN_PARAMETERS -Dfabric8.mode=openshift"
else
MAVEN_PARAMETERS="$MAVEN_PARAMETERS -Dfabric8.mode=kubernetes"
fi
}
function parent() {
pushd parent
"${MAVEN_CMD}" $MAVEN_CLEAN_GOAL install $MAVEN_PARAMETERS
popd
}
docker_login() {
if [ -n "$DOCKER_USER" ] && [ -n "$DOCKER_PASSWORD" ]; then
echo "==== Login to Docker Hub"
docker login -u "$DOCKER_USER" -p "$DOCKER_PASSWORD"
fi
}
function runtime() {
pushd runtime
"${MAVEN_CMD}" -Pjacoco $MAVEN_IMAGE_BUILD_PROFILE $MAVEN_CLEAN_GOAL checkstyle:check install $MAVEN_PARAMETERS
popd
}
function camel() {
pushd camel
"${MAVEN_CMD}" -Pjacoco $MAVEN_CLEAN_GOAL checkstyle:check install $MAVEN_PARAMETERS
popd
}
function ui() {
pushd ui
yarn install --verbose --no-progress
yarn lint
yarn build:lib
if [ -z "$SKIP_TESTS" ]; then
yarn inspect
yarn test:coverage
fi
popd
}
function app() {
pushd app
yarn
popd
}
function docs() {
pushd docs
"${MAVEN_CMD}" $MAVEN_CLEAN_GOAL install $MAVEN_PARAMETERS
"${MAVEN_CMD}" -f pom-javadoc.xml javadoc:aggregate
popd
}
# ============================================================================
# Main loop
init_options
if [ -n "$HELP" ]; then
displayHelp
exit 0
fi
if [ -n "$RELEASE_VERSION" ]; then
echo "=========================================================="
echo "Performing Maven Release ...."
echo "=========================================================="
"${MAVEN_CMD}" -Dtag=atlasmap-${RELEASE_VERSION} \
-DreleaseVersion=${RELEASE_VERSION} \
-DdevelopmentVersion=${DEVELOPMENT_VERSION} \
-Pfabric8,release,community-release \
release:prepare
"${MAVEN_CMD}" -Dtag=atlasmap-${RELEASE_VERSION} \
-DreleaseVersion=${RELEASE_VERSION} \
-DdevelopmentVersion=${DEVELOPMENT_VERSION} \
-Pfabric8,release,community-release \
release:perform
# Push the branch release changes and the tag.
git push origin HEAD
git push origin atlasmap-${RELEASE_VERSION}
# tag the major/minor version and docker push it
if [ -n "$DOCKER_USER" ] && [ -n "$DOCKER_PASSWORD" ]; then
echo "=========================================================="
echo "Pushing docker images to Docker Hub...."
echo "=========================================================="
ATLASMAP_IMAGE="atlasmap/atlasmap"
MAJOR_MINOR_VERSION=$(echo $RELEASE_VERSION | cut -f1,2 -d'.')
docker_login
docker tag "${ATLASMAP_IMAGE}:${RELEASE_VERSION}" "${ATLASMAP_IMAGE}:${MAJOR_MINOR_VERSION}"
docker push "${ATLASMAP_IMAGE}:${RELEASE_VERSION}"
docker push "${ATLASMAP_IMAGE}:${MAJOR_MINOR_VERSION}"
fi
else
"${MAVEN_CMD}" -N install
for module in $(modules_to_build)
do
echo "=========================================================="
echo "Building ${module} ...."
echo "=========================================================="
eval "${module}"
done
fi