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

Improve Docker version detection #1231

Merged
merged 2 commits into from
May 24, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ object DockerPlugin extends AutoPlugin {
// Some of the default values are now provided in the global setting based on
// sbt plugin best practice: https://www.scala-sbt.org/release/docs/Plugins-Best-Practices.html#Provide+default+values+in
override lazy val globalSettings: Seq[Setting[_]] = Seq(
// See https://github.com/sbt/sbt-native-packager/issues/1187
// Note: Do not make this setting depend on the Docker version.
// Docker version may change depending on the person running the build, or even with something like
// `eval $(minikube docker-env)`.
// The Docker image the build creates should be repeatable regardless of who runs it as much as possible.
// Instead of making dockerPermissionStrategy dependent on the Docker version, what we do instead is to
// run validation, and warn the build users if the strategy is not compatible with `docker` that's in scope.
dockerPermissionStrategy := DockerPermissionStrategy.MultiStage,
dockerChmodType := DockerChmodType.UserGroupReadExecute
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import scala.util.matching.Regex
case class DockerVersion(major: Int, minor: Int, patch: Int, release: Option[String])

object DockerVersion {
private val DockerVersionPattern: Regex = "^'?([0-9]+).([0-9]+).([0-9]+)-?([-a-z0-9]+)?'?$".r
private val DockerVersionPattern: Regex = """^'?([0-9]+)\.([0-9]+)(\.[0-9]+)?(\W|_)?(.+)?'?$""".r

def parse(version: String): Option[DockerVersion] =
Option(version).collect {
case DockerVersionPattern(major, minor, patch, release) =>
new DockerVersion(major.toInt, minor.toInt, patch.toInt, Option(release))
case DockerVersionPattern(major, minor, patch, _, release) =>
new DockerVersion(major.toInt, minor.toInt, Option(patch) match {
case Some(p) => p.drop(1).toInt
case _ => 0
}, Option(release))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.typesafe.sbt.packager.docker

import org.scalatest._

class DockerVersionSpec extends FlatSpec with DiagrammedAssertions {
"DockerVersion" should "parse 18.09.2" in {
val v = DockerVersion.parse("18.09.2")
assert(v == Some(DockerVersion(18, 9, 2, None)))
}

it should "parse 18.06.1-ce" in {
val v = DockerVersion.parse("18.06.1-ce")
assert(v == Some(DockerVersion(18, 6, 1, Some("ce"))))
}

it should "parse 18.03.1-ee-8" in {
val v = DockerVersion.parse("18.03.1-ee-8")
assert(v == Some(DockerVersion(18, 3, 1, Some("ee-8"))))
}

it should "parse 18.09.ee.2-1.el7.rhel" in {
val v = DockerVersion.parse("18.09.ee.2-1.el7.rhel")
assert(v == Some(DockerVersion(18, 9, 0, Some("ee.2-1.el7.rhel"))))
}

it should "parse 17.05.0~ce-0ubuntu-xenial" in {
val v = DockerVersion.parse("17.05.0~ce-0ubuntu-xenial")
assert(v == Some(DockerVersion(17, 5, 0, Some("ce-0ubuntu-xenial"))))
}
}