Skip to content

Commit 4c046fb

Browse files
committed
chore(container): optimize layer caching for Maven dependencies
1 parent b7b6402 commit 4c046fb

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

Dockerfile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ FROM maven:3.9-eclipse-temurin-21-alpine AS builder
66

77
WORKDIR /app
88

9-
# Copy pom.xml and source code
9+
# Copy pom.xml and download dependencies. This will be cached until pom.xml
10+
# changes, speeding up the build process.
1011
COPY pom.xml .
11-
COPY src ./src
12+
RUN mvn dependency:go-offline -B
1213

13-
# Build the application and skip tests for faster build
14+
# Copy source code and build the application, skipping tests for faster builds.
15+
COPY src ./src
1416
RUN mvn clean package -DskipTests
1517

1618
# ------------------------------------------------------------------------------
@@ -33,14 +35,14 @@ LABEL org.opencontainers.image.source="https://github.com/nanotaboada/java.sampl
3335
# https://rules.sonarsource.com/docker/RSPEC-6504/
3436

3537
# Copy application JAR file from the builder stage
36-
COPY --from=builder /app/target/*.jar ./app.jar
38+
COPY --from=builder /app/target/*.jar ./app.jar
3739

3840
# Copy metadata docs for container registries (e.g.: GitHub Container Registry)
39-
COPY --chmod=444 README.md ./
40-
COPY --chmod=555 assets/ ./assets/
41+
COPY --chmod=444 README.md ./
42+
COPY --chmod=555 assets/ ./assets/
4143

4244
# Copy entrypoint and healthcheck scripts
43-
COPY --chmod=555 scripts/entrypoint.sh ./entrypoint.sh
45+
COPY --chmod=555 scripts/entrypoint.sh ./entrypoint.sh
4446
COPY --chmod=555 scripts/healthcheck.sh ./healthcheck.sh
4547

4648
# Add system user

0 commit comments

Comments
 (0)