Skip to content

Commit

Permalink
Gradle (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
vlaship authored Feb 26, 2024
1 parent 4d5b485 commit 33c7be8
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 48 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker image
uses: docker/build-push-action@v5
with:
no-cache: true
context: .
file: ./gradle.Dockerfile
run: docker buildx b --no-cache --file jvm.Dockerfile .
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ bin/
out/
*private.env*
.env

*.log
4 changes: 4 additions & 0 deletions .http/cat.http
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Content-Type: application/json
GET {{host}}/api/category/list
Authorization: Bearer {{token}}

### /category/name/test
GET {{host}}/api/category/name/test
Authorization: Bearer {{token}}

### /product/list
GET {{host}}/api/product/list?page=0&size=1&sort=namn,asc
Authorization: Bearer {{token}}
Expand Down
4 changes: 4 additions & 0 deletions backoffice-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ dependencies {
implementation("net.lbruun.springboot:preliquibase-spring-boot-starter:$preLiquibaseVersion")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")

// cache
implementation("org.springframework.boot:spring-boot-starter-cache")
implementation("com.github.ben-manes.caffeine:caffeine")

// actuator
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("io.opentelemetry.instrumentation:opentelemetry-instrumentation-annotations:$openTelemetryVersion")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package dev.vlaship.backoffice.config;

import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;
import java.util.Collection;
import java.util.List;

@Configuration
@EnableCaching
public class CaffeineCacheConfig {

@Bean
public CacheManager cacheManager() {
var cacheManager = new CaffeineCacheManager();
cacheManager.setCaffeine(caffeineCacheBuilder());
cacheManager.setCacheNames(getCacheNames());

cacheManager.registerCustomCache("cacheName1", caffeineCacheBuilder().expireAfterWrite(Duration.ofSeconds(10)).build());

return cacheManager;
}

private Caffeine<Object, Object> caffeineCacheBuilder() {
return Caffeine.newBuilder();
}

private Collection<String> getCacheNames() {
return List.of("cacheName1", "cacheName2", "cacheName3");
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.vlaship.backoffice.controller;

import dev.vlaship.backoffice.api.Api;
import org.springframework.http.ResponseEntity;
import dev.vlaship.backoffice.dto.Dto;
import dev.vlaship.backoffice.facade.Facade;
Expand All @@ -9,7 +8,7 @@

import java.util.List;

public class AbstractController<M extends Model, D extends Dto> implements Api<M, D> {
public class AbstractController<M extends Model, D extends Dto> {

private final Facade<M, D> facade;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.vlaship.backoffice.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.lang.NonNull;
import dev.vlaship.backoffice.model.Category;
import dev.vlaship.backoffice.repository.CategoryRepository;
Expand All @@ -13,16 +14,18 @@

@Slf4j
@Service
@Transactional
public class CategoryService extends AbstractService<Category> {

private final CategoryRepository repository;

@NonNull
@Transactional(readOnly = true)
@Cacheable(value = "cacheName1", keyGenerator = "customKeyGenerator")
public List<Category> findAll(
@NonNull final String name,
@NonNull final Pageable pageable
) {
log.debug("find all categories by name: {}", name);
return repository.findAllByName(name, pageable);
}

Expand Down
6 changes: 5 additions & 1 deletion backoffice-app/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
application:
title: backoffice-app
version: 1.0.0
spring:
application:
name: ${APP_NAME}
Expand Down Expand Up @@ -31,7 +34,7 @@ spring:
ddl-auto: validate
properties:
hibernate:
show_sql: true
show_sql: false
format_sql: true
use_sql_comments: true
default_schema: ${DB_SCHEMA}
Expand All @@ -58,6 +61,7 @@ logging:
root: info
sql: info
web: info
dev.vlaship.backoffice: debug
# ===============================
# = JWT
# ===============================
Expand Down
1 change: 1 addition & 0 deletions backoffice-app/src/main/resources/banner.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
##:::: ##: ##.... ##: ##::: ##: ##:. ##::::::::::: ##:::: ##: ##::::::: ##:::::::: ##:: ##::: ##: ##:::::::
########:: ##:::: ##:. ######:: ##::. ##::::::::::. #######:: ##::::::: ##:::::::'####:. ######:: ########:
........:::..:::::..:::......:::..::::..::::::::::::.......:::..::::::::..::::::::....:::......:::........::
${application.title} ${application.version} | spring boot ${spring-boot.version}
37 changes: 0 additions & 37 deletions gradle.Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
openApiVersion = "2.3.0"
springBootVersion = "3.2.2"
springBootVersion = "3.2.3"
springDepManVersion = "1.1.4"
kotlinGradlePluginVersion = "1.9.22"
graalvmGradlePluginVersion = "0.9.28"
Expand Down
34 changes: 34 additions & 0 deletions jvm.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
### Build stage
# Builder gradle
FROM gradle:jdk21-alpine AS builder

# Set the working directory inside the container
WORKDIR /tmp

# Copy the source code into the container
COPY . .

# Build
RUN gradle clean backoffice-app:bootJar -x test --no-daemon

# Copy the source code into the container
COPY backoffice-app/build/libs/backoffice-app.jar app.jar

# Extract the layers
RUN java -Djarmode=layertools -jar app.jar extract

### Run stage
# Create a minimal production image
FROM azul/zulu-openjdk-alpine:21-jre-headless

# Set the working directory inside the container
WORKDIR /app

# Set the working directory inside the container
COPY --from=builder /tmp/dependencies/ ./
COPY --from=builder /tmp/snapshot-dependencies/ ./
COPY --from=builder /tmp/spring-boot-loader/ ./
COPY --from=builder /tmp/application/ ./

# Run the binary when the container starts
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]

0 comments on commit 33c7be8

Please sign in to comment.