apache-commons-csv
SUCCESS
106m 30s
History Source
SummaryIterations2Transcript23Dockerfile
Dockerfile35 lines · 1528 chars
# syntax=docker/dockerfile:1

# Build stage: compile the project from source using Maven
FROM maven:3.9.15-ibmjava-8 AS builder
WORKDIR /build

# First copy only the pom to leverage Docker cache for dependencies
COPY pom.xml .
RUN mvn -B -Ddoclint=all -DskipTests dependency:go-offline

# Copy the source tree and build the project (skip tests to speed up the image)
COPY src ./src
RUN mvn -B -Ddoclint=all -DskipTests package

# Runtime stage: provide a minimal JRE with the built artifacts
FROM eclipse-temurin:8-jre
WORKDIR /app

# Install JDK in the runtime stage to provide the 'jar' tool for smoke tests
RUN apt-get update && apt-get install -y --no-install-recommends openjdk-8-jdk ca-certificates && rm -rf /var/lib/apt/lists/*

# Copy the built artifacts into the runtime image
COPY --from=builder /build/target /app/target

# Create a stable reference to the main artifact (best effort: pick first suitable jar)
RUN sh -lc 'artifact=$(ls /app/target/*.jar 2>/dev/null | head -n 1); if [ -n "$artifact" ]; then ln -s "$artifact" /app/app.jar; else echo "No runnable jar found"; fi'

# Healthcheck to verify that the artifact exists in the runtime image
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
  CMD ["sh","-lc","test -f /app/app.jar && echo OK || (echo Missing jar; exit 1)"]

# Since this is primarily a library, there is no guaranteed runnable main class.
# Keep the container lightweight and idling when run without a specific command.
CMD ["sh","-c","while true; do sleep 60; done"]