Minimized image by multistage build 94/10694/2
authorBjornMagnussonXA <bjorn.magnusson@est.tech>
Thu, 9 Mar 2023 09:16:12 +0000 (10:16 +0100)
committerBjornMagnussonXA <bjorn.magnusson@est.tech>
Thu, 9 Mar 2023 11:07:04 +0000 (12:07 +0100)
Issue-ID: NONRTRIC-845
Signed-off-by: BjornMagnussonXA <bjorn.magnusson@est.tech>
Change-Id: I7341b4ae826bab7904b001b70be0c6cc0cc0a90c

Dockerfile

index 784664c..5f6e3f0 100644 (file)
@@ -1,6 +1,6 @@
 #
 # ============LICENSE_START=======================================================
-#  Copyright (C) 2019 Nordix Foundation.
+#  Copyright (C) 2019-2023 Nordix Foundation.
 # ================================================================================
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # SPDX-License-Identifier: Apache-2.0
 # ============LICENSE_END=========================================================
 #
-FROM openjdk:17-jdk-slim
+FROM openjdk:17-jdk as jre-build
+
+RUN $JAVA_HOME/bin/jlink \
+--verbose \
+--add-modules ALL-MODULE-PATH \
+--strip-debug \
+--no-man-pages \
+--no-header-files \
+--compress=2 \
+--output /customjre
+
+# Use debian base image (same as openjdk uses)
+FROM debian:11-slim
+
+ENV JAVA_HOME=/jre
+ENV PATH="${JAVA_HOME}/bin:${PATH}"
+
+#copy JRE from the base image
+COPY --from=jre-build /customjre $JAVA_HOME
 
 ARG JAR
 
@@ -45,4 +63,4 @@ RUN chown -R $user:$group /var/log/policy-agent
 USER ${user}
 
 ADD target/${JAR} /opt/app/policy-agent/policy-agent.jar
-CMD ["java", "-jar", "/opt/app/policy-agent/policy-agent.jar"]
\ No newline at end of file
+CMD ["/jre/bin/java", "-jar", "/opt/app/policy-agent/policy-agent.jar"]