Skip to content

About

A sample Spring-based application

Resources

Stars

1 star

Watchers

0 watching

Forks

 
 

Repository files navigation

Spring PetClinic Capstone Application

This repository extends the official Spring PetClinic application with container images, Helm deployments, and GCP delivery workflows.

Capstone delivery (Helm / GKE)

Production path for this fork:

Piece Location
Dockerfile Dockerfile at repo root (Temurin 17 JRE, non-root petclinic user)
Helm chart chart/petclinic
Env values values-dev.yaml / values-prod.yaml
PR / release CI .github/workflows/pr-release.yml, .github/workflows/main-release.yml
Deploy to dev .github/workflows/deploy-dev.yml (push to main)
Manual deploy .github/workflows/manual-deploy.yml (prod, or redeploy a chosen tag)

App resources deploy to the petclinic namespace (not default). That namespace must match the Workload Identity binding in the infra repo (petclinic/petclinic → GCP app SA).

CI runners (ARC + BuildKit)

App workflows run on Actions Runner Controller scale sets in the env GKE cluster (petclinic-arc-dev / petclinic-arc-prod), not on long-lived GCE VMs.

Workflow runs-on Registry
PR gatekeeper petclinic-arc-dev dev Artifact Registry only (no deploy)
Deploy to dev petclinic-arc-dev dev registry, then Helm to the shared petclinic namespace
Main release petclinic-arc-prod prod Artifact Registry only (no deploy)
Manual deploy petclinic-arc-${{ environment }} reads the matching env registry

Trust model: runner pods use GKE Workload Identity (arc-runners K8s SA → github-app-runner-sa-{env}). There is no GitHub→GCP OIDC in these workflows (id-token: write is intentionally absent). Images are built with rootless BuildKit (no Docker socket / DinD); Trivy scans the image tar before crane push.

GitHub Actions variables

Project identifiers are not secrets. Dev and prod are different GCP projects, so set GCP_PROJECT_ID and GCP_REGION on the GitHub Environments named dev and prod (Settings → Environments), not as a single repository variable.

Variable dev Environment prod Environment
GCP_PROJECT_ID Dev GCP project ID Prod GCP project ID
GCP_REGION europe-west1 europe-west1

PR Gatekeeper and Deploy to dev use Environment dev. Main release uses prod. Manual deploy uses the Environment you select. Workflows fail fast if either variable is empty on that Environment. Keep authenticators (tokens, PEMs, passwords) as secrets — not these IDs.

A merge to main is what updates the shared dev cluster (build, scan, push, Helm). Pull requests only prove the change. Production stays a manual promote of a SemVer tag.

Committed values-dev.yaml / values-prod.yaml hold only env-specific non-project settings (replicas, ingress host, environment label, K8s SA name). Project-bound Helm fields are injected at deploy time from the variables above (deterministic names matching the infra modules):

  • image.repository → {REGION}-docker.pkg.dev/{PROJECT_ID}/petclinic-repo-{env}/petclinic
  • googleProjectId → $GCP_PROJECT_ID
  • serviceAccount.gcpEmail → petclinic-sa-{env}@$GCP_PROJECT_ID.iam.gserviceaccount.com
  • cloudSql.instanceConnectionName → $GCP_PROJECT_ID:$GCP_REGION:petclinic-db-{env}

deploy-dev.yml and manual-deploy.yml pass those via --set. Chart defaults leave those four fields empty.

# Example (credentials and cluster already configured)
PROJECT_ID=<GCP_PROJECT_ID>
REGION=<GCP_REGION>
ENV=dev
helm upgrade --install petclinic ./chart/petclinic \
  --namespace petclinic \
  --create-namespace \
  --values ./chart/petclinic/values-${ENV}.yaml \
  --set image.repository=${REGION}-docker.pkg.dev/${PROJECT_ID}/petclinic-repo-${ENV}/petclinic \
  --set image.tag=<tag> \
  --set googleProjectId=${PROJECT_ID} \
  --set serviceAccount.gcpEmail=petclinic-sa-${ENV}@${PROJECT_ID}.iam.gserviceaccount.com \
  --set cloudSql.instanceConnectionName=${PROJECT_ID}:${REGION}:petclinic-db-${ENV} \
  --wait

External access is via the ingress-nginx LoadBalancer (source-restricted in infra), not the app ClusterIP Service. Actuator is limited to health, info, and prometheus; probes use /actuator/health/liveness and /actuator/health/readiness.

Monitoring (Prometheus / Grafana)

Primary cluster path: the chart’s ServiceMonitor scrapes Service port http-web → /actuator/prometheus (Micrometer). Prometheus job label is petclinic (jobLabel: app.kubernetes.io/name). Alerts live in PrometheusRule (e.g. PetclinicInstanceDown); the Micrometer JVM dashboard ConfigMap is labeled grafana_dashboard: "1" for the Grafana sidecar.

Non-primary: the image still runs the JMX Prometheus Java agent on container port 9093 for local/debug use. That port is not on the Kubernetes Service and is not scraped in-cluster.

Infra stack details (retention, Grafana password, demo checklist): capstone-project-infra docs/monitoring.md.

Legacy manifests under k8s/ are local demos only — do not apply them to the GKE clusters.

Infrastructure (GKE, Cloud SQL, WI, Ingress, monitoring) lives in capstone-project-infra.


Understanding the Spring Petclinic application with a few diagrams

See the presentation here: Spring Petclinic Sample Application (legacy slides)

Note: These slides refer to a legacy, pre–Spring Boot version of Petclinic and may not reflect the current Spring Boot–based implementation. For up-to-date information, please refer to this repository and its documentation.

Run Petclinic locally

Spring Petclinic is a Spring Boot application built using Maven or Gradle. Java 17 or later is required for the build, and the application can run with Java 17 or newer.

You first need to clone the project locally:

git clone https://github.com/njakov/capstone-project-app.git
cd capstone-project-app

If you are using Maven, you can start the application on the command-line as follows:

./mvnw spring-boot:run

With Gradle, the command is as follows:

./gradlew bootRun

You can then access the Petclinic at http://localhost:8080/.

petclinic-screenshot

You can, of course, run Petclinic in your favorite IDE. See below for more details.

Building a Container

This fork ships a root Dockerfile used by the CI pipelines (JAR + checksum-pinned JMX agent). Build after assembling the JAR:

./mvnw -DskipTests package
# CI stages spring-petclinic.jar + jmx.jar before the image build
docker build -t petclinic:local .

CI on ARC uses rootless BuildKit instead of docker build (same Dockerfile).

You can also build a container image with the Spring Boot build plugin (if you have a docker daemon):

./mvnw spring-boot:build-image

Running the Container Image

docker images | grep petclinic
docker run -p 8080:8080 docker.io/library/spring-petclinic:latest

In case you find a bug/suggested improvement for Spring Petclinic

Our issue tracker is available here.

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. See the Spring Boot documentation for more detail on how to set the active profile.

You can start MySQL or PostgreSQL locally with whatever installer works for your OS or use docker:

docker run -e MYSQL_USER=petclinic -e MYSQL_PASSWORD=petclinic -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:9.7

or

docker run -e POSTGRES_USER=petclinic -e POSTGRES_PASSWORD=petclinic -e POSTGRES_DB=petclinic -p 5432:5432 postgres:18.4

Further documentation is provided for MySQL and PostgreSQL.

Instead of vanilla docker you can also use the provided docker-compose.yml file to start the database containers. Each one has a service named after the Spring profile:

docker compose up mysql

or

docker compose up postgres

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 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:

Steps

  1. On the command line run:

    git clone https://github.com/njakov/capstone-project-app.git
  2. 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.

  3. Inside IntelliJ IDEA:

    In the main menu, choose File -> Open and select the Petclinic 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'.

  4. Navigate to the Petclinic

    Visit http://localhost:8080 in your browser.

Looking for something in particular?

Spring Boot Configuration Class or Java property files
The Main Class PetClinicApplication
Properties Files application.properties
Caching CacheConfiguration

Interesting Spring Petclinic branches and forks

The Spring Petclinic "main" branch in the spring-projects GitHub org is the "canonical" implementation based on Spring Boot and Thymeleaf. There are quite a few forks in the GitHub org 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 and SPR-10257
Bean Validation / Hibernate Validator: simplify Maven dependencies and backward compatibility HV-790 and HV-792
Spring Data: provide more flexibility when working with JPQL queries DATAJPA-292

Contributing

The issue tracker is the preferred channel for bug reports, feature requests and submitting pull requests.

For pull requests, editor preferences are available in the editor config for easy use in common text editors. Read more and download plugins at https://editorconfig.org. All commits must include a Signed-off-by trailer at the end of each commit message to indicate that the contributor agrees to the Developer Certificate of Origin. For additional details, please refer to the blog post Hello DCO, Goodbye CLA: Simplifying Contributions to Spring.

License

The Spring PetClinic sample application is released under version 2.0 of the Apache License.

About

A sample Spring-based application

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages