/
build.sc
300 lines (250 loc) · 6.82 KB
/
build.sc
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
import $file.webpack
import $file.reboot
import mill._
import scalalib._
import scalafmt._
import mill.scalajslib._
import webpack.{WebpackModule, NpmDependency}
val catsEffectDep = ivy"org.typelevel::cats-effect::2.3.1"
val monocleDeps = Agg(
"monocle-core",
"monocle-macro"
).map { dep => ivy"com.github.julien-truffaut::${dep}::2.1.0" }
val sjsVersion = "1.5.0"
val commonScalacOptions =
Seq(
"-language:implicitConversions",
"-feature",
"-deprecation",
"-Xfatal-warnings",
"-language:higherKinds",
"-language:existentials",
"-Wunused",
"-encoding",
"UTF-8",
"-Yrangepos"
)
trait ProtocolModule extends ScalaModule {
def scalaVersion = "2.13.1"
def scalacOptions = commonScalacOptions
def ivyDeps =
Agg(ivy"org.typelevel::cats-core::2.6.0") ++ Agg(
"circe-core",
"circe-parser",
"circe-generic"
).map { dep => ivy"io.circe::${dep}::0.13.0" }
def millSourcePath = build.millSourcePath / "protocol"
}
object protocolJs extends ProtocolModule with ScalaJSModule {
def scalaJSVersion = sjsVersion
}
object protocolJvm extends ProtocolModule
object server extends ScalaModule {
def scalaVersion = "2.13.1"
def moduleDeps = Seq(protocolJvm)
def compileIvyDeps = Agg(ivy"org.typelevel:::kind-projector::0.11.0")
def scalacOptions = commonScalacOptions
def scalacPluginIvyDeps =
Agg(
ivy"org.typelevel:::kind-projector::0.11.0",
ivy"com.olegpy::better-monadic-for::0.3.1"
)
def ivyDeps =
Agg(
catsEffectDep,
ivy"io.chrisdavenport::log4cats-slf4j::1.1.1",
ivy"ch.qos.logback:logback-classic:1.2.3"
) ++ Agg(
"http4s-dsl",
"http4s-circe",
"http4s-blaze-server",
"http4s-blaze-client"
).map { dep => ivy"org.http4s::${dep}::0.21.13" } ++ Agg(
"tapir-core",
"tapir-json-circe",
"tapir-http4s-server",
"tapir-openapi-docs",
"tapir-openapi-circe-yaml",
"tapir-redoc-http4s"
).map { dep => ivy"com.softwaremill.sttp.tapir::${dep}::0.16.16" } ++ Agg(
"fs2-io",
"fs2-core"
).map { dep => ivy"co.fs2::${dep}::2.4.6" } ++ monocleDeps ++
Agg(ivy"io.chrisdavenport::cats-time::0.3.4")
def assetDir = T.source {
millSourcePath / "src" / "main" / "resources"
}
def localSslKey = T.source {
millSourcePath / "src" / "main" / "resources" / "localkey.pkcs12"
}
object test extends Tests {
def ivyDeps =
Agg(
ivy"org.scalameta::munit::0.7.22",
ivy"org.typelevel::discipline-munit::1.0.9",
ivy"org.typelevel::cats-laws::2.6.0",
ivy"org.scalacheck::scalacheck::1.15.4"
)
def testFrameworks = Seq("munit.Framework")
}
}
object client extends ScalaJSModule {
def scalaVersion = "2.13.1"
def scalaJSVersion = sjsVersion
def scalacPluginIvyDeps =
super.scalacPluginIvyDeps() ++ Agg(
ivy"com.olegpy::better-monadic-for:0.3.1"
)
def scalacOptions = commonScalacOptions
def moduleDeps = Seq(protocolJs)
def ivyDeps =
monocleDeps ++ Agg(
ivy"io.github.cquiroz::scala-java-time::2.3.0",
catsEffectDep
) ++ Agg(
"core",
"extra",
"ext-cats"
).map { dep => ivy"com.github.japgolly.scalajs-react::${dep}::1.7.7" }
}
trait WebModule extends WebpackModule {
def webpackVersion = "4.17.1"
def webpackCliVersion = "3.1.0"
def webpackDevServerVersion = "3.1.7"
def sassVersion = "1.25.0"
def npmDeps =
Agg("react" -> "React", "react-dom" -> "ReactDOM").map { case (n, g) =>
NpmDependency(n, "16.7.0", g)
}
def millSourcePath = build.millSourcePath / "web"
}
object web extends WebModule {
import ammonite.ops._
import ammonite.ops.ImplicitWd._
def mainJS = client.fastOpt
def development = true
import mill.eval._
import mill.define.Task
import mill.api.Strict.{Agg => SAgg}
def runBackground(ev: Evaluator) = T.command {
val t0 = bundle
val t1 = server.assetDir
val t2 = server.localSslKey
val r = ev.evaluate(SAgg[Task[_]](t0, t1, t2)).results
val r0 = r(t0).map(_.asInstanceOf[PathRef])
val r1 = r(t1).map(_.asInstanceOf[PathRef])
val r2 = r(t2).map(_.asInstanceOf[PathRef])
(r0, r1, r2) match {
case (
Result.Success(bundle),
Result.Success(assetDir),
Result.Success(sslKey)
) =>
server.runBackground(
bundle.path.toString,
assetDir.path.toString,
"8443",
"8080",
sslKey.path.toString,
"password"
)
}
}
def run(ev: Evaluator) = T.command {
val t0 = bundle
val t1 = server.assetDir
val t2 = server.localSslKey
val r = ev.evaluate(SAgg[Task[_]](t0, t1, t2)).results
val r0 = r(t0).map(_.asInstanceOf[PathRef])
val r1 = r(t1).map(_.asInstanceOf[PathRef])
val r2 = r(t2).map(_.asInstanceOf[PathRef])
(r0, r1, r2) match {
case (
Result.Success(bundle),
Result.Success(assetDir),
Result.Success(sslKey)
) =>
server.run(
bundle.path.toString,
assetDir.path.toString,
"8443",
"8080",
sslKey.path.toString,
"password"
)
}
}
}
object ci extends WebModule {
import ammonite.ops._
import ammonite.ops.ImplicitWd._
def mainJS = client.fullOpt
def development = false
def account: T[String] = "930183804331"
def region: T[String] = "eu-west-2"
def stack: T[String] = "Website"
def sslPassword: T[String] = System.getenv("LSUG_SSL_PASSWORD")
def devDependencies =
Agg(
"aws-cdk" -> "1.33.1"
)
def scripts = T.source {
PathRef(millSourcePath / "scripts")
}
def synth = T {
val out = T.ctx.dest
os.copy.over(scripts().path, T.ctx.dest)
val upload = out / "upload"
mkdir(upload)
os.copy(
bundle().path,
upload / "static"
)
os.copy.into(
server.assetDir().path,
upload
)
os.copy(
server.assembly().path,
upload / "app.jar"
)
os.write.over(
out / "cdk.json",
ujson
.Obj(
"app" ->
List(
"./stack.sc",
stack(),
account(),
region(),
upload.toString,
sslPassword()
).mkString(" ")
)
.render(2)
)
yarn().%("cdk", "synth")(wd = T.ctx.dest)
PathRef(out)
}
def diff() = T.command {
val wd = synth()
yarn().%("cdk", "diff")(wd = wd.path)
}
def bootstrap() = T.command {
val wd = synth()
yarn().%("cdk", "bootstrap", s"aws://${account()}/${region()}")(wd =
wd.path
)
}
def deploy() = T.command {
val wd = synth()
yarn().%("cdk", "deploy", "--require-approval", "never")(wd = wd.path)
}
def instanceId = T {
$file.reboot.instanceId
}
def reboot() = T.command {
$file.reboot.reboot(instanceId())
}
}