From d53c819f015bcba201e01c96776631ce905bc731 Mon Sep 17 00:00:00 2001 From: Arthur Sengileyev Date: Sat, 20 Feb 2021 20:43:27 +0200 Subject: [PATCH] chown values overrides for Docker format --- .../com/typesafe/sbt/packager/docker/DockerPlugin.scala | 8 ++++++-- .../scala/com/typesafe/sbt/packager/docker/Keys.scala | 4 ++++ src/sphinx/formats/docker.rst | 6 ++++++ 3 files changed, 16 insertions(+), 2 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 1a4b2caa4..c481123b8 100644 --- a/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala @@ -161,6 +161,8 @@ object DockerPlugin extends AutoPlugin { val uidOpt = (daemonUserUid in Docker).value val group = (daemonGroup in Docker).value val gidOpt = (daemonGroupGid in Docker).value + val cUser = (chownUser in Docker).value.getOrElse((daemonUser in Docker).value) + val cGroup = (chownGroup in Docker).value.getOrElse((daemonGroup in Docker).value) val base = dockerBaseImage.value val addPerms = dockerAdditionalPermissions.value val multiStageId = UUID.randomUUID().toString @@ -211,14 +213,14 @@ object DockerPlugin extends AutoPlugin { (strategy match { case DockerPermissionStrategy.MultiStage => layerIdsAscending.map { layerId => - makeCopyFrom(pathInLayer(dockerBaseDirectory, layerId), dockerBaseDirectory, stage0name, user, group) + makeCopyFrom(pathInLayer(dockerBaseDirectory, layerId), dockerBaseDirectory, stage0name, cUser, cGroup) } case DockerPermissionStrategy.Run => layerIdsAscending.map(layerId => makeCopyLayerDirect(layerId, dockerBaseDirectory)) ++ Seq(makeChmodRecursive(dockerChmodType.value, Seq(dockerBaseDirectory))) ++ (addPerms map { case (tpe, v) => makeChmod(tpe, Seq(v)) }) case DockerPermissionStrategy.CopyChown => - layerIdsAscending.map(layerId => makeCopyChown(layerId, dockerBaseDirectory, user, group)) + layerIdsAscending.map(layerId => makeCopyChown(layerId, dockerBaseDirectory, cUser, cGroup)) case DockerPermissionStrategy.None => layerIdsAscending.map(layerId => makeCopyLayerDirect(layerId, dockerBaseDirectory)) }) @@ -310,6 +312,8 @@ object DockerPlugin extends AutoPlugin { daemonUserUid := Some("1001"), daemonGroup := "root", daemonGroupGid := Some("0"), + chownUser := None, + chownGroup := None, defaultLinuxInstallLocation := "/opt/docker", validatePackage := Validation .runAndThrow(validatePackageValidators.value, streams.value.log), 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 cc2ac031c..17d8c620e 100644 --- a/src/main/scala/com/typesafe/sbt/packager/docker/Keys.scala +++ b/src/main/scala/com/typesafe/sbt/packager/docker/Keys.scala @@ -68,4 +68,8 @@ private[packager] trait DockerKeysEx extends DockerKeys { ) val dockerLayerMappings = taskKey[Seq[LayeredMapping]]("List of layer, source file and destination in Docker image.") + val chownUser = + SettingKey[Option[String]]("chown-user", "Optional alternative user to use in chown in COPY command") + val chownGroup = + SettingKey[Option[String]]("chown-group", "Optional alternative group to use in chown in COPY command") } diff --git a/src/sphinx/formats/docker.rst b/src/sphinx/formats/docker.rst index e2175f5e2..f9f2d81fc 100644 --- a/src/sphinx/formats/docker.rst +++ b/src/sphinx/formats/docker.rst @@ -99,6 +99,12 @@ Environment Settings ``daemonUser in Docker`` The user to use when executing the application. Files below the install path also have their ownership set to this user. + ``chownUser in Docker`` + Optionally overrides user value used for applying to ``chown`` in ``COPY`` commands. + + ``chownGroup in Docker`` + Optionally overrides group value used for applying to ``chown`` in ``COPY`` commands. + ``dockerExposedPorts`` A list of TCP ports to expose from the Docker image.