forked from dsugden/cluster-console
-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.sbt
225 lines (192 loc) · 8.79 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
import com.lihaoyi.workbench.Plugin._
import com.typesafe.sbt.less.Import.LessKeys
import com.typesafe.sbt.web.Import.WebKeys._
import com.typesafe.sbt.web.SbtWeb
import org.scalajs.sbtplugin.ScalaJSPlugin.AutoImport._
import com.typesafe.sbt.packager.archetypes._
import com.typesafe.sbt.web.Import.WebKeys._
import com.typesafe.sbt.web.Import._
import com.typesafe.sbt.web.SbtWeb
import spray.revolver.RevolverPlugin.Revolver
import com.typesafe.sbt.packager.docker.ExecCmd
name := "astrolabe"
version := "1.1-SNAPSHOT"
scalaVersion := "2.11.7"
organization := "com.boldradius"
maintainer := "Dave Sugden <[email protected]>, Brendan McAdams <[email protected]> "
scalaJSStage in Global := FastOptStage
// a special crossProject for configuring a JS/JVM/shared structure
// root project aggregating the JS and JVM projects
lazy val root = project.in(file(".")).
aggregate(js, jvm).
settings(
organization := "com.boldradius",
name := "astrolabe",
version := Settings.version,
commands += ReleaseCmd,
commands ++= Seq(DockerizeCmd, DockerizeLocalCmd, DockerizeStageCmd),
publish := {},
publishLocal := {}
)
.enablePlugins(SbtWeb)
.enablePlugins(JavaAppPackaging)
// Command for building a release
lazy val ReleaseCmd = Command.command("release") {
state => "set productionBuild in js := true" ::
"set elideOptions in js := Seq(\"-Xelide-below\", \"WARNING\")" ::
"sharedProjectJS/test" ::
"sharedProjectJS/fullOptJS" ::
"sharedProjectJS/packageJSDependencies" ::
"sharedProjectJVM/test" ::
"sharedProjectJVM/stage" ::
"set productionBuild in js := false" ::
state
}
lazy val DockerizeCmd = Command.command("dockerize") { state =>
"release" ::
"project sharedProjectJVM" ::
"docker:publish" ::
state
}
lazy val DockerizeLocalCmd = Command.command("dockerizeLocal") { state =>
"release" ::
"project sharedProjectJVM" ::
"docker:publishLocal" ::
state
}
lazy val DockerizeStageCmd = Command.command("dockerizeStage") { state =>
"release" ::
"project sharedProjectJVM" ::
"docker:stage" ::
state
}
val sharedSrcDir = "shared"
val productionBuild = settingKey[Boolean]("Build for production")
val elideOptions = settingKey[Seq[String]]("Set limit for elidable functions")
val copyWebJarResources = taskKey[Unit]("Copy resources from WebJars")
// a special crossProject for configuring a JS/JVM/shared structure
lazy val sharedProject = crossProject.in(file("."))
.settings(
name := Settings.name,
version := Settings.version,
scalaVersion := Settings.versions.scala,
scalacOptions ++= Settings.scalacOptions,
sourceDirectory in Assets := baseDirectory.value / "src" / "main" / "assets",
LessKeys.compress in Assets := true,
libraryDependencies ++= Settings.sharedDependencies.value,
copyWebJarResources := {
// copy the compiled CSS
val s = streams.value
s.log("Copying webjar resources")
val compiledCss = webTarget.value / "less" / "main" / "stylesheets"
val targetDir = (classDirectory in Compile).value / "web"
IO.createDirectory(targetDir / "stylesheets")
IO.copyDirectory(compiledCss, targetDir / "stylesheets")
// copy font-awesome fonts from WebJar
val fonts = (webModuleDirectory in Assets).value / "webjars" / "lib" / "font-awesome" / "fonts"
IO.createDirectory(targetDir / "fonts")
IO.copyDirectory(fonts, targetDir / "fonts")
},
// run the copy after compile/assets but before managed resources
copyWebJarResources <<= copyWebJarResources dependsOn(compile in Compile, assets in Compile),
managedResources in Compile <<= (managedResources in Compile) dependsOn copyWebJarResources
)
// set up settings specific to the JVM project
.jvmSettings(Revolver.settings: _*)
.jvmSettings(
libraryDependencies ++= Settings.jvmDependencies.value,
// copy resources from the "shared" project
unmanagedResourceDirectories in Compile += file(".") / sharedSrcDir / "src" / "main" / "resources",
unmanagedResourceDirectories in Test += file(".") / sharedSrcDir / "src" / "test" / "resources",
javaOptions in Revolver.reStart ++= Settings.jvmRuntimeOptions,
// configure a specific port for debugging, so you can easily debug multiple projects at the same time if necessary
Revolver.enableDebugging(port = 5111, suspend = false)
)
// set up settings specific to the JS project
.jsSettings(workbenchSettings: _*)
.jsSettings(
libraryDependencies ++= Settings.scalajsDependencies.value,
// by default we do development build
productionBuild := false,
elideOptions := Seq(),
scalacOptions ++= elideOptions.value,
// scalacOptions in (Compile, fullOptJS) ++= Seq("-Xelide-below", "WARNING"),
// select JS dependencies according to build setting
jsDependencies ++= {if (!productionBuild.value) Settings.jsDependencies.value else Settings.jsDependenciesProduction.value},
jsDependencies ++= Settings.jsDependencies.value,
// RuntimeDOM is needed for tests
jsDependencies += RuntimeDOM % "test",
scalacOptions ++= Seq({
val a = js.base.toURI.toString.replaceFirst("[^/]+/?$", "")
s"-P:scalajs:mapSourceURI:$a->/srcmaps/"
}),
// yes, we want to package JS dependencies
skip in packageJSDependencies := false,
// copy resources from the "shared" project
unmanagedResourceDirectories in Compile += file(".") / sharedSrcDir / "src" / "main" / "resources",
unmanagedResourceDirectories in Test += file(".") / sharedSrcDir / "src" / "test" / "resources",
// use uTest framework for tests
testFrameworks += new TestFramework("utest.runner.Framework"),
// define where the JS-only application will be hosted by the Workbench plugin
localUrl :=("localhost", 13131),
refreshBrowsers <<= refreshBrowsers.triggeredBy(fastOptJS in Compile),
bootSnippet := "astrolabeApp().main();"
)
// configure a specific directory for scalajs output
val scalajsOutputDir = Def.settingKey[File]("directory for javascript files output by scalajs")
// make all JS builds use the output dir defined later
lazy val js2jvmSettings = Seq(fastOptJS, fullOptJS, packageJSDependencies) map { packageJSKey =>
crossTarget in(js, Compile, packageJSKey) := scalajsOutputDir.value
}
// instantiate the JS project for SBT with some additional settings
lazy val js: Project = sharedProject.js.settings(
fastOptJS in Compile := {
// make a copy of the produced JS-file (and source maps) under the js project as well,
// because the original goes under the jvm project
// NOTE: this is only done for fastOptJS, not for fullOptJS
val base = (fastOptJS in Compile).value
IO.copyFile(base.data, (classDirectory in Compile).value / "web" / "js" / base.data.getName)
IO.copyFile(base.data, (classDirectory in Compile).value / "web" / "js" / (base.data.getName + ".map"))
base
},
packageJSDependencies in Compile := {
// make a copy of the produced jsdeps file under the js project as well,
// because the original goes under the jvm project
val base = (packageJSDependencies in Compile).value
IO.copyFile(base, (classDirectory in Compile).value / "web" / "js" / base.getName)
base
}
).settings(scalariformSettings).enablePlugins(SbtWeb)
// instantiate the JVM project for SBT with some additional settings
lazy val jvm: Project = sharedProject.jvm.settings(js2jvmSettings: _*)
.settings(scalariformSettings)
.settings(
// scala.js output is directed under "web/js" dir in the jvm project
scalajsOutputDir := (classDirectory in Compile).value / "web" / "js",
// set environment variables in the execute scripts
NativePackagerKeys.batScriptExtraDefines += "set PRODUCTION_MODE=true",
NativePackagerKeys.bashScriptExtraDefines += "export PRODUCTION_MODE=true",
// reStart depends on running fastOptJS on the JS project
Revolver.reStart <<= Revolver.reStart dependsOn (fastOptJS in(js, Compile)),
// Runs Fabric 8, alpine based JDK. Official JDK8 is almost a gig, Alpine is ~200MB
// MUST be defined or defaults to java:latest, which overrides anything defined in compose
dockerBaseImage := "fabric8/java-alpine-openjdk8-jdk:1.0.10",
dockerExposedPorts ++= Seq(9000),
version in Docker := "latest",
packageName in Docker := "astrolabe",
dockerRepository in Docker := Some("boldradius"),
fork := true,
mainClass in (Compile, run):= Some("com.boldradius.astrolabe.ClusterConsoleApp")
)
.enablePlugins(DockerPlugin)
.enablePlugins(AshScriptPlugin) // Use SBT Docker's support for busyBox to not use bash.
.enablePlugins(SbtWeb)
.enablePlugins(JavaAppPackaging)
lazy val sampleCluster = (project in file("sampleCluster"))
.settings(scalariformSettings)
.settings(
name := "samplecluster",
version := "1.0.0",
scalaVersion := "2.11.7",
libraryDependencies ++= Settings.jvmDependencies.value
).enablePlugins(JavaServerAppPackaging, JDebPackaging)