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

Support nerdctl #132

Merged
merged 2 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
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
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