A sample Spring-based application
Find a file
Krishna Manchikalapudi 7976e36e29 JF docker cli
2024-07-22 20:49:12 -07:00
.devcontainer Latest Java version 2023-05-09 10:35:25 +01:00
.github/workflows Bump actions version to latest one (checkout * setup-java) 2024-01-23 12:22:42 +00:00
.jfrog/projects JF_CLI jenkinsfile 2024-07-01 18:23:14 -07:00
.mvn/wrapper Update dependency 2023-11-26 09:08:45 +00:00
gradle/wrapper Bump gradle from 8.4 to 8.6 2024-02-29 14:35:20 +00:00
src Make maven and gradle share checkstyle configuration 2024-02-14 14:06:03 +00:00
.editorconfig Add Gradle files indentation to .editorconfig 2024-02-20 17:14:43 +00:00
.gitattributes Gradle wrapper files should have correct line endings 2024-02-29 14:35:20 +00:00
.gitignore Add devcontainer and gitpod 2022-06-09 11:24:17 +01:00
.gitpod.yml Add devcontainer and gitpod 2022-06-09 11:24:17 +01:00
build.gradle Use gradle Java plugin configuration block 2024-02-29 14:35:20 +00:00
cipipeline.svg pipeline svg 2024-03-08 07:30:59 -08:00
docker-compose.yml Update dependency 2023-11-26 09:08:45 +00:00
Dockerfile Jenkins continuous integration (CI) pipeline 2024-03-08 07:25:39 -08:00
Dockerfile-cli JF docker cli 2024-07-22 20:49:12 -07:00
gradlew Update dependency 2023-11-26 09:08:45 +00:00
gradlew.bat Bump gradle from 8.4 to 8.6 2024-02-29 14:35:20 +00:00
Jenkinsfile Alignment with readme & mypetclinic.sh clean fix 2024-03-08 12:36:32 -08:00
Jenkinsfile.jfrog-cli JF_CLI jenkinsfile 2024-07-01 18:23:14 -07:00
jf-cli-docker.sh JF docker cli 2024-07-22 20:49:12 -07:00
jf-cli.sh JF_CLI jenkinsfile 2024-07-01 18:23:14 -07:00
jf-cli.wsd JF_CLI jenkinsfile 2024-07-01 18:23:14 -07:00
LICENSE.txt Add license file 2021-10-05 16:49:36 +01:00
mvnw Upgrade for Spring Boot 3.1 (#1253) 2023-05-26 18:56:00 +01:00
mvnw.cmd Upgrade for Spring Boot 3.1 (#1253) 2023-05-26 18:56:00 +01:00
mypetclinic.sh Alignment with readme & mypetclinic.sh clean fix 2024-03-08 12:36:32 -08:00
pom.xml Make maven and gradle share checkstyle configuration 2024-02-14 14:06:03 +00:00
readme-original.md Jenkins continuous integration (CI) pipeline 2024-03-08 07:25:39 -08:00
readme.md update 2024-06-27 14:34:46 -07:00
settings.gradle Make build work with Gradle 2021-12-16 11:25:09 +00:00
spring-petclinic.code-workspace last uncommit 2024-06-07 20:13:46 -07:00

Spring PetClinic Sample Application

Prerequisites

  • Read and understand the PetClinic application documentation: ReadME.MD

Objective

Develop a DevOps pipeline to automate tasks such as code compile, unit testing, creation of container, and upload of artifacts to a repository. This will streamline the software development process.

Note: This process with not deploy to the envionrmnet platform.

Changelog

  • The original 'readme.md' file has been renamed to 'readme-orignial.md'.
  • Add new files
    • readme.md
    • Dockerfile
    • Jenkinsfile

DevOps steps

Video walkthrough

Walk through demo

Assumption

My assumption is that the user has the necessary infrastucture in place, including Java v17+, Maven v3.8+, Docker v25+, and a Jenkins v2.445+ server, to implement an automated pipeline for the PetClinic application.

docker pull psazuse.jfrog.io/krishnam-docker-virtual/myjenkins:latest

docker pull psazuse.jfrog.io/krishnam-docker-virtual/krishnamanchikalapudi/myjenkins:latest

Pipeline

The Jenkins pipeline script performs the following stages:

Stage: Code

The stage 'Code' contains the following sequential sub-stages:

clean

This sub-stage remove any exisiting petclinc directory

rm -rf spring-petclinic
clone

This sub-stage clones the GitHub repository

git branch: 'main', url: 'https://github.com/krishnamanchikalapudi/spring-petclinic.git'
compile

This sub-stage compiles and skips tests the project using Apache Maven

mvn clean install -DskipTests=true

Stage: Tests

The stage 'Tests' contains parallel sub-stages:

unitTest

This sub-stage runs unit tests using Apache Maven command and generates a surefire html report at the ${project}/${buildNumber}/target/site/surefire-report.html. Note: If the execution is not completed within ten (10) minutes, the stage is failed.

mvn test surefire-report:report
checkStyle

This sub-stage runs the Checkstyle checks using Apache Maven command and generates a checkstyle html report at the ${project}/${buildNumber}/target/site/checkstyle.html. Note: If the execution is not completed within two (2) minutes, the stage is failed.

mvn checkstyle:checkstyle
codeCoverage

This sub-stage generates Jacoco code coverage reports using Apache Maven command and generates a Jacoco html report at the ${project}/${buildNumber}/target/site/jacoco/index.html. Note: If the execution is not completed within two (2) minutes, the stage is failed.

mvn jacoco:report

Stage: Container

The stage 'Docker' contains the following sub-stages:

build

This sub-stage builds the Docker image using the Dockerfile. The image is tagged with the project name and the Jenkins build ID.

docker image build -f Dockerfile -t mypetclinic:${env.BUILD_ID} .
tag

This sub-stage lists Docker containers and images, tags the built image with project name and latest tags, and tags the built image with the project name and build ID.

docker tag mypetclinic:${env.BUILD_ID} krishnamanchikalapudi/mypetclinic:${env.BUILD_ID}
docker tag mypetclinic:${env.BUILD_ID} krishnamanchikalapudi/mypetclinic:latest
publish

This sub-stage pushes the Docker images to the Docker registry using Docker login credentials stored in Jenkins credentials. It pushes both the latest and build ID tagged images.

docker push krishnamanchikalapudi/mypetclinic:${env.BUILD_ID}
docker push krishnamanchikalapudi/mypetclinic:latest
clean

This sub-stage performs cleanup tasks such as pruning unused Docker images and containers, and removing the built image from the local system.

docker system prune -f --filter until=1h
docker rmi -f mypetclinic

Repository

  • The container images from the Jenkin pipeline was uploaded to the Docker repository

Docker image execution

A few options are available to execute the Docker image krishnamanchikalapudi/mypetclinic:latest

Option 1

./mypetclinic.sh start
  • Stop the image
./mypetclinic.sh stop

Option 2

  • Prerequisite
    • Device operating system: Mac, Linux, or Windows
    • Docker version 25+
  • Download the docker image
docker pull krishnamanchikalapudi/mypetclinic:latest
docker pull psazuse.jfrog.io/krishnam-docker-virtual/krishnamanchikalapudi/mypetclinic:latest
  • Execute the container
docker run -d --name mypetclinic -p 7080:8080 krishnamanchikalapudi/mypetclinic:latest
- NOTE: Update port '7080', if any other service is currently running.
docker stop $(docker ps -q --filter ancestor=mypetclinic)
docker ps --filter name=mypetclinic --filter status=running -aq | xargs docker stop

Jenkins Setup

Prerequisite

New project

Learnings

Access issue on my device

error

The Jenkins pipeline stage docker/build throws an error when it tries to make mypetclinic image as below.

ERROR: permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "%2Fvar%2Frun%2Fdocker.sock/_ping": dial unix /var/run/docker.sock: connect: permission denied

solution

My device is running with user 'krishna' and Jenkins service is running with the user 'jenkins'. Therefore, I need to grant the user 'jenkins' access to docker.sock and command follows

sudo setfacl -R -m user:jenkins:rwx /var/run/docker.sock

LAST UMCOMMIT

git reset --hard HEAD~1
git push origin -f

License

The Spring PetClinic sample application is released under version 2.0 of the Apache License.