From 3f2657104428ac519f06ef0dd2ada471496ac5d5 Mon Sep 17 00:00:00 2001 From: kimxogus Date: Mon, 21 Aug 2017 11:40:10 +0900 Subject: [PATCH 1/4] wrap labels with " character --- .../com/typesafe/sbt/packager/docker/DockerPlugin.scala | 8 ++++++-- .../scala/com/typesafe/sbt/packager/docker/Keys.scala | 2 +- src/sbt-test/docker/labels/build.sbt | 2 +- src/sbt-test/docker/labels/test | 5 +++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala index b64c96fef..3f46929bd 100644 --- a/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala @@ -167,9 +167,13 @@ object DockerPlugin extends AutoPlugin { * @param label * @return LABEL command */ - private final def makeLabel(label: Tuple2[String, String]): CmdLike = { + private final def makeLabel(label: (String, Any)): CmdLike = { val (variable, value) = label - Cmd("LABEL", s"${variable}=${value}") + val valueString = value match { + case n: Number => n.toString + case _ => "\"" + value.toString + "\"" + } + Cmd("LABEL", s"$variable=$valueString") } /** diff --git a/src/main/scala/com/typesafe/sbt/packager/docker/Keys.scala b/src/main/scala/com/typesafe/sbt/packager/docker/Keys.scala index 6c7fcb758..1f3164b54 100644 --- a/src/main/scala/com/typesafe/sbt/packager/docker/Keys.scala +++ b/src/main/scala/com/typesafe/sbt/packager/docker/Keys.scala @@ -31,7 +31,7 @@ trait DockerKeys { val dockerExecCommand = SettingKey[Seq[String]]("dockerExecCommand", "The shell command used to exec Docker") val dockerBuildOptions = SettingKey[Seq[String]]("dockerBuildOptions", "Options used for the Docker build") val dockerBuildCommand = SettingKey[Seq[String]]("dockerBuildCommand", "Command for building the Docker image") - val dockerLabels = SettingKey[Map[String, String]]("dockerLabels", "Labels applied to the Docker image") + val dockerLabels = SettingKey[Map[String, Any]]("dockerLabels", "Labels applied to the Docker image") val dockerRmiCommand = SettingKey[Seq[String]]("dockerRmiCommand", "Command for removing the Docker image from the local registry") diff --git a/src/sbt-test/docker/labels/build.sbt b/src/sbt-test/docker/labels/build.sbt index 4be6e3807..a5dee3e90 100644 --- a/src/sbt-test/docker/labels/build.sbt +++ b/src/sbt-test/docker/labels/build.sbt @@ -4,4 +4,4 @@ name := "simple-test" version := "0.1.0" -dockerLabels := Map("foo" -> "bar", "Hello" -> "World") +dockerLabels := Map("foo" -> "foo", "fooBar" -> "foo bar", "number" -> 123) diff --git a/src/sbt-test/docker/labels/test b/src/sbt-test/docker/labels/test index df22a3379..0eacb2721 100644 --- a/src/sbt-test/docker/labels/test +++ b/src/sbt-test/docker/labels/test @@ -1,4 +1,5 @@ # Stage the distribution and ensure files show up. > docker:stage -$ exec grep -q -F 'LABEL foo=bar' target/docker/Dockerfile -$ exec grep -q -F 'LABEL Hello=World' target/docker/Dockerfile +$ exec grep -q -F 'LABEL foo="bar"' target/docker/Dockerfile +$ exec grep -q -F 'LABEL fooBar="foo bar"' target/docker/Dockerfile +$ exec grep -q -F 'LABEL number=123' target/docker/Dockerfile From 13fb677b388a42e176127cfd052c994600fa1e4a Mon Sep 17 00:00:00 2001 From: kimxogus Date: Mon, 21 Aug 2017 22:36:58 +0900 Subject: [PATCH 2/4] wrap all values in double quetes and fix dockerLabels type --- .../com/typesafe/sbt/packager/docker/DockerPlugin.scala | 8 ++------ .../scala/com/typesafe/sbt/packager/docker/Keys.scala | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala index 3f46929bd..2c02b0068 100644 --- a/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala @@ -167,13 +167,9 @@ object DockerPlugin extends AutoPlugin { * @param label * @return LABEL command */ - private final def makeLabel(label: (String, Any)): CmdLike = { + private final def makeLabel(label: (String, String)): CmdLike = { val (variable, value) = label - val valueString = value match { - case n: Number => n.toString - case _ => "\"" + value.toString + "\"" - } - Cmd("LABEL", s"$variable=$valueString") + Cmd("LABEL", s"$variable=\"${value.toString}\"") } /** diff --git a/src/main/scala/com/typesafe/sbt/packager/docker/Keys.scala b/src/main/scala/com/typesafe/sbt/packager/docker/Keys.scala index 1f3164b54..6c7fcb758 100644 --- a/src/main/scala/com/typesafe/sbt/packager/docker/Keys.scala +++ b/src/main/scala/com/typesafe/sbt/packager/docker/Keys.scala @@ -31,7 +31,7 @@ trait DockerKeys { val dockerExecCommand = SettingKey[Seq[String]]("dockerExecCommand", "The shell command used to exec Docker") val dockerBuildOptions = SettingKey[Seq[String]]("dockerBuildOptions", "Options used for the Docker build") val dockerBuildCommand = SettingKey[Seq[String]]("dockerBuildCommand", "Command for building the Docker image") - val dockerLabels = SettingKey[Map[String, Any]]("dockerLabels", "Labels applied to the Docker image") + val dockerLabels = SettingKey[Map[String, String]]("dockerLabels", "Labels applied to the Docker image") val dockerRmiCommand = SettingKey[Seq[String]]("dockerRmiCommand", "Command for removing the Docker image from the local registry") From 30ad70539163bfc64ccbaf65ebafca5c0f52b7c9 Mon Sep 17 00:00:00 2001 From: kimxogus Date: Mon, 21 Aug 2017 22:45:50 +0900 Subject: [PATCH 3/4] update sbt-test --- src/sbt-test/docker/labels/build.sbt | 2 +- src/sbt-test/docker/labels/test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sbt-test/docker/labels/build.sbt b/src/sbt-test/docker/labels/build.sbt index a5dee3e90..0103c2757 100644 --- a/src/sbt-test/docker/labels/build.sbt +++ b/src/sbt-test/docker/labels/build.sbt @@ -4,4 +4,4 @@ name := "simple-test" version := "0.1.0" -dockerLabels := Map("foo" -> "foo", "fooBar" -> "foo bar", "number" -> 123) +dockerLabels := Map("foo" -> "foo", "fooBar" -> "foo bar", "number" -> "123") diff --git a/src/sbt-test/docker/labels/test b/src/sbt-test/docker/labels/test index 0eacb2721..f53ab8c26 100644 --- a/src/sbt-test/docker/labels/test +++ b/src/sbt-test/docker/labels/test @@ -2,4 +2,4 @@ > docker:stage $ exec grep -q -F 'LABEL foo="bar"' target/docker/Dockerfile $ exec grep -q -F 'LABEL fooBar="foo bar"' target/docker/Dockerfile -$ exec grep -q -F 'LABEL number=123' target/docker/Dockerfile +$ exec grep -q -F 'LABEL number="123"' target/docker/Dockerfile From be21c0a16dd25f2bd4d3af2923a94b0d2899e3e5 Mon Sep 17 00:00:00 2001 From: kimxogus Date: Mon, 21 Aug 2017 23:01:50 +0900 Subject: [PATCH 4/4] fix compile error --- .../scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala index 2c02b0068..a3e34055a 100644 --- a/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala @@ -169,7 +169,7 @@ object DockerPlugin extends AutoPlugin { */ private final def makeLabel(label: (String, String)): CmdLike = { val (variable, value) = label - Cmd("LABEL", s"$variable=\"${value.toString}\"") + Cmd("LABEL", variable + "=\"" + value.toString + "\"") } /**