From 27a511fda983771cf8f0c6f50c9f2ee744216fb2 Mon Sep 17 00:00:00 2001 From: Dmitriy Shepelev Date: Tue, 9 Jan 2024 14:38:11 +0400 Subject: [PATCH] issue 134: detect podman from dockerPath and read digest from file if isPodman true --- src/main/scala/sbtdocker/DockerPush.scala | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/scala/sbtdocker/DockerPush.scala b/src/main/scala/sbtdocker/DockerPush.scala index a053209..285d4e4 100644 --- a/src/main/scala/sbtdocker/DockerPush.scala +++ b/src/main/scala/sbtdocker/DockerPush.scala @@ -2,6 +2,7 @@ package sbtdocker import sbt._ +import scala.io.Source import scala.sys.process.{Process, ProcessLogger} object DockerPush { @@ -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