Skip to content

Instantly share code, notes, and snippets.

@azolotko
Last active November 23, 2022 14:21
Show Gist options
  • Save azolotko/bc642cd868c631038f690cacc2750b99 to your computer and use it in GitHub Desktop.
Save azolotko/bc642cd868c631038f690cacc2750b99 to your computer and use it in GitHub Desktop.
Generating a scratch-based container image with a GraalVM static native-image binary (via sbt-native-packager's GraalVMNativeImagePlugin and DockerPlugin)
enablePlugins(
GraalVMNativeImagePlugin,
DockerPlugin
)
GraalVMNativeImage / containerBuildImage := Some("ghcr.io/graalvm/native-image")
GraalVMNativeImage / graalVMNativeImageOptions += "--static"
GraalVMNativeImage / packageBin := (GraalVMNativeImage / packageBin).map { f =>
scala.sys.process.Process(Seq("chmod", "u+x", f.absolutePath)).!!; f
}.value
dockerExecCommand := Seq("podman") // for those who use podman
dockerBaseImage := "scratch"
dockerPermissionStrategy := com.typesafe.sbt.packager.docker.DockerPermissionStrategy.None
Docker / daemonUserUid := None
dockerCommands := dockerCommands.value.filter {
case com.typesafe.sbt.packager.docker.Cmd("USER", _*) => false
case _ => true
}
Docker / mappings := Seq(
(GraalVMNativeImage / packageBin).value ->
(Docker / dockerEntrypoint).value.head
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment