stleary-json-java
SUCCESS
10m 10s
History Source
SummaryIterations1Transcript20Dockerfile
Dockerfile29 lines · 891 chars
# Multi-stage build for JSON-Java project

FROM maven:3.6.3-jdk-8 AS build
WORKDIR /build

# Copy pom and source for dependency caching
COPY pom.xml ./
COPY src ./src

# Build the project (skip tests for a faster image build)
RUN mvn -B -q -DskipTests package

FROM eclipse-temurin:8-jre
WORKDIR /app

# Copy built artifacts from the builder stage; run as root to allow this copy
COPY --from=build /build/target /app/target

# Create a non-root user to run the application
RUN groupadd -r app && useradd -r -g app app

# Ensure app user can access /app
RUN mkdir -p /app && chown -R app:app /app

USER app

# Entry point: try to run the built jar; fallback to an interactive shell
ENTRYPOINT ["/bin/sh", "-c", "JAR=$(ls /app/target/*.jar 2>/dev/null | head -n 1); if [ -n \"$JAR\" ]; then echo Running $JAR; exec java -jar \"$JAR\"; else echo No jar found in /app/target; exec /bin/sh; fi"]