-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.sbt
76 lines (70 loc) · 3.95 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
ThisBuild / scalaVersion := "3.6.2"
ThisBuild / organization := "dev.usommerl"
ThisBuild / libraryDependencySchemes += "com.softwaremill.sttp.apispec" %% "openapi-model" % "early-semver"
ThisBuild / libraryDependencySchemes += "com.softwaremill.sttp.apispec" %% "apispec-model" % "early-semver"
val v = new {
val apispec = "0.11.5"
val circe = "0.14.10"
val ciris = "3.7.0"
val http4s = "0.23.30"
val odin = "0.14.0"
val tapir = "1.11.11"
val munit = "1.0.3"
val munitCE = "2.0.0"
}
val upx = "UPX_COMPRESSION"
lazy val graalnative4s = project
.in(file("."))
.enablePlugins(BuildInfoPlugin, sbtdocker.DockerPlugin, GraalVMNativeImagePlugin)
.settings(
libraryDependencies ++= Seq(
"com.softwaremill.sttp.apispec" %% "openapi-circe-yaml" % v.apispec,
"com.softwaremill.sttp.tapir" %% "tapir-core" % v.tapir,
"com.softwaremill.sttp.tapir" %% "tapir-http4s-server" % v.tapir,
"com.softwaremill.sttp.tapir" %% "tapir-json-circe" % v.tapir,
"com.softwaremill.sttp.tapir" %% "tapir-openapi-docs" % v.tapir,
"com.softwaremill.sttp.tapir" %% "tapir-refined" % v.tapir,
"com.softwaremill.sttp.tapir" %% "tapir-swagger-ui" % v.tapir,
"dev.scalafreaks" %% "odin-core" % v.odin,
"dev.scalafreaks" %% "odin-json" % v.odin,
"dev.scalafreaks" %% "odin-slf4j" % v.odin,
"io.circe" %% "circe-core" % v.circe,
"io.circe" %% "circe-generic" % v.circe,
"io.circe" %% "circe-parser" % v.circe,
"io.circe" %% "circe-literal" % v.circe,
"is.cir" %% "ciris" % v.ciris,
"is.cir" %% "ciris-refined" % v.ciris,
"org.http4s" %% "http4s-ember-server" % v.http4s,
"org.http4s" %% "http4s-circe" % v.http4s,
"org.http4s" %% "http4s-dsl" % v.http4s,
"org.scalameta" %% "munit" % v.munit % Test,
"org.typelevel" %% "munit-cats-effect" % v.munitCE % Test
),
testFrameworks += new TestFramework("munit.Framework"),
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion, Test / libraryDependencies),
buildInfoPackage := organization.value,
buildInfoOptions ++= Seq[BuildInfoOption](BuildInfoOption.BuildTime),
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision,
docker / dockerfile := NativeDockerfile(file("Dockerfile")),
docker / imageNames := Seq(ImageName(s"ghcr.io/usommerl/${name.value}:$dockerImageTag")),
docker / dockerBuildArguments := dockerBuildArgs,
assembly / test := (Test / test).value,
assembly / assemblyMergeStrategy := {
case "META-INF/maven/org.webjars/swagger-ui/pom.properties" => MergeStrategy.singleOrError
case x if x.endsWith("module-info.class") => MergeStrategy.discard
case x => (assembly / assemblyMergeStrategy).value(x)
}
)
def dockerImageTag: String = {
import sys.process._
val regex = """v\d+\.\d+\.\d+""".r.regex
val versionTags = "git tag --points-at HEAD".!!.trim.split("\n").filter(_.matches(regex))
val version = versionTags.sorted(Ordering.String.reverse).headOption.map(_.replace("v", "")).getOrElse("latest")
val upxSuffix = sys.env.get(upx).map(s => s"-upx${s.replace("--", "-")}").getOrElse("")
s"$version$upxSuffix"
}
def dockerBuildArgs: Map[String, String] =
sys.env.foldLeft(Map.empty[String, String]) { case (acc, (k, v)) =>
if (Set("UPX_COMPRESSION", "PRINT_REPORTS").contains(k)) acc + (k.toLowerCase -> v) else acc
}