# Builder Image
FROM amazoncorretto:21-alpine as jdk

# Required for strip-debug to work
RUN apk add --no-cache binutils

# Build JRE image with all modules
RUN $JAVA_HOME/bin/jlink \
    --verbose \
    --add-modules ALL-MODULE-PATH \
    --strip-debug \
    --no-man-pages \
    --no-header-files \
    --compress=zip-6 \
    --output /full-jre

# Remove legal docs and unuseful binaries
RUN rm -rf /full-jre/legal &&\
    find /full-jre/bin -type f \
         ! -name java \
         ! -name jcmd \
         -delete


# Production image
FROM alpine:3.19

# Useful for container health check
RUN apk add --no-cache curl

# Move JRE and JAR into production image
COPY --from=jdk /full-jre /jre
COPY build/libs/server-all.jar app.jar

ENTRYPOINT [ "/jre/bin/java" ]
CMD [ "-jar", "app.jar"]

EXPOSE 80