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 96faf5674..5ead342dd 100644 --- a/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala @@ -176,6 +176,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 @@ -226,14 +228,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)) }) @@ -325,6 +327,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 2079884d9..8cc332f5e 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.