Dockerfile70 lines · 2072 chars # Build container for the MyBatis repository (library)
# Builder stage: use a lightweight Debian-based image with OpenJDK 17 and manual Maven wiring
FROM debian:11-slim AS builder
ENV DEBIAN_FRONTEND=noninteractive
# Install JDK 17, curl, and git (to satisfy git hooks)
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
openjdk-17-jdk-headless \
ca-certificates \
curl \
git \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /workspace
# Copy pom and wrapper first for caching
COPY pom.xml pom.xml
COPY mvnw mvnw
COPY .mvn .mvn
RUN chmod +x mvnw
# Initialize a temporary git repository to satisfy git-build-hook during build
RUN git init \
&& git config user.email "build@example.com" \
&& git config user.name "BuildAgent" \
&& git add -A \
&& git commit -m "initial commit" --allow-empty
# Pre-fetch dependencies using the wrapper (license skip to reduce prompts)
RUN ./mvnw -B -Dlicense.skip=true -DskipTests dependency:go-offline
# Copy sources and build
COPY src src
RUN ./mvnw -B -Dlicense.skip=true -DskipTests -Dgit.build.hook.skip=true clean package
# Normalize the built jar name to app.jar for predictable entrypoint behavior
RUN set -e; JAR=$(ls target/*.jar 2>/dev/null | head -n 1); if [ -n "$JAR" ]; then cp "$JAR" target/app.jar; fi
# Runtime stage
FROM debian:11-slim AS runtime
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
ENV PATH="$JAVA_HOME/bin:$PATH"
WORKDIR /app
# Install JRE and curl for health checks
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
openjdk-17-jre-headless \
ca-certificates \
curl \
tini \
&& rm -rf /var/lib/apt/lists/*
# Copy built artifacts
COPY --from=builder /workspace/target /app/target
# Copy entrypoint script and ensure it is executable
COPY docker-entrypoint.sh /app/docker-entrypoint.sh
RUN chmod +x /app/docker-entrypoint.sh
# Ensure docker-entrypoint.sh exists in final image
RUN [ -f /app/docker-entrypoint.sh ]
# Entry point to launch the application
ENTRYPOINT ["tini", "--", "/app/docker-entrypoint.sh"]