Browse Source

테스트용 앱 세팅

develop
bean 2 years ago
parent
commit
2d9189cd77
  1. 79
      build.gradle.kts
  2. 9
      db.yaml
  3. 2
      gradle.properties

79
build.gradle.kts

@ -1,4 +1,8 @@
import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.FileInputStream
plugins {
id("org.springframework.boot") version "3.2.2"
@ -10,6 +14,12 @@ plugins {
id("org.liquibase.gradle") version "2.2.1"
}
buildscript {
dependencies {
classpath("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.16.1")
}
}
group = "com.example"
version = "0.0.1-SNAPSHOT"
@ -27,6 +37,7 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-validation")
liquibaseRuntime("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.16.1")
liquibaseRuntime("org.liquibase:liquibase-core")
liquibaseRuntime("org.liquibase.ext:liquibase-hibernate6:4.25.1")
liquibaseRuntime("info.picocli:picocli:4.6.3")
@ -47,45 +58,51 @@ tasks.withType<Test> {
useJUnitPlatform()
}
val profile: String by project
val profileDbConf = getDbConf(profile)
val referencedProfile: String? by project
val referencedProfileDbConf = getDbConf(referencedProfile)
val defaultChangeLogFile: String by project
liquibase {
val profile = System.getProperty("profile") ?: "local"
// TODO: db.yaml objectMapper 로 읽어서 세팅?
activities.register("local") {
this.arguments = mapOf(
"url" to "jdbc:postgresql://localhost:15432/localdb",
"username" to "flower",
"password" to "flower"
)
}
activities.register("dev") {
this.arguments = mapOf(
"url" to "jdbc:postgresql://flower-fragrance-stage.cluster-cbth1bnhfbdg.ap-northeast-2.rds.amazonaws.com:5432/devdb",
"username" to "anypoint",
"password" to "*emflaj*"
)
activities.register(profile) {
this.arguments = (profileDbConf?.toMap() ?: emptyMap()) +
(referencedProfileDbConf?.toReferenceMap() ?: emptyMap()) +
mapOf("changelogFile" to defaultChangeLogFile)
}
runList = profile
}
fun addArguments(name: String, args: Map<String, String>) {
val activity = liquibase.activities.getByName(name)
activity.name = name
val activityArgs = activity.arguments as Map<*, *>
val newArgs = mutableMapOf<String, String>()
newArgs.putAll(activityArgs.map { it.key as String to it.value as String })
newArgs.putAll(args)
data class DbConf(
val url: String? = null,
val username: String? = null,
val password: String? = null
) {
fun toMap(): Map<String, String?> = mapOf(
"url" to url,
"username" to username,
"password" to password
)
newArgs.forEach {
println("arguments[\"${it.key}\"]=\"${it.value}\"")
}
fun toReferenceMap(): Map<String, String?> = mapOf(
"reference-url" to url,
"reference-username" to username,
"reference-password" to password
)
}
activity.arguments = newArgs
fun getDbConf(profile: String?): DbConf? = profile?.let {
ObjectMapper(YAMLFactory())
.readValue(
FileInputStream(File(projectDir, "db.yaml")),
object : TypeReference<Map<String, DbConf>>() {}
)[profile]
}
tasks.getByName("generateChangelog").doFirst {
val changeLogFile = "src/main/resources/liquibase/postgres/changelog/generated.yaml"
delete(changeLogFile)
val name = System.getProperty("name") ?: "local"
addArguments(name, mapOf("changeLogFile" to changeLogFile))
delete(defaultChangeLogFile)
}
tasks.getByName("diffChangelog").doFirst {
delete(defaultChangeLogFile)
}

9
db.yaml

@ -0,0 +1,9 @@
local:
url: jdbc:postgresql://localhost:15432/localdb
username: flower
password: flower
dev:
url: jdbc:postgresql://flower-fragrance-stage.cluster-cbth1bnhfbdg.ap-northeast-2.rds.amazonaws.com:5432/devdb
username: anypoint
password: '*emflaj*'

2
gradle.properties

@ -0,0 +1,2 @@
profile=local
defaultChangeLogFile=src/main/resources/liquibase/postgres/changelog/generated.yaml
Loading…
Cancel
Save