This repository has been archived by the owner on Mar 17, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
build.sbt
235 lines (216 loc) · 10.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
import Dependencies._
import com.typesafe.sbt.packager.docker.{Cmd, ExecCmd}
import com.typesafe.sbt.packager.docker.DockerPlugin.autoImport._
import ReleaseTransformations._
import ReleasePlugin.autoImport._
import ReleaseKeys._
import sbt.IO
import scala.sys.process._
// for Alpakka Kafka snapshots
resolvers += Resolver.bintrayRepo("akka", "snapshots")
lazy val kafkaLagExporter =
Project(id = "kafka-lag-exporter", base = file("."))
.enablePlugins(AutomateHeaderPlugin)
.enablePlugins(JavaAppPackaging)
.enablePlugins(DockerPlugin)
.settings(commonSettings)
.settings(
name := "kafka-lag-exporter",
description := "Kafka lag exporter finds and reports Kafka consumer group lag metrics",
libraryDependencies ++= Vector(
LightbendConfig,
Kafka,
Akka,
AkkaTyped,
AkkaSlf4j,
AkkaStreams,
AkkaStreamsProtobuf,
AkkaInfluxDB,
Fabric8Model,
Fabric8Client,
Prometheus,
PrometheusHotSpot,
PrometheusHttpServer,
ScalaJava8Compat,
AkkaHttp,
Logback,
ScalaTest,
AkkaTypedTestKit,
MockitoScala,
AkkaStreamsTestKit,
AlpakkaKafkaTestKit,
TestcontainersKafka,
TestcontainersInfluxDb
),
dockerRepository := Option(System.getenv("DOCKER_REPOSITORY")).orElse(None),
dockerUsername := Option(System.getenv("DOCKER_USERNAME")).orElse(Some("lightbend")),
dockerUpdateLatest := true,
// Based on best practices found in OpenShift Creating images guidelines
// https://docs.openshift.com/container-platform/3.10/creating_images/guidelines.html
dockerCommands := Seq(
Cmd("FROM", "centos:8"),
Cmd("RUN", "yum -y install java-1.8.0-openjdk-headless && yum update -y && yum clean all -y"),
Cmd("RUN", "useradd -r -m -u 1001 -g 0 kafkalagexporter"),
Cmd("ADD", "opt /opt"),
Cmd("RUN", "chgrp -R 0 /opt && chmod -R g=u /opt"),
Cmd("WORKDIR", "/opt/docker"),
Cmd("USER", "1001"),
ExecCmd("CMD", "/opt/docker/bin/kafka-lag-exporter",
"-Dconfig.file=/opt/docker/conf/application.conf",
"-Dlogback.configurationFile=/opt/docker/conf/logback.xml"),
),
updateHelmChart := {
import scala.sys.process._
val repo = dockerAlias.value.withTag(None).toString
s"./scripts/update_chart.sh ${version.value} $repo" !
},
skip in publish := true,
parallelExecution in Test := false,
releaseProcess := Seq[ReleaseStep](
lintHelmChart, // Lint the Helm Chart for errors
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
updateHelmChartRelease, // Update the Helm Chart
publishDockerImage, // Publish the Docker images used by the chart
packageChart, // Package the Helm Chart
// buildChartsIndex, // Build Helm Charts index
packageJavaApp, // Package the standalone Java App
commitReleaseVersion,
updateReadmeRelease, // Update the README.md with this version
commitReadmeVersion, // Commit the README.md
commitChartThisVersion, // Commit the Helm Chart
tagRelease,
githubReleaseDraft, // Create a GitHub release draft
// publishChartsIndex, // Publish Helm Charts index
setNextVersion,
updateHelmChartNextVersion, // Update the Helm Chart with the next snapshot version
commitChartNextVersion, // Commit the Helm Chart
commitNextVersion,
pushChanges
)
)
lazy val commonSettings = Seq(
organization := "com.lightbend.kafkalagexporter",
scalaVersion := Version.Scala,
scalacOptions ++= Seq(
"-encoding", "UTF-8",
"-target:jvm-1.8",
"-Xlog-reflective-calls",
"-Xlint",
"-Ywarn-unused",
"-Ywarn-unused-import",
"-deprecation",
"-feature",
"-language:_",
"-unchecked"
),
maintainer := "sean.glover@lightbend.com",
scalacOptions in (Compile, console) := (scalacOptions in (Global)).value.filter(_ == "-Ywarn-unused-import"),
scalacOptions in (Test, console) := (scalacOptions in (Compile, console)).value,
organizationName := "Lightbend Inc. <http://www.lightbend.com>",
startYear := Some(2020),
licenses += ("Apache-2.0", new URL("https://www.apache.org/licenses/LICENSE-2.0.txt"))
)
lazy val updateHelmChart = taskKey[Unit]("Update Helm Chart")
def exec(cmd: String, errorMessage: String): Unit = {
val e = cmd.!
if (e != 0) sys.error(errorMessage)
}
lazy val lintHelmChart = ReleaseStep(action = st => {
exec("./scripts/lint_chart.sh", "Error while linting Helm Chart")
st
})
lazy val updateHelmChartRelease = ReleaseStep(action = st => {
val (releaseVersion, _) = st.get(versions).getOrElse(sys.error("No versions are set! Was this release part executed before inquireVersions?"))
val extracted = Project.extract(st)
val repo = extracted.get(dockerAlias in thisProjectRef).withTag(None)
exec(s"./scripts/update_chart.sh $releaseVersion $repo", "Error while updating Helm Chart")
st
})
lazy val updateHelmChartNextVersion = ReleaseStep(action = st => {
val (_, nextVersion) = st.get(versions).getOrElse(sys.error("No versions are set! Was this release part executed before inquireVersions?"))
val extracted = Project.extract(st)
val repo = extracted.get(dockerAlias in thisProjectRef).withTag(None)
exec(s"./scripts/update_chart.sh $nextVersion $repo", "Error while updating Helm Chart")
st
})
lazy val updateReadmeRelease = ReleaseStep(action = st => {
val (releaseVersion, _) = st.get(versions).getOrElse(sys.error("No versions are set! Was this release part executed before inquireVersions?"))
exec(s"./scripts/update_readme_version.sh $releaseVersion", "Error while updating README")
st
})
lazy val commitReadmeVersion = ReleaseStep(action = st => {
val (releaseVersion, _) = st.get(versions).getOrElse(sys.error("No versions are set! Was this release part executed before inquireVersions?"))
val vcs = Project.extract(st).get(releaseVcs).getOrElse(sys.error("Aborting release. Working directory is not a repository of a recognized VCS."))
val readme = (vcs.baseDir / "README.md").getCanonicalFile
val base = vcs.baseDir.getCanonicalFile
val relativeReadme = IO.relativize(base, readme).getOrElse("Version file [%s] is outside of this VCS repository with base directory [%s]!" format(readme, base))
vcs.add(relativeReadme).!!
vcs.commit(s"Update version in README for $releaseVersion", sign = false, signOff = false).!
st
})
lazy val commitChartNextVersion = ReleaseStep(action = st => {
val (_, nextVersion) = st.get(versions).getOrElse(sys.error("No versions are set! Was this release part executed before inquireVersions?"))
val vcs = Project.extract(st).get(releaseVcs).getOrElse(sys.error("Aborting release. Working directory is not a repository of a recognized VCS."))
val chartYaml = (vcs.baseDir / "charts/kafka-lag-exporter/Chart.yaml").getCanonicalFile
val valuesYaml = (vcs.baseDir / "charts/kafka-lag-exporter/values.yaml").getCanonicalFile
val base = vcs.baseDir.getCanonicalFile
val relativeChartYaml = IO.relativize(base, chartYaml).getOrElse("Version file [%s] is outside of this VCS repository with base directory [%s]!" format(chartYaml, base))
val relativeValuesYaml = IO.relativize(base, valuesYaml).getOrElse("Version file [%s] is outside of this VCS repository with base directory [%s]!" format(valuesYaml, base))
vcs.add(relativeChartYaml).!!
vcs.add(relativeValuesYaml).!!
vcs.commit(s"Update versions in chart for $nextVersion", sign = false, signOff = false).!
st
})
lazy val commitChartThisVersion = ReleaseStep(action = st => {
val (releaseVersion, _) = st.get(versions).getOrElse(sys.error("No versions are set! Was this release part executed before inquireVersions?"))
val vcs = Project.extract(st).get(releaseVcs).getOrElse(sys.error("Aborting release. Working directory is not a repository of a recognized VCS."))
val chartYaml = (vcs.baseDir / "charts/kafka-lag-exporter/Chart.yaml").getCanonicalFile
val valuesYaml = (vcs.baseDir / "charts/kafka-lag-exporter/values.yaml").getCanonicalFile
val base = vcs.baseDir.getCanonicalFile
val relativeChartYaml = IO.relativize(base, chartYaml).getOrElse("Version file [%s] is outside of this VCS repository with base directory [%s]!" format(chartYaml, base))
val relativeValuesYaml = IO.relativize(base, valuesYaml).getOrElse("Version file [%s] is outside of this VCS repository with base directory [%s]!" format(valuesYaml, base))
vcs.add(relativeChartYaml).!!
vcs.add(relativeValuesYaml).!!
vcs.commit(s"Update versions in chart for $releaseVersion", sign = false, signOff = false).!
st
})
lazy val packageChart = ReleaseStep(action = st => {
exec("./scripts/package_chart.sh", "Error while packaging Helm Chart")
st
})
lazy val buildChartsIndex = ReleaseStep(action = st => {
val (releaseVersion, _) = st.get(versions).getOrElse(sys.error("No versions are set! Was this release part executed before inquireVersions?"))
exec(
s"./scripts/build_charts_index.sh https://github.com/lightbend/kafka-lag-exporter/releases/download/v$releaseVersion/ https://lightbend.github.io/kafka-lag-exporter/index.yaml",
"Error while building Helm Charts index")
st
})
lazy val publishChartsIndex = ReleaseStep(action = st => {
exec("./scripts/publish_charts_index.sh", "Error while publishing Helm Charts index")
st
})
lazy val githubReleaseDraft = ReleaseStep(action = st => {
val (releaseVersion, _) = st.get(versions).getOrElse(sys.error("No versions are set! Was this release part executed before inquireVersions?"))
exec(
s"./scripts/github_release.sh lightbend/kafka-lag-exporter v$releaseVersion -- .helm-release-packages/kafka-lag-exporter-$releaseVersion.tgz ./target/universal/kafka-lag-exporter-$releaseVersion.zip",
"Error while publishing GitHub release draft")
st
})
lazy val publishDockerImage = ReleaseStep(
action = { st: State =>
val extracted = Project.extract(st)
val ref = extracted.get(thisProjectRef)
extracted.runAggregated(publish in Docker in ref, st)
}
)
lazy val packageJavaApp = ReleaseStep(
action = { st: State =>
val extracted = Project.extract(st)
val ref = extracted.get(thisProjectRef)
extracted.runAggregated(packageBin in Universal in ref, st)
}
)