mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-08-07 04:31:12 +00:00
Add debugBackend module with database and security setup
Introduced a new `debugBackend` module to support debugging and development tasks. This includes configuration for PostgreSQL, Redis, Hibernate, Spring Boot, and a basic security setup. Also added required entities, repositories, and runtime hints for SnapAdmin integration.
This commit is contained in:
76
debugBackend/build.gradle.kts
Normal file
76
debugBackend/build.gradle.kts
Normal file
@@ -0,0 +1,76 @@
|
||||
plugins {
|
||||
kotlin("jvm") version "2.1.10"
|
||||
kotlin("plugin.spring") version "2.1.10"
|
||||
id("org.hibernate.orm") version "6.5.2.Final"
|
||||
id("org.springframework.boot") version "3.4.5"
|
||||
id("io.spring.dependency-management") version "1.1.7"
|
||||
id("org.graalvm.buildtools.native") version "0.10.5"
|
||||
}
|
||||
|
||||
group = "space.mori.dalbodeule"
|
||||
version = "0.5.1"
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(21)
|
||||
}
|
||||
}
|
||||
|
||||
hibernate {
|
||||
enhancement {
|
||||
enableAssociationManagement.set(false)
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.springframework.boot:spring-boot-starter-actuator")
|
||||
implementation("org.springframework.boot:spring-boot-starter-batch")
|
||||
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
|
||||
implementation("org.springframework.boot:spring-boot-starter-data-redis")
|
||||
implementation("org.springframework.boot:spring-boot-starter-security")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
||||
implementation("org.springframework.boot:spring-boot-starter-websocket")
|
||||
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.6")
|
||||
|
||||
implementation("io.swagger.core.v3:swagger-core:2.2.30")
|
||||
implementation("io.swagger.core.v3:swagger-annotations:2.2.30")
|
||||
|
||||
implementation("io.github.cdimascio:dotenv-kotlin:6.4.1")
|
||||
|
||||
developmentOnly("org.springframework.boot:spring-boot-docker-compose")
|
||||
runtimeOnly("org.postgresql:postgresql:42.7.4")
|
||||
|
||||
implementation("jakarta.xml.bind:jakarta.xml.bind-api:4.0.2")
|
||||
implementation("javax.xml.bind:jaxb-api:2.3.1")
|
||||
|
||||
// HTTP 클라이언트
|
||||
implementation("org.springframework.boot:spring-boot-starter-webflux")
|
||||
|
||||
implementation(rootProject)
|
||||
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
|
||||
testImplementation("org.springframework.batch:spring-batch-test")
|
||||
testImplementation("org.springframework.security:spring-security-test")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
|
||||
testImplementation(kotlin("test"))
|
||||
}
|
||||
|
||||
tasks.named<org.springframework.boot.gradle.tasks.run.BootRun>("bootRun") {
|
||||
systemProperty("spring.profiles.active", "dev")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
freeCompilerArgs.addAll("-Xjsr305=strict")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<Test> {
|
||||
useJUnitPlatform()
|
||||
}
|
21
debugBackend/compose.yaml
Normal file
21
debugBackend/compose.yaml
Normal file
@@ -0,0 +1,21 @@
|
||||
services:
|
||||
pgvector:
|
||||
image: 'pgvector/pgvector:pg16'
|
||||
environment:
|
||||
- 'POSTGRES_DB=mydatabase'
|
||||
- 'POSTGRES_PASSWORD=secret'
|
||||
- 'POSTGRES_USER=myuser'
|
||||
labels:
|
||||
- "org.springframework.boot.service-connection=postgres"
|
||||
ports:
|
||||
- target: 5432
|
||||
published: 55432
|
||||
protocol: tcp
|
||||
volumes:
|
||||
- postgresql:/var/lib/postgresql/data
|
||||
redis:
|
||||
image: 'redis:latest'
|
||||
ports:
|
||||
- '6379'
|
||||
volumes:
|
||||
postgresql:
|
@@ -0,0 +1,32 @@
|
||||
package space.mori.dalbodeule.debug
|
||||
|
||||
import io.github.cdimascio.dotenv.dotenv
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScan
|
||||
import org.springframework.boot.runApplication
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories
|
||||
import space.mori.dalbodeule.snapadmin.external.annotations.SnapAdminEnabled
|
||||
|
||||
val dotenv = dotenv {
|
||||
ignoreIfMissing = true
|
||||
}
|
||||
|
||||
@SnapAdminEnabled
|
||||
@SpringBootApplication
|
||||
@EnableJpaRepositories(basePackages = ["space.mori.dalbodeule.debug.repository"])
|
||||
@EntityScan(basePackages = ["space.mori.dalbodeule.debug.model"])
|
||||
class DebugApplication
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val envVars = mapOf(
|
||||
"DB_HOST" to dotenv["DB_HOST"],
|
||||
"DB_PORT" to dotenv["DB_PORT"],
|
||||
"DB_NAME" to dotenv["DB_NAME"],
|
||||
"DB_USER" to dotenv["DB_USER"],
|
||||
"DB_PASSWORD" to dotenv["DB_PASSWORD"]
|
||||
)
|
||||
|
||||
runApplication<DebugApplication>(*args) {
|
||||
setDefaultProperties(envVars)
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
package space.mori.dalbodeule.debug.config
|
||||
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
|
||||
import org.springframework.security.core.userdetails.User
|
||||
import org.springframework.security.core.userdetails.UserDetailsService
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
|
||||
import org.springframework.security.crypto.password.PasswordEncoder
|
||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager
|
||||
import org.springframework.security.web.SecurityFilterChain
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
class SecurityConfig {
|
||||
|
||||
@Bean
|
||||
fun filterChain(http: HttpSecurity): SecurityFilterChain {
|
||||
return http
|
||||
.csrf { it.disable() }
|
||||
.authorizeHttpRequests {
|
||||
it.anyRequest().authenticated()
|
||||
}
|
||||
.httpBasic {}
|
||||
.build()
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun userDetailsService(passwordEncoder: PasswordEncoder): UserDetailsService {
|
||||
val admin = User.builder()
|
||||
.username("test@gmail.com")
|
||||
.password(passwordEncoder.encode("password"))
|
||||
.roles("ADMIN")
|
||||
.build()
|
||||
return InMemoryUserDetailsManager(admin)
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun passwordEncoder(): PasswordEncoder {
|
||||
return BCryptPasswordEncoder()
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package space.mori.dalbodeule.debug.model
|
||||
|
||||
import jakarta.persistence.Column
|
||||
import jakarta.persistence.Entity
|
||||
import jakarta.persistence.GeneratedValue
|
||||
import jakarta.persistence.GenerationType
|
||||
import jakarta.persistence.Id
|
||||
import jakarta.persistence.Table
|
||||
|
||||
@Entity
|
||||
@Table(name="test_table")
|
||||
data class TestTable(
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.UUID)
|
||||
var id: String? = null,
|
||||
|
||||
@Column(nullable = false, length = 32)
|
||||
var name: String
|
||||
) {
|
||||
constructor(): this(null, "")
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package space.mori.dalbodeule.debug.repository
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import space.mori.dalbodeule.debug.model.TestTable
|
||||
|
||||
interface TestTableRepository: JpaRepository<TestTable, String> {
|
||||
}
|
18
debugBackend/src/main/resources/application.yml
Normal file
18
debugBackend/src/main/resources/application.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}
|
||||
username: ${DB_USER}
|
||||
password: ${DB_PASSWORD}
|
||||
driver-class-name: org.postgresql.Driver
|
||||
jpa:
|
||||
hibernate:
|
||||
ddl-auto: update
|
||||
show-sql: true
|
||||
database-platform: org.hibernate.dialect.PostgreSQLDialect
|
||||
snapadmin:
|
||||
enabled: true
|
||||
baseUrl: admin
|
||||
models-package: space.mori.dalbodeule.debug.model
|
||||
logging:
|
||||
level:
|
||||
root: INFO
|
Reference in New Issue
Block a user