Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM maven:3.9.6-eclipse-temurin-17 AS build
WORKDIR /app

COPY pom.xml .
RUN mvn dependency:go-offline -B

COPY src ./src
RUN mvn clean package -DskipTests


FROM eclipse-temurin:17-jre-alpine
WORKDIR /app

COPY --from=build /app/target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
77 changes: 77 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
pipeline {
agent any

environment {

DOCKER_HUB_USER = "lokokun290"
DOCKER_IMAGE = "spring-petclinic-bar"
JFROG_DOMAIN = "bardpetclinic"
JFROG_REPO = "libs-release-local"
}

stages {
stage('Compile') {
steps {
echo 'Compiling the code'
sh './mvnw compile'
}
}

stage('Test') {
steps {
echo 'Running unit tests'
sh './mvnw test'
}
}

stage('Package') {
steps {
echo 'Packaging project to JAR'

sh './mvnw package -DskipTests'
}
}

stage('Artifact to JFrog') {
steps {
script {
echo 'Uploading JAR to JFrog Artifactory'
withCredentials([usernamePassword(credentialsId: 'jfrog-creds', passwordVariable: 'JF_PASS', usernameVariable: 'JF_USER')]) {
sh """
curl -u ${JF_USER}:${JF_PASS} -X PUT "https://${JFROG_DOMAIN}.jfrog.io/artifactory/${JFROG_REPO}/spring-petclinic-${env.BUILD_ID}.jar" -T target/*.jar
"""
}
}
}
}

stage('Build Docker Image') {
steps {
echo 'Building Docker image'
sh "docker build -t ${DOCKER_IMAGE}:${env.BUILD_ID} ."
sh "docker tag ${DOCKER_IMAGE}:${env.BUILD_ID} ${DOCKER_HUB_USER}/${DOCKER_IMAGE}:latest"
}
}

stage('Push to Docker Hub') {
steps {
script {
echo 'Pushing image to Docker Hub'
withCredentials([usernamePassword(credentialsId: 'docker-hub-creds', passwordVariable: 'DOCKER_PASS', usernameVariable: 'DOCKER_USER')]) {
sh "docker login -u ${DOCKER_USER} -p ${DOCKER_PASS}"
sh "docker push ${DOCKER_HUB_USER}/${DOCKER_IMAGE}:latest"
}
}
}
}
}

post {
success {
echo 'Pipeline completed successfully! Artifact is in JFrog and Image is in Docker Hub.'
}
failure {
echo 'Pipeline failed. Check the logs.'
}
}
}
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
DevOps Assignment: Spring PetClinic CI/CD Pipeline
Submitted by: Bar

## Overview
This repository contains a fully automated CI/CD pipeline for the Spring PetClinic application. The solution automates the process from source code to a publicly available Docker image, ensuring a professional and scalable development workflow.

```bash
Pipeline Architecture:

Compile: Resolves all dependencies from Maven Central and compiles the source code.
Test: Runs the unit test suite to ensure application stability.
Package: Builds a runnable JAR file
Artifact to JFrog Uploads the JAR file to a JFrog Artifactory instance (bardpetclinic.jfrog.io) for binary management.
Build Docker Image: Creates a production-ready image based on the Dockerfile.
Push to Docker Hub: Tags and pushes the final image to a public registry.

Deliverables & Access
Jenkinsfile: (Compile -> Test -> Package -> Docker Build).
Dockerfile: Multi-stage/JRE-optimized build for the Java application.
Docker Hub Repository: lokokun290/spring-petclinic-bar
JFrog Artifactory: Integrated as a binary repository for artifact versioning.
Branch All work is done on the 'jenkins-pipeline' branch.

Spring PetClinic CI Pipeline

This project implements a full CI/CD pipeline using Jenkins and Docker.

Architecture
The pipeline consists of the following stages:

Compile: Resolves dependencies from Maven Central and compiles source code.

Test: Runs Unit tests.

Package: Builds a runnable JAR file (skipping tests for speed).

Build Image: Creates a Docker image containing the application.

How to Run :

option 1 - Run the pre-built image from Docker Hub :

docker run -p 8080:8080 lokokun290/spring-petclinic-bar:latest

option 2 - Build and Run locally :

git clone https://github.com/lokokun1/spring-petclinic.git
cd spring-petclinic

docker build -t spring-petclinic-bar .
docker run -p 8080:8080 spring-petclinic-bar

Access the app: Open http://localhost:8080 in your browser

---
hub.docker.com
https://hub.docker.com/repositories/lokokun290

lokokun290/spring-petclinic-bar:latest
lokokun290/jenkins:lts
---
# Spring PetClinic Sample Application [![Build Status](https://github.com/spring-projects/spring-petclinic/actions/workflows/maven-build.yml/badge.svg)](https://github.com/spring-projects/spring-petclinic/actions/workflows/maven-build.yml)[![Build Status](https://github.com/spring-projects/spring-petclinic/actions/workflows/gradle-build.yml/badge.svg)](https://github.com/spring-projects/spring-petclinic/actions/workflows/gradle-build.yml)

[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/spring-projects/spring-petclinic) [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=7517918)
Expand Down