-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
260 lines (245 loc) · 8.02 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.google.cloud.tools.jib.gradle.JibTask
import com.google.protobuf.gradle.generateProtoTasks
import com.google.protobuf.gradle.id
import com.google.protobuf.gradle.plugins
import com.google.protobuf.gradle.protobuf
import com.google.protobuf.gradle.protoc
import io.micronaut.gradle.MicronautRuntime.NONE
import io.micronaut.gradle.MicronautTestRuntime.JUNIT_5
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.util.prefixIfNot
import java.net.URL
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
import java.nio.file.StandardOpenOption
val commonsVersion: String by project
val usersVersion: String by project
val kotlinVersion: String by project
val micronautVersion: String by project
val kMongoVersion: String by project
val basePackage = "com.github.jntakpe"
val protoDescriptorPath = "$buildDir/generated/proto.pb"
val grpcServices = listOf("availabilities.UsersAvailabilityService")
val grpcHealthProbeDir = "$buildDir/tmp/bin/"
val probeExecName = "grpc_health_probe"
val imageName = "micronaut-availability"
val gcloudProjectId = System.getenv("GCP_PROJECT_ID") ?: "gcloud-equidis"
plugins {
idea
`maven-publish`
jacoco
val kotlinVersion = "1.4.30"
kotlin("jvm") version kotlinVersion
kotlin("kapt") version kotlinVersion
kotlin("plugin.allopen") version kotlinVersion
kotlin("plugin.serialization") version kotlinVersion
id("com.google.protobuf") version "0.8.15"
id("io.micronaut.application") version "3.1.1"
id("com.google.cloud.tools.jib") version "2.7.1"
id("com.github.johnrengelman.shadow") version "6.1.0"
}
version = "0.1.9"
group = "com.github.jntakpe"
repositories {
mavenLocal()
mavenCentral()
jcenter()
mavenGithub("equidis/commons")
mavenGithub("equidis/micronaut-grpc-users-service")
}
micronaut {
runtime(NONE)
testRuntime(JUNIT_5)
processing {
incremental(true)
module(project.name)
group(project.group.toString())
annotations("$basePackage.*")
}
}
dependencies {
kapt(enforcedPlatform("io.micronaut:micronaut-bom:$micronautVersion"))
kapt("io.micronaut:micronaut-inject-java")
kapt("org.litote.kmongo:kmongo-annotation-processor:$kMongoVersion")
implementation(enforcedPlatform("io.micronaut:micronaut-bom:$micronautVersion"))
implementation("com.github.jntakpe:commons-cache:$commonsVersion")
implementation("com.github.jntakpe:commons-grpc:$commonsVersion")
implementation("com.github.jntakpe:commons-management:$commonsVersion")
implementation("com.github.jntakpe:commons-micronaut:$commonsVersion")
implementation("com.github.jntakpe:commons-mongo:$commonsVersion")
implementation("com.github.jntakpe:commons-tracing:$commonsVersion")
runtimeOnly("ch.qos.logback:logback-classic")
kaptTest(enforcedPlatform("io.micronaut:micronaut-bom:$micronautVersion"))
kaptTest("io.micronaut:micronaut-inject-java")
testImplementation("com.github.jntakpe:commons-cache-test:$commonsVersion")
testImplementation("com.github.jntakpe:commons-grpc-test:$commonsVersion")
testImplementation("com.github.jntakpe:commons-mongo-test:$commonsVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}
application {
mainClass.set("$basePackage.availability.ApplicationKt")
}
java {
sourceCompatibility = JavaVersion.VERSION_11
}
sourceSets {
main {
java {
val dirs = listOf("grpc", "java", "javapgv", "reactor")
srcDirs(dirs.map { it.prefixIfNot("build/generated/source/proto/main/") })
}
}
}
protobuf {
val grpcId = "grpc"
val javaPgvId = "javapgv"
val reactorId = "reactor"
val krotoId = "kroto"
protoc {
artifact = "com.google.protobuf:protoc:3.14.0"
}
plugins {
id(grpcId) {
artifact = "io.grpc:protoc-gen-grpc-java:1.35.0"
}
id(javaPgvId) {
artifact = "io.envoyproxy.protoc-gen-validate:protoc-gen-validate:0.4.1"
}
id(reactorId) {
artifact = "com.salesforce.servicelibs:reactor-grpc:1.0.1"
}
id(krotoId) {
artifact = "com.github.marcoferrer.krotoplus:protoc-gen-kroto-plus:0.6.1"
}
}
dependencies {
protobuf("com.github.jntakpe:users:$usersVersion:proto")
}
generateProtoTasks {
val krotoConfig = file("kroto-config.yaml")
all().forEach {
it.generateDescriptorSet = true
it.descriptorSetOptions.includeImports = true
it.descriptorSetOptions.path = protoDescriptorPath
it.inputs.files(krotoConfig)
it.plugins {
id(grpcId)
id(javaPgvId) {
option("lang=java")
}
id(reactorId)
id(krotoId) {
outputSubDir = "java"
option("ConfigPath=${krotoConfig.name}")
}
}
}
}
}
jib {
to {
image = "eu.gcr.io/$gcloudProjectId/$imageName:${project.version}"
}
from {
image = "gcr.io/distroless/java:11"
}
extraDirectories {
paths {
path {
setFrom(grpcHealthProbeDir)
into = "/bin"
}
}
permissions = mapOf("/bin/${probeExecName}" to "755")
}
}
tasks {
withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "11"
javaParameters = true
}
}
jacocoTestReport {
dependsOn(test)
reports {
xml.isEnabled = true
}
classDirectories.setFrom(
sourceSets.main.get().output.asFileTree.matching {
exclude("build/generated", "**/model/entity/**")
}
)
}
check {
dependsOn(jacocoTestReport)
}
val deploymentZip = register<Zip>("deploymentZip") {
val path = Paths.get("$buildDir/generated/build-metadata.yaml")
doFirst {
if (!Files.exists(path)) Files.createFile(path)
Files.writeString(
path,
"""
app:
name: ${project.name}
version: ${project.version}
kind: grpc
dependencies:
mongodb: true
redis: true
image:
name: $imageName
api:
services: ${grpcServices.joinToString(prefix = "[", postfix = "]")}
""".trimIndent(), StandardOpenOption.SYNC
)
}
archiveFileName.set("deployment-metadata.zip")
destinationDirectory.set(Paths.get(buildDir.toString(), "distributions").toFile())
from(path.toString(), protoDescriptorPath)
}
assemble {
dependsOn(deploymentZip)
}
withType<JibTask> {
doFirst { downloadHealthProbeBinary() }
}
}
val protoJar = tasks.register<Jar>("protoJar") {
dependsOn(tasks.jar)
from("src/main/proto", protoDescriptorPath)
archiveClassifier.set("proto")
}
val shadowJar = tasks.named<ShadowJar>("shadowJar") {
dependsOn(protoJar.name)
mergeServiceFiles()
}
publishing {
publications {
create<MavenPublication>("mavenProto") {
artifact(tasks.getByName(protoJar.name))
}
}
repositories {
mavenGithub("equidis/micronaut-grpc-availability-service")
}
}
fun RepositoryHandler.mavenGithub(repository: String) = maven {
name = "Github_packages"
setUrl("https://maven.pkg.github.com/$repository")
credentials {
val githubActor: String? by project
val githubToken: String? by project
username = githubActor
password = githubToken
}
}
fun downloadHealthProbeBinary() {
val probeVersion = "v0.3.6"
val url = URL("https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${probeVersion}/${probeExecName}-linux-amd64")
Files.createDirectories(Paths.get(grpcHealthProbeDir))
Files.copy(url.openStream(), Paths.get(grpcHealthProbeDir, probeExecName), StandardCopyOption.REPLACE_EXISTING)
}