Created
February 14, 2020 03:17
-
-
Save mballoni/4324d7e89e43103778b2cc0e24d26e42 to your computer and use it in GitHub Desktop.
Jlink experimentations with Spring Boot an minimal image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM openjdk:11-slim-buster AS builder | |
WORKDIR /workspace/app | |
COPY abc.jar demo.jar | |
RUN jar -xf demo.jar | |
RUN mkdir custom | |
RUN jlink --no-header-files --no-man-pages --compress=2 --strip-debug --add-modules java.base,java.logging,java.naming,java.desktop,java.management,java.security.jgss,java.instrument,java.sql --output custom/jre | |
#FROM debian:buster-slim | |
FROM alpine:3.11 | |
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8' | |
#magic packages goten from https://github.com/AdoptOpenJDK/openjdk-docker/blob/master/11/jre/alpine/Dockerfile.openj9.releases.full | |
RUN apk add --no-cache --virtual .build-deps curl binutils \ | |
&& GLIBC_VER="2.29-r0" \ | |
&& ALPINE_GLIBC_REPO="https://github.com/sgerrand/alpine-pkg-glibc/releases/download" \ | |
&& GCC_LIBS_URL="https://archive.archlinux.org/packages/g/gcc-libs/gcc-libs-9.1.0-2-x86_64.pkg.tar.xz" \ | |
&& GCC_LIBS_SHA256="91dba90f3c20d32fcf7f1dbe91523653018aa0b8d2230b00f822f6722804cf08" \ | |
&& ZLIB_URL="https://archive.archlinux.org/packages/z/zlib/zlib-1%3A1.2.11-3-x86_64.pkg.tar.xz" \ | |
&& ZLIB_SHA256=17aede0b9f8baa789c5aa3f358fbf8c68a5f1228c5e6cba1a5dd34102ef4d4e5 \ | |
&& curl -LfsS https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub -o /etc/apk/keys/sgerrand.rsa.pub \ | |
&& SGERRAND_RSA_SHA256="823b54589c93b02497f1ba4dc622eaef9c813e6b0f0ebbb2f771e32adf9f4ef2" \ | |
&& echo "${SGERRAND_RSA_SHA256} */etc/apk/keys/sgerrand.rsa.pub" | sha256sum -c - \ | |
&& curl -LfsS ${ALPINE_GLIBC_REPO}/${GLIBC_VER}/glibc-${GLIBC_VER}.apk > /tmp/glibc-${GLIBC_VER}.apk \ | |
&& apk add --no-cache /tmp/glibc-${GLIBC_VER}.apk \ | |
&& curl -LfsS ${ALPINE_GLIBC_REPO}/${GLIBC_VER}/glibc-bin-${GLIBC_VER}.apk > /tmp/glibc-bin-${GLIBC_VER}.apk \ | |
&& apk add --no-cache /tmp/glibc-bin-${GLIBC_VER}.apk \ | |
&& curl -Ls ${ALPINE_GLIBC_REPO}/${GLIBC_VER}/glibc-i18n-${GLIBC_VER}.apk > /tmp/glibc-i18n-${GLIBC_VER}.apk \ | |
&& apk add --no-cache /tmp/glibc-i18n-${GLIBC_VER}.apk \ | |
&& /usr/glibc-compat/bin/localedef --force --inputfile POSIX --charmap UTF-8 "$LANG" || true \ | |
&& echo "export LANG=$LANG" > /etc/profile.d/locale.sh \ | |
&& curl -LfsS ${GCC_LIBS_URL} -o /tmp/gcc-libs.tar.xz \ | |
&& echo "${GCC_LIBS_SHA256} */tmp/gcc-libs.tar.xz" | sha256sum -c - \ | |
&& mkdir /tmp/gcc \ | |
&& tar -xf /tmp/gcc-libs.tar.xz -C /tmp/gcc \ | |
&& mv /tmp/gcc/usr/lib/libgcc* /tmp/gcc/usr/lib/libstdc++* /usr/glibc-compat/lib \ | |
&& strip /usr/glibc-compat/lib/libgcc_s.so.* /usr/glibc-compat/lib/libstdc++.so* \ | |
&& curl -LfsS ${ZLIB_URL} -o /tmp/libz.tar.xz \ | |
&& echo "${ZLIB_SHA256} */tmp/libz.tar.xz" | sha256sum -c - \ | |
&& mkdir /tmp/libz \ | |
&& tar -xf /tmp/libz.tar.xz -C /tmp/libz \ | |
&& mv /tmp/libz/usr/lib/libz.so* /usr/glibc-compat/lib \ | |
&& apk del --purge .build-deps glibc-i18n \ | |
&& rm -rf /tmp/*.apk /tmp/gcc /tmp/gcc-libs.tar.xz /tmp/libz /tmp/libz.tar.xz /var/cache/apk/* | |
VOLUME /tmp | |
RUN mkdir /app | |
ARG DEPENDENCY=/workspace/app/ | |
COPY --from=builder ${DEPENDENCY}/custom/jre /app/jre | |
COPY --from=builder ${DEPENDENCY}/BOOT-INF/lib /app/lib | |
COPY --from=builder ${DEPENDENCY}/META-INF /app/META-INF | |
COPY --from=builder ${DEPENDENCY}/BOOT-INF/classes /app | |
ENTRYPOINT ["/app/jre/bin/java","-cp","app:app/lib/*","com.example.demo.DemoApplication"] |
jdeps --ignore-missing-deps --list-deps BOOT-INF/lib/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Jdeps scripting idea faces an issue:
https://bugs.openjdk.java.net/browse/JDK-8207162
https://stackoverflow.com/questions/52195964/use-jdeps-for-module-which-has-multi-version-implementation-but-root-module-doe