mypetclinic.sh stop fix

This commit is contained in:
Krishna 2024-03-08 09:07:34 -08:00
parent 1520aa2128
commit da1ca5f3f4
3 changed files with 30 additions and 27 deletions

36
Jenkinsfile vendored
View file

@ -25,6 +25,8 @@ node {
timeout(time: 10, unit: 'MINUTES') { timeout(time: 10, unit: 'MINUTES') {
sh """ #!/bin/bash sh """ #!/bin/bash
mvn test surefire-report:report mvn test surefire-report:report
echo 'surefire report generated in /target/site/surefire-report.html'
""" """
} // timeout } // timeout
} // stage: unittest } // stage: unittest
@ -32,7 +34,9 @@ node {
stage ("checkStyle") { stage ("checkStyle") {
timeout(time: 2, unit: 'MINUTES') { timeout(time: 2, unit: 'MINUTES') {
sh """ #!/bin/bash sh """ #!/bin/bash
mvn validate mvn checkstyle:checkstyle
echo 'checkstyle report generated in /target/site/checkstyle.html'
""" """
} // timeout } // timeout
} // stage: validate } // stage: validate
@ -41,6 +45,8 @@ node {
timeout(time: 2, unit: 'MINUTES') { timeout(time: 2, unit: 'MINUTES') {
sh """ #!/bin/bash sh """ #!/bin/bash
mvn jacoco:report mvn jacoco:report
echo 'Jacoco report generated in /target/site/jacoco/index.html'
""" """
} // timeout } // timeout
} // stage: Jacoo } // stage: Jacoo
@ -49,8 +55,6 @@ node {
stage ("Docker") { stage ("Docker") {
stage('build') { stage('build') {
sh """ #!/bin/bash sh """ #!/bin/bash
# docker login
# docker image build -f Dockerfile -t petclinic:cli .
docker image build -f Dockerfile -t ${projectName}:${env.BUILD_ID} . docker image build -f Dockerfile -t ${projectName}:${env.BUILD_ID} .
""" """
} // stage: build } // stage: build
@ -77,7 +81,7 @@ node {
withCredentials([usernamePassword(credentialsId: 'dockerhub', passwordVariable: 'DOCKER_REGISTRY_PWD', usernameVariable: 'DOCKER_REGISTRY_USER')]) { withCredentials([usernamePassword(credentialsId: 'dockerhub', passwordVariable: 'DOCKER_REGISTRY_PWD', usernameVariable: 'DOCKER_REGISTRY_USER')]) {
sh """ #!/bin/bash sh """ #!/bin/bash
docker login -u $DOCKER_REGISTRY_USER -p $DOCKER_REGISTRY_PWD 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}:${env.BUILD_ID}
docker push krishnamanchikalapudi/${projectName}:latest docker push krishnamanchikalapudi/${projectName}:latest
@ -88,23 +92,13 @@ node {
} // withCredentials: dockerhub } // withCredentials: dockerhub
} // stage: push } // stage: push
stage('clean') { stage('clean') {
parallel pruneImage: { sh """ #!/bin/bash
sh """ #!/bin/bash docker image ls
docker image prune -f --filter until=1h echo 'Deleting local images...'
""" docker rmi -f $(docker images -aq)
}, pruneContainer: {
sh """ #!/bin/bash docker image ls
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}
"""
}
} // stage: clean } // stage: clean
} // stage: docker } // stage: docker
} }

View file

@ -23,6 +23,7 @@ clean() {
docker image prune -a -f --filter "until=1h" docker image prune -a -f --filter "until=1h"
docker container prune -f --filter "until=1h" docker container prune -f --filter "until=1h"
docker system prune -f --filter "until=1h" docker system prune -f --filter "until=1h"
docker rmi -f $(docker images -aq)
} }
startContainer() { startContainer() {
printf "\n -------- Downloading container: ${containerName} -------- \n " printf "\n -------- Downloading container: ${containerName} -------- \n "
@ -32,16 +33,18 @@ startContainer() {
docker run -d --name ${containerName} -p ${exposePort}:8080 ${orgName}/${imageName}:latest docker run -d --name ${containerName} -p ${exposePort}:8080 ${orgName}/${imageName}:latest
sleep 5 sleep 5
open -a 'Google Chrome' $WEB_ADDR docker logs -f ${containerName} &
sleep 2
docker logs -f $containerId &
# 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() { stopContainer() {
printf "\n -------- Stop container: ${containerName} -------- \n " printf "\n -------- Stop container: ${containerName} -------- \n "
# docker container stop ${docker container ls -a | grep postgres | awk '{print $1}'} # 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 docker rm -f $containerName
} }

View file

@ -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) - The container images from the Jenkin pipeline was uploaded to the [Docker repository](https://hub.docker.com/orgs/krishnamanchikalapudi/repositories)
## Docker image execution ## 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 ### Option 1
- Prerequisite - Prerequisite
- Device operating system: Mac or Linux - Device operating system: Mac or Linux
@ -135,3 +135,9 @@ sudo setfacl -R -m user:jenkins:rwx /var/run/docker.sock
## License ## License
The Spring PetClinic sample application is released under version 2.0 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0). 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/)