lightbend / cloudflow

Cloudflow enables users to quickly develop, orchestrate, and operate distributed streaming applications on Kubernetes.
https://cloudflow.io
Apache License 2.0
321 stars 89 forks source link

[idea] Switch from sbt-docker to sbt-native-packager #771

Open andreaTP opened 3 years ago

andreaTP commented 3 years ago

Currently, Cloudflow relies on sbt-docker internally(e.g. the operator image) and for the buildApp task of the sbt plugin.

This causes small issues, especially with caches, such as buildApp task needs to be run after a clean when you change Cloudflow version (I can confirm that this is automatically solved by sbt-native-packager).

Also sbt-native-packager is a more widely used and maintained project.

Our dependency on sbt-docker is the extraction of the digest that can be replaced by something like:

val testPublish = taskKey[String]("test")
testPublish := {
  val _ = publishLocal.value
  val alias = dockerAliases.value

  var digest: String = null
  import sbt.internal.util.ManagedLogger
  class MyManagedLogger(ml: ManagedLogger) extends ManagedLogger(ml.name, ml.channelName, ml.execId, null) {
    val PushedImageDigestSha256 = ".* digest: sha256:([0-9a-f]+) .*".r

    override def log(level: Level.Value, message: => String): Unit = {
      message match {
        case PushedImageDigestSha256(d) => digest = d
        case _ =>
      }
    }
  }
  val log = new MyManagedLogger(streams.value.log)
  val execCommand = dockerExecCommand.value
  alias.foreach { aliasValue =>
    _root_.com.typesafe.sbt.packager.docker.DockerPlugin.publishDocker(execCommand, aliasValue.toString, log)
  }

  digest
}

On the downside this is going to be a breaking change for the user.

seglo commented 3 years ago

Oh, cloudflow was using sbt-native-packager, but I guess it was changed at some point?

One thing to keep an eye out if we do this is that the images are still built efficiently. The app artifacts should be in a single layer so only 1 small layer change is required for each new image push. sbt-native-packager (IIRC) puts all artifacts in a single directory (including dependencies) which can result in a bigger layer every time the app is changed.

This has been a topic of some debate to make this functionality the default in sbt-native-packager for Docker targets. https://github.com/sbt/sbt-native-packager/pull/1310