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

Using podman dockerBuildAndPush error Could not parse Docker image #134 #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
19 changes: 15 additions & 4 deletions src/main/scala/sbtdocker/DockerPush.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sbtdocker

import sbt._

import scala.io.Source
import scala.sys.process.{Process, ProcessLogger}

object DockerPush {
Expand Down Expand Up @@ -41,19 +42,29 @@ object DockerPush {
}
)

val command = dockerPath :: "push" :: imageName.toString :: Nil
val isPodman = dockerPath.contains("podman")
val digestFileName = "digestFile"

val command = dockerPath :: "push" :: imageName.toString :: (if (!isPodman) Nil else List("--digestfile", digestFileName))
log.debug(s"Running command: '${command.mkString(" ")}'")

val process = Process(command)
val exitCode = process ! processLog
if (exitCode != 0) throw new DockerPushException(s"Failed to run 'docker push' on image $imageName. Exit code $exitCode")

val PushedImageDigestSha256 = ".* digest: sha256:([0-9a-f]+) .*".r

val imageDigest = lines.collect {
val digestPrefix = if(isPodman) "" else " digest: "
val PushedImageDigestSha256 = (s".*${digestPrefix}sha256:([0-9a-f]+).*").r
val imageDigest = (if(isPodman) {
val source = Source.fromFile(digestFileName)
val digestLines = source.getLines.toList
source.close()
digestLines
}
else lines).collect {
case PushedImageDigestSha256(digest) => ImageDigest("sha256", digest)
}.lastOption


imageDigest match {
case Some(digest) =>
imageName -> digest
Expand Down