devops(backend): switch to multi-stage Docker build #238

Merged
marcel merged 4 commits from devops/multi-stage-docker-build into main 2026-04-15 11:33:04 +02:00
3 changed files with 20 additions and 10 deletions

4
backend/.dockerignore Normal file
View File

@@ -0,0 +1,4 @@
target/
.git/
*.md
api_tests/

View File

@@ -1,9 +1,18 @@
FROM eclipse-temurin:21-jdk FROM eclipse-temurin:21.0.10_7-jdk-noble AS builder
WORKDIR /app 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. COPY src ./src
# Maven dependencies are cached in a named volume (~/.m2). # -Dmaven.test.skip=true skips test compilation entirely (not just execution)
CMD ["./mvnw", "spring-boot:run"] RUN --mount=type=cache,target=/root/.m2 ./mvnw clean package -Dmaven.test.skip=true -q
FROM eclipse-temurin:21.0.10_7-jre-noble
WORKDIR /app
# Spring Boot repackages to *.jar; pre-repackage artifact uses .jar.original, not .jar
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 container_name: archive-backend
restart: unless-stopped restart: unless-stopped
volumes: volumes:
- ./backend:/app
- ./import:/import - ./import:/import
- maven_cache:/root/.m2
depends_on: depends_on:
db: db:
condition: service_healthy condition: service_healthy
@@ -155,7 +153,7 @@ services:
interval: 15s interval: 15s
timeout: 5s timeout: 5s
retries: 10 retries: 10
start_period: 60s start_period: 30s # JAR starts in ~15s; was 60s when compilation happened at startup
# --- Frontend: SvelteKit (Dev Server) --- # --- Frontend: SvelteKit (Dev Server) ---
frontend: frontend:
@@ -191,6 +189,5 @@ networks:
volumes: volumes:
frontend_node_modules: frontend_node_modules:
maven_cache:
ocr_models: ocr_models:
ocr_cache: ocr_cache: