Skip to content

Commit

Permalink
Reduce image size by using custom JRE
Browse files Browse the repository at this point in the history
  • Loading branch information
artnc committed Nov 14, 2024
1 parent 7acc1c7 commit 4059009
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ RUN tsc \
entry.ts \
&& chmod +x entry.js

# "Creating a JRE using jlink" at https://hub.docker.com/_/eclipse-temurin
# List of required modules is determined by starting with `docker run --rm
# eclipse-temurin:21-alpine java --list-modules`, then removing modules by trial
# and error until `make test` throws ClassNotFoundException
FROM eclipse-temurin:21-alpine as jre
RUN jlink \
--add-modules java.se,jdk.compiler,jdk.unsupported \
--compress 2 \
--no-header-files \
--no-man-pages \
--output /jre \
--strip-debug

FROM alpine:3.20.3
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
ENV PIP_NO_CACHE_DIR=1
Expand All @@ -18,12 +31,12 @@ RUN apk add --no-cache --virtual .build-deps \
gcc \
musl-dev \
npm \
openjdk17-jre-headless \
py3-pip \
python3-dev \
&& apk add --no-cache \
libxslt \
nodejs \
openjdk17-jre-headless \
python3 \
&& pip3 install --break-system-packages \
autoflake==1.7.8 \
Expand All @@ -39,7 +52,6 @@ RUN apk add --no-cache --virtual .build-deps \
@prettier/[email protected] \
[email protected] \
[email protected] \
&& apk del .build-deps \
&& wget https://github.com/muttleyxd/clang-tools-static-binaries/releases/download/master-32d3ac78/clang-format-18_linux-amd64 -O clang-format \
&& chmod +x clang-format \
&& wget https://github.com/google/google-java-format/releases/download/v1.24.0/google-java-format-1.24.0-all-deps.jar -O google-java-format \
Expand All @@ -59,6 +71,7 @@ RUN apk add --no-cache --virtual .build-deps \
--standalone \
-o scalafmt \
&& touch /emptyfile \
&& apk del .build-deps \
&& rm -rf \
/bin/coursier \
/black21-venv/lib/python3.11/site-packages/pip \
Expand All @@ -70,5 +83,7 @@ RUN apk add --no-cache --virtual .build-deps \
/var/cache
# https://stackoverflow.com/a/59485924
COPY --from=golang:1.23.3-alpine3.20 /usr/local/go/bin/gofmt /gofmt
ENV PATH="/jre/bin:${PATH}"
COPY --from=jre /jre /jre
COPY . .
COPY --from=entry /entry.js /entry

0 comments on commit 4059009

Please sign in to comment.