This commit is contained in:
Lihan 2024-07-27 15:14:06 -04:00
parent 3d02e1b15c
commit 53ef24191b
3 changed files with 5 additions and 14 deletions

View file

@ -1,20 +1,10 @@
# Use an official OpenJDK runtime as a parent image # Use an official OpenJDK runtime as a parent image
FROM openjdk FROM openjdk:11
# Set the working directory inside the container # Set the working directory inside the container
WORKDIR /app WORKDIR /app
# Copy the Maven wrapper and the pom.xml file # Copy the built JAR file from the build context
COPY .mvn/ .mvn
COPY mvnw pom.xml ./
# Copy the project source code
COPY src ./src
# Package the application
RUN ./mvnw clean package -DskipTests
# Copy the JAR file to the app directory
COPY target/*.jar app.jar COPY target/*.jar app.jar
# Run the jar file # Run the jar file

4
Jenkinsfile vendored
View file

@ -21,15 +21,17 @@ pipeline {
steps { steps {
script { script {
echo "Building Docker Image..." echo "Building Docker Image..."
// Ensure Maven build is executed
sh './mvnw clean package -DskipTests'
def dockerImage = docker.build("spring-petclinic") def dockerImage = docker.build("spring-petclinic")
echo "Docker Image built: ${dockerImage.id}" echo "Docker Image built: ${dockerImage.id}"
// Store the Docker image ID in the environment if needed across stages // Store the Docker image ID in the environment if needed across stages
env.DOCKER_IMAGE_ID = dockerImage.id env.DOCKER_IMAGE_ID = dockerImage.id
sh 'ls -la target/'
} }
} }
} }
} }
post { post {

View file

@ -52,7 +52,6 @@ services:
- jenkins_data:/var/jenkins_home - jenkins_data:/var/jenkins_home
- ./jenkins.yaml:/var/jenkins_home/casc_configs/jenkins.yaml - ./jenkins.yaml:/var/jenkins_home/casc_configs/jenkins.yaml
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock
- ./target:/var/jenkins_home/target
networks: networks:
- custom-network - custom-network