diff --git a/API/Dockerfile b/API/Dockerfile index 3f11a10..38a6d55 100644 --- a/API/Dockerfile +++ b/API/Dockerfile @@ -1,22 +1,30 @@ -FROM maven:3.8.5-openjdk-17-slim +# Stage 1: Build +FROM maven:3.8.5-openjdk-17-slim AS build -# Set the working directory WORKDIR /home/container -# Copy project files -COPY . . +# Copy only the files needed for the build +COPY pom.xml ./ +COPY src ./src # Build the app RUN mvn clean package -q -DskipTests -T4C -# Exposting on port 80 so we can -# access via a reverse proxy for Dokku -ENV HOSTNAME "0.0.0.0" -EXPOSE 80 -ENV PORT 80 +# Stage 2: Runtime +FROM openjdk:17-jdk-slim -# We're running in production -ENV APP_ENV "production" +WORKDIR /home/container + +# Copy the jar from the build stage +COPY --from=build /home/container/target/TextPurify-API.jar ./TextPurify-API.jar + +# Expose port +EXPOSE 80 + +# Set environment variables +ENV HOSTNAME="0.0.0.0" +ENV PORT=80 +ENV APP_ENV="production" # Start the app -CMD ["java", "-jar", "target/TextPurify-API.jar"] \ No newline at end of file +CMD ["java", "-jar", "TextPurify-API.jar"] \ No newline at end of file