Skip to content

Commit

Permalink
hotfix: reduce size docker image file.
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonardoMeireles55 committed Jan 26, 2025
1 parent 21cf1f8 commit 5bd6b98
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
28 changes: 24 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Stage 1: Build custom Java runtime using jlink
FROM eclipse-temurin:21 as jre-build

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

# Stage 2: Build the application
FROM eclipse-temurin:21-jdk-alpine AS build

RUN apk add --no-cache maven
Expand All @@ -7,15 +20,22 @@ COPY pom.xml /app

WORKDIR /app
RUN mvn clean package -DskipTests -U \
&& rm -rf /root/.m2
&& rm -rf /root/.m2 \
&& rm -rf /app/src

# Run stage
FROM eclipse-temurin:21-jre-alpine
# Stage 3: Create the final image with the custom Java runtime and application
FROM debian:buster-slim
ENV JAVA_HOME=/opt/java/openjdk
ENV PATH="${JAVA_HOME}/bin:${PATH}"
COPY --from=jre-build /javaruntime $JAVA_HOME

# Copy the application JAR from the build stage
WORKDIR /usr/src/app
COPY --from=build /app/target/QualityLabPro-0.7.jar ./app.jar

# Set environment variables
ENV SPRING_PROFILES_ACTIVE=prod \
SERVER_PORT=8080

EXPOSE ${SERVER_PORT}
# Expose the application port
EXPOSE ${SERVER_PORT}
22 changes: 22 additions & 0 deletions Dockerfile_OLD_2
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM eclipse-temurin:21-jdk-alpine AS build

RUN apk add --no-cache maven

COPY src /app/src
COPY pom.xml /app

WORKDIR /app
RUN mvn clean package -DskipTests -U \
&& rm -rf /root/.m2 \
&& rm -rf /app/src

# Run stage
FROM eclipse-temurin:21-jre-alpine

WORKDIR /usr/src/app
COPY --from=build /app/target/QualityLabPro-0.7.jar ./app.jar

ENV SPRING_PROFILES_ACTIVE=prod \
SERVER_PORT=8080

EXPOSE ${SERVER_PORT}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class StringToLocalDateTimeConverter implements Converter<String, LocalDa
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

@Override
@NonNull
public LocalDateTime convert(@NonNull String source) {
return LocalDateTime.parse(source, FORMATTER);
}
Expand Down

0 comments on commit 5bd6b98

Please sign in to comment.