devops(backend): switch to multi-stage Docker build
Some checks failed
CI / Unit & Component Tests (push) Failing after 2s
CI / Backend Unit Tests (push) Failing after 1s
CI / Unit & Component Tests (pull_request) Failing after 1s
CI / Backend Unit Tests (pull_request) Failing after 1s

Replace runtime mvn spring-boot:run with a proper multi-stage build:
- Stage 1 (builder): compiles JAR with BuildKit cache mount for ~/.m2
- Stage 2 (runtime): eclipse-temurin:21-jre with only the JAR

Removes the backend source volume mount and maven_cache named volume.
Deploy with: docker compose up -d --build

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-15 11:15:05 +02:00
parent 3d3d4b8616
commit d943aac3e3
2 changed files with 13 additions and 9 deletions

View File

@@ -1,9 +1,16 @@
FROM eclipse-temurin:21-jdk
FROM eclipse-temurin:21-jdk AS builder
WORKDIR /app
EXPOSE 8080
# Copy wrapper and POM first — dependency layer is cached separately from source
COPY .mvn .mvn
COPY mvnw pom.xml ./
RUN --mount=type=cache,target=/root/.m2 ./mvnw dependency:go-offline -q
# Source code and mvnw are mounted via docker-compose volume at runtime.
# Maven dependencies are cached in a named volume (~/.m2).
CMD ["./mvnw", "spring-boot:run"]
COPY src ./src
RUN --mount=type=cache,target=/root/.m2 ./mvnw clean package -DskipTests -q
FROM eclipse-temurin:21-jre
WORKDIR /app
COPY --from=builder /app/target/*.jar app.jar
EXPOSE 8080
CMD ["java", "-jar", "app.jar"]

View File

@@ -112,9 +112,7 @@ services:
container_name: archive-backend
restart: unless-stopped
volumes:
- ./backend:/app
- ./import:/import
- maven_cache:/root/.m2
depends_on:
db:
condition: service_healthy
@@ -191,6 +189,5 @@ networks:
volumes:
frontend_node_modules:
maven_cache:
ocr_models:
ocr_cache: