# Build Guava from source using Maven with JDK 17 FROM maven:3.9.0-openjdk-17 AS build WORKDIR /workspace # Copy the entire repository and build from source COPY . . # Build all modules from source, skip tests for faster image creation RUN mvn -B -ntp -DskipTests install -Dtoolchain.skip=true -U # Final runtime image FROM eclipse-temurin:17-jre WORKDIR /app # Copy built artifacts and the repository for runtime usage COPY --from=build /workspace /app # Default to an interactive shell so users can run Java/Guava commands CMD ["bash"]
# Build Guava from source using Maven with JDK 17 (Maven Wrapper will download Maven automatically) FROM openjdk:17-jdk-slim AS build WORKDIR /workspace # Copy the repository and build from source COPY . . # Ensure wrapper is executable and run the build (skipping tests for speed) RUN chmod +x mvnw RUN ./mvnw -B -ntp -DskipTests install -U # Final runtime image FROM openjdk:17-jre-slim AS runtime WORKDIR /app # Copy built artifacts from the build stage COPY --from=build /workspace /app # Default to a shell so users can run commands or test the built artifacts CMD ["bash"]
# Build Guava from source using Maven with JDK 17 FROM openjdk:17-jdk-slim AS build WORKDIR /workspace # Copy the repository and build from source COPY . . # Ensure wrapper is executable and run the build (skipping tests for speed) RUN chmod +x mvnw RUN ./mvnw -B -ntp -DskipTests install -U # Final runtime image FROM openjdk:17-jre-slim AS runtime WORKDIR /app # Copy built artifacts from the build stage COPY --from=build /workspace /app # Default to a shell so users can run commands or test the built artifacts CMD ["bash"]
# Build Guava from source using Maven on Ubuntu 22.04 with OpenJDK 17
FROM ubuntu:22.04 AS build
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y --no-install-recommends \
openjdk-17-jdk \
maven \
ca-certificates \
curl \
ca-certificates-java \
git && \
rm -rf /var/lib/apt/lists/*
WORKDIR /workspace
COPY . .
# Build the project from source
RUN mvn -B -ntp -DskipTests install -U
# Final runtime image
FROM ubuntu:22.04 AS runtime
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y --no-install-recommends \
openjdk-17-jre-headless && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=build /workspace /app
# Provide an interactive shell by default
CMD ["bash"]
# Ignore VCS and build artifacts .git .gitignore node_modules -target out build .DS_Store *.log README.md
Concerns: The runtime image ends with a default interactive shell (bash). This is not ideal for automated usage; consider specifying a default CMD that runs a test or a binary if applicable., If the project builds a shaded/uber Jar, ensure the produced artifact is self-contained. If not, runtime dependencies may be missing unless packaging is adjusted. Smoke [PASS]: set -e; if find /app -name '*.jar' -print -quit >/dev/null 2>&1; then echo jar_present; else echo jar_missing; exit 1; fi Smoke [PASS]: java -version Smoke [PASS]: ls -la /app | head -n 20