This commit is contained in:
Lihan 2024-07-28 01:05:45 -04:00
parent d2b23badf3
commit d6a0b57127
2 changed files with 7 additions and 22 deletions

View file

@ -1,24 +1,11 @@
# Use an official OpenJDK runtime as a parent image
FROM openjdk
FROM openjdk:11-jdk-slim
# Set the working directory inside the container
WORKDIR /app
# Copy the Maven wrapper and the pom.xml file
COPY .mvn/ .mvn
COPY mvnw pom.xml ./
# Copy the project source code
COPY src ./src
# Use an argument to force a rebuild
ARG FORCE_REBUILD=unknown
# Package the application
RUN ./mvnw clean package -Dmaven.test.skip=true && ls -alh /app/target/
# Move the JAR file to the app directory (update this if necessary based on actual JAR names)
COPY target/*.jar /app/app.jar
# Copy the JAR file to the app directory (adjust this path according to your actual JAR file name in the target directory)
COPY target/*.jar app.jar
# Run the jar file
CMD ["java", "-jar", "app.jar"]

10
Jenkinsfile vendored
View file

@ -17,11 +17,11 @@ pipeline {
}
}
stage('Prepare Environment') {
stage('Build JAR') {
steps {
script {
sh "pwd" // Prints the current working directory
sh "ls -alh" // Lists all files in the current directory
echo "Building JAR..."
sh './mvnw clean package -Dmaven.test.skip=true'
}
}
}
@ -30,8 +30,7 @@ pipeline {
steps {
script {
echo "Building Docker Image..."
// Correctly escape dollar signs in Groovy string
def dockerImage = docker.build("spring-petclinic", "--no-cache --build-arg FORCE_REBUILD=$(date +%s) .")
def dockerImage = docker.build("spring-petclinic", "--no-cache .")
echo "Docker Image built: ${dockerImage.id}"
// Store the Docker image ID in the environment if needed across stages
env.DOCKER_IMAGE_ID = dockerImage.id
@ -40,7 +39,6 @@ pipeline {
}
// Further stages would reference env.DOCKER_IMAGE_ID if needed
}
post {