From f7ca13847b154be59676eb676c010e186f29e9d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Cort=C3=AAs?= Date: Sat, 4 Nov 2017 12:01:58 +0000 Subject: [PATCH 1/3] Remove redundant Dockerfile Fixes #1060 --- .../typesafe/sbt/packager/docker/DockerPlugin.scala | 11 +++++------ 1 file changed, 5 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 88ee7772e..a1f35d7cb 100644 --- a/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala @@ -112,10 +112,6 @@ object DockerPlugin extends AutoPlugin { Seq( executableScriptName := executableScriptName.value, mappings ++= dockerPackageMappings.value, - mappings ++= { - val baseDir = target.value - Seq(dockerGenerateConfig.value) pair (file => IO.relativize(baseDir, file)) - }, name := name.value, packageName := packageName.value, publishLocal := { @@ -144,14 +140,17 @@ object DockerPlugin extends AutoPlugin { } }, sourceDirectory := sourceDirectory.value / "docker", - stage := Stager.stage(Docker.name)(streams.value, stagingDirectory.value, mappings.value), + stage := { + dockerGenerateConfig.value + Stager.stage(Docker.name)(streams.value, stagingDirectory.value, mappings.value) + }, stagingDirectory := (target in Docker).value / "stage", target := target.value / "docker", daemonUser := "daemon", daemonGroup := daemonUser.value, defaultLinuxInstallLocation := "/opt/docker", dockerPackageMappings := MappingsHelper.contentOf(sourceDirectory.value), - dockerGenerateConfig := generateDockerConfig(dockerCommands.value, target.value) + dockerGenerateConfig := generateDockerConfig(dockerCommands.value, stagingDirectory.value) ) ) From 8a7b9a15a33cfd4f7d41b0fb8e987e8d0d3158ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Cort=C3=AAs?= Date: Sun, 5 Nov 2017 10:33:11 +0000 Subject: [PATCH 2/3] Update tests --- src/sbt-test/docker/entrypoint/test | 2 +- src/sbt-test/docker/labels/build.sbt | 2 +- src/sbt-test/docker/ports/test | 2 +- src/sbt-test/docker/test-executableScriptName/build.sbt | 2 +- src/sbt-test/docker/test-packageName-universal/build.sbt | 2 +- src/sbt-test/docker/test-packageName/build.sbt | 2 +- src/sbt-test/docker/udp-only-ports/test | 2 +- src/sbt-test/docker/volumes/test | 6 +++--- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/sbt-test/docker/entrypoint/test b/src/sbt-test/docker/entrypoint/test index 6ab640bcb..8fba43b1f 100644 --- a/src/sbt-test/docker/entrypoint/test +++ b/src/sbt-test/docker/entrypoint/test @@ -1,3 +1,3 @@ # Stage the distribution and ensure files show up. > docker:stage -$ exec grep -q -F 'ENTRYPOINT ["/bin/sh", "-c", "env"]' target/docker/Dockerfile +$ exec grep -q -F 'ENTRYPOINT ["/bin/sh", "-c", "env"]' target/docker/stage/Dockerfile diff --git a/src/sbt-test/docker/labels/build.sbt b/src/sbt-test/docker/labels/build.sbt index c8617d663..818491b08 100644 --- a/src/sbt-test/docker/labels/build.sbt +++ b/src/sbt-test/docker/labels/build.sbt @@ -8,7 +8,7 @@ dockerLabels := Map("foo" -> "bar", "fooBar" -> "foo bar", "number" -> "123") TaskKey[Unit]("checkDockerfile") := { - val dockerfile = IO.read((target in Docker).value / "Dockerfile") + val dockerfile = IO.read((stagingDirectory in Docker).value / "Dockerfile") assert(dockerfile contains """LABEL foo="bar"""", s"does not contain foo=bar\n$dockerfile") assert(dockerfile contains """LABEL fooBar="foo bar"""", s"does not contain foo=bar\n$dockerfile") diff --git a/src/sbt-test/docker/ports/test b/src/sbt-test/docker/ports/test index a23ca52d4..8d6e17b83 100644 --- a/src/sbt-test/docker/ports/test +++ b/src/sbt-test/docker/ports/test @@ -1,3 +1,3 @@ # Stage the distribution and ensure files show up. > docker:stage -$ exec grep -q -F 'EXPOSE 9000 9001 10000/udp 10001/udp' target/docker/Dockerfile +$ exec grep -q -F 'EXPOSE 9000 9001 10000/udp 10001/udp' target/docker/stage/Dockerfile diff --git a/src/sbt-test/docker/test-executableScriptName/build.sbt b/src/sbt-test/docker/test-executableScriptName/build.sbt index 93086b161..bbe73e03e 100644 --- a/src/sbt-test/docker/test-executableScriptName/build.sbt +++ b/src/sbt-test/docker/test-executableScriptName/build.sbt @@ -11,7 +11,7 @@ version := "0.1.0" maintainer := "Gary Coady " TaskKey[Unit]("checkDockerfile") := { - val dockerfile = IO.read(target.value / "docker" / "Dockerfile") + val dockerfile = IO.read((stagingDirectory in Docker).value / "Dockerfile") assert( dockerfile.contains("ENTRYPOINT [\"bin/docker-exec\"]\n"), "dockerfile doesn't contain ENTRYPOINT [\"docker-exec\"]\n" + dockerfile diff --git a/src/sbt-test/docker/test-packageName-universal/build.sbt b/src/sbt-test/docker/test-packageName-universal/build.sbt index 17c214855..919e75ae3 100644 --- a/src/sbt-test/docker/test-packageName-universal/build.sbt +++ b/src/sbt-test/docker/test-packageName-universal/build.sbt @@ -9,7 +9,7 @@ version := "0.1.0" maintainer := "Gary Coady " TaskKey[Unit]("checkDockerfile") := { - val dockerfile = IO.read(target.value / "docker" / "Dockerfile") + val dockerfile = IO.read((stagingDirectory in Docker).value / "Dockerfile") assert( dockerfile.contains("ENTRYPOINT [\"bin/docker-test\"]\n"), "dockerfile doesn't contain ENTRYPOINT [\"docker-test\"]\n" + dockerfile diff --git a/src/sbt-test/docker/test-packageName/build.sbt b/src/sbt-test/docker/test-packageName/build.sbt index f855ea17b..9149bbeb8 100644 --- a/src/sbt-test/docker/test-packageName/build.sbt +++ b/src/sbt-test/docker/test-packageName/build.sbt @@ -10,7 +10,7 @@ version := "0.1.0" maintainer := "Gary Coady " TaskKey[Unit]("checkDockerfile") := { - val dockerfile = IO.read(target.value / "docker" / "Dockerfile") + val dockerfile = IO.read((stagingDirectory in Docker).value / "Dockerfile") assert( dockerfile.contains("ENTRYPOINT [\"bin/docker-test\"]\n"), "dockerfile doesn't contain ENTRYPOINT [\"docker-test\"]\n" + dockerfile diff --git a/src/sbt-test/docker/udp-only-ports/test b/src/sbt-test/docker/udp-only-ports/test index 6c60b6b0f..2061f2a57 100644 --- a/src/sbt-test/docker/udp-only-ports/test +++ b/src/sbt-test/docker/udp-only-ports/test @@ -1,3 +1,3 @@ # Stage the distribution and ensure files show up. > docker:stage -$ exec grep -q -F 'EXPOSE 10000/udp 10001/udp' target/docker/Dockerfile +$ exec grep -q -F 'EXPOSE 10000/udp 10001/udp' target/docker/stage/Dockerfile diff --git a/src/sbt-test/docker/volumes/test b/src/sbt-test/docker/volumes/test index 302f8845a..03bc826a9 100644 --- a/src/sbt-test/docker/volumes/test +++ b/src/sbt-test/docker/volumes/test @@ -1,5 +1,5 @@ # Stage the distribution and ensure files show up. > docker:stage -$ exec grep -q -F 'VOLUME ["/opt/docker/logs", "/opt/docker/config"]' target/docker/Dockerfile -$ exec grep -q -F 'RUN ["chown", "-R", "daemon:daemon", "/opt/docker/logs", "/opt/docker/config"]' target/docker/Dockerfile -$ exec grep -q -F 'RUN ["mkdir", "-p", "/opt/docker/logs", "/opt/docker/config"]' target/docker/Dockerfile +$ exec grep -q -F 'VOLUME ["/opt/docker/logs", "/opt/docker/config"]' target/docker/stage/Dockerfile +$ exec grep -q -F 'RUN ["chown", "-R", "daemon:daemon", "/opt/docker/logs", "/opt/docker/config"]' target/docker/stage/Dockerfile +$ exec grep -q -F 'RUN ["mkdir", "-p", "/opt/docker/logs", "/opt/docker/config"]' target/docker/stage/Dockerfile From 1e72b69e19b357f449a1d01cc15473ba3b584f6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Cort=C3=AAs?= Date: Sun, 5 Nov 2017 10:34:02 +0000 Subject: [PATCH 3/3] Change stage task to use dependsOn --- .../com/typesafe/sbt/packager/docker/DockerPlugin.scala | 6 ++---- 1 file changed, 2 insertions(+), 4 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 a1f35d7cb..87d4c0930 100644 --- a/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala @@ -140,10 +140,8 @@ object DockerPlugin extends AutoPlugin { } }, sourceDirectory := sourceDirectory.value / "docker", - stage := { - dockerGenerateConfig.value - Stager.stage(Docker.name)(streams.value, stagingDirectory.value, mappings.value) - }, + stage := Stager.stage(Docker.name)(streams.value, stagingDirectory.value, mappings.value), + stage := (stage dependsOn dockerGenerateConfig).value, stagingDirectory := (target in Docker).value / "stage", target := target.value / "docker", daemonUser := "daemon",