-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
200 lines (171 loc) · 7.39 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import com.bmuschko.gradle.docker.tasks.image.DockerPushImage
import com.bmuschko.gradle.docker.tasks.image.Dockerfile
import io.ktor.plugin.features.*
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink
plugins {
alias(libs.plugins.kotlinx.serialization)
id("build-kmp")
// id("io.ktor.plugin")
alias(libs.plugins.ktor)
// id("com.bmuschko.docker-remote-api") - Универсальный плагин для докера
alias(libs.plugins.muschko.remote)
}
application {
mainClass.set("io.ktor.server.cio.EngineMain")
}
ktor {
configureNativeImage(project)
docker {
localImageName.set(project.name)
imageTag.set(project.version.toString())
jreVersion.set(JavaVersion.VERSION_21)
}
}
jib {
container.mainClass = application.mainClass.get()
}
kotlin {
// !!! Обязательно. Иначе не проходит сборка толстых джанриков в shadowJar
jvm { withJava() }
targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget> {
binaries {
executable {
entryPoint = "ru.otus.otuskotlin.marketplace.app.ktor.main"
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(kotlin("stdlib-common"))
implementation(libs.ktor.server.core)
implementation(libs.ktor.server.cio)
implementation(libs.ktor.server.cors)
implementation(libs.ktor.server.yaml)
implementation(libs.ktor.server.negotiation)
implementation(libs.ktor.server.headers.response)
implementation(libs.ktor.server.headers.caching)
implementation(libs.ktor.server.websocket)
// // Для того, чтоб получать содержимое запроса более одного раза
// В Application.main добавить `install(DoubleReceive)`
// implementation("io.ktor:ktor-server-double-receive:${libs.versions.ktor.get()}")
implementation(project(":ok-marketplace-common"))
implementation(project(":ok-marketplace-app-common"))
implementation(project(":ok-marketplace-biz"))
// v2 api
implementation(project(":ok-marketplace-api-v2-kmp"))
// Stubs
implementation(project(":ok-marketplace-stubs"))
// RabbitMQ
// implementation(project(":ok-marketplace-app-rabbit"))
implementation(libs.kotlinx.serialization.core)
implementation(libs.kotlinx.serialization.json)
implementation(libs.ktor.serialization.json)
// DB
implementation(libs.uuid)
implementation(projects.okMarketplaceRepoCommon)
implementation(projects.okMarketplaceRepoStubs)
implementation(projects.okMarketplaceRepoInmemory)
implementation(projects.okMarketplaceRepoPostgres)
// States
implementation(libs.mkpl.state.common)
implementation(libs.mkpl.state.biz)
// logging
implementation(project(":ok-marketplace-api-log1"))
implementation(libs.mkpl.logs.common)
implementation(libs.mkpl.logs.kermit)
implementation(libs.mkpl.logs.socket)
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
// DB
implementation(projects.okMarketplaceRepoCommon)
implementation(libs.ktor.server.test)
implementation(libs.ktor.client.negotiation)
}
}
val jvmMain by getting {
dependencies {
implementation(kotlin("stdlib-jdk8"))
// jackson
implementation(libs.ktor.serialization.jackson)
implementation(libs.ktor.server.calllogging)
implementation(libs.ktor.server.headers.default)
implementation(libs.logback)
// transport models
implementation(projects.okMarketplaceApiV1Jackson)
implementation(projects.okMarketplaceApiV1Mappers)
implementation(projects.okMarketplaceApiV2Kmp)
implementation(projects.okMarketplaceRepoCassandra)
implementation(projects.okMarketplaceRepoGremlin)
implementation(libs.mkpl.logs.logback)
implementation(libs.testcontainers.cassandra)
implementation(libs.testcontainers.core)
}
}
val jvmTest by getting {
dependencies {
implementation(kotlin("test-junit"))
}
}
}
}
tasks {
shadowJar {
isZip64 = true
}
// Если ошибка: "Entry application.yaml is a duplicate but no duplicate handling strategy has been set."
// Возникает из-за наличия файлов как в common, так и в jvm платформе
withType(ProcessResources::class) {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
val linkReleaseExecutableLinuxX64 by getting(KotlinNativeLink::class)
val nativeFileX64 = linkReleaseExecutableLinuxX64.binary.outputFile
val linuxX64ProcessResources by getting(ProcessResources::class)
val dockerDockerfileX64 by creating(Dockerfile::class) {
dependsOn(linkReleaseExecutableLinuxX64)
dependsOn(linuxX64ProcessResources)
group = "docker"
from(Dockerfile.From("ubuntu:22.04").withPlatform("linux/amd64"))
doFirst {
copy {
from(nativeFileX64)
from(linuxX64ProcessResources.destinationDir)
into("${[email protected]()}")
}
}
runCommand("apt-get update && apt-get install -y libpq5 && rm -rf /var/lib/apt/lists/*")
copyFile(nativeFileX64.name, "/app/")
copyFile("application.yaml", "/app/")
exposePort(8080)
workingDir("/app")
entryPoint("/app/${nativeFileX64.name}", "-config=./application.yaml")
}
val registryUser: String? = System.getenv("CONTAINER_REGISTRY_USER")
val registryPass: String? = System.getenv("CONTAINER_REGISTRY_PASS")
val registryHost: String? = System.getenv("CONTAINER_REGISTRY_HOST")
val registryPref: String? = System.getenv("CONTAINER_REGISTRY_PREF")
val imageName = registryPref?.let { "$it/${project.name}" } ?: project.name
val dockerBuildX64Image by creating(DockerBuildImage::class) {
group = "docker"
dependsOn(dockerDockerfileX64)
images.add("$imageName-x64:${rootProject.version}")
images.add("$imageName-x64:latest")
platform.set("linux/amd64")
}
val dockerPushX64Image by creating(DockerPushImage::class) {
group = "docker"
dependsOn(dockerBuildX64Image)
images.set(dockerBuildX64Image.images)
registryCredentials {
username.set(registryUser)
password.set(registryPass)
url.set("https://$registryHost/v1/")
}
}
}