From da1ca5f3f4c6f26e9c67de54fe79ceedf3fd342b Mon Sep 17 00:00:00 2001 From: Krishna Date: Fri, 8 Mar 2024 09:07:34 -0800 Subject: [PATCH] mypetclinic.sh stop fix --- Jenkinsfile | 36 +++++++++++++++--------------------- mypetclinic.sh | 13 ++++++++----- readme.md | 8 +++++++- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a332e17ac..0c6f2446e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -25,6 +25,8 @@ node { timeout(time: 10, unit: 'MINUTES') { sh """ #!/bin/bash mvn test surefire-report:report + + echo 'surefire report generated in /target/site/surefire-report.html' """ } // timeout } // stage: unittest @@ -32,7 +34,9 @@ node { stage ("checkStyle") { timeout(time: 2, unit: 'MINUTES') { sh """ #!/bin/bash - mvn validate + mvn checkstyle:checkstyle + + echo 'checkstyle report generated in /target/site/checkstyle.html' """ } // timeout } // stage: validate @@ -41,6 +45,8 @@ node { timeout(time: 2, unit: 'MINUTES') { sh """ #!/bin/bash mvn jacoco:report + + echo 'Jacoco report generated in /target/site/jacoco/index.html' """ } // timeout } // stage: Jacoo @@ -49,8 +55,6 @@ node { stage ("Docker") { stage('build') { sh """ #!/bin/bash - # docker login - # docker image build -f Dockerfile -t petclinic:cli . docker image build -f Dockerfile -t ${projectName}:${env.BUILD_ID} . """ } // stage: build @@ -77,7 +81,7 @@ node { withCredentials([usernamePassword(credentialsId: 'dockerhub', passwordVariable: 'DOCKER_REGISTRY_PWD', usernameVariable: 'DOCKER_REGISTRY_USER')]) { sh """ #!/bin/bash docker login -u $DOCKER_REGISTRY_USER -p $DOCKER_REGISTRY_PWD - echo 'Login success' + echo 'Login success...' docker push krishnamanchikalapudi/${projectName}:${env.BUILD_ID} docker push krishnamanchikalapudi/${projectName}:latest @@ -88,23 +92,13 @@ node { } // withCredentials: dockerhub } // stage: push stage('clean') { - parallel pruneImage: { - sh """ #!/bin/bash - docker image prune -f --filter until=1h - """ - }, pruneContainer: { - sh """ #!/bin/bash - docker container prune -f --filter until=1h - """ - }, pruneSystem: { - sh """ #!/bin/bash - docker system prune -f --filter until=1h - """ - }, rmiImages: { - sh """ #!/bin/bash - docker rmi -f ${projectName} - """ - } + sh """ #!/bin/bash + docker image ls + echo 'Deleting local images...' + docker rmi -f $(docker images -aq) + + docker image ls + """ } // stage: clean } // stage: docker } diff --git a/mypetclinic.sh b/mypetclinic.sh index 65033ff53..ea60a5c52 100755 --- a/mypetclinic.sh +++ b/mypetclinic.sh @@ -23,6 +23,7 @@ clean() { docker image prune -a -f --filter "until=1h" docker container prune -f --filter "until=1h" docker system prune -f --filter "until=1h" + docker rmi -f $(docker images -aq) } startContainer() { printf "\n -------- Downloading container: ${containerName} -------- \n " @@ -32,16 +33,18 @@ startContainer() { docker run -d --name ${containerName} -p ${exposePort}:8080 ${orgName}/${imageName}:latest sleep 5 - open -a 'Google Chrome' $WEB_ADDR - - sleep 2 - docker logs -f $containerId & + docker logs -f ${containerName} & + # xdg-open $WEB_ADDR # ubuntu + # open 'Google Chrome' $WEB_ADDR # mac + printf "\n ---------------------------------------------------------------- " + printf "\n ---------- In Web Browser, open http://localhost:7080 ---------- " + printf "\n ---------------------------------------------------------------- " } stopContainer() { printf "\n -------- Stop container: ${containerName} -------- \n " # docker container stop ${docker container ls -a | grep postgres | awk '{print $1}'} - docker container stop $containerId -t 0 + docker stop $containerName -t 0 docker rm -f $containerName } diff --git a/readme.md b/readme.md index c6c59df74..9e392671a 100644 --- a/readme.md +++ b/readme.md @@ -80,7 +80,7 @@ docker rmi -f mypetclinic - The container images from the Jenkin pipeline was uploaded to the [Docker repository](https://hub.docker.com/orgs/krishnamanchikalapudi/repositories) ## Docker image execution -A few options are available to execute the Docker image [krishnamanchikalapudi/mypetclinic:latest](https://hub.docker.com/repository/docker/krishnamanchikalapudi/mypetclinic) +A few options are available to execute the Docker image [krishnamanchikalapudi/mypetclinic:latest](https://hub.docker.com/r/krishnamanchikalapudi/mypetclinic/tags) ### Option 1 - Prerequisite - Device operating system: Mac or Linux @@ -135,3 +135,9 @@ sudo setfacl -R -m user:jenkins:rwx /var/run/docker.sock ## License The Spring PetClinic sample application is released under version 2.0 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0). + + +## References +- [Dockerfile reference](https://docs.docker.com/reference/dockerfile/) +- [Docker CLI reference](https://docs.docker.com/reference/cli/docker/) +- [Jenkins Docs](https://www.jenkins.io/doc/) \ No newline at end of file