Code Monkey home page Code Monkey logo

spring-petclinic's Introduction

Scanned by Frogbot

Jenkins pipeline for Spring Petclinic Application

Prerequisites

  1. A Jenkins Controller
  2. Recommended plugins, including
  • Git plugin
  • Pipeline Maven Integration plugin
  • JUnit plugin
  1. An agent/node with the following tools installed (agent label: maven-agent)
  • JDK 17
  • Maven
  • Docker

Tested on Jenkins 2.401, with Maven 3.6.3 and Docker 24.0.5

Run the pipeline

Create a simple pipeline, with:

  • Definition: Pipeline script from SCM
  • SCM: Git
  • Repository URL: https://github.com/fgibelin/spring-petclinic
  • Branch to build: */main

The first stage of the pipeline will clone the repository, then use Maven to compile, run the unit tests, and build the jar file in `target/ folder.

The command used is mvn clean verify (recap on Maven Lifecycle)

If you wish to use Artifactory plugin instead, you can replace the first stage with the following block (please replace with the ID you have set in the Manage Jenkins -> System -> Artifactory).

You will need the following Maven repositories setup in that example:

        stage('Build and deploy to Artifactory') {
            steps {
                script {
                    git(url:'https://github.com/fgibelin/spring-petclinic', branch: 'main')
                    pom = readMavenPom file: "pom.xml";
                    filesByGlob = findFiles(glob: "target/*.${pom.packaging}");
                    artifactPath = filesByGlob[0].path;
                    artifactExists = fileExists artifactPath;
                    if (artifactExists) {
                        env.petclinicVersion = pom.version
                        rtMavenResolver (
                            id: 'maven-resolver',
                            serverId: '<artifactory-server-id>',
                            releaseRepo: 'maven',
                            snapshotRepo: 'maven',
                        )
                        rtMavenDeployer (
                            id: 'maven-deployer',
                            serverId: '<artifactory-server-id>',
                            releaseRepo: 'maven-local-releases',
                            snapshotRepo: 'maven-local-snapshots',
                        )
                        rtMavenRun (
                            useWrapper: true,
                            pom: 'pom.xml',
                            goals: 'verify',
                            resolverId: 'maven-resolver',
                            deployerId: 'maven-deployer',
                            buildName: '${env.JOB_NAME}',
                            buildNumber: '${currentBuild.number}',
                            deployArtifacts: true,
                            project: 'spring-petclinic'
                        )
                    }
                }
            }
        }

The second stage will build the Docker image from the Dockerfile with the built jar file, using:

docker build -t spring-petclinic:<tag> --build-arg petclinicArtifacto=<path to spring petclinic jar file> .

Run Docker image

You can run the built Docker image using the following command:

docker run -p 8080:8080 -d --name spring-petclinic spring-petclinic:3.1.0-SNAPSHOT

Or replace the tag 3.1.0-SNAPSHOT with the version from the application you built. This will run the container in a detached mode, exposing port 8080 You can then access Petclinic application on http://localhost:8080 You can follow the logs using docker logs spring-petclinic -f

Stop application

docker stop spring-petclinic
docker rm spring-petclinic

Pull application from a public registry

The built Docker image is available in a public JFrog Container Registry. This registry is insecured, so please add:

{
  "insecure-registries" : ["35.195.23.92"]
}

in your /etc/docker/daemon.json, and restart your docker daemon.

You can then pull the image using:

docker pull 35.195.23.92/docker-local/spring-petclinic:3.1.0-SNAPSHOT
docker tag 35.195.23.92/docker-local/spring-petclinic:3.1.0-SNAPSHOT spring-petclinic:3.1.0-SNAPSHOT
docker rmi 35.195.23.92/docker-local/spring-petclinic:3.1.0-SNAPSHOT

Then run it:

docker run -p 8080:8080 -d --name spring-petclinic spring-petclinic:3.1.0-SNAPSHOT

spring-petclinic's People

Contributors

arey avatar bdemers avatar bijomutta avatar boykoalex avatar cruftex avatar crydust avatar cyrille-leclerc avatar doggy8088 avatar dsyer avatar eskibear avatar fgibelin avatar freemansoft avatar gordonad avatar jdubois avatar liouxiao avatar martinlippert avatar nroi avatar odrotbohm avatar oscr avatar patbaumgartner avatar rstoyanchev avatar sdeleuze avatar snicoll avatar spring-operator avatar tduchateau avatar trepel avatar trisberg avatar verydapeng avatar win777 avatar xerx593 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.