|
|
@@ -1,15 +1,21 @@
|
|
|
-#FROM openjdk:17-slim
|
|
|
-#COPY target/*.jar /app/app.jar
|
|
|
-#COPY src/main/resources/application-prod.yaml /app/application.yaml
|
|
|
-#WORKDIR /app
|
|
|
-#CMD ["java", "-jar", "/app/app.jar", "-Duser.timezone=Asia/Shanghai", "--spring.config.location=/app/application.yaml"]
|
|
|
-#EXPOSE 8080
|
|
|
|
|
|
+
|
|
|
+# Use an official Maven image as the base image
|
|
|
+FROM maven:3.8.5-openjdk-17-slim AS build
|
|
|
+# Set the working directory in the container
|
|
|
+WORKDIR /app
|
|
|
+# Copy the pom.xml and the project files to the container
|
|
|
+COPY pom.xml .
|
|
|
+COPY src ./src
|
|
|
+# Build the application using Maven
|
|
|
+RUN mvn clean package -DskipTests
|
|
|
+
|
|
|
+# Use an official OpenJDK image as the base image
|
|
|
FROM openjdk:17-jdk-slim
|
|
|
-# 定义构建时传递的JAR文件名参数
|
|
|
-ARG JAR_FILE
|
|
|
-COPY ${JAR_FILE} /app/app.jar
|
|
|
-COPY application-prod.yaml /app/application.yaml
|
|
|
+# Set the working directory in the container
|
|
|
WORKDIR /app
|
|
|
-CMD ["java", "-jar", "/app/app.jar", "--spring.config.location=file:/app/application.yaml"]
|
|
|
-EXPOSE 8080
|
|
|
+# Copy the built JAR file from the previous stage to the container
|
|
|
+COPY --from=build /app/target/*.jar ./app.jar
|
|
|
+# Set the command to run the application
|
|
|
+CMD ["java", "-jar", "/app/app.jar","--spring.config.location=file:/app/application.yaml"]
|
|
|
+EXPOSE 8080
|