-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild-mvn.sh
executable file
·54 lines (41 loc) · 1.39 KB
/
build-mvn.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
#!/bin/bash
# Exits if the previous command failed.
function isOK() {
if [ $? -ne 0 ]; then
echo "$1"
exit 1
fi
}
if [[ -z "${JAVA_HOME}" ]]; then
echo "JAVA_HOME is not defined. Set it to JDK 10 or above"
exit 1
fi
JAVA_VERSION=$("${JAVA_HOME}/bin/java" -version 2>&1 | awk -F '"' '/version/ {print $2}')
if [[ "${JAVA_VERSION}" < "10.0.0" ]]; then
echo "Requires JDK 10 or above. Set JAVA_HOME to JDK 10 or above"
exit 1
fi
JDEPS="${JAVA_HOME}/bin/jdeps"
JLINK="${JAVA_HOME}/bin/jlink"
DEPLOY_DIR=target
echo "Cleaning deploy directory"
rm -rf "${DEPLOY_DIR}"
echo "Building Helidon based user CRUD service..."
mvn clean package
isOK "FAILED: Gradle execution failed"
echo "Preparing custom JRE image..."
cd "$DEPLOY_DIR"
JAVA_BASE_MODS=$(find . -name "*.jar" -exec jdeps --module-path libs:*.jar -s {} \; | sed -En "s/.* -> (java.*)/ \1;/p" | sort | uniq | grep -v "java.annotation" | tr -s ';\n ' ',')
cd ..
# Add java.management and jdk.unsupported to allow netty to access required classes.
"${JLINK}" --module-path "${JAVA_HOME}/jmods:target/libs:target/*.jar" \
--add-modules java.management,jdk.unsupported"${JAVA_BASE_MODS}" \
--strip-debug \
--compress 2 \
--no-header-files \
--no-man-pages \
--output ${DEPLOY_DIR}/image
isOK "Unable to build custom JRE image"
echo "Preparing Docker image..."
cd target
docker build -t mod-demo:latest .