Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve: use jlink to reduce jdk size in the image #4456

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@
# under the License.
#

FROM eclipse-temurin:17 as jre-build

# Create a custom Java runtime
RUN $JAVA_HOME/bin/jlink \
--add-modules ALL-MODULE-PATH \
--strip-debug \
--no-man-pages \
--no-header-files \
--compress=2 \
--output /javaruntime

RUN echo networkaddress.cache.ttl=1 >> /javaruntime/conf/security/java.security
RUN echo networkaddress.cache.negative.ttl=1 >> /javaruntime/conf/security/java.security

FROM ubuntu:22.04
MAINTAINER Apache BookKeeper <[email protected]>

Expand All @@ -42,7 +56,6 @@ RUN set -x \
&& adduser "${BK_USER}" \
&& apt-get update \
&& apt-get install -y ca-certificates apt-transport-https \
&& apt-get install -y --no-install-recommends openjdk-17-jdk \
nodece marked this conversation as resolved.
Show resolved Hide resolved
&& apt-get install -y --no-install-recommends python3 pip \
&& ln -s /usr/bin/python3 /usr/bin/python \
&& apt-get install -y --no-install-recommends gpg gpg-agent wget sudo \
Expand All @@ -66,10 +79,9 @@ RUN set -x \

WORKDIR /opt/bookkeeper

ENV JAVA_HOME /usr/lib/jvm/java-17-openjdk-$TARGETARCH

RUN echo networkaddress.cache.ttl=1 >> $JAVA_HOME/conf/security/java.security \
&& echo networkaddress.cache.negative.ttl=1 >> $JAVA_HOME/conf/security/java.security
ENV JAVA_HOME=/opt/java/openjdk
ENV PATH="$PATH:$JAVA_HOME/bin"
COPY --from=jre-build /javaruntime $JAVA_HOME

COPY scripts /opt/bookkeeper/scripts
RUN chmod +x -R /opt/bookkeeper/scripts/
Expand Down