Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fugerit-org/springboot-photobook
Sample photobook spring boot app
https://github.com/fugerit-org/springboot-photobook
Last synced: 13 days ago
JSON representation
Sample photobook spring boot app
- Host: GitHub
- URL: https://github.com/fugerit-org/springboot-photobook
- Owner: fugerit-org
- License: apache-2.0
- Created: 2023-05-21T12:49:01.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-08T14:25:25.000Z (3 months ago)
- Last Synced: 2024-11-06T01:10:12.279Z (2 months ago)
- Language: Java
- Size: 709 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Springboot Photobook Demo App
[![Keep a Changelog v1.1.0 badge](https://img.shields.io/badge/changelog-Keep%20a%20Changelog%20v1.1.0-%23E05735)](https://github.com/fugerit-org/springboot-photobook/blob/master/CHANGELOG.md)
[![license](https://img.shields.io/badge/License-Apache%20License%202.0-teal.svg)](https://opensource.org/licenses/Apache-2.0)
[![code of conduct](https://img.shields.io/badge/conduct-Contributor%20Covenant-purple.svg)](https://github.com/fugerit-org/fj-universe/blob/main/CODE_OF_CONDUCT.md)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=fugerit-org_springboot-photobook&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=fugerit-org_springboot-photobook)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=fugerit-org_springboot-photobook&metric=coverage)](https://sonarcloud.io/summary/new_code?id=fugerit-org_springboot-photobook)
[![Docker images](https://img.shields.io/badge/dockerhub-images-important.svg?logo=Docker)](https://hub.docker.com/repository/docker/fugeritorg/springboot-photobook/general)## Introduction
Recently I followed some [Mongo DB courses](https://learn.mongodb.com/) and attended the [Spring I/O 2023](https://2023.springio.net/).
So I decided to practice a bit. This project is the result.
Currently is just a simple POC integration of Mongo DB and Spring Boot.There is a live version at the link [https://springio23.fugerit.org/photobook-demo/home/index.html](https://springio23.fugerit.org/photobook-demo/home/index.html)
## Prerequisites
| software | docker compose | local build and run |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------|---------------------|
| [![Java runtime version](https://img.shields.io/badge/run%20on-java%2021+-%23113366.svg?style=for-the-badge&logo=openjdk&logoColor=white)](https://universe.fugerit.org/src/docs/versions/java21.html) | no | yes |
| [![Java build version](https://img.shields.io/badge/build%20on-GraalVM%2021+-%23ED8B00.svg?style=for-the-badge&logo=openjdk&logoColor=white)](https://universe.fugerit.org/src/docs/versions/gvm21.html) | no | yes |
| [![Apache Maven](https://img.shields.io/badge/Apache%20Maven-3.9.0+-C71A36?style=for-the-badge&logo=Apache%20Maven&logoColor=white)](https://universe.fugerit.org/src/docs/versions/maven3_9.html) | no | yes |
| [![Node JS](https://img.shields.io/badge/Node%20JS-20+-1AC736?style=for-the-badge&logo=node.js&logoColor=white)](https://universe.fugerit.org/src/docs/versions/node.html) | no | yes |
| [![Docker](https://img.shields.io/badge/docker-26+-1266E7?style=for-the-badge&logo=docker&logoColor=white)](https://universe.fugerit.org/src/docs/versions/docker.html) | yes | no |## Quickstart
### Start via docker compose
```shell
docker-compose -f src/main/docker/docker-compose.yml up -d
```access home page
### Start in dev mode
1. Create mongo db instance with db initialization (script src/test/resources/mongo-db/mongo-init.js) :
```shell
docker run --rm -p 27017:27017 --name MONGO8 -v `pwd`/src/test/resources/mongo-db/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js mongo:8.0.0-rc7
```This will start a mongo db linked on the default port and with the default username/password (root/example).
2. Start the application in dev mode
The back end
```shell
mvn spring-boot:run
```And front end
```shell
cd src/main/react
npm install
npm run start
```3. Access home page
## project environment variables
In case you want a custom mongo db connection :
| key | dedault |
|-------------|------------------------------------------|
| MONGODB_URL | mongodb://localhost:27017/photobook_demo |## container environment variables
Other custom environment variables :
| key | dedault | description |
|------------------|---------|---------------------------------------------|
| JAVA_OPTS_APPEND | | append java options (for instance '-Xmx1g') |## Spring Boot package
It is possible to compile the application to a single jar package :
```shell
mvn package -Pbuildreact
```And then run
```shell
java -jar ./target/springboot-photobook-*.jar
```## Native image compilation
The code has been set for native compilation with [GraalVM](https://www.graalvm.org/) (tested with GraalVM 22.3 CE).
It is possible to compile :
```shell
mvn -Pbuildreact,native clean native:compile
```And then run
```shell
./target/springboot-photobook
```Refer to [Spring Boot Documentation](https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html) for more informations.
## Docker image
### docker container (jvm)
Build spring application (jar)
```shell
mvn package -P buildreact
```Build container openjdk
```shell
docker build -t springboot-photobook-jvm -f src/main/docker/Dockerfile.jvm .
```Running the container :
```shell
docker run -it -p 8080:8080 --name springboot-photobook-jvm springboot-photobook-jvm
```### docker container (native)
Building the native image :
```shell
mvn -Pbuildreact,native clean native:compile
```Building the container image :
```shell
docker build -t springboot-photobook-native -f src/main/docker/Dockerfile.native .
```Running the container :
```shell
docker run -it -p 8080:8080 --name springboot-photobook-native springboot-photobook-native
```## Native optimization : PGO
This section is based on .
One of the most powerful performance optimizations in Native Image is profile-guided optimizations (PGO).
1. Build an instrumented image:
```shell
mvn -Pnative,instrumented native:compile
```2. Run the app and apply relevant workload:
```shell
./target/springboot-photobook-instrumented
``````shell
hey -n=30000 http://localhost:8080/photobook-demo/api/photobook/view/list
``````shell
hey -n=30000 http://localhost:8080/photobook-demo/api/photobook/view/images/springio23/language/it/current_page/1/page_size/5
```after you shut down the app, you'll see an `iprof` file in your working directory.
3. Build an app with profiles (they are being picked up via `--pgo=${project.basedir}/default.iprof`):
```shell
mvn -Pnative,optimized native:compile
```## Benchmark scripts
Prerequisites :
- running mongo db
- `hey` installed
- `psrecord` installedAt the end of a run, an image will be plotted in the `target` folder.
### 1. Benchmark JIT
```shell
mvn clean package
``````shell
./src/main/script/bench-jit.sh
```### 2. Benchmark native
Follow steps in 'Native optimization : PGO' section
```shell
./src/main/script/bench-native.sh
```### 3. Benchmark result
Sample result of JIT benchmark run :
![JIT Benchmark Result](src/main/docs/images/bench-result-jit-20240617.png)
Sample result of native (AOT) benchmark run :
![Native Benchmark Result](src/main/docs/images/bench-result-native-20240617.png)
## application stack
| Layer | 2023 version | 2024 version |
|-------------------|------------------|------------------|
| Persistence | MongoDB 6 | MongoDB 8 |
| Java version | GraalVM 17 | GraalVM 21 |
| API REST | SpringBoot 3.0.0 | SpringBoot 3.3.0 |
| Node JS | Node 18 | Node 20 |
| Front end package | React scripts | Vite |
| Front end UI | React 18.2 | React 18.3 |## Deploy on Google App Engine
Prerequisites :
* google cloud account
* GCloud CLI[Simple app.yaml for AOT](src/main/appengine/app-aot.yaml) and
[Simple app.yaml for JIT](src/main/appengine/app-jit.yaml)Customize the app.yaml and run gcloud
```shell
gcloud micronaut-photobook-*runner.jar --appyaml=src/main/appengine/app-jit.yaml
```For JIT version or
```shell
gcloud micronaut-photobook --appyaml=src/main/appengine/app-aot.yaml
```For AOT version
Further reference :
*
## Deploy on KNativePrerequisites :
* container environment (docker / podman)
* Kubernates (for instance minikube)
* KnativeAfter setting up Knative,
Customize the [micronaut-photobook-jit.yaml](src/main/knative/micronaut-photobook-jit.yaml) or
[micronaut-photobook-aot.yaml](src/main/knative/micronaut-photobook-aot.yaml) service deployment.And run
```shell
kubectl apply -f micronaut-photobook-jit.yaml
```For JIT version or
```shell
kubectl apply -f micronaut-photobook-aot.yaml
```For AOT version