Spring PetClinic Application using a CI/Jenkins Pipeline building, testing and containerizing a Docker Image and finally scanning and storing it in JFrog Artifactory.
This project uses:
- macOS
- Jenkins for pipeline creation (installed locally) - CI/CD pipeline tool for automation of software builds and pacakging
- A trial of the JFrog Platform (SaaS version) - a universal artifact manager for all different package types: dependencies, binaries, configs, etc
- This repository for SCM - to pipeline checkout (you could also clone it in the pipeline). Forked from www.github.com/Spring-Projects/Spring-Petclinic
- Docker (locally on Mac) utilzing the docker cli for build, scan, and push to JFrog
- JDK 17 (uses maven or gradle for building and testing)
- Install Jenkins - I chose macOS (https://www.jenkins.io/download/lts/macos/) - (note: you could also spin up a VM (AWS, Azure, GCP etc) and install Jenkins following the Linux install option as well)
- Sign up for JFrog Platform 14-day trial
2a) When you do this, there is a very intuitive set of wizards that walks you thru setting up your first repository for artifact hosting
and getting JFrog set up to use in your pipeline (for me Jenkins)
...by following the wizard above, a token will created for use when pushing to Artifactory, and the Jfrog cli to run in your pipeline (Jfrog 'jf') - this can be viewed/configured in Jenkins under Manaage Jenkins->Tools under JFrog CLI installations. The doc to follow is here (also listed below) https://github.com/jfrog/jenkins-jfrog-plugin?tab=readme-ov-file#readme
- Ensure you have the docker client / cli on your Jenkins Server
- Docker pipeline plugin installed (in Jenkins Dashboard->Manage Jenkins->Plugins->Available Plugins->Docker Pipeline->select Install)
- JDK17 on your Jenkins server with maven/gradle (I chose maven as you can see, in the Jenkinsfile)
- In Jenkins select "New Item"
- Give the item a name (SpringPetClinicPipeline)
- Select "Pipeline" and "OK"
- On the next page, at the bottom under "Pipeline",
- In the "Definition" field select 'Pipeline from SCM,
- In the "SCM" field, select 'Git'
- In "Repository URL", enter 'https://github.com/hesterch/spring-petclinic',
- In "Branch Specifier" put '*/main'
- and All other settings should be the same (eg Script Path (as Jenkinsfile is in the root, the default is fine).
- Click "Save"
- In your Jenkins Dashboard, see your new pipeline, select it, then click on "Build Now" Watch the pipeline execute in a number of ways "Console Output", "Pipeline Overview", "Pipeline Steps" etc.
By using the JFrog plugins with Jenkins, along with the jf - the 'jf docker scan' entry scans a Docker image for security vulnerabilities with JFrog Xray and you will see that tabled in the console output, and in JFrog under Xray, Scans List
- Take some time to familiarize yourself with the Spring-Petclinic app. Build it, run it. Consider dockerizing/containerizing it.
- If you have multiple JDKs installed (eg 11 and 17), you can specify which JDK to use under Manage Jenkins->Tools. In a non hacky/playground environment, you would have a specific JDK installed for consistency, stability, security etc. For example if the default JDK is 11, the project won't build :(
- Speaking of best practices, in any environments besides a sandbox type of environment, it's best to have different agents for different tasks: for example you would have a build-agent, test-agent and a docker-agent as
agent { label 'docker-agent' }
in your stage block before you run your steps. This is a best practice that would enhance resource optimization, maintainability, iso purposes, scalability, etc. These stages/steps mentioned can be resource intensive. I did not do that here for this project. - I searched, experimented and found solutions as I iterated thru this project, to get the pipeline to build - but this process made me learn a lot more along the way. JFrog has a github page with walkthroughs and samples as well, the best resource: https://github.com/jfrog/jenkins-jfrog-plugin?tab=readme-ov-file#readme
- Feel free to experiment, change syntax there are cli-ish ways to script or method builders (eg docker build... or docker.build)
- Use the Jenkins Snippet Generator as well, it's going to suggest the best practice, most efficient way to scipt your pipeline. This pipeline script ended up being pretty "bash"-y
- You can ru-run a pipeline from a certain stage as long as you haven't changed the Jenkinsfile. But if you modified a Dockerfile, you could re-run the "Build Docker Image" stage (as the build and test stages do taka a while).
- Have fun along the way!!