-
Notifications
You must be signed in to change notification settings - Fork 18
/
build.sbt
270 lines (270 loc) · 11.5 KB
/
build.sbt
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
/*
* Copyright 2018-2020 Radicalbit S.r.l.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.typesafe.sbt.SbtMultiJvm
import com.typesafe.sbt.SbtMultiJvm.MultiJvmKeys.MultiJvm
import com.typesafe.sbt.packager.docker.{Cmd, ExecCmd}
import Path.relativeTo
lazy val root = project
.in(file("."))
.settings(
name := "nsdb",
publish := {},
publishLocal := {}
)
.aggregate(
`nsdb-common`,
`nsdb-core`,
`nsdb-http`,
`nsdb-cluster`,
`nsdb-security`,
`nsdb-rpc`,
`nsdb-java-api`,
`nsdb-scala-api`,
`nsdb-sql`,
`nsdb-cli`,
`nsdb-perf`,
`nsdb-minicluster`,
`nsdb-it`
)
lazy val packageDist = taskKey[File]("create universal package and move it to package folder")
lazy val packageDeb = taskKey[File]("create debian package and move it to package folder")
lazy val packageRpm = taskKey[File]("create RPM package and move it to package folder")
addCommandAlias("fix", "all compile:scalafix test:scalafix")
addCommandAlias("fixCheck", "; compile:scalafix --check ; test:scalafix --check")
addCommandAlias("dist", "packageDist")
addCommandAlias("deb", "packageDeb")
addCommandAlias("rpm", "packageRpm")
addCommandAlias("testAll", "test; multi-jvm:test; it:test")
lazy val `nsdb-common` = project
.settings(Commons.crossScalaVersionSettings: _*)
.settings(PublishSettings.settings: _*)
.enablePlugins(AutomateHeaderPlugin)
.enablePlugins(BuildInfoPlugin)
.settings(
buildInfoKeys := Seq[BuildInfoKey](version),
buildInfoPackage := "io.radicalbit.nsdb"
)
.settings(LicenseHeader.settings: _*)
.settings(libraryDependencies ++= Dependencies.Common.libraries)
lazy val `nsdb-core` = project
.settings(Commons.settings: _*)
.settings(PublishSettings.dontPublish: _*)
.enablePlugins(AutomateHeaderPlugin)
.settings(LicenseHeader.settings: _*)
.settings(libraryDependencies ++= Dependencies.Core.libraries)
.dependsOn(`nsdb-common` % "compile->compile;test->test")
lazy val `nsdb-http` = project
.settings(Commons.settings: _*)
.settings(PublishSettings.dontPublish: _*)
.enablePlugins(AutomateHeaderPlugin)
.settings(LicenseHeader.settings: _*)
.settings(libraryDependencies ++= Dependencies.Http.libraries)
.dependsOn(`nsdb-core` % "compile->compile;test->test", `nsdb-sql`, `nsdb-security`)
lazy val `nsdb-rpc` = project
.settings(Commons.crossScalaVersionSettings: _*)
.settings(PublishSettings.settings: _*)
.settings(libraryDependencies ++= Dependencies.RPC.libraries)
.settings(coverageExcludedPackages := "io\\.radicalbit\\.nsdb.*")
.settings(
Compile / PB.targets := Seq(
scalapb.gen() -> (Compile / sourceManaged).value
),
Test / PB.targets := Seq(
scalapb.gen() -> (Test / sourceManaged).value
)
)
.settings(LicenseHeader.settings: _*)
.enablePlugins(AutomateHeaderPlugin)
.dependsOn(`nsdb-sql`, `nsdb-security`, `nsdb-core`, `nsdb-common` % "compile->compile;test->test")
lazy val `nsdb-cluster` = project
.settings(Commons.settings: _*)
.settings(PublishSettings.dontPublish: _*)
.enablePlugins(JavaServerAppPackaging, SbtNativePackager)
.settings(libraryDependencies ++= Dependencies.Cluster.libraries)
.enablePlugins(MultiJvmPlugin)
.configs(MultiJvm)
.enablePlugins(AutomateHeaderPlugin)
.settings(LicenseHeader.settings: _*)
.settings(bashScriptDefines / scriptClasspath += "../ext-lib/*")
.settings(SbtMultiJvm.multiJvmSettings)
.configs(MultiJvm)
.settings(
/* Docker Settings - to create, run as:
$ sbt `project nsdb-cluster` docker:publishLocal
See here for details:
http://www.scala-sbt.org/sbt-native-packager/formats/docker.html
*/
Docker / packageName := "nsdb",
Docker / mappings ++= {
val confDir = baseDirectory.value / "src/main/resources"
val confResources = ((confDir ** "*" --- confDir) pair (relativeTo(confDir), false)).filterNot{case (_,name) => name.contains("application")}
for {
(file, relativePath) <- confResources
} yield file -> s"/opt/${(Docker / packageName).value}/conf/$relativePath"
},
Docker / mappings ++= {
val scriptDir = baseDirectory.value / "../docker-scripts"
for {
(file, relativePath) <- (scriptDir ** "*" --- scriptDir) pair (relativeTo(scriptDir), false)
} yield file -> s"/opt/${(Docker / packageName).value}/bin/$relativePath"
},
Docker / version := version.value,
Docker / maintainer := organization.value,
dockerRepository := Some("weareradicalbit"),
Docker / defaultLinuxInstallLocation := s"/opt/${(Docker / packageName).value}",
dockerCommands := Seq(
Cmd("FROM", "adoptopenjdk/openjdk11:alpine-slim"),
Cmd("LABEL", s"""MAINTAINER="${organization.value}""""),
Cmd("RUN", "apk add", "--no-cache", "bash", "udev"),
Cmd("WORKDIR", s"/opt/${(Docker / packageName).value}"),
Cmd("RUN", "addgroup", "-S", "nsdb", "&&", "adduser", "-S", "nsdb", "-G", "nsdb"),
Cmd("ADD", "opt", "/opt"),
ExecCmd("RUN", "chown", "-R", "nsdb:nsdb", "."),
Cmd("USER", "nsdb"),
Cmd("HEALTHCHECK", "--timeout=3s", "CMD", "bin/nsdb-healthcheck"),
Cmd("CMD", "bin/nsdb-cluster -Dlogback.configurationFile=conf/logback.xml -DconfDir=conf/")
)
)
.settings(
/* Debian Settings - to create, run as:
$ sbt `project nsdb-cluster` debian:packageBin
See here for details:
http://www.scala-sbt.org/sbt-native-packager/formats/debian.html
*/
Debian / name := "nsdb",
Debian / version := version.value,
Debian / maintainer := "Radicalbit <[email protected]>",
Debian / packageSummary := "NSDb is an open source, brand new distributed time series Db, streaming oriented, optimized for the serving layer and completely based on Scala and Akka",
Debian / packageDescription := "NSDb is an open source, brand new distributed time series Db, streaming oriented, optimized for the serving layer and completely based on Scala and Akka",
packageDeb := {
val distFile = (Debian / packageBin).value
val output = baseDirectory.value / ".." / "package" / distFile.getName
IO.move(distFile, output)
output
}
)
.settings(
/* RPM Settings - to create, run as:
$ sbt `project nsdb-cluster` rpm:packageBin
See here for details:
http://www.scala-sbt.org/sbt-native-packager/formats/rpm.html
*/
Rpm / version := version.value,
Rpm / packageName := "nsdb",
rpmRelease := "1",
Rpm / packageSummary := "NSDb is an open source, brand new distributed time series Db, streaming oriented, optimized for the serving layer and completely based on Scala and Akka",
Rpm / packageDescription := "NSDb is an open source, brand new distributed time series Db, streaming oriented, optimized for the serving layer and completely based on Scala and Akka",
rpmVendor := "Radicalbit",
rpmUrl := Some("https://github.com/radicalbit/NSDb"),
rpmLicense := Some("Apache"),
packageRpm := {
val distFile = (Rpm / packageBin).value
val output = baseDirectory.value / ".." / "package" / distFile.getName
IO.move(distFile, output)
output
}
)
.settings(
/* Universal Settings - to create, run as:
$ sbt `project nsdb-cluster` universal:packageBin
See here for details:
http://www.scala-sbt.org/sbt-native-packager/formats/universal.html
*/
Universal / packageName := s"nsdb-${version.value}",
Universal / mappings ++= {
val confDir = baseDirectory.value / "src/main/resources"
val confResources = ((confDir ** "*" --- confDir) pair (relativeTo(confDir), false)).filterNot{case (_,name) => name.contains("application")}
for {
(file, relativePath) <- confResources
} yield file -> s"conf/$relativePath"
},
Compile / discoveredMainClasses ++= (`nsdb-cli` / Compile / discoveredMainClasses).value,
bashScriptDefines ++= Seq(
"""addJava "-DconfDir=${app_home}/../conf"""",
"""addJava "-Dlogback.configurationFile=${app_home}/../conf/logback.xml""""
),
packageDist := {
val distFile = (Universal / packageBin).value
val output = baseDirectory.value / ".." / "package" / distFile.getName
IO.move(distFile, output)
output
}
)
.dependsOn(`nsdb-core` % "compile->compile;test->test", `nsdb-security`, `nsdb-http`, `nsdb-rpc`, `nsdb-cli`)
lazy val `nsdb-security` = project
.settings(Commons.settings: _*)
.settings(PublishSettings.settings: _*)
.settings(crossPaths := false)
.enablePlugins(AutomateHeaderPlugin)
.settings(LicenseHeader.settings: _*)
lazy val `nsdb-sql` = project
.settings(Commons.crossScalaVersionSettings: _*)
.settings(PublishSettings.settings: _*)
.settings(libraryDependencies ++= Dependencies.SQL.libraries)
.enablePlugins(AutomateHeaderPlugin)
.settings(LicenseHeader.settings: _*)
.dependsOn(`nsdb-common` % "compile->compile;test->test")
lazy val `nsdb-java-api` = project
.settings(Commons.settings: _*)
.settings(crossPaths := false)
.settings(PublishSettings.settings: _*)
.settings(libraryDependencies ++= Dependencies.JavaAPI.libraries)
.enablePlugins(AutomateHeaderPlugin)
.settings(LicenseHeader.settings: _*)
.dependsOn(`nsdb-rpc`)
lazy val `nsdb-scala-api` = project
.settings(Commons.crossScalaVersionSettings: _*)
.settings(PublishSettings.settings: _*)
.settings(libraryDependencies ++= Dependencies.ScalaAPI.libraries)
.enablePlugins(AutomateHeaderPlugin)
.settings(LicenseHeader.settings: _*)
.dependsOn(`nsdb-rpc`)
lazy val `nsdb-cli` = project
.settings(Commons.settings: _*)
.settings(PublishSettings.dontPublish: _*)
.settings(libraryDependencies ++= Dependencies.CLI.libraries)
.settings(coverageExcludedPackages := "io\\.radicalbit\\.nsdb.*")
.enablePlugins(AutomateHeaderPlugin)
.settings(LicenseHeader.settings: _*)
.dependsOn(`nsdb-rpc`)
.dependsOn(`nsdb-common` % "compile->compile;test->test")
lazy val `nsdb-perf` = (project in file("nsdb-perf"))
.settings(Commons.settings: _*)
.settings(PublishSettings.dontPublish: _*)
.settings(libraryDependencies ++= Dependencies.Performance.libraries)
.enablePlugins(AutomateHeaderPlugin)
.settings(LicenseHeader.settings: _*)
.enablePlugins(GatlingPlugin)
lazy val `nsdb-minicluster` = (project in file("nsdb-minicluster"))
.settings(Commons.settings: _*)
.settings(PublishSettings.settings: _*)
.enablePlugins(AutomateHeaderPlugin)
.settings(LicenseHeader.settings: _*)
.settings(libraryDependencies ++= Dependencies.Minicluster.libraries)
.dependsOn(`nsdb-cluster`)
.dependsOn(`nsdb-scala-api`)
lazy val `nsdb-it` = (project in file("nsdb-it"))
.settings(Commons.settings: _*)
.settings(PublishSettings.dontPublish: _*)
.enablePlugins(AutomateHeaderPlugin)
.settings(LicenseHeader.settings: _*)
.settings(libraryDependencies ++= Dependencies.It.libraries)
.configs(IntegrationTest)
.settings(Defaults.itSettings)
.dependsOn(`nsdb-minicluster`)
ThisBuild / scalafmtOnCompile := true
// make run command include the provided dependencies
Compile / run := Defaults.runTask(Compile / fullClasspath, Compile / run / mainClass, Compile / run / runner)