diff --git a/Dockerfile b/Dockerfile index 0e394b307..ce19ac4ef 100644 --- a/Dockerfile +++ b/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"] diff --git a/Jenkinsfile b/Jenkinsfile index 8ac23c6f0..a0428726d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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}" } } } diff --git a/docker-compose_spring-petclinic.yml b/docker-compose_spring-petclinic.yml index 7771d2831..cbad04772 100644 --- a/docker-compose_spring-petclinic.yml +++ b/docker-compose_spring-petclinic.yml @@ -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: