Skip to content

Commit

Permalink
common: Prune system libs from distroless image (close #728)
Browse files Browse the repository at this point in the history
  • Loading branch information
istreeter committed Nov 17, 2022
1 parent f85e48a commit 0de2af3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 35 deletions.
28 changes: 14 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ lazy val streamCommon = project

lazy val streamKinesis = project
.in(file("modules/stream/kinesis"))
.enablePlugins(JavaAppPackaging, DockerPlugin)
.enablePlugins(JavaAppPackaging, SnowplowDockerPlugin)
.settings(streamKinesisBuildSettings)
.settings(libraryDependencies ++= streamKinesisDependencies)
.settings(excludeDependencies ++= exclusions)
.dependsOn(streamCommon)

lazy val streamKinesisDistroless = project
.in(file("modules/distroless/stream/kinesis"))
.enablePlugins(JavaAppPackaging, DockerPlugin, LauncherJarPlugin)
.enablePlugins(JavaAppPackaging, SnowplowDistrolessDockerPlugin)
.settings(sourceDirectory := (streamKinesis / sourceDirectory).value)
.settings(streamKinesisDistrolessBuildSettings)
.settings(libraryDependencies ++= streamKinesisDependencies)
Expand All @@ -58,15 +58,15 @@ lazy val streamKinesisDistroless = project

lazy val streamKafka = project
.in(file("modules/stream/kafka"))
.enablePlugins(JavaAppPackaging, DockerPlugin)
.enablePlugins(JavaAppPackaging, SnowplowDockerPlugin)
.settings(streamKafkaBuildSettings)
.settings(libraryDependencies ++= streamKafkaDependencies)
.settings(excludeDependencies ++= exclusions)
.dependsOn(streamCommon)

lazy val streamKafkaDistroless = project
.in(file("modules/distroless/stream/kafka"))
.enablePlugins(JavaAppPackaging, DockerPlugin, LauncherJarPlugin)
.enablePlugins(JavaAppPackaging, SnowplowDistrolessDockerPlugin)
.settings(sourceDirectory := (streamKafka / sourceDirectory).value)
.settings(streamKafkaDistrolessBuildSettings)
.settings(libraryDependencies ++= streamKafkaDependencies)
Expand All @@ -75,15 +75,15 @@ lazy val streamKafkaDistroless = project

lazy val streamNsq = project
.in(file("modules/stream/nsq"))
.enablePlugins(JavaAppPackaging, DockerPlugin)
.enablePlugins(JavaAppPackaging, SnowplowDockerPlugin)
.settings(streamNsqBuildSettings)
.settings(libraryDependencies ++= streamNsqDependencies)
.settings(excludeDependencies ++= exclusions)
.dependsOn(streamCommon)

lazy val streamNsqDistroless = project
.in(file("modules/distroless/stream/nsq"))
.enablePlugins(JavaAppPackaging, DockerPlugin, LauncherJarPlugin)
.enablePlugins(JavaAppPackaging, SnowplowDistrolessDockerPlugin)
.settings(sourceDirectory := (streamNsq / sourceDirectory).value)
.settings(streamNsqDistrolessBuildSettings)
.settings(libraryDependencies ++= streamNsqDependencies)
Expand All @@ -108,7 +108,7 @@ lazy val commonFs2 = project

lazy val pubsub = project
.in(file("modules/pubsub"))
.enablePlugins(BuildInfoPlugin, JavaAppPackaging, DockerPlugin)
.enablePlugins(BuildInfoPlugin, JavaAppPackaging, SnowplowDockerPlugin)
.settings(pubsubBuildSettings)
.settings(libraryDependencies ++= pubsubDependencies)
.settings(excludeDependencies ++= exclusions)
Expand All @@ -117,7 +117,7 @@ lazy val pubsub = project

lazy val pubsubDistroless = project
.in(file("modules/distroless/pubsub"))
.enablePlugins(BuildInfoPlugin, JavaAppPackaging, DockerPlugin, LauncherJarPlugin)
.enablePlugins(BuildInfoPlugin, JavaAppPackaging, SnowplowDistrolessDockerPlugin)
.settings(sourceDirectory := (pubsub / sourceDirectory).value)
.settings(pubsubDistrolessBuildSettings)
.settings(libraryDependencies ++= pubsubDependencies)
Expand All @@ -128,7 +128,7 @@ lazy val pubsubDistroless = project

lazy val kinesis = project
.in(file("modules/kinesis"))
.enablePlugins(BuildInfoPlugin, JavaAppPackaging, DockerPlugin)
.enablePlugins(BuildInfoPlugin, JavaAppPackaging, SnowplowDockerPlugin)
.settings(kinesisBuildSettings)
.settings(libraryDependencies ++= kinesisDependencies ++ Seq(
// integration tests dependencies
Expand All @@ -144,7 +144,7 @@ lazy val kinesis = project

lazy val kinesisDistroless = project
.in(file("modules/distroless/kinesis"))
.enablePlugins(BuildInfoPlugin, JavaAppPackaging, DockerPlugin, LauncherJarPlugin)
.enablePlugins(BuildInfoPlugin, JavaAppPackaging, SnowplowDistrolessDockerPlugin)
.settings(sourceDirectory := (kinesis / sourceDirectory).value)
.settings(kinesisDistrolessBuildSettings)
.settings(libraryDependencies ++= kinesisDependencies)
Expand All @@ -154,7 +154,7 @@ lazy val kinesisDistroless = project

lazy val kafka = project
.in(file("modules/kafka"))
.enablePlugins(BuildInfoPlugin, JavaAppPackaging, DockerPlugin)
.enablePlugins(BuildInfoPlugin, JavaAppPackaging, SnowplowDockerPlugin)
.settings(kafkaBuildSettings)
.settings(libraryDependencies ++= kafkaDependencies ++ Seq(
// integration tests dependencies
Expand All @@ -168,7 +168,7 @@ lazy val kafka = project

lazy val kafkaDistroless = project
.in(file("modules/distroless/kafka"))
.enablePlugins(BuildInfoPlugin, JavaAppPackaging, DockerPlugin, LauncherJarPlugin)
.enablePlugins(BuildInfoPlugin, JavaAppPackaging, SnowplowDistrolessDockerPlugin)
.settings(sourceDirectory := (kafka / sourceDirectory).value)
.settings(kafkaDistrolessBuildSettings)
.settings(libraryDependencies ++= kafkaDependencies)
Expand All @@ -183,7 +183,7 @@ lazy val bench = project

lazy val rabbitmq = project
.in(file("modules/rabbitmq"))
.enablePlugins(BuildInfoPlugin, JavaAppPackaging, DockerPlugin)
.enablePlugins(BuildInfoPlugin, JavaAppPackaging, SnowplowDockerPlugin)
.settings(rabbitmqBuildSettings)
.settings(libraryDependencies ++= rabbitmqDependencies)
.settings(excludeDependencies ++= exclusions)
Expand All @@ -192,7 +192,7 @@ lazy val rabbitmq = project

lazy val rabbitmqDistroless = project
.in(file("modules/distroless/rabbitmq"))
.enablePlugins(BuildInfoPlugin, JavaAppPackaging, DockerPlugin, LauncherJarPlugin)
.enablePlugins(BuildInfoPlugin, JavaAppPackaging, SnowplowDistrolessDockerPlugin)
.settings(sourceDirectory := (rabbitmq / sourceDirectory).value)
.settings(rabbitmqDistrolessBuildSettings)
.settings(libraryDependencies ++= rabbitmqDependencies)
Expand Down
25 changes: 5 additions & 20 deletions project/BuildSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import sbtbuildinfo.BuildInfoPlugin.autoImport.{BuildInfoKey, buildInfoKeys, bui
import sbtdynver.DynVerPlugin.autoImport._
import com.typesafe.sbt.SbtNativePackager.autoImport._
import com.typesafe.sbt.packager.archetypes.jar.LauncherJarPlugin.autoImport.packageJavaLauncherJar
import com.typesafe.sbt.packager.docker.DockerPermissionStrategy
import com.typesafe.sbt.packager.docker.DockerPlugin.autoImport._
import com.typesafe.sbt.packager.linux.LinuxPlugin.autoImport._
import com.typesafe.sbt.packager.universal.UniversalPlugin.autoImport._
Expand Down Expand Up @@ -194,28 +193,14 @@ object BuildSettings {
)

lazy val dockerSettingsFocal = Seq(
Universal / javaOptions ++= Seq("-Dnashorn.args=--language=es6"),
Docker / maintainer := "Snowplow Analytics Ltd. <[email protected]>",
dockerBaseImage := "eclipse-temurin:11-jre-focal",
dockerRepository := Some("snowplow"),
Docker / daemonUser := "snowplow",
Docker / defaultLinuxInstallLocation := "/home/snowplow",
dockerUpdateLatest := true
Universal / javaOptions ++= Seq("-Dnashorn.args=--language=es6")
)

lazy val dockerSettingsDistroless = Seq(
Universal / javaOptions ++= Seq("-Dnashorn.args=--language=es6"),
Docker / maintainer := "Snowplow Analytics Ltd. <[email protected]>",
dockerBaseImage := "gcr.io/distroless/java11-debian11:nonroot",
Docker / daemonUser := "nonroot",
Docker / daemonGroup := "nonroot",
dockerRepository := Some("snowplow"),
Docker / daemonUserUid := None,
Docker / defaultLinuxInstallLocation := "/home/snowplow",
dockerEntrypoint := Seq("java", "-jar",s"/home/snowplow/lib/${(packageJavaLauncherJar / artifactPath).value.getName}"),
dockerPermissionStrategy := DockerPermissionStrategy.CopyChown,
dockerAlias := dockerAlias.value.copy(tag = dockerAlias.value.tag.map(t => s"$t-distroless")),
dockerUpdateLatest := false
dockerEntrypoint := {
val orig = dockerEntrypoint.value
orig.head +: "-Dnashorn.args=--language=es6" +: orig.tail
}
)

// TESTS
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.9")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.7")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2")
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.17")
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.3.1")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.2")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.0")
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.7")
addSbtPlugin("com.snowplowanalytics" % "sbt-snowplow-release" % "0.1.0")

0 comments on commit 0de2af3

Please sign in to comment.