mirror of
https://gitea.gofwd.group/Forward_Group/ballistic-builder-spring.git
synced 2025-12-06 11:06:45 -05:00
34 lines
1.1 KiB
Docker
34 lines
1.1 KiB
Docker
|
|
# Stage 1: Build the application (The Build Stage)
|
||
|
|
# Use a Java SDK image with Maven pre-installed
|
||
|
|
FROM maven:3.9-jdk-17-slim AS build
|
||
|
|
|
||
|
|
# Set the working directory inside the container
|
||
|
|
WORKDIR /app
|
||
|
|
|
||
|
|
# Copy the Maven project files (pom.xml) first to leverage Docker layer caching
|
||
|
|
COPY pom.xml .
|
||
|
|
|
||
|
|
# Copy the source code
|
||
|
|
COPY src ./src
|
||
|
|
|
||
|
|
# Build the Spring Boot application, skipping tests to speed up the Docker build
|
||
|
|
# This creates the executable JAR file in the 'target' directory
|
||
|
|
RUN mvn clean package -DskipTests
|
||
|
|
|
||
|
|
# Stage 2: Create the final lightweight image (The Runtime Stage)
|
||
|
|
# Use a smaller Java Runtime Environment (JRE) image for a smaller footprint
|
||
|
|
FROM openjdk:17-jre-slim
|
||
|
|
|
||
|
|
# Set the working directory in the final image
|
||
|
|
WORKDIR /app
|
||
|
|
|
||
|
|
# Copy the built JAR file from the 'build' stage into the final image
|
||
|
|
# The JAR file is typically named 'target/<your-app-name>-<version>.jar'
|
||
|
|
# You may need to adjust the name if you have a non-standard pom.xml
|
||
|
|
COPY --from=build /app/target/*.jar app.jar
|
||
|
|
|
||
|
|
# Expose the default Spring Boot port
|
||
|
|
EXPOSE 8080
|
||
|
|
|
||
|
|
# Define the command to run the application
|
||
|
|
ENTRYPOINT ["java", "-jar", "app.jar"]
|