FROM amazoncorretto:21.0.2 AS builder

WORKDIR application

ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} /application/
RUN mv *.jar application.jar
RUN java -Djarmode=layertools -jar application.jar extract

FROM amazoncorretto:21.0.2

COPY --from=builder application/spring-boot-loader/ ./
COPY --from=builder application/dependencies/ ./
COPY --from=builder application/snapshot-dependencies/ ./
COPY --from=builder application/application/ ./

ENTRYPOINT ["java", "-Xms1g", "-Xmx8g", "org.springframework.boot.loader.launch.JarLauncher"]
