-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathbuild.gradle
405 lines (357 loc) · 15.3 KB
/
build.gradle
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
buildscript {
ext {
vertxJooqVersion = '6.5.5'
}
repositories {
mavenLocal()
// for jooq from github
maven { url 'https://jitpack.io' }
mavenCentral()
}
dependencies {
classpath "io.github.jklingsporn:vertx-jooq-generate:$vertxJooqVersion"
classpath "org.postgresql:postgresql:$postgresqlVersion"
classpath "io.vertx:vertx-core:$vertxVersion"
}
}
plugins {
id 'docker'
id 'com.google.cloud.tools.jib' version "$googleContainerToolsJibVersion"
id "org.flywaydb.flyway" version "$flywayVersion"
id 'com.gradleup.shadow' version "$shadowPluginVersion"
id 'org.javamodularity.moduleplugin'
id 'idea'
id 'application'
}
apply from: '../gradle/instrument.gradle'
repositories {
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
}
evaluationDependsOn(':spellsource-containers')
import com.bmuschko.gradle.docker.tasks.container.DockerCreateContainer
import com.bmuschko.gradle.docker.tasks.container.DockerRemoveContainer
import com.bmuschko.gradle.docker.tasks.container.DockerStartContainer
import com.bmuschko.gradle.docker.tasks.container.DockerStopContainer
import com.bmuschko.gradle.docker.tasks.image.DockerPullImage
import io.github.jklingsporn.vertx.jooq.shared.postgres.JSONBToJsonObjectConverter
import io.vertx.core.json.JsonObject
import org.apache.tools.ant.taskdefs.condition.Os
import org.jooq.codegen.GenerationTool
import org.jooq.meta.jaxb.*
def isWindows = Os.isFamily(Os.FAMILY_WINDOWS)
def localUsername = 'admin'
def localPassword = 'password'
def localDatabaseName = 'spellsource'
def localPort = '5432'
def mainClassNameConst = 'com.hiddenswitch.framework.EntryPoint'
def jdbcUrl = "jdbc:postgresql://localhost:5432/$localDatabaseName"
def jvmArgs = ['--enable-preview', '--add-opens', 'java.base/java.lang=ALL-UNNAMED']
application {
mainClassName mainClassNameConst
}
dependencies {
compileOnly 'org.infinispan:infinispan-component-annotations:15.0.0.Dev01'
implementation project(':spellsource-common')
implementation project(':spellsource-game')
implementation project(':spellsource-cards-git')
implementation "io.github.classgraph:classgraph:$classgraphVersion"
implementation group: 'io.vertx', name: 'vertx-infinispan', version: vertxVersion
implementation group: 'io.vertx', name: 'vertx-web-client', version: vertxVersion
implementation group: 'io.vertx', name: 'vertx-service-discovery', version: vertxVersion
implementation group: 'io.vertx', name: 'vertx-web', version: vertxVersion
implementation group: 'io.vertx', name: 'vertx-auth-jwt', version: vertxVersion
implementation "io.vertx:vertx-rx-java3:$vertxVersion"
implementation 'javax.activation:activation:1.1.1'
// keycloak
implementation 'net.openhft:zero-allocation-hashing:0.16'
implementation platform("org.keycloak.bom:keycloak-bom-parent:$keycloakVersion")
implementation(group: 'org.keycloak', name: 'keycloak-admin-client', version: "$keycloakVersion") {
exclude group: 'org.jboss.resteasy', module: 'resteasy-client'
}
implementation 'jakarta.ws.rs:jakarta.ws.rs-api:3.1.0'
implementation "org.keycloak:keycloak-server-spi:$keycloakVersion"
implementation "org.keycloak:keycloak-server-spi-private:$keycloakVersion"
implementation "ch.qos.logback:logback-classic:$logbackVersion"
implementation group: 'com.lambdaworks', name: 'scrypt', version: '1.4.0'
implementation group: 'commons-validator', name: 'commons-validator', version: '1.7'
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-smile:$jacksonVersion") {
exclude group: 'jakarta.xml.bind', module: '*'
exclude group: 'jakarta.activation', module: '*'
}
implementation("com.fasterxml.jackson.module:jackson-module-afterburner:$jacksonVersion") {
exclude group: 'jakarta.xml.bind', module: '*'
exclude group: 'jakarta.activation', module: '*'
}
implementation("com.avast.grpc.jwt:grpc-java-jwt:0.5.8") {
exclude group: 'com.google.code.gson'
exclude group: 'io.grpc'
exclude group: 'org.keycloak'
}
implementation("org.postgresql:postgresql:$postgresqlVersion") {
exclude group: 'org.checkerframework', module: 'checker-qual'
}
implementation("org.jboss.resteasy:resteasy-client:$resteasyVersion") {
exclude group: 'io.vertx', module: 'vertx-core'
}
implementation group: "io.netty", name: "netty-resolver-dns-native-macos", version: nettyVersion, classifier: "osx-aarch_64"
implementation 'org.jooq:jooq:3.17.3'
implementation "io.vertx:vertx-pg-client:$vertxVersion"
implementation("io.github.jklingsporn:vertx-jooq-classic-reactive:$vertxJooqVersion") {
exclude group: "io.vertx", module: '*'
}
implementation group: 'io.vertx', name: 'vertx-auth-common', version: vertxVersion
implementation(group: 'io.vertx', name: 'vertx-opentracing', version: vertxVersion) {
exclude group: 'io.jaegertracing', module: '*'
}
implementation "io.vertx:vertx-micrometer-metrics:$vertxVersion"
implementation "io.micrometer:micrometer-core:$micrometerVersion"
implementation "io.micrometer:micrometer-registry-prometheus:$micrometerVersion"
implementation "io.micrometer:micrometer-registry-jmx:$micrometerVersion"
implementation 'com.be-hase.grpc-micrometer:grpc-micrometer:0.0.2'
implementation 'io.opentracing.contrib:opentracing-grpc:0.2.3'
implementation "io.jaegertracing:jaeger-client:$jaegerVersion"
implementation("com.github.marschall:micrometer-jfr:1.10.0") {
exclude group: 'io.micrometer', module: 'micrometer-core'
}
implementation "org.flywaydb:flyway-core:$flywayVersion"
implementation 'org.redisson:redisson:3.40.1'
implementation(group: 'com.github.pcj', name: 'google-options', version: '1.0.0') {
exclude group: 'com.google.guava', module: 'guava'
}
implementation "io.github.kobylynskyi:graphql-java-codegen:5.9.0"
implementation 'com.graphql-java:graphql-java:22.3'
testImplementation "ch.qos.logback:logback-classic:$logbackVersion"
testImplementation(project(':spellsource-containers'))
testImplementation project(':spellsource-testutils')
testImplementation("org.testcontainers:testcontainers:$testcontainersVersion")
testImplementation("org.testcontainers:junit-jupiter:$testcontainersVersion")
testImplementation group: 'io.vertx', name: 'vertx-junit5', version: vertxVersion
testImplementation group: 'io.vertx', name: 'vertx-web-client', version: vertxVersion
testImplementation group: 'io.vertx', name: 'vertx-web-common', version: vertxVersion
testImplementation "com.google.guava:guava:$guavaVersion"
testImplementation "io.github.classgraph:classgraph:$classgraphVersion"
testImplementation 'org.jetbrains:annotations'
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
testImplementation 'uk.org.webcompere:system-stubs-jupiter:2.0.2'
}
javadoc {
def javadocOptions = options as CoreJavadocOptions
javadocOptions.addStringOption("source", "20")
javadocOptions.addBooleanOption("-enable-preview", true)
}
jar {
manifest {
attributes 'Main-Class': mainClassNameConst
}
}
shadowJar {
mergeServiceFiles()
zip64 true
manifest {
attributes 'Main-Class': mainClassNameConst
}
}
run {
group('spellsource')
description("Starts the Spellsource server locally. Starts all dependencies using Docker (must be installed).")
dependsOn += [classes, testClasses]
classpath sourceSets.test.runtimeClasspath
mainClass.set('com.hiddenswitch.framework.tests.applications.EntryPoint')
// to preserve sql db for keycloak as a practical matter
environment("TESTCONTAINERS_REUSE_ENABLE", "true")
jvmArgs.addAll(jvmArgs)
}
artifacts {
archives shadowJar
}
application {
mainClass.set(mainClassNameConst)
}
tasks.register('stopExistingPostgresContainer', DockerStopContainer) {
containerId.set('gradleSupabasePostgres')
onError({})
}
tasks.register('removeExistingPostgresContainer', DockerRemoveContainer) {
dependsOn stopExistingPostgresContainer
containerId.set('gradleSupabasePostgres')
onError({})
}
tasks.register('pullPostgresImage', DockerPullImage) {
image.set("docker.io/postgres:13.11-bullseye")
}
tasks.register('pullKeycloakImage', DockerPullImage) {
image.set("quay.io/keycloak/keycloak:20.0")
}
tasks.register('createPostgresContainer', DockerCreateContainer) {
dependsOn += [removeExistingPostgresContainer, pullPostgresImage]
imageId.set("docker.io/postgres:13.11-bullseye")
containerName.set('gradleSupabasePostgres')
hostConfig.portBindings.set(['5432:5432'])
entrypoint.set(["/bin/bash", "-c", "mkdir -pv /docker-entrypoint-initdb.d/ && echo 'create schema if not exists keycloak;' > /docker-entrypoint-initdb.d/init.sql && docker-entrypoint.sh postgres"])
cmd.set([])
envVars.putAll([
'POSTGRES_DB' : localDatabaseName,
'POSTGRES_USER' : localUsername,
'POSTGRES_PASSWORD': localPassword, 'POSTGRES_PORT': localPort])
hostConfig.autoRemove.set(true)
}
tasks.register('startPostgresContainer', DockerStartContainer) {
dependsOn createPostgresContainer
targetContainerId createPostgresContainer.getContainerId()
doLast {
sleep(12000)
}
}
tasks.register('stopPostgresContainer', DockerStopContainer) {
targetContainerId createPostgresContainer.getContainerId()
}
tasks.register('createKeycloakContainer', DockerCreateContainer) {
dependsOn += [createPostgresContainer, pullKeycloakImage]
imageId.set("quay.io/keycloak/keycloak:22.0.3")
envVars.putAll([
'KEYCLOAK_ADMIN_USERNAME': "admin",
'KEYCLOAK_ADMIN_PASSWORD': 'password',
'KC_DB' : 'postgres',
'KC_DB_URL_HOST' : 'gradleSupabasePostgres',
'KC_DB_URL_PORT' : localPort,
'KC_DB_URL_DATABASE' : localDatabaseName,
'KC_DB_USERNAME' : localUsername,
'KC_DB_PASSWORD' : localPassword,
'KC_DB_SCHEMA' : 'keycloak',
'KC_HOSTNAME_STRICT' : 'false',
'KC_FEATURES' : 'declarative-user-profile'
])
cmd.set(["start-dev"])
hostConfig.autoRemove.set(true)
hostConfig.portBindings.set(["8080:8080"])
hostConfig.links.set(['gradleSupabasePostgres:gradleSupabasePostgres'])
}
tasks.register('startKeycloakContainer', DockerStartContainer) {
dependsOn += [createKeycloakContainer, startPostgresContainer]
targetContainerId createKeycloakContainer.getContainerId()
doLast {
sleep(30000)
}
}
tasks.register('stopKeycloakContainer', DockerStopContainer) {
targetContainerId createKeycloakContainer.getContainerId()
}
tasks.register('jooqGenerate') {
// Do all migrations first
dependsOn flywayMigrate
finalizedBy = [stopKeycloakContainer, stopPostgresContainer]
def outputDir = "$project.projectDir/src/main/java"
inputs.dir("$project.projectDir/src/main/resources/db/migration")
outputs.dir(outputDir + '/com/hiddenswitch/framework/schema')
def configuration = new Configuration()
configuration
.withJdbc(new Jdbc()
.withDriver('org.postgresql.Driver')
.withUrl(jdbcUrl)
.withUser(localUsername)
.withPassword(localPassword))
.withGenerator(new Generator()
.withName('io.github.jklingsporn.vertx.jooq.generate.classic.ClassicReactiveVertxGenerator')
.withDatabase(new Database()
.withName('org.jooq.meta.postgres.PostgresDatabase')
.withSchemata(new SchemaMappingType().withInputSchema("keycloak").withOutputSchema('keycloak'),
new SchemaMappingType().withInputSchema("spellsource").withOutputSchema('spellsource'),
new SchemaMappingType().withInputSchema("hiddenswitch").withOutputSchema("hiddenswitch"))
.withForcedTypes(
new ForcedType()
.withUserType(JsonObject.class.getName())
.withConverter(JSONBToJsonObjectConverter.class.getName())
.withIncludeTypes("jsonb"))
.withIncludeTables(true)
.withIncludeRoutines(true)
.withIncludePackages(false)
.withIncludeUDTs(true)
.withIncludeSequences(true)
.withExcludes('schema_version')
.withIncludes('.*'))
.withGenerate(new Generate()
.withDeprecated(false)
.withRecords(true)
.withInterfaces(true)
.withFluentSetters(true)
.withPojos(true)
.withDaos(true))
.withTarget(new Target()
.withPackageName('com.hiddenswitch.framework.schema')
.withDirectory(outputDir))
.withStrategy(new Strategy()
.withName('io.github.jklingsporn.vertx.jooq.generate.VertxGeneratorStrategy')))
doLast() {
GenerationTool.generate(configuration)
exec {
// dump the generated ddl to a file
workingDir project.projectDir
// this is using docker-wrapped pg_dump
environment('PGPASSWORD', localPassword)
environment('PGDATABASE', localDatabaseName)
environment('PGUSER', localUsername)
def containerId = startPostgresContainer.containerId.get()
environment('DOCKER_OPTS', "--link " + containerId + ":database")
if (isWindows) {
// postgres is bound to localhost
commandLine "$project.rootProject.projectDir\\bin\\pg_dump.exe", '-h', 'localhost', '-s', '-f', "$project.projectDir\\src\\main\\resources\\db\\ddl.sql"
} else {
commandLine "$project.rootProject.projectDir/bin/pg_dump", '-h', "database", '-s', '-f', "/git/$project.projectDir.name/src/main/resources/db/ddl.sql"
}
}
}
}
tasks.register('migrationsOrSqlChanged') {
group('spellsource')
description("Run whenever the schema as encoded in $project.projectDir.name/src/main/resources/db/migration has changed - recreates the JOOQ DSL and dumps a ddl.sql file for autocompletion")
dependsOn += [jooqGenerate]
}
flyway {
url = jdbcUrl
user = localUsername
password = localPassword
schemas = ['hiddenswitch', 'spellsource']
locations = ['filesystem:src/main/resources/db/migration']
}
// Make sure keycloak has done its migration first
flywayMigrate.dependsOn += [startKeycloakContainer]
test {
group('spellsource')
useJUnitPlatform()
enableAssertions = false
maxHeapSize = '4096m'
systemProperty("vertx.grpc.stack.traces", "true")
testLogging {
showExceptions true
exceptionFormat "full"
showCauses true
showStackTraces true
}
}
def spellsourceTags = ['latest', project.version.toString()]
def spellsourceImage = 'ghcr.io/hiddenswitch/spellsource'
jib {
from {
image = "eclipse-temurin:21-ubi9-minimal"
}
to {
image = spellsourceImage
tags = spellsourceTags
}
container {
// todo: should this be 8081?
ports = ['8080']
jvmFlags = jvmArgs
}
}
tasks.register('githubDockerPush') {
dependsOn jibDockerBuild
doLast {
for (def image : spellsourceTags.collect { tag -> "$spellsourceImage:$tag" }) {
exec {
commandLine(['docker', 'push'] + [image])
}
}
}
}