forked from linkerd/linkerd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinkerdBuild.scala
606 lines (522 loc) · 19.3 KB
/
LinkerdBuild.scala
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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
import sbt._
import sbt.Keys._
import sbtassembly.AssemblyKeys._
import sbtdocker.DockerKeys._
import sbtunidoc.Plugin._
import scoverage.ScoverageKeys._
import pl.project13.scala.sbt.JmhPlugin
object LinkerdBuild extends Base {
val Minimal = config("minimal")
val Bundle = config("bundle") extend Minimal
val Dcos = config("dcos") extend Bundle
val consul = projectDir("consul")
.withTwitterLib(Deps.finagle("http"))
.withLibs(Deps.jackson)
.withTests()
val etcd = projectDir("etcd")
.withTwitterLib(Deps.finagle("http"))
.withLibs(Deps.jackson ++ Deps.jodaTime)
.withTests().withIntegration()
lazy val k8s = projectDir("k8s")
.dependsOn(Namer.core)
.withTwitterLib(Deps.finagle("http"))
.withLibs(Deps.jackson)
.withTests()
val marathon = projectDir("marathon")
.withTwitterLib(Deps.finagle("http"))
.withLibs(Deps.jackson)
.withTests()
object Router {
val core = projectDir("router/core")
.withTwitterLib(Deps.finagle("core"))
.withTests()
.withE2e()
.settings(coverageExcludedPackages := ".*XXX_.*")
val http = projectDir("router/http")
.dependsOn(core)
.withTwitterLibs(Deps.finagle("http"))
.withTests()
.withE2e()
val mux = projectDir("router/mux")
.dependsOn(core)
.withTwitterLib(Deps.finagle("mux"))
.withE2e()
val thriftIdl = projectDir("router/thrift-idl")
.withTwitterLib(Deps.finagle("thrift"))
.settings(coverageExcludedPackages := ".*thriftscala.*")
val thrift = projectDir("router/thrift")
.withTwitterLib(Deps.finagle("thrift"))
.withTests()
.withE2e()
.dependsOn(
core,
thriftIdl % "test,e2e"
)
val all = projectDir("router")
.settings(aggregateSettings)
.aggregate(core, http, mux, thrift)
}
val configCore = projectDir("config")
.withTwitterLibs(Deps.finagle("core"))
.withLibs(Deps.jackson)
.withLib(Deps.jacksonYaml)
object Namer {
val core = projectDir("namer/core")
.dependsOn(configCore)
.withLib(Deps.jacksonCore)
.withTests()
val consul = projectDir("namer/consul")
.dependsOn(LinkerdBuild.consul, core)
.withTests()
val fs = projectDir("namer/fs")
.dependsOn(core % "compile->compile;test->test")
.withTests()
val k8s = projectDir("namer/k8s")
.dependsOn(LinkerdBuild.k8s, core)
.withTests()
val marathon = projectDir("namer/marathon")
.dependsOn(LinkerdBuild.marathon, core)
.withTests()
val serversets = projectDir("namer/serversets")
.withTwitterLib(Deps.finagle("serversets").exclude("org.slf4j", "slf4j-jdk14"))
.withTests()
.dependsOn(core % "compile->compile;test->test")
val zkLeader = projectDir("namer/zk-leader")
.dependsOn(core)
.withLib(Deps.zkCandidate)
.withTests()
val all = projectDir("namer")
.settings(aggregateSettings)
.aggregate(core, consul, fs, k8s, marathon, serversets, zkLeader)
}
val admin = projectDir("admin")
.dependsOn(configCore, Namer.core)
.withTwitterLib(Deps.twitterServer)
.withTwitterLib(Deps.finagle("stats"))
.withTests()
object Telemetry {
val core = projectDir("telemetry/core")
.dependsOn(configCore)
.withTwitterLib(Deps.finagle("core"))
.withTwitterLib(Deps.finagle("stats") % Test)
.withTests()
val tracelog = projectDir("telemetry/tracelog")
.dependsOn(core, Router.core)
.withTests()
val all = projectDir("telemetry")
.settings(aggregateSettings)
.aggregate(core, tracelog)
}
val ConfigFileRE = """^(.*)\.yaml$""".r
val execScriptJvmOptions =
"""|DEFAULT_JVM_OPTIONS="-Djava.net.preferIPv4Stack=true \
| -Dsun.net.inetaddr.ttl=60 \
| -Xms${JVM_HEAP_MIN:-32M} \
| -Xmx${JVM_HEAP_MAX:-1024M} \
| -XX:+AggressiveOpts \
| -XX:+UseConcMarkSweepGC \
| -XX:+CMSParallelRemarkEnabled \
| -XX:+CMSClassUnloadingEnabled \
| -XX:+ScavengeBeforeFullGC \
| -XX:+CMSScavengeBeforeRemark \
| -XX:+UseCMSInitiatingOccupancyOnly \
| -XX:CMSInitiatingOccupancyFraction=70 \
| -XX:-TieredCompilation \
| -XX:+UseStringDeduplication "
|""".stripMargin
object Namerd {
val core = projectDir("namerd/core")
.dependsOn(
admin,
configCore,
Namer.core,
Namer.fs % "test"
)
.withTests()
object Storage {
val inMemory = projectDir("namerd/storage/in-memory")
.dependsOn(core % "test->test;compile->compile")
.withTests()
val etcd = projectDir("namerd/storage/etcd")
.dependsOn(core, LinkerdBuild.etcd % "integration->integration;compile->compile")
.withTests()
.withIntegration()
val zk = projectDir("namerd/storage/zk")
.dependsOn(core)
.withTwitterLib(Deps.finagle("serversets").exclude("org.slf4j", "slf4j-jdk14"))
.withTests()
val k8s = projectDir("namerd/storage/k8s")
.dependsOn(core)
.dependsOn(LinkerdBuild.k8s)
.withTests()
val consul = projectDir("namerd/storage/consul")
.dependsOn(core)
.dependsOn(LinkerdBuild.consul)
.withTests()
val all = projectDir("namerd/storage")
.settings(aggregateSettings)
.aggregate(inMemory, zk, k8s, etcd, consul)
}
object Iface {
val controlHttp = projectDir("namerd/iface/control-http")
.withTwitterLib(Deps.finagle("http"))
.withTests().dependsOn(
core % "test->test;compile->compile",
Storage.inMemory % "test"
)
val interpreterThriftIdl = projectDir("namerd/iface/interpreter-thrift-idl")
.withTwitterLib(Deps.finagle("thrift"))
.settings(coverageExcludedPackages := ".*thriftscala.*")
val interpreterThrift = projectDir("namerd/iface/interpreter-thrift")
.dependsOn(core)
.dependsOn(interpreterThriftIdl)
.withLib(Deps.guava)
.withTwitterLibs(Deps.finagle("thrift"), Deps.finagle("thriftmux"))
.withTests()
val all = projectDir("namerd/iface")
.settings(aggregateSettings)
.aggregate(controlHttp, interpreterThriftIdl, interpreterThrift)
}
val main = projectDir("namerd/main")
.dependsOn(core, admin, configCore)
.withBuildProperties()
.settings(coverageExcludedPackages := ".*")
/**
* An assembly-running script that adds the namerd plugin directory
* to the classpath if it exists.
*/
val execScript = (
"""|#!/bin/sh
|
|jars="$0"
|if [ -n "$NAMERD_HOME" ] && [ -d $NAMERD_HOME/plugins ]; then
| for jar in $NAMERD_HOME/plugins/*.jar ; do
| jars="$jars:$jar"
| done
|fi
|""" +
execScriptJvmOptions +
"""|exec ${JAVA_HOME:-/usr}/bin/java -XX:+PrintCommandLineFlags \
| ${JVM_OPTIONS:-$DEFAULT_JVM_OPTIONS} -cp $jars -server \
| io.buoyant.namerd.Main "$@"
|"""
).stripMargin
val Minimal = config("minimal")
val MinimalSettings = Defaults.configSettings ++ appPackagingSettings ++ Seq(
mainClass := Some("io.buoyant.namerd.Main"),
assemblyExecScript := execScript.split("\n").toSeq,
dockerEnvPrefix := "NAMERD_",
unmanagedBase := baseDirectory.value / "plugins"
)
val Bundle = config("bundle") extend Minimal
val BundleSettings = MinimalSettings ++ Seq(
assemblyJarName in assembly := s"${name.value}-${version.value}-exec",
dockerTag := version.value
)
/**
* A DCOS-specific assembly-running script that:
* 1) adds the namerd plugin directory to the classpath if it exists
* 2) bootstraps zookeeper with a default path and dtabs
* 3) boots namerd
*/
val dcosExecScript = (
"""|#!/bin/sh
|
|jars="$0"
|if [ -n "$NAMERD_HOME" ] && [ -d $NAMERD_HOME/plugins ]; then
| for jar in $NAMERD_HOME/plugins/*.jar ; do
| jars="$jars:$jar"
| done
|fi
|""" +
execScriptJvmOptions +
"""|${JAVA_HOME:-/usr}/bin/java -XX:+PrintCommandLineFlags \
|${JVM_OPTIONS:-$DEFAULT_JVM_OPTIONS} -cp $jars -server \
|io.buoyant.namerd.DcosBootstrap "$@"
|
|${JAVA_HOME:-/usr}/bin/java -XX:+PrintCommandLineFlags \
|${JVM_OPTIONS:-$DEFAULT_JVM_OPTIONS} -cp $jars -server \
|io.buoyant.namerd.Main "$@"
|
|exit
|"""
).stripMargin
val dcosBootstrap = projectDir("namerd/dcos-bootstrap")
.dependsOn(core, admin, configCore, Storage.zk)
val DcosSettings = MinimalSettings ++ Seq(
assemblyExecScript := dcosExecScript.split("\n").toSeq
)
val all = projectDir("namerd")
.settings(aggregateSettings)
.aggregate(core, dcosBootstrap, Storage.all, Iface.all, main)
.configs(Minimal, Bundle, Dcos)
// Minimal cofiguration includes a runtime, HTTP routing and the
// fs service discovery.
.configDependsOn(Minimal)(
core, main, Namer.fs, Storage.inMemory, Router.http,
Iface.controlHttp, Iface.interpreterThrift
)
.settings(inConfig(Minimal)(MinimalSettings))
.withTwitterLib(Deps.finagle("stats") % Minimal)
// Bundle includes all of the supported features:
.configDependsOn(Bundle)(
Namer.consul, Namer.k8s, Namer.marathon, Namer.serversets,
Storage.etcd, Storage.inMemory, Storage.k8s, Storage.zk, Storage.consul
)
.settings(inConfig(Bundle)(BundleSettings))
.configDependsOn(Dcos)(dcosBootstrap)
.settings(inConfig(Dcos)(DcosSettings))
.settings(
assembly <<= assembly in Bundle,
docker <<= docker in Bundle,
dockerBuildAndPush <<= dockerBuildAndPush in Bundle,
dockerPush <<= dockerPush in Bundle
)
// Find example configurations by searching the examples directory for config files.
val exampleConfigs = file("namerd/examples").list().toSeq.collect {
case ConfigFileRE(name) => config(name) -> exampleConfig(name)
}
def exampleConfig(name: String): Configuration = name match {
case "basic" => Minimal
case _ => Bundle
}
val examples = projectDir("namerd/examples")
.withExamples(Namerd.all, exampleConfigs)
}
object Interpreter {
val namerd = projectDir("interpreter/namerd")
.withTests()
.dependsOn(Namer.core, Namerd.Iface.interpreterThrift)
val fs = projectDir("interpreter/fs")
.withTests()
.dependsOn(Namer.core, Namer.fs)
val all = projectDir("interpreter")
.settings(aggregateSettings)
.aggregate(namerd, fs)
}
object Linkerd {
val core = projectDir("linkerd/core")
.dependsOn(
configCore,
LinkerdBuild.admin,
Telemetry.core % "compile->compile;test->test",
Namer.core % "compile->compile;test->test",
Router.core
)
.withLib(Deps.jacksonCore)
.withTests()
.configWithLibs(Test)(Deps.jacksonDatabind, Deps.jacksonYaml)
.withBuildProperties()
val tls = projectDir("linkerd/tls")
.dependsOn(core)
.withTests()
object Protocol {
val http = projectDir("linkerd/protocol/http")
.withTests().withE2e().withIntegration()
.withTwitterLibs(Deps.finagle("netty4-http"))
.dependsOn(
core % "compile->compile;e2e->test;integration->test",
tls % "integration",
Namer.fs % "integration",
Router.http)
val mux = projectDir("linkerd/protocol/mux")
.dependsOn(core, Router.mux)
val thrift = projectDir("linkerd/protocol/thrift")
.dependsOn(core, Router.thrift)
.withTests()
val all = projectDir("linkerd/protocol")
.settings(aggregateSettings)
.aggregate(http, mux, thrift)
val benchmark = projectDir("linkerd/protocol/benchmark")
.dependsOn(http, Protocol.http)
.withTests()
.withTwitterLib(Deps.twitterUtil("benchmark"))
.enablePlugins(JmhPlugin)
}
object Tracer {
val zipkin = projectDir("linkerd/tracer/zipkin")
.withTwitterLibs(Deps.finagle("zipkin-core"), Deps.finagle("zipkin"))
.dependsOn(core)
.withTests()
val all = projectDir("linkerd/tracer")
.settings(aggregateSettings)
.aggregate(zipkin)
}
object Announcer {
val serversets = projectDir("linkerd/announcer/serversets")
.withTwitterLib(Deps.finagle("serversets").exclude("org.slf4j", "slf4j-jdk14"))
.dependsOn(core)
val all = projectDir("linkerd/announcer")
.aggregate(serversets)
}
val admin = projectDir("linkerd/admin")
.withTwitterLib(Deps.twitterServer)
.withTests()
.dependsOn(core % "compile->compile;test->test")
.dependsOn(LinkerdBuild.admin, Namer.core)
.dependsOn(Protocol.thrift % "test")
val main = projectDir("linkerd/main")
.dependsOn(admin, configCore, core, LinkerdBuild.admin)
.withTwitterLib(Deps.twitterServer)
.withLibs(Deps.jacksonCore, Deps.jacksonDatabind, Deps.jacksonYaml)
.withBuildProperties()
.settings(coverageExcludedPackages := ".*")
/*
* linkerd packaging configurations.
*
* linkerd is configured to be assembled into an executable and may
* be assembled into a dockerfile.
*/
/**
* An assembly-running script that adds the linkerd plugin directory
* to the classpath if it exists.
*/
val execScript = (
"""|#!/bin/sh
|
|jars="$0"
|if [ -n "$L5D_HOME" ] && [ -d $L5D_HOME/plugins ]; then
| for jar in $L5D_HOME/plugins/*.jar ; do
| jars="$jars:$jar"
| done
|fi
|""" +
execScriptJvmOptions +
"""|exec ${JAVA_HOME:-/usr}/bin/java -XX:+PrintCommandLineFlags \
| ${JVM_OPTIONS:-$DEFAULT_JVM_OPTIONS} -cp $jars -server \
| io.buoyant.Linkerd "$@"
|"""
).stripMargin
val MinimalSettings = Defaults.configSettings ++ appPackagingSettings ++ Seq(
mainClass := Some("io.buoyant.Linkerd"),
assemblyExecScript := execScript.split("\n").toSeq,
dockerEnvPrefix := "L5D_",
unmanagedBase := baseDirectory.value / "plugins"
)
val BundleSettings = MinimalSettings ++ Seq(
assemblyJarName in assembly := s"${name.value}-${version.value}-exec",
dockerTag := version.value
)
val all = projectDir("linkerd")
.settings(aggregateSettings)
.aggregate(admin, core, main, configCore, Namer.all, Protocol.all, Tracer.all, Announcer.all, tls)
.configs(Minimal, Bundle)
// Minimal cofiguration includes a runtime, HTTP routing and the
// fs service discovery.
.configDependsOn(Minimal)(admin, core, main, configCore, Namer.fs, Protocol.http, Telemetry.tracelog)
.settings(inConfig(Minimal)(MinimalSettings))
.withTwitterLib(Deps.finagle("stats") % Minimal)
// Bundle is includes all of the supported features:
.configDependsOn(Bundle)(
Namer.consul, Namer.k8s, Namer.marathon, Namer.serversets, Namer.zkLeader,
Interpreter.namerd, Interpreter.fs,
Protocol.mux, Protocol.thrift,
Announcer.serversets,
Telemetry.core, Telemetry.tracelog,
Tracer.zipkin,
tls)
.settings(inConfig(Bundle)(BundleSettings))
.settings(
assembly <<= assembly in Bundle,
docker <<= docker in Bundle,
dockerBuildAndPush <<= dockerBuildAndPush in Bundle,
dockerPush <<= dockerPush in Bundle
)
// Find example configurations by searching the examples directory for config files.
val exampleConfigs = file("linkerd/examples").list().toSeq.collect {
case ConfigFileRE(name) => config(name) -> exampleConfig(name)
}
def exampleConfig(name: String): Configuration = name match {
case "http" => Minimal
case _ => Bundle
}
val examples = projectDir("linkerd/examples")
.withExamples(Linkerd.all, exampleConfigs)
}
val validateAssembled = taskKey[Unit]("run validation against assembled artifacts")
val validator = projectDir("validator")
.withTwitterLibs(Deps.twitterServer, Deps.twitterUtil("events"), Deps.finagle("http"))
.settings(
mainClass := Some("io.buoyant.namerd.Validator"),
validateAssembled := (Def.taskDyn {
val linkerd = (assembly in Bundle in Linkerd.all).value
val namerd = (assembly in Bundle in Namerd.all).value
Def.task {
(run in Compile).toTask(s" -linkerd.exec=$linkerd -namerd.exec=$namerd").value
}
}).value,
coverageExcludedPackages := ".*"
)
// All projects must be exposed at the root of the object in
// dependency-order:
val router = Router.all
val routerCore = Router.core
val routerHttp = Router.http
val routerMux = Router.mux
val routerThrift = Router.thrift
val routerThriftIdl = Router.thriftIdl
val telemetry = Telemetry.all
val telemetryCore = Telemetry.core
val telemetryTracelog = Telemetry.tracelog
val namer = Namer.all
val namerCore = Namer.core
val namerConsul = Namer.consul
val namerFs = Namer.fs
val namerK8s = Namer.k8s
val namerMarathon = Namer.marathon
val namerServersets = Namer.serversets
val namerZkLeader = Namer.zkLeader
val namerd = Namerd.all
val namerdExamples = Namerd.examples
val namerdCore = Namerd.core
val namerdDcosBootstrap = Namerd.dcosBootstrap
val namerdIfaceControlHttp = Namerd.Iface.controlHttp
val namerdIfaceInterpreterThriftIdl = Namerd.Iface.interpreterThriftIdl
val namerdIfaceInterpreterThrift = Namerd.Iface.interpreterThrift
val namerdStorageEtcd = Namerd.Storage.etcd
val namerdStorageInMemory = Namerd.Storage.inMemory
val namerdStorageK8s = Namerd.Storage.k8s
val namerdStorageZk = Namerd.Storage.zk
val namerdStorageConsul = Namerd.Storage.consul
val namerdStorage = Namerd.Storage.all
val namerdIface = Namerd.Iface.all
val namerdMain = Namerd.main
val interpreter = Interpreter.all
val interpreterNamerd = Interpreter.namerd
val interpreterFs = Interpreter.fs
val linkerd = Linkerd.all
val linkerdBenchmark = Linkerd.Protocol.benchmark
val linkerdExamples = Linkerd.examples
val linkerdAdmin = Linkerd.admin
val linkerdConfig = configCore
val linkerdCore = Linkerd.core
val linkerdMain = Linkerd.main
val linkerdProtocol = Linkerd.Protocol.all
val linkerdProtocolHttp = Linkerd.Protocol.http
val linkerdProtocolMux = Linkerd.Protocol.mux
val linkerdProtocolThrift = Linkerd.Protocol.thrift
val linkerdTracer = Linkerd.Tracer.all
val linkerdTracerZipkin = Linkerd.Tracer.zipkin
val linkerdAnnouncer = Linkerd.Announcer.all
val linkerdAnnouncerServersets = Linkerd.Announcer.serversets
val linkerdTls = Linkerd.tls
// Unified documentation via the sbt-unidoc plugin
val all = project("all", file("."))
.settings(unidocSettings)
.settings(aggregateSettings)
.aggregate(
admin,
configCore,
consul,
etcd,
k8s,
marathon,
testUtil,
Interpreter.all,
Linkerd.all,
Namer.all,
Namerd.all,
Router.all,
Telemetry.all
)
}