mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 14:55:50 +00:00
latest
This commit is contained in:
parent
d0bfd8b78e
commit
c556ebc308
2 changed files with 22 additions and 14 deletions
29
Dockerfile
29
Dockerfile
|
@ -1,14 +1,23 @@
|
||||||
# Use an official OpenJDK runtime as a parent image
|
# First stage: Build the application using Maven
|
||||||
FROM openjdk:11
|
FROM maven:3.8.1-openjdk-17 AS build
|
||||||
|
|
||||||
# Set the working directory inside the container
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy the built JAR file from the build context
|
# Copy the Maven wrapper and the pom.xml file
|
||||||
COPY target/*.jar app.jar
|
COPY .mvn/ .mvn
|
||||||
|
COPY mvnw pom.xml ./
|
||||||
|
|
||||||
|
# Copy the project source code
|
||||||
|
COPY src ./src
|
||||||
|
|
||||||
|
# Package the application
|
||||||
|
RUN ./mvnw package
|
||||||
|
|
||||||
|
# Second stage: Use an official OpenJDK runtime as a parent image
|
||||||
|
FROM openjdk
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy the JAR file from the build stage
|
||||||
|
COPY --from=build /app/target/*.jar app.jar
|
||||||
|
|
||||||
# Run the jar file
|
# Run the jar file
|
||||||
CMD ["java", "-jar", "app.jar"]
|
CMD ["java", "-jar", "app"]
|
||||||
|
|
||||||
# Expose the port the app runs on
|
|
||||||
EXPOSE 8080
|
|
7
Jenkinsfile
vendored
7
Jenkinsfile
vendored
|
@ -21,8 +21,6 @@ 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
|
||||||
|
@ -31,16 +29,17 @@ pipeline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Further stages would reference env.DOCKER_IMAGE_ID if needed
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
post {
|
post {
|
||||||
always {
|
always {
|
||||||
script {
|
script {
|
||||||
|
// Use the saved Docker image ID from the environment if needed
|
||||||
if (env.DOCKER_IMAGE_ID) {
|
if (env.DOCKER_IMAGE_ID) {
|
||||||
echo "Stopping and removing Docker Image with ID: ${env.DOCKER_IMAGE_ID}"
|
echo "Stopping and removing Docker Image with ID: ${env.DOCKER_IMAGE_ID}"
|
||||||
// Using shell command to remove Docker image
|
docker.rmi(env.DOCKER_IMAGE_ID)
|
||||||
sh "docker rmi ${env.DOCKER_IMAGE_ID}"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue