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

Add: dockerAdditionalVersions #806

Closed
wants to merge 2 commits into from
Closed
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
26 changes: 20 additions & 6 deletions src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ object DockerPlugin extends AutoPlugin {
dockerExposedVolumes := Seq(),
dockerRepository := None,
dockerUpdateLatest := false,
dockerAdditionalVersions := Seq(),
dockerEntrypoint := Seq("bin/%s" format executableScriptName.value),
dockerCmd := Seq(),
dockerCommands := {
Expand Down Expand Up @@ -104,17 +105,21 @@ object DockerPlugin extends AutoPlugin {
mappings ++= Seq(dockerGenerateConfig.value) pair relativeTo(target.value),
name := name.value,
packageName := packageName.value,
publishLocal <<= (stage, dockerTarget, dockerUpdateLatest, streams) map {
(context, target, updateLatest, s) =>
publishLocalDocker(context, target, updateLatest, s.log)
publishLocal <<= (stage, dockerTarget, dockerUpdateLatest, dockerAdditionalVersions, streams) map {
(context, target, updateLatest, additionalVersions, s) =>
publishLocalDocker(context, target, updateLatest, additionalVersions, s.log)
},
publish <<= (publishLocal, dockerTarget, dockerUpdateLatest, streams) map {
(_, target, updateLatest, s) =>
publish <<= (publishLocal, dockerTarget, dockerUpdateLatest, dockerAdditionalVersions, streams) map {
(_, target, updateLatest, additionalVersions, s) =>
publishDocker(target, s.log)
if (updateLatest) {
val name = target.substring(0, target.lastIndexOf(":")) + ":latest"
publishDocker(name, s.log)
}
additionalVersions foreach { v =>
val name = target.substring(0, target.lastIndexOf(":")) + ":" + v
publishDocker(name, s.log)
}
},
sourceDirectory := sourceDirectory.value / "docker",
stage <<= (streams, stagingDirectory, mappings) map Stager.stage(Docker.name),
Expand Down Expand Up @@ -279,7 +284,7 @@ object DockerPlugin extends AutoPlugin {
}
}

def publishLocalDocker(context: File, tag: String, latest: Boolean, log: Logger): Unit = {
def publishLocalDocker(context: File, tag: String, latest: Boolean, additionalVersions: Seq[String], log: Logger): Unit = {
val cmd = Seq("docker", "build", "--force-rm", "-t", tag, ".")

log.debug("Executing Native " + cmd.mkString(" "))
Expand All @@ -300,6 +305,15 @@ object DockerPlugin extends AutoPlugin {
case n => sys.error("Failed to run docker tag")
}
}

additionalVersions foreach { v =>
val name = tag.substring(0, tag.lastIndexOf(":")) + ":" + v
val cmd = Seq("docker", "tag", "-f", tag, name)
Process(cmd).! match {
case 0 => log.info("Update version " + v + " from image " + tag)
case n => sys.error("Failed to run docker tag")
}
}
}

def publishDocker(tag: String, log: Logger): Unit = {
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/com/typesafe/sbt/packager/docker/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ trait DockerKeys {
val dockerExposedVolumes = SettingKey[Seq[String]]("dockerExposedVolumes", "Volumes exposed by Docker image")
val dockerRepository = SettingKey[Option[String]]("dockerRepository", "Repository for published Docker image")
val dockerUpdateLatest = SettingKey[Boolean]("dockerUpdateLatest", "Set to update latest tag")
val dockerAdditionalVersions = SettingKey[Seq[String]]("dockerAdditionalVersions", "Set additional version tags such as git branch or git tag")
val dockerEntrypoint = SettingKey[Seq[String]]("dockerEntrypoint", "Entrypoint arguments passed in exec form")
val dockerCmd = SettingKey[Seq[String]]("dockerCmd", "Docker CMD. Used together with dockerEntrypoint. Arguments passed in exec form")

Expand Down