Merge pull request #3 from CChariot/FinalProject_main

Final project main
This commit is contained in:
CChariot 2024-07-27 13:51:29 -04:00 committed by GitHub
commit a3c15027d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 26 deletions

View file

@ -12,7 +12,7 @@ COPY mvnw pom.xml ./
COPY src ./src COPY src ./src
# Package the application # Package the application
RUN ./mvnw clean package RUN ./mvnw clean package -DskipTests
# Copy the JAR file to the app directory # Copy the JAR file to the app directory
COPY target/*.jar app.jar COPY target/*.jar app.jar

50
Jenkinsfile vendored
View file

@ -2,48 +2,50 @@ pipeline {
agent any agent any
environment { environment {
DOCKER_CREDENTIALS_ID = 'your-docker-credentials-id' // Replace with your actual Docker credentials ID SONARQUBE_URL = 'http://sonarqube:9000'
SONARQUBE_CREDENTIALS_ID = 'admin'
GITHUB_TOKEN = credentials('github-token')
} }
stages { stages {
stage('Checkout') { stage('Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps { steps {
script { script {
sh './mvnw clean package' echo "Checking out code..."
git url: 'https://github.com/CChariot/spring-petclinic.git', branch: 'FinalProject_main', credentialsId: 'github-token'
} }
} }
} }
stage('Build Docker Image') { stage('Build Docker Image') {
steps { steps {
script { script {
// Build the Docker image echo "Building Docker Image..."
sh 'docker build -t petclinic:latest .' def dockerImage = docker.build("spring-petclinic")
echo "Docker Image built: ${dockerImage.id}"
// Store the Docker image ID in the environment if needed across stages
env.DOCKER_IMAGE_ID = dockerImage.id
} }
} }
} }
stage('Push Docker Image') {
steps { }
script {
// Push the Docker image to a registry post {
docker.withRegistry('https://index.docker.io/v1/', "${DOCKER_CREDENTIALS_ID}") { always {
sh 'docker tag petclinic:latest your-docker-username/petclinic:latest' script {
sh 'docker push your-docker-username/petclinic:latest' // 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)
} }
} }
} }
stage('Deploy') { success {
steps { echo 'Pipeline completed successfully!'
script { }
// Deploy the application using Docker Compose failure {
sh 'docker-compose up -d' echo 'Pipeline failed.'
}
}
} }
} }
} }

View file

@ -36,7 +36,10 @@ services:
- prometheus - prometheus
jenkins: jenkins:
image: jenkins/jenkins:lts build:
context: .
dockerfile: Dockerfile.jenkins
image: my-jenkins:latest
ports: ports:
- "8081:8080" - "8081:8080"
- "50000:50000" - "50000:50000"
@ -48,6 +51,7 @@ services:
volumes: volumes:
- 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
networks: networks:
- custom-network - custom-network