Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : reactive cache using redis #1381

Merged
merged 4 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions r2dbc/boot-reactive-cache/.github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CI Build

on:
push:
branches:
- "**"

jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
distribution: [ 'temurin' ]
java: [ '17' ]
steps:
- uses: actions/checkout@v4

- name: Setup Java ${{ matrix.java }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: ${{ matrix.distribution }}
cache: 'maven'

- name: Grant execute permission for mvnw
run: chmod +x mvnw

- name: Build with Maven
run: ./mvnw clean verify

- if: ${{ github.ref == 'refs/heads/main' }}
name: SonarQube Scan
run: ./mvnw compile sonar:sonar -Dsonar.login=${{ secrets.SONAR_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- if: ${{ github.ref == 'refs/heads/main' }}
name: Build and Publish Docker Image
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
./mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=${{ secrets.DOCKER_USERNAME }}/boot-reactive-cache
docker push ${{ secrets.DOCKER_USERNAME }}/boot-reactive-cache
37 changes: 37 additions & 0 deletions r2dbc/boot-reactive-cache/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Misc ###
*.log
.DS_Store
Binary file not shown.
19 changes: 19 additions & 0 deletions r2dbc/boot-reactive-cache/.mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
wrapperVersion=3.3.2
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.8/apache-maven-3.9.8-bin.zip
12 changes: 12 additions & 0 deletions r2dbc/boot-reactive-cache/.yo-rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"generator-springboot": {
"appName": "boot-reactive-cache",
"packageName": "com.example.cache",
"databaseType": "postgresql",
"dbMigrationTool": "flywaydb",
"features": [],
"buildTool": "maven",
"packageFolder": "com/example/cache",
"flywayMigrationCounter": 2
}
}
14 changes: 14 additions & 0 deletions r2dbc/boot-reactive-cache/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM eclipse-temurin:17.0.11_9-jre-focal as builder
WORKDIR application
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use absolute paths for WORKDIR.

To comply with best practices, use absolute paths for WORKDIR.

Use this diff to update the WORKDIR paths:

-WORKDIR application
+WORKDIR /application

Also applies to: 9-9

Tools
Hadolint

[error] 2-2: Use absolute WORKDIR

(DL3000)

ARG JAR_FILE=target/boot-reactive-cache-0.0.1-SNAPSHOT.jar
COPY ${JAR_FILE} application.jar
RUN java -Djarmode=layertools -jar application.jar extract

# the second stage of our build will copy the extracted layers
FROM eclipse-temurin:17.0.11_9-jre-focal
WORKDIR application
COPY --from=builder application/dependencies/ ./
COPY --from=builder application/spring-boot-loader/ ./
COPY --from=builder application/snapshot-dependencies/ ./
COPY --from=builder application/application/ ./
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]
19 changes: 19 additions & 0 deletions r2dbc/boot-reactive-cache/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
pipeline {
agent any

triggers {
pollSCM('* * * * *')
}

environment {
APPLICATION_NAME = 'boot-reactive-cache'
}

stages {
stage('Build') {
steps {
sh './mvnw clean verify'
}
}
}
Comment on lines +12 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding more stages to the pipeline.

Additional stages such as testing, deployment, or notifications could enhance the CI/CD process.

}
33 changes: 33 additions & 0 deletions r2dbc/boot-reactive-cache/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# boot-reactive-cache

### Format code

```shell
$ ./mvnw spotless:apply
```

### Run tests

```shell
$ ./mvnw clean verify
```

### Run locally

```shell
$ docker-compose -f docker/docker-compose.yml up -d
$ ./mvnw spring-boot:run -Dspring-boot.run.profiles=local
```

### Using Testcontainers at Development Time
You can run `TestApplication.java` from your IDE directly.
You can also run the application using Maven as follows:

```shell
./mvnw spring-boot:test-run
```


### Useful Links
* Swagger UI: http://localhost:8080/swagger-ui.html
* Actuator Endpoint: http://localhost:8080/actuator
17 changes: 17 additions & 0 deletions r2dbc/boot-reactive-cache/docker/docker-compose-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3.8'
services:

boot-reactive-cache:
build: ..
ports:
- "18080:8080"
- "18787:8787"
restart: always
depends_on:
- postgresqldb
environment:
- SPRING_PROFILES_ACTIVE=docker
- SPRING_DATASOURCE_DRIVER_CLASS_NAME=org.postgresql.Driver
- SPRING_DATASOURCE_URL=jdbc:postgresql://postgresqldb:5432/appdb
- SPRING_DATASOURCE_USERNAME=appuser
- SPRING_DATASOURCE_PASSWORD=secret
12 changes: 12 additions & 0 deletions r2dbc/boot-reactive-cache/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.8'
services:

postgresqldb:
image: postgres:16.3-alpine
environment:
- POSTGRES_USER=appuser
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=appdb
ports:
- "5432:5432"

1 change: 1 addition & 0 deletions r2dbc/boot-reactive-cache/lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lombok.addLombokGeneratedAnnotation = true
Loading