/
build.sbt
279 lines (250 loc) · 11.1 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
271
272
273
274
275
276
277
278
279
import rapture.core.booleanRepresentations.trueFalse
import com.typesafe.sbt.SbtNativePackager.autoImport.NativePackagerHelper._
import com.typesafe.sbt.packager.docker.DockerPlugin.autoImport.{Docker, dockerRepository}
import com.typesafe.sbt.packager.docker.{Cmd, ExecCmd}
import org.knora.Dependencies
import sbt._
import sbt.Keys.version
import sbt.librarymanagement.Resolver
import scala.language.postfixOps
import scala.sys.process.Process
//////////////////////////////////////
// GLOBAL SETTINGS
//////////////////////////////////////
// when true enables run cancellation w/o exiting sbt
cancelable in Global := true
lazy val aggregatedProjects: Seq[ProjectReference] = Seq(webapi, sipi)
lazy val buildSettings = Seq(
organization := "org.knora",
version := (ThisBuild / version).value
)
lazy val rootBaseDir = ThisBuild / baseDirectory
lazy val root: Project = Project(id = "root", file("."))
.aggregate(webapi, apiMain)
.enablePlugins(GitVersioning, GitBranchPrompt)
.settings(
// values set for all sub-projects
// These are normal sbt settings to configure for release, skip if already defined
Global / onChangedBuildSource := ReloadOnSourceChanges,
ThisBuild / licenses := Seq("Apache License, Version 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
ThisBuild / homepage := Some(url("https://github.com/dasch-swiss/dsp-api")),
ThisBuild / scmInfo := Some(
ScmInfo(url("https://github.com/dasch-swiss/dsp-api"), "scm:git:git@github.com:dasch-swiss/dsp-api.git")
),
Global / scalaVersion := Dependencies.scalaVersion,
// use 'git describe' for deriving the version
git.useGitDescribe := true,
// override generated version string because docker hub rejects '+' in tags
ThisBuild / version ~= (_.replace('+', '-')),
// use Ctrl-c to stop current task but not quit SBT
Global / cancelable := true,
publish / skip := true
)
//////////////////////////////////////
// DSP's custom SIPI
//////////////////////////////////////
lazy val sipi: Project = Project(id = "sipi", base = file("sipi"))
.enablePlugins(DockerPlugin)
.settings(
Compile / packageDoc / mappings := Seq(),
Compile / packageSrc / mappings := Seq(),
Docker / dockerRepository := Some("daschswiss"),
Docker / packageName := "knora-sipi",
dockerUpdateLatest := true,
dockerBaseImage := Dependencies.sipiImage,
Docker / maintainer := "support@dasch.swiss",
Docker / dockerExposedPorts ++= Seq(1024),
Docker / defaultLinuxInstallLocation := "/sipi",
Universal / mappings ++= {
// copy the sipi/scripts folder
directory("sipi/scripts")
},
// use filterNot to return all items that do NOT meet the criteria
dockerCommands := dockerCommands.value.filterNot {
// ExecCmd is a case class, and args is a varargs variable, so you need to bind it with @
// remove ENTRYPOINT
case ExecCmd("ENTRYPOINT", args @ _*) => true
// remove CMD
case ExecCmd("CMD", args @ _*) => true
case Cmd("USER", args @ _*) => true
// don't filter the rest; don't filter out anything that doesn't match a pattern
case cmd => false
}
)
//////////////////////////////////////
// WEBAPI (./webapi)
//////////////////////////////////////
run / connectInput := true
lazy val webApiCommonSettings = Seq(
name := "webapi"
)
lazy val webapi: Project = Project(id = "webapi", base = file("webapi"))
.settings(buildSettings)
.enablePlugins(SbtTwirl, JavaAppPackaging, DockerPlugin, GatlingPlugin, JavaAgent, RevolverPlugin, BuildInfoPlugin)
.settings(
name := "webapi",
resolvers ++= Seq(
Resolver.bintrayRepo("hseeberger", "maven")
),
libraryDependencies ++= Dependencies.webapiLibraryDependencies
)
.settings(
inConfig(Test)(Defaults.testTasks ++ baseAssemblySettings)
)
.settings(
// add needed files to production jar
Compile / packageBin / mappings ++= Seq(
(rootBaseDir.value / "knora-ontologies" / "knora-admin.ttl") -> "knora-ontologies/knora-admin.ttl",
(rootBaseDir.value / "knora-ontologies" / "knora-base.ttl") -> "knora-ontologies/knora-base.ttl",
(rootBaseDir.value / "knora-ontologies" / "salsah-gui.ttl") -> "knora-ontologies/salsah-gui.ttl",
(rootBaseDir.value / "knora-ontologies" / "standoff-data.ttl") -> "knora-ontologies/standoff-data.ttl",
(rootBaseDir.value / "knora-ontologies" / "standoff-onto.ttl") -> "knora-ontologies/standoff-onto.ttl",
(rootBaseDir.value / "webapi" / "scripts" / "fuseki-repository-config.ttl.template") -> "webapi/scripts/fuseki-repository-config.ttl.template" // needed for initialization of triplestore
),
// use packaged jars (through packageBin) on classpaths instead of class directories for production
Compile / exportJars := true,
// add needed files to test jar
Test / packageBin / mappings ++= Seq(
(rootBaseDir.value / "webapi" / "scripts" / "fuseki-repository-config.ttl.template") -> "webapi/scripts/fuseki-repository-config.ttl.template", // needed for initialization of triplestore
(rootBaseDir.value / "sipi" / "config" / "sipi.docker-config.lua") -> "sipi/config/sipi.docker-config.lua"
),
// use packaged jars (through packageBin) on classpaths instead of class directories for test
Test / exportJars := true
)
.settings(
scalacOptions ++= Seq("-feature", "-unchecked", "-deprecation", "-Yresolve-term-conflict:package"),
logLevel := Level.Info,
run / javaOptions := webapiJavaRunOptions,
reStart / javaOptions ++= resolvedJavaAgents.value map { resolved =>
"-javaagent:" + resolved.artifact.absolutePath + resolved.agent.arguments
}, // allows sbt-javaagent to work with sbt-revolver
reStart / javaOptions ++= webapiJavaRunOptions,
javaAgents += Dependencies.aspectjweaver,
fork := true, // run tests in a forked JVM
Test / testForkedParallel := false, // run forked tests in parallel
Test / parallelExecution := false, // run non-forked tests in parallel
// Global / concurrentRestrictions += Tags.limit(Tags.Test, 1), // restrict the number of concurrently executing tests in all projects
Test / javaOptions ++= Seq("-Dconfig.resource=fuseki.conf") ++ webapiJavaTestOptions,
// Test / javaOptions ++= Seq("-Dakka.log-config-on-start=on"), // prints out akka config
// Test / javaOptions ++= Seq("-Dconfig.trace=loads"), // prints out config locations
Test / testOptions += Tests.Argument("-oDF"), // show full stack traces and test case durations
// add test framework for running zio-tests
Test / testFrameworks ++= Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.settings(
// prepare for publishing
// Skip packageDoc and packageSrc task on stage
Compile / packageDoc / mappings := Seq(),
Compile / packageSrc / mappings := Seq(),
// define folders inside container
Universal / mappings ++= {
// copy the scripts folder
directory("webapi/scripts") ++
// add knora-ontologies
directory("knora-ontologies") ++
// copy configuration files to config directory
contentOf("webapi/src/main/resources").toMap.mapValues("config/" + _)
},
// add 'config' directory to the classpath of the start script,
Universal / scriptClasspath := Seq("webapi/scripts", "knora-ontologies", "../config/") ++ scriptClasspath.value,
// need this here, so that the Manifest inside the jars has the correct main class set.
Compile / mainClass := Some("org.knora.webapi.app.Main"),
// add dockerCommands used to create the image
// docker:stage, docker:publishLocal, docker:publish, docker:clean
Docker / dockerRepository := Some("daschswiss"),
Docker / packageName := "knora-api",
dockerUpdateLatest := true,
dockerBaseImage := "eclipse-temurin:17-jre-focal",
Docker / maintainer := "support@dasch.swiss",
Docker / dockerExposedPorts ++= Seq(3333),
Docker / defaultLinuxInstallLocation := "/opt/docker",
// use filterNot to return all items that do NOT meet the criteria
dockerCommands := dockerCommands.value.filterNot {
// Remove USER command
case Cmd("USER", args @ _*) => true
// don't filter the rest; don't filter out anything that doesn't match a pattern
case cmd => false
}
)
.settings(
buildInfoKeys ++= Seq[BuildInfoKey](
name,
version,
"akkaHttp" -> Dependencies.akkaHttpVersion,
"sipi" -> Dependencies.sipiImage,
"fuseki" -> Dependencies.fusekiImage
),
buildInfoPackage := "org.knora.webapi.http.version"
)
lazy val webapiJavaRunOptions = Seq(
// "-showversion",
"-Xms1G",
"-Xmx1G",
// "-verbose:gc",
//"-XX:+UseG1GC",
//"-XX:MaxGCPauseMillis=500"
"-Dcom.sun.management.jmxremote",
// "-Dcom.sun.management.jmxremote.port=1617",
"-Dcom.sun.management.jmxremote.authenticate=false",
"-Dcom.sun.management.jmxremote.ssl=false"
//"-agentpath:/Applications/YourKit-Java-Profiler-2018.04.app/Contents/Resources/bin/mac/libyjpagent.jnilib"
)
lazy val webapiJavaTestOptions = Seq(
// "-showversion",
"-Xms1G",
"-Xmx1G"
// "-verbose:gc",
//"-XX:+UseG1GC",
//"-XX:MaxGCPauseMillis=500",
//"-XX:MaxMetaspaceSize=4096m"
)
//////////////////////////////////////
// DSP's new codebase
//////////////////////////////////////
lazy val apiMain = project
.in(file("dsp-api-main"))
.settings(
name := "dsp-api-main",
libraryDependencies ++= Dependencies.dspApiMainLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.dependsOn(schemaCore, schemaRepo, schemaApi)
lazy val schemaApi = project
.in(file("dsp-schema/api"))
.settings(
name := "schemaApi",
libraryDependencies ++= Dependencies.schemaApiLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.dependsOn(schemaCore)
lazy val schemaCore = project
.in(file("dsp-schema/core"))
.settings(
name := "schemaCore",
libraryDependencies ++= Dependencies.schemaCoreLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
lazy val schemaRepo = project
.in(file("dsp-schema/repo"))
.settings(
name := "schemaRepo",
libraryDependencies ++= Dependencies.schemaRepoLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.dependsOn(schemaCore)
lazy val schemaRepoEventStoreService = project
.in(file("dsp-schema/repo-eventstore-service"))
.settings(
name := "schemaRepoEventstoreService",
libraryDependencies ++= Dependencies.schemaRepoEventStoreServiceLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.dependsOn(schemaRepo)
lazy val schemaRepoSearchService = project
.in(file("dsp-schema/repo-search-service"))
.settings(
name := "dsp-schema-repo-search-service",
libraryDependencies ++= Dependencies.schemaRepoSearchServiceLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.dependsOn(schemaRepo)