From c0ce905e4ad04fb54a2b9ce59900319752ce4ccf Mon Sep 17 00:00:00 2001 From: James Roper Date: Wed, 18 Mar 2020 00:24:47 +1100 Subject: [PATCH] Name the main docker stage (#1316) Fixes #1315 --- .../typesafe/sbt/packager/docker/DockerPlugin.scala | 9 +-------- src/sbt-test/docker/file-permission/build.sbt | 12 ++++++------ 2 files changed, 7 insertions(+), 14 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 bba03837a..6eaefa1ac 100644 --- a/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala @@ -157,7 +157,7 @@ object DockerPlugin extends AutoPlugin { val base = dockerBaseImage.value val addPerms = dockerAdditionalPermissions.value val multiStageId = UUID.randomUUID().toString - val generalCommands = makeFrom(base) +: makeMaintainer((maintainer in Docker).value).toSeq + val generalCommands = makeFromAs(base, "mainstage") +: makeMaintainer((maintainer in Docker).value).toSeq val stage0name = "stage0" val layerIdsAscending = (dockerLayerMappings in Docker).value.map(_.layerId).distinct.sorted val stage0: Seq[CmdLike] = strategy match { @@ -309,13 +309,6 @@ object DockerPlugin extends AutoPlugin { private final def makeMaintainer(maintainer: String): Option[CmdLike] = if (maintainer.isEmpty) None else Some(makeLabel(Tuple2("MAINTAINER", maintainer))) - /** - * @param dockerBaseImage - * @return FROM command - */ - private final def makeFrom(dockerBaseImage: String): CmdLike = - Cmd("FROM", dockerBaseImage) - /** * @param dockerBaseImage * @param name diff --git a/src/sbt-test/docker/file-permission/build.sbt b/src/sbt-test/docker/file-permission/build.sbt index 2311a198a..f87b177fd 100644 --- a/src/sbt-test/docker/file-permission/build.sbt +++ b/src/sbt-test/docker/file-permission/build.sbt @@ -26,7 +26,7 @@ lazy val root = (project in file(".")) |RUN ["chmod", "-R", "u=rX,g=rX", "/2/opt/docker"] |RUN ["chmod", "u+x,g+x", "/1/opt/docker/bin/file-permission-test"] | - |FROM fabric8/java-centos-openjdk8-jdk + |FROM fabric8/java-centos-openjdk8-jdk as mainstage |USER root |RUN id -u demiourgos728 1>/dev/null 2>&1 || (( getent group 0 1>/dev/null 2>&1 || ( type groupadd 1>/dev/null 2>&1 && groupadd -g 0 root || addgroup -g 0 -S root )) && ( type useradd 1>/dev/null 2>&1 && useradd --system --create-home --uid 1001 --gid 0 demiourgos728 || adduser -S -u 1001 -G root demiourgos728 )) |WORKDIR /opt/docker @@ -41,7 +41,7 @@ lazy val root = (project in file(".")) val dockerfile = IO.read((stagingDirectory in Docker).value / "Dockerfile") val lines = dockerfile.linesIterator.toList assertEquals(lines, - """FROM fabric8/java-centos-openjdk8-jdk + """FROM fabric8/java-centos-openjdk8-jdk as mainstage |USER root |RUN id -u demiourgos728 1>/dev/null 2>&1 || (( getent group 0 1>/dev/null 2>&1 || ( type groupadd 1>/dev/null 2>&1 && groupadd -g 0 root || addgroup -g 0 -S root )) && ( type useradd 1>/dev/null 2>&1 && useradd --system --create-home --uid 1001 --gid 0 demiourgos728 || adduser -S -u 1001 -G root demiourgos728 )) |WORKDIR /opt/docker @@ -56,7 +56,7 @@ lazy val root = (project in file(".")) val dockerfile = IO.read((stagingDirectory in Docker).value / "Dockerfile") val lines = dockerfile.linesIterator.toList assertEquals(lines, - """FROM fabric8/java-centos-openjdk8-jdk + """FROM fabric8/java-centos-openjdk8-jdk as mainstage |USER root |RUN id -u demiourgos728 1>/dev/null 2>&1 || (( getent group 5000 1>/dev/null 2>&1 || ( type groupadd 1>/dev/null 2>&1 && groupadd -g 5000 sbt || addgroup -g 5000 -S sbt )) && ( type useradd 1>/dev/null 2>&1 && useradd --system --create-home --uid 1001 --gid 5000 demiourgos728 || adduser -S -u 1001 -G sbt demiourgos728 )) |WORKDIR /opt/docker @@ -71,7 +71,7 @@ lazy val root = (project in file(".")) val dockerfile = IO.read((stagingDirectory in Docker).value / "Dockerfile") val lines = dockerfile.linesIterator.toList assertEquals(lines, - """FROM openjdk:8 + """FROM openjdk:8 as mainstage |USER root |RUN id -u demiourgos728 1>/dev/null 2>&1 || (( getent group 0 1>/dev/null 2>&1 || ( type groupadd 1>/dev/null 2>&1 && groupadd -g 0 root || addgroup -g 0 -S root )) && ( type useradd 1>/dev/null 2>&1 && useradd --system --create-home --uid 1001 --gid 0 demiourgos728 || adduser -S -u 1001 -G root demiourgos728 )) |WORKDIR /opt/docker @@ -88,7 +88,7 @@ lazy val root = (project in file(".")) val dockerfile = IO.read((stagingDirectory in Docker).value / "Dockerfile") val lines = dockerfile.linesIterator.toList assertEquals(lines, - """FROM fabric8/java-centos-openjdk8-jdk + """FROM fabric8/java-centos-openjdk8-jdk as mainstage |WORKDIR /opt/docker |COPY --chown=daemon:root 1/opt /opt |COPY --chown=daemon:root 2/opt /opt @@ -113,7 +113,7 @@ lazy val root = (project in file(".")) |RUN ["chmod", "-R", "u=rwX,g=rwX", "/2/opt/docker"] |RUN ["chmod", "u+x,g+x", "/1/opt/docker/bin/file-permission-test"] | - |FROM fabric8/java-centos-openjdk8-jdk + |FROM fabric8/java-centos-openjdk8-jdk as mainstage |USER root |RUN id -u demiourgos728 1>/dev/null 2>&1 || (( getent group 0 1>/dev/null 2>&1 || ( type groupadd 1>/dev/null 2>&1 && groupadd -g 0 root || addgroup -g 0 -S root )) && ( type useradd 1>/dev/null 2>&1 && useradd --system --create-home --uid 1001 --gid 0 demiourgos728 || adduser -S -u 1001 -G root demiourgos728 )) |WORKDIR /opt/docker