mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 14:55:50 +00:00
Latest Jenkins config
This commit is contained in:
parent
d40ba0ccb9
commit
eb1f493e71
3 changed files with 19 additions and 17 deletions
16
Dockerfile
16
Dockerfile
|
@ -1,21 +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
|
||||
|
||||
# Package the application
|
||||
RUN ./mvnw clean package -DskipTests
|
||||
|
||||
# Copy the JAR file to the app directory. This is created in the build process
|
||||
RUN cp /app/target/*.jar 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"]
|
||||
|
|
14
Jenkinsfile
vendored
14
Jenkinsfile
vendored
|
@ -17,11 +17,20 @@ pipeline {
|
|||
}
|
||||
}
|
||||
|
||||
stage('Build JAR') {
|
||||
steps {
|
||||
script {
|
||||
echo "Building JAR..."
|
||||
sh './mvnw clean package -Dmaven.test.skip=true'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build Docker Image') {
|
||||
steps {
|
||||
script {
|
||||
echo "Building Docker Image..."
|
||||
def dockerImage = docker.build("spring-petclinic")
|
||||
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
|
||||
|
@ -29,6 +38,7 @@ pipeline {
|
|||
}
|
||||
}
|
||||
|
||||
// Further stages would reference env.DOCKER_IMAGE_ID if needed
|
||||
}
|
||||
|
||||
post {
|
||||
|
@ -37,7 +47,7 @@ pipeline {
|
|||
// Use the saved Docker image ID from the environment if needed
|
||||
if (env.DOCKER_IMAGE_ID) {
|
||||
echo "Stopping and removing Docker Image with ID: ${env.DOCKER_IMAGE_ID}"
|
||||
docker.rmi(env.DOCKER_IMAGE_ID)
|
||||
sh "docker rmi -f ${env.DOCKER_IMAGE_ID}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,15 +39,17 @@ services:
|
|||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.jenkins
|
||||
image: my-jenkins:latest
|
||||
ports:
|
||||
- "8081:8080"
|
||||
- "50000:50000"
|
||||
|
||||
privileged: true
|
||||
user: root
|
||||
environment:
|
||||
- JAVA_OPTS=-Djenkins.install.runSetupWizard=false
|
||||
- CASC_JENKINS_CONFIG=/var/jenkins_home/casc_configs/jenkins.yaml
|
||||
volumes:
|
||||
- ./jenkins_data:/var/jenkins_home
|
||||
- jenkins_data:/var/jenkins_home
|
||||
- ./jenkins.yaml:/var/jenkins_home/casc_configs/jenkins.yaml
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
networks:
|
||||
|
|
Loading…
Reference in a new issue