Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect docker buildkit stderr to info #1373

Merged
merged 1 commit into from
Oct 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -592,13 +592,31 @@ object DockerPlugin extends AutoPlugin {
case s if s.startsWith("Sending build context") =>
log.debug(s) // 1.0
case s if !s.trim.isEmpty => log.error(s)
case s =>
case _ =>
}

override def out(inf: => String): Unit =
inf match {
case s if !s.trim.isEmpty => log.info(s)
case s =>
case _ =>
}

override def buffer[T](f: => T): T = f
}

// BuildKit ouputs everything to stderr, so we redirect it
private[this] def publishLocalBuildkitLogger(log: Logger) =
new sys.process.ProcessLogger {
override def err(err: => String): Unit =
err match {
case s if !s.trim.isEmpty => log.info(s)
case _ =>
}

override def out(inf: => String): Unit =
inf match {
case s if !s.trim.isEmpty => log.info(s)
case _ =>
}

override def buffer[T](f: => T): T = f
Expand All @@ -615,7 +633,12 @@ object DockerPlugin extends AutoPlugin {
log.debug("Executing Native " + buildCommand.mkString(" "))
log.debug("Working directory " + context.toString)

val ret = sys.process.Process(buildCommand, context) ! publishLocalLogger(log)
val logger = sys.env
.get("DOCKER_BUILDKIT")
.filter(_ == "1")
.map(_ => publishLocalBuildkitLogger(log))
.getOrElse(publishLocalLogger(log))
val ret = sys.process.Process(buildCommand, context) ! logger

if (removeIntermediateImages) {
val labelKey = "snp-multi-stage-id"
Expand All @@ -629,9 +652,8 @@ object DockerPlugin extends AutoPlugin {
case Some(id) =>
val label = s"${labelKey}=${id}"
log.info(s"""Removing intermediate image(s) (labeled "${label}") """)
val retImageClean = sys.process.Process(
execCommand ++ s"image prune -f --filter label=${label}".split(" ")
) ! publishLocalLogger(log)
val retImageClean =
sys.process.Process(execCommand ++ s"image prune -f --filter label=${label}".split(" ")) ! logger
// FYI: "docker image prune" returns 0 (success) no matter if images were removed or not
if (retImageClean != 0)
log.err(
Expand Down