-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.sbt
450 lines (414 loc) · 15.6 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
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
import _root_.cats.effect.kernel.syntax.resource
import Settings.Libraries._
import Settings.LibraryVersions
import Common._
import sbt.Keys._
import NativePackagerHelper._
import org.scalajs.linker.interface.ModuleSplitStyle
import scala.sys.process._
import sbt.nio.file.FileTreeView
val build = taskKey[File]("Build module for deployment")
name := "observe"
ThisBuild / dockerExposedPorts ++= Seq(9090, 9091) // Must match deployed app.conf web-server.port
ThisBuild / dockerBaseImage := "eclipse-temurin:17-jre"
// TODO REMOVE ONCE THIS WORKS AGAIN
ThisBuild / tlCiScalafmtCheck := false
ThisBuild / tlCiScalafixCheck := false
ThisBuild / resolvers := List(Resolver.mavenLocal)
val pushCond = "github.event_name == 'push'"
val prCond = "github.event_name == 'pull_request'"
val mainCond = "github.ref == 'refs/heads/main'"
val notMainCond = "github.ref != 'refs/heads/main'"
val geminiRepoCond = "startsWith(github.repository, 'gemini')"
val notDependabotCond = "github.actor != 'dependabot[bot]'"
val isMergedCond = "github.event.pull_request.merged == true"
def allConds(conds: String*) = conds.mkString("(", " && ", ")")
def anyConds(conds: String*) = conds.mkString("(", " || ", ")")
val faNpmAuthToken = "FONTAWESOME_NPM_AUTH_TOKEN" -> "${{ secrets.FONTAWESOME_NPM_AUTH_TOKEN }}"
val herokuToken = "HEROKU_API_KEY" -> "${{ secrets.HEROKU_API_KEY }}"
ThisBuild / githubWorkflowSbtCommand := "sbt -v -J-Xmx6g"
ThisBuild / githubWorkflowEnv += faNpmAuthToken
ThisBuild / githubWorkflowEnv += herokuToken
lazy val setupNodeNpmInstall =
List(
WorkflowStep.Use(
UseRef.Public("actions", "setup-node", "v4"),
name = Some("Setup Node.js"),
params = Map(
"node-version" -> "20",
"cache" -> "npm",
"cache-dependency-path" -> "modules/web/client/package-lock.json"
)
),
WorkflowStep.Use(
UseRef.Public("actions", "cache", "v3"),
name = Some("Cache node_modules"),
id = Some("cache-node_modules"),
params = {
val prefix = "node_modules"
val key = s"$prefix-$${{ hashFiles('modules/web/client/package-lock.json') }}"
Map("path" -> "node_modules", "key" -> key, "restore-keys" -> prefix)
}
),
WorkflowStep.Run(
List("cd modules/web/client", "npm clean-install --verbose"),
name = Some("npm clean-install"),
cond = Some("steps.cache-node_modules.outputs.cache-hit != 'true'")
)
)
lazy val dockerHubLogin =
WorkflowStep.Run(
List(
"echo ${{ secrets.DOCKER_HUB_TOKEN }} | docker login --username nlsoftware --password-stdin"
),
name = Some("Login to Docker Hub")
)
lazy val sbtDockerPublish =
WorkflowStep.Sbt(
List("deploy/docker:publish"),
name = Some("Build and Publish Docker image")
)
lazy val herokuDeployAndRelease =
WorkflowStep.Run(
List(
"npm install -g heroku",
"heroku container:login",
"docker tag noirlab/gpp-obs registry.heroku.com/${{ secrets.HEROKU_APP_NAME_GN }}/web",
"docker push registry.heroku.com/${{ secrets.HEROKU_APP_NAME_GN }}/web",
"heroku container:release web -a ${{ secrets.HEROKU_APP_NAME_GN }} -v",
"docker tag noirlab/gpp-obs registry.heroku.com/${{ secrets.HEROKU_APP_NAME_GS }}/web",
"docker push registry.heroku.com/${{ secrets.HEROKU_APP_NAME_GS }}/web",
"heroku container:release web -a ${{ secrets.HEROKU_APP_NAME_GS }} -v"
),
name = Some("Deploy and release app in Heroku")
)
ThisBuild / githubWorkflowAddedJobs +=
WorkflowJob(
"deploy",
"Build and publish Docker image / Deploy to Heroku",
githubWorkflowJobSetup.value.toList :::
setupNodeNpmInstall :::
dockerHubLogin ::
sbtDockerPublish ::
herokuDeployAndRelease ::
Nil,
scalas = List(scalaVersion.value),
javas = githubWorkflowJavaVersions.value.toList.take(1),
cond = Some(allConds(mainCond, geminiRepoCond))
)
ThisBuild / lucumaCssExts += "svg"
Global / onChangedBuildSource := ReloadOnSourceChanges
ThisBuild / scalafixDependencies += "edu.gemini" % "lucuma-schemas_3" % LibraryVersions.lucumaSchemas
ThisBuild / scalaVersion := "3.6.2"
ThisBuild / crossScalaVersions := Seq("3.6.2")
ThisBuild / scalacOptions ++= Seq("-language:implicitConversions")
ThisBuild / scalafixResolvers += coursierapi.MavenRepository.of(
"https://s01.oss.sonatype.org/content/repositories/snapshots/"
)
// Gemini repository
ThisBuild / resolvers += "Gemini Repository".at(
"https://github.com/gemini-hlsw/maven-repo/raw/master/releases"
)
// TODO Remove once we stop using http4s snapshot
ThisBuild / resolvers += "s01-oss-sonatype-org-snapshots".at(
"https://s01.oss.sonatype.org/content/repositories/snapshots"
)
ThisBuild / evictionErrorLevel := Level.Info
// Uncomment for local gmp testing
// ThisBuild / resolvers += "Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository"
enablePlugins(GitBranchPrompt)
lazy val esModule = Seq(
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.ESModule) },
Compile / fastLinkJS / scalaJSLinkerConfig ~= { _.withSourceMap(false) },
Compile / fullLinkJS / scalaJSLinkerConfig ~= { _.withSourceMap(false) },
Compile / fastLinkJS / scalaJSLinkerConfig ~= (_.withModuleSplitStyle(
ModuleSplitStyle.FewestModules
)),
Compile / fullLinkJS / scalaJSLinkerConfig ~= (_.withModuleSplitStyle(
ModuleSplitStyle.FewestModules
))
)
//////////////
// Projects
//////////////
lazy val root = tlCrossRootProject.aggregate(
observe_web_server,
observe_web_client,
observe_server,
observe_model,
observe_ui_model,
observe_engine
)
lazy val stateengine = project
.in(file("modules/stateengine"))
.settings(
name := "stateengine",
libraryDependencies ++= Seq(
CatsEffect.value,
Mouse.value,
Fs2.value
) ++ MUnit.value ++ Cats.value
)
lazy val observe_web_server = project
.in(file("modules/web/server"))
.enablePlugins(BuildInfoPlugin)
.enablePlugins(GitBranchPrompt)
.settings(commonSettings: _*)
.settings(
libraryDependencies ++= Seq(
UnboundId,
LucumaSSO.value,
JwtCore,
JwtCirce,
Http4sServer,
Log4CatsNoop.value
) ++
Http4sJDKClient.value ++ Http4s ++ PureConfig ++ Logging.value,
// Supports launching the server in the background
reStart / mainClass := Some("observe.web.server.http4s.WebServerLauncher")
)
.settings(
buildInfoUsePackageAsPath := true,
buildInfoKeys ++= Seq[BuildInfoKey](name, version, buildInfoBuildNumber),
buildInfoOptions += BuildInfoOption.BuildTime,
buildInfoObject := "OcsBuildInfo",
buildInfoPackage := "observe.web.server"
)
.settings(
Compile / packageBin / mappings ~= { _.filter(!_._1.getName.endsWith(".conf")) },
Compile / packageBin / mappings ~= { _.filter(!_._1.getName.endsWith("logback.xml")) }
)
.dependsOn(observe_server)
.dependsOn(observe_model.jvm % "compile->compile;test->test")
/**
* Mappings common to applications, including configuration and web application
*/
lazy val deployedAppMappings = Seq(
Universal / mappings ++= {
val clientDir = (observe_web_client / build).value
directory(clientDir).flatMap(path =>
// Don't include environment confs, if present.
if (path._2.endsWith(".conf.json")) None
else Some(path._1 -> ("app/" + path._1.relativeTo(clientDir).get.getPath))
)
},
// The only thing we include from the base deployment app is app.conf. We remove the "conf" path.
Compile / packageBin / mappings ~= {
_.filter(_._1.getName.endsWith(".conf")).map(mapping => mapping._1 -> mapping._1.getName)
}
)
// Mappings for a particular release.
lazy val releaseAppMappings = Seq(
// Copy the resource directory, with customized configuration files, but first remove existing mappings.
Universal / mappings := { // maps =>
val resourceDir = (Compile / resourceDirectory).value
val resourceDirMappings =
directory(resourceDir).map(path => path._1 -> path._1.relativeTo(resourceDir).get.getPath)
val resourceDirFiles = resourceDirMappings.map(_._2)
(Universal / mappings).value.filterNot(map => resourceDirFiles.contains(map._2)) ++
resourceDirMappings
}
)
lazy val observe_ui_model = project
.in(file("modules/web/client-model"))
.settings(lucumaGlobalSettings: _*)
.enablePlugins(ScalaJSPlugin)
.settings(
coverageEnabled := false,
libraryDependencies ++= Crystal.value ++ LucumaUI.value ++ LucumaSchemas.value ++ LucumaCore.value ++ Circe.value ++ MUnit.value
)
.dependsOn(observe_model.js)
lazy val observe_web_client = project
.in(file("modules/web/client"))
.settings(lucumaGlobalSettings: _*)
.settings(esModule: _*)
.enablePlugins(ScalaJSPlugin, LucumaCssPlugin, CluePlugin, BuildInfoPlugin)
.settings(
Test / test := {},
coverageEnabled := false,
libraryDependencies ++= Seq(
Kittens.value,
CatsEffect.value,
Clue.value,
ClueJs.value,
Fs2.value,
Http4sClient.value,
Http4sDom.value
) ++ Crystal.value ++ LucumaUI.value ++ LucumaSchemas.value ++ ScalaJSReactIO.value ++ Cats.value ++ LucumaReact.value ++ Monocle.value ++ LucumaCore.value ++ Log4CatsLogLevel.value,
scalacOptions ~= (_.filterNot(Set("-Vtype-diffs"))),
buildInfoKeys := Seq[BuildInfoKey](
scalaVersion,
sbtVersion,
git.gitHeadCommit,
"buildDateTime" -> System.currentTimeMillis()
),
buildInfoPackage := "observe.ui",
Test / scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) }
)
.settings(
build / fileInputs += (Compile / fullLinkJS / scalaJSLinkerOutputDirectory).value.toGlob,
build := {
if ((Process("npx" :: "vite" :: "build" :: Nil, baseDirectory.value) !) != 0)
throw new Exception("Error building web client")
else
baseDirectory.value / "deploy" // Must match directory declared in vite.config.js
},
build := build.dependsOn(Compile / fullLinkJS).value
)
.dependsOn(observe_model.js, observe_ui_model)
// List all the modules and their inter dependencies
lazy val observe_server = project
.in(file("modules/server_new"))
.enablePlugins(GitBranchPrompt, BuildInfoPlugin, CluePlugin)
.settings(commonSettings: _*)
.settings(
libraryDependencies ++=
Seq(
Http4sCirce.value,
Http4sXml,
Log4Cats.value,
Log4CatsNoop.value,
PPrint.value,
Clue.value,
ClueHttp4s,
CatsParse.value,
ACM,
GiapiScala
) ++ Coulomb.value ++ LucumaSchemas.value ++ MUnit.value ++ Http4s ++ Http4sJDKClient.value ++ PureConfig ++ Monocle.value ++
Circe.value,
headerSources / excludeFilter := HiddenFileFilter || (file(
"modules/server_new"
) / "src/main/scala/pureconfig/module/http4s/package.scala").getName
)
.settings(
buildInfoUsePackageAsPath := true,
buildInfoKeys ++= Seq[BuildInfoKey](name, version),
buildInfoObject := "OcsBuildInfo",
buildInfoPackage := "observe.server"
)
.dependsOn(observe_engine % "compile->compile;test->test",
// ocs2_api.jvm,
observe_model.jvm % "compile->compile;test->test"
)
.settings(
unmanagedSources / excludeFilter := (unmanagedSources / excludeFilter).value
|| (Compile / sourceDirectory).value + "/scala/observe/server/flamingos2/*"
|| (Compile / sourceDirectory).value + "/scala/observe/server/ghost/*"
|| (Compile / sourceDirectory).value + "/scala/observe/server/gnirs/*"
|| (Compile / sourceDirectory).value + "/scala/observe/server/gpi/*"
|| (Compile / sourceDirectory).value + "/scala/observe/server/gsaoi/*"
|| (Compile / sourceDirectory).value + "/scala/observe/server/nifs/*"
|| (Compile / sourceDirectory).value + "/scala/observe/server/niri/*"
)
// Unfortunately crossProject doesn't seem to work properly at the module/build.sbt level
// We have to define the project properties at this level
lazy val observe_model = crossProject(JVMPlatform, JSPlatform)
.crossType(CrossType.Full)
.in(file("modules/model"))
.enablePlugins(GitBranchPrompt)
.settings(
libraryDependencies ++= Seq(
Mouse.value,
CatsTime.value,
Http4sCore.value,
Http4sCirce.value,
Http4sLaws.value,
LucumaODBSchema.value
) ++ Coulomb.value ++ MUnit.value ++ Monocle.value ++ LucumaCore.value ++ Circe.value
)
.jvmSettings(commonSettings)
.jsSettings(
// And add a custom one
libraryDependencies += JavaTimeJS.value,
coverageEnabled := false
)
lazy val observe_engine = project
.in(file("modules/engine"))
.enablePlugins(GitBranchPrompt)
.dependsOn(observe_model.jvm % "compile->compile;test->test")
.settings(commonSettings: _*)
.settings(
libraryDependencies ++= Seq(
Fs2.value,
CatsEffect.value,
Log4Cats.value
) ++ Monocle.value ++ MUnit.value
)
/**
* Common settings for the Observe instances
*/
lazy val observeCommonSettings = Seq(
// Main class for launching
Compile / mainClass := Some("observe.web.server.http4s.WebServerLauncher"),
// Name of the launch script
executableScriptName := "observe-server",
// No javadocs
Compile / packageDoc / mappings := Seq(),
// Don't create launchers for Windows
makeBatScripts := Seq.empty,
// Specify a different name for the config file
bashScriptConfigLocation := Some("${app_home}/../conf/launcher.args"),
bashScriptExtraDefines += """addJava "-Dlogback.configurationFile=${app_home}/../conf/logback.xml"""",
// Copy logback.xml to let users customize it on site
Universal / mappings += {
val f = (observe_web_server / Compile / resourceDirectory).value / "logback.xml"
f -> ("conf/" + f.getName)
},
// Launch options
Universal / javaOptions ++= Seq(
// -J params will be added as jvm parameters
"-J-Xmx1024m",
"-J-Xms256m",
// Support remote JMX access
"-J-Dcom.sun.management.jmxremote",
"-J-Dcom.sun.management.jmxremote.authenticate=false",
"-J-Dcom.sun.management.jmxremote.port=2407",
"-J-Dcom.sun.management.jmxremote.ssl=false",
// Ensure the local is correctly set
"-J-Duser.language=en",
"-J-Duser.country=US",
// Support remote debugging
"-J-Xdebug",
"-J-Xnoagent",
"-J-XX:+HeapDumpOnOutOfMemoryError",
// Make sure the application exits on OOM
"-J-XX:+ExitOnOutOfMemoryError",
"-J-XX:+CrashOnOutOfMemoryError",
"-J-XX:HeapDumpPath=/tmp",
"-J-Xrunjdwp:transport=dt_socket,address=8457,server=y,suspend=n"
)
) ++ commonSettings
/**
* Settings for Observe in Linux
*/
lazy val observeLinux = Seq(
// User/Group for execution
Linux / daemonUser := "software",
Linux / daemonGroup := "software",
Universal / maintainer := "Software Group <[email protected]>",
// This lets us build RPMs from snapshot versions
Linux / name := "Observe Server",
Linux / version := {
(ThisBuild / version).value.replace("-SNAPSHOT", "").replace("-", "_").replace(" ", "")
}
)
/**
* Project for the observe server app for development
*/
lazy val deploy = project
.in(file("deploy"))
.enablePlugins(NoPublishPlugin)
.enablePlugins(DockerPlugin)
.enablePlugins(JavaServerAppPackaging)
.enablePlugins(GitBranchPrompt)
.dependsOn(observe_web_server)
.settings(observeCommonSettings: _*)
.settings(deployedAppMappings: _*)
.settings(releaseAppMappings: _*)
.settings(
description := "Observe Server",
Docker / packageName := "gpp-obs",
dockerBuildOptions ++= Seq("--platform", "linux/amd64"),
dockerUpdateLatest := true,
dockerUsername := Some("noirlab")
)