Skip to content

Commit

Permalink
Merge pull request #132 from giabao/master
Browse files Browse the repository at this point in the history
Support nerdctl
  • Loading branch information
marcuslonnberg committed Aug 24, 2023
2 parents 8b868e3 + 6261c3d commit eedbd60
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
13 changes: 6 additions & 7 deletions src/main/scala/sbtdocker/DockerBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -184,32 +184,31 @@ object DockerBuild {
"--rm=true"
}
}
val pullFlag = {
val value = buildOptions.pullBaseImage match {
case BuildOptions.Pull.Always => true
case BuildOptions.Pull.IfMissing => false
}
"--pull=" + value
val pullFlag = buildOptions.pullBaseImage match {
case BuildOptions.Pull.Always => List("--pull")
case BuildOptions.Pull.IfMissing => Nil
}
val platformsFlag: List[String] = buildOptions.platforms match {
case Seq() => Nil
case platforms => List(s"--platform=${platforms.mkString(",")}")
}

cacheFlag :: removeFlag :: pullFlag :: platformsFlag ::: buildOptions.additionalArguments.toList
cacheFlag :: removeFlag :: pullFlag ::: platformsFlag ::: buildOptions.additionalArguments.toList
}

private val SuccessfullyBuilt = "^Successfully built ([0-9a-f]+)$".r
private val SuccessfullyBuiltBuildKit = ".* writing image sha256:([0-9a-f]+) .*\\bdone$".r
private val SuccessfullyBuiltBuildx = ".* exporting config sha256:([0-9a-f]+) .*\\bdone$".r
private val SuccessfullyBuiltPodman = "^([0-9a-f]{64})$".r
private val SuccessfullyBuiltNerdctl = "^Loaded image: .*sha256:([0-9a-f]+)$".r

private[sbtdocker] def parseImageId(lines: Seq[String]): Option[ImageId] = {
lines.collect {
case SuccessfullyBuilt(id) => ImageId(id)
case SuccessfullyBuiltBuildKit(id) => ImageId(id)
case SuccessfullyBuiltBuildx(id) => ImageId(id)
case SuccessfullyBuiltPodman(id) => ImageId(id)
case SuccessfullyBuiltNerdctl(id) => ImageId(id)
}.lastOption
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/scala/sbtdocker/DockerBuildSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class DockerBuildSpec extends AnyFreeSpec with Matchers {

val flags = DockerBuild.generateBuildOptionFlags(options)

flags should contain theSameElementsAs Seq("--no-cache=false", "--pull=false", "--rm=true")
flags should contain theSameElementsAs Seq("--no-cache=false", "--rm=true")
}

"No cache" in {
Expand All @@ -88,14 +88,14 @@ class DockerBuildSpec extends AnyFreeSpec with Matchers {
val options = BuildOptions(removeIntermediateContainers = BuildOptions.Remove.Never)
val flags = DockerBuild.generateBuildOptionFlags(options)

flags should contain("--pull=false")
flags should contain("--rm=false")
}

"Always pull" in {
val options = BuildOptions(pullBaseImage = BuildOptions.Pull.Always)
val flags = DockerBuild.generateBuildOptionFlags(options)

flags should contain("--pull=true")
flags should contain("--pull")
}

"Add platform argument for cross build" in {
Expand Down

0 comments on commit eedbd60

Please sign in to comment.