mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 14:55:50 +00:00
Jenkins continuous integration (CI) pipeline
This commit is contained in:
parent
516722647a
commit
40f4e71222
5 changed files with 494 additions and 147 deletions
12
Dockerfile
Normal file
12
Dockerfile
Normal file
|
@ -0,0 +1,12 @@
|
|||
# base image https://hub.docker.com/layers/library/openjdk/17-jdk-alpine/
|
||||
FROM openjdk:17-jdk-alpine
|
||||
|
||||
ENV JAR_FILE spring-petclinic-3.2.0-SNAPSHOT.jar
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY target/${JAR_FILE} /app/
|
||||
|
||||
# Set the command to run the Spring Boot application
|
||||
# java -jar target/spring-petclinic-3.2.0-SNAPSHOT.jar --server.port=7080
|
||||
CMD java -jar ${JAR_FILE}
|
124
Jenkinsfile
vendored
Normal file
124
Jenkinsfile
vendored
Normal file
|
@ -0,0 +1,124 @@
|
|||
node {
|
||||
projectName="mypetclinic";
|
||||
dockerRegistryOrg="krishnamanchikalapudi"
|
||||
environment {
|
||||
softwareVersion()
|
||||
}
|
||||
stage('Code') {
|
||||
stage('clean') {
|
||||
sh """ #!/bin/bash
|
||||
rm -rf spring-petclinic
|
||||
"""
|
||||
}
|
||||
stage('clone') {
|
||||
git branch: 'main', url: 'https://github.com/krishnamanchikalapudi/spring-petclinic.git'
|
||||
} // stage: clone
|
||||
stage('compile') {
|
||||
sh """ #!/bin/bash
|
||||
mvn clean install -DskipTests=true
|
||||
"""
|
||||
} // stage: compile
|
||||
} // stage: code
|
||||
stage('Tests') {
|
||||
parallel unitTest: {
|
||||
stage ("unitTest") {
|
||||
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
|
||||
}, checkstyle: {
|
||||
stage ("checkStyle") {
|
||||
timeout(time: 2, unit: 'MINUTES') {
|
||||
sh """ #!/bin/bash
|
||||
mvn checkstyle:checkstyle
|
||||
|
||||
echo 'checkstyle report generated in /target/site/checkstyle.html'
|
||||
"""
|
||||
} // timeout
|
||||
} // stage: validate
|
||||
}, codeCoverage: {
|
||||
stage ("codeCoverage") {
|
||||
timeout(time: 2, unit: 'MINUTES') {
|
||||
sh """ #!/bin/bash
|
||||
mvn jacoco:report
|
||||
|
||||
echo 'Jacoco report generated in /target/site/jacoco/index.html'
|
||||
"""
|
||||
} // timeout
|
||||
} // stage: Jacoo
|
||||
} // parallel
|
||||
} // stage: tests
|
||||
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
|
||||
stage('tag') {
|
||||
parallel listContainers: {
|
||||
sh """ #!/bin/bash
|
||||
docker container ls -a
|
||||
"""
|
||||
}, listImages: {
|
||||
sh """ #!/bin/bash
|
||||
docker image ls -a
|
||||
"""
|
||||
}, tagBuildNumb: {
|
||||
sh """ #!/bin/bash
|
||||
docker tag ${projectName}:${env.BUILD_ID} krishnamanchikalapudi/${projectName}:${env.BUILD_ID}
|
||||
"""
|
||||
}, tagLatest: {
|
||||
sh """ #!/bin/bash
|
||||
docker tag ${projectName}:${env.BUILD_ID} krishnamanchikalapudi/${projectName}:latest
|
||||
"""
|
||||
}
|
||||
} // stage: tag
|
||||
stage('publish') {
|
||||
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'
|
||||
|
||||
docker push krishnamanchikalapudi/${projectName}:${env.BUILD_ID}
|
||||
docker push krishnamanchikalapudi/${projectName}:latest
|
||||
|
||||
docker logout
|
||||
echo 'Logut...'
|
||||
"""
|
||||
} // 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}
|
||||
"""
|
||||
}
|
||||
} // stage: clean
|
||||
} // stage: docker
|
||||
}
|
||||
def softwareVersion() {
|
||||
sh """ #!/bin/bash
|
||||
java -version
|
||||
mvn -version
|
||||
docker version
|
||||
echo '\n'
|
||||
"""
|
||||
}
|
70
mypetclinic.sh
Executable file
70
mypetclinic.sh
Executable file
|
@ -0,0 +1,70 @@
|
|||
#!/bin/bash
|
||||
arg=${1}
|
||||
|
||||
DATE_TIME=`date '+%Y-%m-%d %H:%M:%S'`
|
||||
printf -v date '%(%Y-%m-%d %H:%M:%S)T\n'
|
||||
# Contanier details at https://hub.docker.com/orgs/krishnamanchikalapudi/repositories
|
||||
|
||||
export containerName=mypetclinic
|
||||
export orgName=krishnamanchikalapudi
|
||||
export imageName=mypetclinic
|
||||
export hostAddress=127.0.0.1
|
||||
export exposePort=7080
|
||||
export WEB_ADDR="http://${hostAddress}:${exposePort}/"
|
||||
|
||||
current_folder=`pwd`
|
||||
# docker container ls -a | grep petclinic | awk '{print $1}'
|
||||
containerId=`docker container ls -a | grep ${imageName} | awk '{print $1}'`
|
||||
imageId=`docker image ls -a | grep ${containerName} | awk '{print $3}'`
|
||||
|
||||
clean() {
|
||||
printf "\n Cleaning container: ${containerName} and image-id: ${imageId} \n "
|
||||
# docker rmi -f ${imageId}
|
||||
docker image prune -a -f --filter "until=1h"
|
||||
docker container prune -f --filter "until=1h"
|
||||
docker system prune -f --filter "until=1h"
|
||||
}
|
||||
startContainer() {
|
||||
printf "\n -------- Downloading container: ${containerName} -------- \n "
|
||||
docker pull ${orgName}/${imageName}:latest
|
||||
|
||||
# docker run -d --name mypetclinic -p 7080:8080 petclinic:cli
|
||||
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 &
|
||||
|
||||
}
|
||||
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 rm -f $containerName
|
||||
}
|
||||
|
||||
# -z option with $1, if the first argument is NULL. Set to default
|
||||
if [[ -z "$1" ]] ; then # check for null
|
||||
echo "User action is NULL, setting to default RESTART"
|
||||
arg='START'
|
||||
fi
|
||||
# -n string - True if the string length is non-zero.
|
||||
if [[ -n $arg ]] ; then
|
||||
arg_len=${#arg}
|
||||
# uppercase the argument
|
||||
arg=$(echo ${arg} | tr [a-z] [A-Z] | xargs)
|
||||
echo "User Action: ${arg}, and arg length: ${arg_len}"
|
||||
|
||||
if [[ "CLEAN" == "${arg}" ]] ; then # Clean
|
||||
clean
|
||||
elif [[ "START" == "${arg}" ]] ; then # Download & start
|
||||
startContainer
|
||||
elif [[ "START" == "${arg}" ]] ; then # stop
|
||||
stopContainer
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
printf '%(%Y-%m-%d %H:%M:%S)T\n'
|
162
readme-original.md
Normal file
162
readme-original.md
Normal file
|
@ -0,0 +1,162 @@
|
|||
# Spring PetClinic Sample Application [](https://github.com/spring-projects/spring-petclinic/actions/workflows/maven-build.yml)
|
||||
|
||||
[](https://gitpod.io/#https://github.com/spring-projects/spring-petclinic) [](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=7517918)
|
||||
|
||||
## Understanding the Spring Petclinic application with a few diagrams
|
||||
|
||||
[See the presentation here](https://speakerdeck.com/michaelisvy/spring-petclinic-sample-application)
|
||||
|
||||
## Run Petclinic locally
|
||||
|
||||
Spring Petclinic is a [Spring Boot](https://spring.io/guides/gs/spring-boot) application built using [Maven](https://spring.io/guides/gs/maven/) or [Gradle](https://spring.io/guides/gs/gradle/). You can build a jar file and run it from the command line (it should work just as well with Java 17 or newer):
|
||||
|
||||
```bash
|
||||
git clone https://github.com/spring-projects/spring-petclinic.git
|
||||
cd spring-petclinic
|
||||
./mvnw package
|
||||
java -jar target/*.jar
|
||||
```
|
||||
|
||||
You can then access the Petclinic at <http://localhost:8080/>.
|
||||
|
||||
<img width="1042" alt="petclinic-screenshot" src="https://cloud.githubusercontent.com/assets/838318/19727082/2aee6d6c-9b8e-11e6-81fe-e889a5ddfded.png">
|
||||
|
||||
Or you can run it from Maven directly using the Spring Boot Maven plugin. If you do this, it will pick up changes that you make in the project immediately (changes to Java source files require a compile as well - most people use an IDE for this):
|
||||
|
||||
```bash
|
||||
./mvnw spring-boot:run
|
||||
```
|
||||
|
||||
> NOTE: If you prefer to use Gradle, you can build the app using `./gradlew build` and look for the jar file in `build/libs`.
|
||||
|
||||
## Building a Container
|
||||
|
||||
There is no `Dockerfile` in this project. You can build a container image (if you have a docker daemon) using the Spring Boot build plugin:
|
||||
|
||||
```bash
|
||||
./mvnw spring-boot:build-image
|
||||
```
|
||||
|
||||
## In case you find a bug/suggested improvement for Spring Petclinic
|
||||
|
||||
Our issue tracker is available [here](https://github.com/spring-projects/spring-petclinic/issues).
|
||||
|
||||
## Database configuration
|
||||
|
||||
In its default configuration, Petclinic uses an in-memory database (H2) which
|
||||
gets populated at startup with data. The h2 console is exposed at `http://localhost:8080/h2-console`,
|
||||
and it is possible to inspect the content of the database using the `jdbc:h2:mem:<uuid>` URL. The UUID is printed at startup to the console.
|
||||
|
||||
A similar setup is provided for MySQL and PostgreSQL if a persistent database configuration is needed. Note that whenever the database type changes, the app needs to run with a different profile: `spring.profiles.active=mysql` for MySQL or `spring.profiles.active=postgres` for PostgreSQL.
|
||||
|
||||
You can start MySQL or PostgreSQL locally with whatever installer works for your OS or use docker:
|
||||
|
||||
```bash
|
||||
docker run -e MYSQL_USER=petclinic -e MYSQL_PASSWORD=petclinic -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:8.2
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```bash
|
||||
docker run -e POSTGRES_USER=petclinic -e POSTGRES_PASSWORD=petclinic -e POSTGRES_DB=petclinic -p 5432:5432 postgres:16.1
|
||||
```
|
||||
|
||||
Further documentation is provided for [MySQL](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt)
|
||||
and [PostgreSQL](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources/db/postgres/petclinic_db_setup_postgres.txt).
|
||||
|
||||
Instead of vanilla `docker` you can also use the provided `docker-compose.yml` file to start the database containers. Each one has a profile just like the Spring profile:
|
||||
|
||||
```bash
|
||||
docker-compose --profile mysql up
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```bash
|
||||
docker-compose --profile postgres up
|
||||
```
|
||||
|
||||
## Test Applications
|
||||
|
||||
At development time we recommend you use the test applications set up as `main()` methods in `PetClinicIntegrationTests` (using the default H2 database and also adding Spring Boot Devtools), `MySqlTestApplication` and `PostgresIntegrationTests`. These are set up so that you can run the apps in your IDE to get fast feedback and also run the same classes as integration tests against the respective database. The MySql integration tests use Testcontainers to start the database in a Docker container, and the Postgres tests use Docker Compose to do the same thing.
|
||||
|
||||
## Compiling the CSS
|
||||
|
||||
There is a `petclinic.css` in `src/main/resources/static/resources/css`. It was generated from the `petclinic.scss` source, combined with the [Bootstrap](https://getbootstrap.com/) library. If you make changes to the `scss`, or upgrade Bootstrap, you will need to re-compile the CSS resources using the Maven profile "css", i.e. `./mvnw package -P css`. There is no build profile for Gradle to compile the CSS.
|
||||
|
||||
## Working with Petclinic in your IDE
|
||||
|
||||
### Prerequisites
|
||||
|
||||
The following items should be installed in your system:
|
||||
|
||||
- Java 17 or newer (full JDK, not a JRE)
|
||||
- [Git command line tool](https://help.github.com/articles/set-up-git)
|
||||
- Your preferred IDE
|
||||
- Eclipse with the m2e plugin. Note: when m2e is available, there is an m2 icon in `Help -> About` dialog. If m2e is
|
||||
not there, follow the install process [here](https://www.eclipse.org/m2e/)
|
||||
- [Spring Tools Suite](https://spring.io/tools) (STS)
|
||||
- [IntelliJ IDEA](https://www.jetbrains.com/idea/)
|
||||
- [VS Code](https://code.visualstudio.com)
|
||||
|
||||
### Steps
|
||||
|
||||
1. On the command line run:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/spring-projects/spring-petclinic.git
|
||||
```
|
||||
|
||||
1. Inside Eclipse or STS:
|
||||
|
||||
Open the project via `File -> Import -> Maven -> Existing Maven project`, then select the root directory of the cloned repo.
|
||||
|
||||
Then either build on the command line `./mvnw generate-resources` or use the Eclipse launcher (right-click on project and `Run As -> Maven install`) to generate the CSS. Run the application's main method by right-clicking on it and choosing `Run As -> Java Application`.
|
||||
|
||||
1. Inside IntelliJ IDEA:
|
||||
|
||||
In the main menu, choose `File -> Open` and select the Petclinic [pom.xml](pom.xml). Click on the `Open` button.
|
||||
|
||||
- CSS files are generated from the Maven build. You can build them on the command line `./mvnw generate-resources` or right-click on the `spring-petclinic` project then `Maven -> Generates sources and Update Folders`.
|
||||
|
||||
- A run configuration named `PetClinicApplication` should have been created for you if you're using a recent Ultimate version. Otherwise, run the application by right-clicking on the `PetClinicApplication` main class and choosing `Run 'PetClinicApplication'`.
|
||||
|
||||
1. Navigate to the Petclinic
|
||||
|
||||
Visit [http://localhost:8080](http://localhost:8080) in your browser.
|
||||
|
||||
## Looking for something in particular?
|
||||
|
||||
|Spring Boot Configuration | Class or Java property files |
|
||||
|--------------------------|---|
|
||||
|The Main Class | [PetClinicApplication](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java) |
|
||||
|Properties Files | [application.properties](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources) |
|
||||
|Caching | [CacheConfiguration](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java) |
|
||||
|
||||
## Interesting Spring Petclinic branches and forks
|
||||
|
||||
The Spring Petclinic "main" branch in the [spring-projects](https://github.com/spring-projects/spring-petclinic)
|
||||
GitHub org is the "canonical" implementation based on Spring Boot and Thymeleaf. There are
|
||||
[quite a few forks](https://spring-petclinic.github.io/docs/forks.html) in the GitHub org
|
||||
[spring-petclinic](https://github.com/spring-petclinic). If you are interested in using a different technology stack to implement the Pet Clinic, please join the community there.
|
||||
|
||||
## Interaction with other open-source projects
|
||||
|
||||
One of the best parts about working on the Spring Petclinic application is that we have the opportunity to work in direct contact with many Open Source projects. We found bugs/suggested improvements on various topics such as Spring, Spring Data, Bean Validation and even Eclipse! In many cases, they've been fixed/implemented in just a few days.
|
||||
Here is a list of them:
|
||||
|
||||
| Name | Issue |
|
||||
|------|-------|
|
||||
| Spring JDBC: simplify usage of NamedParameterJdbcTemplate | [SPR-10256](https://jira.springsource.org/browse/SPR-10256) and [SPR-10257](https://jira.springsource.org/browse/SPR-10257) |
|
||||
| Bean Validation / Hibernate Validator: simplify Maven dependencies and backward compatibility |[HV-790](https://hibernate.atlassian.net/browse/HV-790) and [HV-792](https://hibernate.atlassian.net/browse/HV-792) |
|
||||
| Spring Data: provide more flexibility when working with JPQL queries | [DATAJPA-292](https://jira.springsource.org/browse/DATAJPA-292) |
|
||||
|
||||
## Contributing
|
||||
|
||||
The [issue tracker](https://github.com/spring-projects/spring-petclinic/issues) is the preferred channel for bug reports, feature requests and submitting pull requests.
|
||||
|
||||
For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at <https://editorconfig.org>. If you have not previously done so, please fill out and submit the [Contributor License Agreement](https://cla.pivotal.io/sign/spring).
|
||||
|
||||
## License
|
||||
|
||||
The Spring PetClinic sample application is released under version 2.0 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0).
|
273
readme.md
273
readme.md
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue