# Multi-stage build: build from source and produce runnable jars
FROM debian:11-slim AS builder
RUN apt-get update \
&& apt-get install -y --no-install-recommends openjdk-11-jdk maven ca-certificates curl \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /workspace
# Copy the entire repository
COPY . .
# Ensure mvnw is executable if present
RUN if [ -f ./mvnw ]; then chmod +x ./mvnw; fi
# Build all modules and produce jars
RUN mvn -V -B -DskipTests package
# Runtime stage: minimal image with JRE
FROM debian:11-slim
RUN apt-get update \
&& apt-get install -y --no-install-recommends openjdk-11-jre-headless ca-certificates \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy built artifacts from builder
COPY --from=builder /workspace /app
# Copy a small launcher script and make it executable
COPY run.sh /app/run.sh
RUN chmod +x /app/run.sh
ENTRYPOINT ["/app/run.sh"]