# syntax=docker/dockerfile:1 FROM gradle:jdk8-ubi9 AS builder WORKDIR /workspace # Copy Gradle wrapper and build files COPY gradlew . COPY gradle gradle COPY build.gradle . COPY settings.gradle || true COPY pom.xml pom.xml COPY gradle/wrapper gradle/wrapper COPY src src RUN chmod +x gradlew # Build the project (this will download dependencies and compile sources) RUN ./gradlew clean build -x test # Runtime stage FROM openjdk:8-jre-slim WORKDIR /app # Copy built artifacts from the builder stage COPY --from=builder /workspace/build/libs /app/libs # Ensure the libs directory exists (no-op if already present) RUN mkdir -p /app/libs # If a jar is produced, run it by default. If not, just start a shell. ENTRYPOINT ["/bin/sh","-c","set -e; JAR=$(ls /app/libs/*.jar 2>/dev/null | head -n 1 || true); if [ -n \"$JAR\" ]; then exec java -jar \"$JAR\" \"$@\"; else echo \"No jar found in /app/libs\"; fi"]
# syntax=docker/dockerfile:1 FROM gradle:jdk8-ubi9 AS builder WORKDIR /workspace # Copy Gradle wrapper and build files COPY gradlew ./gradlew COPY gradle ./gradle COPY build.gradle ./build.gradle COPY settings.gradle || true COPY pom.xml pom.xml COPY src src COPY README.md README.md RUN chmod +x gradlew # Build the project (this will download dependencies and compile sources) RUN ./gradlew clean build -x test # Runtime stage FROM openjdk:8-jre WORKDIR /app # Copy built artifacts from the builder stage COPY --from=builder /workspace/build/libs /app/libs # Ensure the libs directory exists (no-op if already present) RUN mkdir -p /app/libs # If a jar is produced, run it by default. If not, just start a shell. ENTRYPOINT ["/bin/sh","-c","set -e; JAR=$(ls /app/libs/*.jar 2>/dev/null | head -n 1 || true); if [ -n \"$JAR\" ]; then exec java -jar \"$JAR\" \"$@\"; else echo \"No jar found in /app/libs\"; exec /bin/bash; fi"]
# syntax=docker/dockerfile:1 FROM gradle:jdk8-ubi9 AS builder WORKDIR /workspace # Copy Gradle wrapper and build files COPY gradlew ./gradlew COPY gradle ./gradle COPY build.gradle ./build.gradle COPY pom.xml pom.xml COPY settings.gradle || true COPY src src COPY README.md README.md RUN chmod +x gradlew # Build the project (this will download dependencies and compile sources) RUN ./gradlew clean build -x test # Runtime stage (reuse the same base image to ensure compatibility) FROM gradle:jdk8-ubi9 WORKDIR /app # Copy built artifacts from the builder stage COPY --from=builder /workspace/build/libs /app/libs # Ensure the libs directory exists RUN mkdir -p /app/libs # Run the library JAR if present ENTRYPOINT ["/bin/sh","-c","set -e; JAR=$(ls /app/libs/*.jar 2>/dev/null | head -n 1 || true); if [ -n \"$JAR\" ]; then exec java -jar \"$JAR\"; else echo 'No jar found in /app/libs'; fi"]
# Exclude VCS and IDE files .git .gitignore .gradle build/ out/ doc/ .DS_Store *.iml *.class !.dockerignore
Concerns: Syntax error: COPY settings.gradle || true is invalid Dockerfile syntax (the '|| true' is a shell construct and cannot be used after COPY). This will cause the Docker build to fail., COPY pom.xml pom.xml is unusual for a Gradle-based project and may indicate misconfiguration or leftover Maven artifacts., Runtime base image gradle:jdk8-ubi9 is heavy for a library artifact; consider using a lighter JRE image and ensure the built jar is truly executable. Also, the final image relies on a jar being present; there is no explicit verification of the build output in the image.
# syntax=docker/dockerfile:1 FROM gradle:jdk8-ubi9 AS builder WORKDIR /workspace # Copy Gradle wrapper and build files COPY gradlew . COPY gradle ./gradle COPY build.gradle ./build.gradle COPY src ./src RUN chmod +x gradlew # Build the project (this will download dependencies and compile sources) RUN ./gradlew clean build -x test # Runtime stage reuse the same base image for compatibility FROM gradle:jdk8-ubi9 WORKDIR /app # Copy built artifacts from the builder stage COPY --from=builder /workspace/build/libs /app/libs # Ensure the libs directory exists RUN mkdir -p /app/libs # Run the library JAR if present ENTRYPOINT ["bash","-lc","JAR=$(ls /app/libs/*.jar 2>/dev/null | head -n 1 || true); if [ -n \"$JAR\" ]; then exec java -jar \"$JAR\"; else echo 'No jar found in /app/libs'; fi"]
Concerns: Possible missing settings.gradle in the copied sources; Gradle build may require settings.gradle to configure multi-project builds., ENTRYPOINT currently attempts to execute the first JAR found; if the project is a non-executable library or requires specific main args, container startup may fail or be non-intuitive., Redundant mkdir -p /app/libs after copying the libs directory (copy will create the destination if needed); not harmful but unnecessary. Smoke [PASS]: ls -la /app/libs | head -n 20 Smoke [PASS]: if ls /app/libs/*.jar 1> /dev/null 2>&1; then echo jar_present; else echo no_jar; fi Smoke [PASS]: java -version