-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.sbt
97 lines (83 loc) · 3.05 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
/*
* Copyright 2020 Noel Welsh
*
* 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 sbt._
import scala.sys.process._
import java.io.File
ThisBuild / organization := "co.innerproduct"
ThisBuild / name := "ping"
ThisBuild / scalaVersion := "2.13.1"
ThisBuild / useSuperShell := false
libraryDependencies ++= Seq(
Dependencies.catsCore.value,
Dependencies.catsEffect.value,
Dependencies.miniTest.value,
Dependencies.miniTestLaws.value,
Dependencies.http4sBlazeServer.value,
Dependencies.http4sBlazeClient.value,
Dependencies.http4sCirce.value,
Dependencies.http4sDsl.value,
Dependencies.logback.value,
Dependencies.janino.value
)
testFrameworks += new TestFramework("minitest.runner.Framework")
lazy val nativeImageLocal =
taskKey[File]("Build a standalone executable on this machine using GraalVM Native Image")
nativeImageLocal := {
import sbt.Keys.streams
val assemblyFatJar = assembly.value
val assemblyFatJarPath = assemblyFatJar.getAbsolutePath()
val outputName = "ping-server.local"
val outputPath = (baseDirectory.value / "out" / outputName).getAbsolutePath()
val cmd = s"""native-image
| -jar ${assemblyFatJarPath}
| ${outputPath}""".stripMargin.filter(_ != '\n')
val log = streams.value.log
log.info(s"Building local native image from ${assemblyFatJarPath}")
log.debug(cmd)
val result = (cmd.!(log))
if (result == 0) file(s"${outputPath}")
else {
log.error(s"Local native image command failed:\n ${cmd}")
throw new Exception("Local native image command failed")
}
}
lazy val nativeImage =
taskKey[File]("Build a standalone Linux executable using GraalVM Native Image")
nativeImage := {
import sbt.Keys.streams
val assemblyFatJar = assembly.value
val assemblyFatJarPath = assemblyFatJar.getParent()
val assemblyFatJarName = assemblyFatJar.getName()
val outputPath = (baseDirectory.value / "out").getAbsolutePath()
val outputName = "ping-server"
val nativeImageDocker = "inner-product/graalvm-native-image"
val cmd = s"""docker run
| --volume ${assemblyFatJarPath}:/opt/assembly
| --volume ${outputPath}:/opt/native-image
| ${nativeImageDocker}
| --static
| -jar /opt/assembly/${assemblyFatJarName}
| ${outputName}""".stripMargin.filter(_ != '\n')
val log = streams.value.log
log.info(s"Building native image from ${assemblyFatJarName}")
log.debug(cmd)
val result = (cmd.!(log))
if (result == 0) file(s"${outputPath}/${outputName}")
else {
log.error(s"Native image command failed:\n ${cmd}")
throw new Exception("Native image command failed")
}
}