forked from zalando/nakadi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
422 lines (353 loc) · 11.8 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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
import java.util.concurrent.TimeUnit
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'application'
apply plugin: 'spring-boot'
apply plugin: "jacoco"
apply plugin: 'findbugs'
// if this is applied, include scala dependencies (see below)
// apply plugin: 'scala'
group 'de.zalando.aruha'
sourceCompatibility = 1.8
targetCompatibility = 1.8
mainClassName = 'de.zalando.aruha.nakadi.Application'
def dockerGroup = "aruha"
def dockerApplicationName = "nakadi"
def dockerContainerName = "nakadi-local"
def storagesContainerName = "local-storages"
/* config parameters */
def dockerImageName = "$dockerGroup/$dockerApplicationName"
if (project.hasProperty("dockerImageName")) {
dockerImageName = project.property("dockerImageName")
}
def dockerImageVersion = "AUTOBUILD"
if (project.hasProperty("dockerImageVersion")) {
dockerImageVersion = project.property("dockerImageVersion")
}
def dockerImageTag = "$dockerImageName:$dockerImageVersion"
def dockerBuildTimeout = 300
def loadYaml() {
org.yaml.snakeyaml.DumperOptions options = new org.yaml.snakeyaml.DumperOptions();
options.setDefaultFlowStyle(org.yaml.snakeyaml.DumperOptions.FlowStyle.BLOCK);
def yaml = new org.yaml.snakeyaml.Yaml(options)
def file = new File("src/main/resources/application.yml").text
def cfg = (Map) yaml.load(file)
return cfg
}
def application_config = loadYaml()
repositories {
mavenCentral()
}
sourceSets {
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integration-test/java')
}
resources.srcDir file('src/integration-test/resources')
}
acceptanceTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/acceptance-test/java')
}
resources.srcDir file('src/acceptance-test/resources')
}
}
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE"
classpath 'org.yaml:snakeyaml:1.14'
}
}
jar {
baseName = 'nakadi'
}
configurations {
all*.exclude module : 'spring-boot-starter-logging'
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
acceptanceTestCompile.extendsFrom testCompile
acceptanceTestRuntime.extendsFrom testRuntime
pgsql
}
findbugs {
reportLevel = "high"
sourceSets = []
}
dependencies {
ext {
dropwizardVersion = '3.1.2'
}
pgsql 'org.postgresql:postgresql:9.4.1207'
// spring
compile('org.springframework.boot:spring-boot-starter-web:1.3.1.RELEASE') {
exclude module: 'logback-classic'
exclude module: 'log4j-over-slf4j'
}
compile 'org.springframework:spring-context:4.2.0.RELEASE'
compile 'org.springframework:spring-web:4.2.0.RELEASE'
compile 'org.springframework:spring-webmvc:4.2.0.RELEASE'
// oauth
compile 'org.springframework.security.oauth:spring-security-oauth2:2.0.8.RELEASE'
compile('org.springframework.boot:spring-boot-starter-security') {
exclude module: "logback-classic"
}
// storage
compile 'org.springframework.boot:spring-boot-starter-jdbc:1.3.1.RELEASE'
compile 'org.postgresql:postgresql:9.4.1207'
// misc
compile 'org.apache.httpcomponents:httpclient:4.5.1'
compile ('org.zalando.stups:stups-spring-oauth2-server:1.0.10') {
exclude module: "httpclient"
}
compile 'org.zalando:jackson-datatype-problem:0.5.0'
compile 'org.zalando:problem:0.5.0'
compile 'org.zalando:problem-spring-web:0.5.0'
compile 'com.google.guava:guava:19.0'
compile 'joda-time:joda-time:2.2'
compile 'javax.ws.rs:javax.ws.rs-api:2.0.1'
compile 'org.slf4j:slf4j-log4j12:1.7.14'
compile "io.dropwizard.metrics:metrics-core:$dropwizardVersion"
compile "com.ryantenney.metrics:metrics-spring:$dropwizardVersion"
compile "io.dropwizard.metrics:metrics-servlets:$dropwizardVersion"
compile "io.dropwizard.metrics:metrics-jvm:$dropwizardVersion"
compile 'org.apache.commons:commons-lang3:3.4'
compile 'org.zalando:problem-spring-web:0.5.0'
compile 'org.zalando:jackson-datatype-problem:0.5.0'
// kafka & zookeeper
compile 'org.apache.kafka:kafka-clients:0.9.0.0'
compile 'org.apache.kafka:kafka_2.11:0.9.0.0'
compile 'org.apache.curator:curator-framework:2.9.1'
compile 'org.apache.curator:curator-recipes:2.9.1'
// json
compile 'org.everit.json:org.everit.json.schema:1.2.0'
compile ('com.fasterxml.jackson.datatype:jackson-datatype-json-org:2.4.0') {
exclude module: "json"
}
// scala dependencies
//compile 'org.scala-lang:scala-library:2.11.6'
//testCompile 'org.scalatest:scalatest_2.11:2.2.4'
// tests
testCompile 'org.hamcrest:hamcrest-all:1.3'
testCompile('junit:junit:4.12') {
exclude module: "hamcrest-core"
}
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'org.skyscreamer:jsonassert:1.3.0'
testCompile 'uk.co.datumedge:hamcrest-json:0.2'
testCompile 'org.mockito:mockito-all:1.10.19'
testCompile('com.jayway.restassured:rest-assured:2.5.0') {
exclude module: "hamcrest-core"
exclude module: "hamcrest-library"
}
testCompile 'com.jayway.jsonpath:json-path:2.2.0'
testCompile 'org.echocat.jomon:runtime:1.6.2'
testRuntime 'org.pegdown:pegdown:1.1.0'
}
// end::dependencies[]
// tag::wrapper[]
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
tasks.withType(FindBugs) {
reports {
xml.enabled = false
html.enabled = true
}
}
task cleanDb << {
def sql = getSqlInstance(application_config["spring"]["datasource"])
sql.execute('TRUNCATE zn_data.event_type')
sql.close()
}
task dbBootstrap << {
def db = application_config["spring"]["datasource"]
def sql = getSqlInstance(db)
def sqlFileList = getSortedSqlFiles()
sqlFileList.each {
println 'Running script: ' + it
String sqlString = it.text
sql.execute(sqlString)
}
sql.execute("RESET ROLE")
sql.execute("CREATE ROLE " + db['username'] + " WITH LOGIN PASSWORD '" + db['password'] + "'")
sql.execute("GRANT zalando_nakadi_data_writer TO " + db['username'])
sql.close()
}
def getSortedSqlFiles() {
def sqlFileList = []
new File('database').eachFileRecurse(groovy.io.FileType.FILES) {
if (it.name.endsWith('.sql')) {
sqlFileList << it
}
}
sqlFileList.sort()
}
def getSqlInstance(db) {
// This is needed to get postgreSQL driver onto the Groovy/Gradle classpath
configurations.pgsql.each { file ->
println "Adding URL: $file"
gradle.class.classLoader.addURL(file.toURI().toURL())
}
groovy.sql.Sql.newInstance(db.url, 'nakadi', db.password, db.driverClassName)
}
def runMakeStorages(target, options="", timeout=15) {
execAndWait("make " + options + " --directory local-storages " + target, timeout)
}
task stopAndRemoveStoragesInDocker {
doLast {
runMakeStorages("stop-and-remove", "", dockerBuildTimeout)
}
outputs.upToDateWhen { false }
}
task startStoragesInDockerBound() {
finalizedBy dbBootstrap
doLast {
runMakeStorages("run", "PUBLISH_NAKADI_PORT=\"-p 8080:8080\"", dockerBuildTimeout)
}
outputs.upToDateWhen { false }
}
task startStoragesInDocker() {
finalizedBy dbBootstrap
doLast {
runMakeStorages("run", "", dockerBuildTimeout)
}
outputs.upToDateWhen { false }
}
task generateScmSourceJson() {
def rev = new ByteArrayOutputStream()
exec {
commandLine "git", "rev-parse", "HEAD"
standardOutput = rev
}
rev = rev.toString().trim()
def url = new ByteArrayOutputStream()
exec {
commandLine "git", "config", "--get", "remote.origin.url"
standardOutput = url
}
url = url.toString().trim()
def status = new ByteArrayOutputStream()
exec {
commandLine "git", "status", "--porcelain"
standardOutput = status
}
status = status.toString().trim().replaceAll("[\n\r]", "\\\\n")
if (status) {
rev = "$rev (locally modified)"
}
def scmSource = new FileOutputStream("scm-source.json")
scmSource.write("{\"url\": \"git:${url}\", \"revision\":\"${rev}\", \"author\": \"${System.getenv()['USER']}\", \"status\": \"${status}\"}".getBytes())
scmSource.close()
}
task buildDockerImage {
dependsOn bootRepackage, generateScmSourceJson
doLast {
println "Building docker image with tag: $dockerImageTag"
if (execAndWait("docker build -t " + dockerImageTag + " .", dockerBuildTimeout) != 0) {
throw new GradleException("docker build failed.")
}
}
outputs.upToDateWhen { false }
}
task pushDockerImage {
dependsOn buildDockerImage
doLast {
println "Pushing docker image with tag: $dockerImageTag"
if (execAndWait("docker push " + dockerImageTag, dockerBuildTimeout) != 0) {
throw new GradleException("docker push failed.")
}
}
}
task removeOldDockerContainer(type: Exec) {
commandLine "bash", "-c",
"for c in `docker ps -qaf name=$dockerContainerName`; do docker rm -f \$c; done"
}
task startDockerContainer(type: Exec) {
commandLine "bash", "-c", "docker run -e \"NAKADI_OAUTH2_MODE=OFF\" " +
"--net container:$storagesContainerName --name $dockerContainerName -i -t -d $dockerImageTag"
dependsOn buildDockerImage, removeOldDockerContainer, startStoragesInDockerBound
}
task stopAndRemoveDockerContainer(type: Exec) {
dependsOn stopAndRemoveStoragesInDocker
commandLine "bash", "-c",
"for c in `docker ps -qaf name=$dockerContainerName`; do docker rm -f \$c; done"
}
task integrationTest(type: Test) {
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
}
task acceptanceTest(type: Test) {
testClassesDir = sourceSets.acceptanceTest.output.classesDir
classpath = sourceSets.acceptanceTest.runtimeClasspath
}
def execAndWait(command, timeoutInSeconds = 15) {
println "Running command: " + command
ProcessBuilder pb = new ProcessBuilder(["bash", "-c", command]).inheritIO();
Process proc = pb.start();
proc.waitFor(timeoutInSeconds, TimeUnit.SECONDS);
return proc.exitValue()
}
task startDockerContainerAndWait() {
// start app with docker
dependsOn startDockerContainer
doLast {
// wait till application is up (health check is successful)
int result = 1
while (result != 0) {
result = execAndWait('curl http://localhost:8080/health')
sleep(1000L)
}
}
outputs.upToDateWhen { false }
}
task fullAcceptanceTest(type: GradleBuild) {
dependsOn startDockerContainerAndWait
tasks = ['acceptanceTest']
finalizedBy cleanDb, stopAndRemoveStoragesInDocker, stopAndRemoveDockerContainer
}
test {
testLogging {
events "passed", "skipped", "failed"
}
}
integrationTest {
testLogging {
events "passed", "skipped", "failed"
}
}
acceptanceTest {
testLogging {
events "passed", "skipped", "failed"
}
}
task development << {
jvmArgs = ["-Dnakadi.config=envs/development.conf"]
//bootRun.systemProperty 'nakadi.config', 'envs/development.conf'
}
bootRun {
addResources = false
main = 'de.zalando.aruha.nakadi.Application'
environment 'NAKADI_OAUTH2_MODE', 'OFF'
}
run {
}
jacocoTestReport {
reports {
xml.enabled = true
html.enabled = true
}
}
check.dependsOn jacocoTestReport
check.dependsOn integrationTest
integrationTest.mustRunAfter test