dockerfile

This commit is contained in:
rhita-rh 2025-11-17 22:54:58 +01:00
parent 3aff9cc2d6
commit 3f9dec91b7
3 changed files with 37 additions and 12 deletions

View file

@ -1,11 +0,0 @@
# Not actually used by the devcontainer, but it is used by gitpod
ARG VARIANT=17-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/java:0-${VARIANT}
ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
ARG USER=vscode
VOLUME /home/$USER/.m2
VOLUME /home/$USER/.gradle
ARG JAVA_VERSION=17.0.7-ms
RUN sudo mkdir /home/$USER/.m2 /home/$USER/.gradle && sudo chown $USER:$USER /home/$USER/.m2 /home/$USER/.gradle
RUN bash -lc '. /usr/local/sdkman/bin/sdkman-init.sh && sdk install java $JAVA_VERSION && sdk use java $JAVA_VERSION'

View file

@ -1,6 +1,6 @@
services:
app:
image: lilitaa/pet-clinic
image: lilitaa/my-java-app
ports:
- "8080:8080"
environment:

36
dockerfile Normal file
View file

@ -0,0 +1,36 @@
# -------------------------
# Stage 1: Build
# -------------------------
FROM maven:3.9-eclipse-temurin-17 AS build
WORKDIR /app
# Copy Maven configuration and wrapper first (cache dependencies)
COPY pom.xml .
COPY mvnw .
COPY .mvn .mvn
# Download dependencies (cached if pom.xml doesn't change)
RUN mvn dependency:go-offline -B || true
# Copy source code
COPY src ./src
# Optional: fix formatting
RUN mvn spring-javaformat:apply -B || true
# Build the project (skip tests)
RUN mvn clean package -DskipTests -B
# -------------------------
# Stage 2: Runtime
# -------------------------
FROM eclipse-temurin:17
WORKDIR /app
# Copy the built JAR from the build stage
COPY --from=build /app/target/*.jar app.jar
# Run the application
CMD ["java", "-jar", "app.jar"]