Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chown values overrides for Docker format #1400

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
})
Expand Down Expand Up @@ -325,6 +327,8 @@ object DockerPlugin extends AutoPlugin {
daemonUserUid := Some("1001"),
daemonGroup := "root",
daemonGroupGid := Some("0"),
chownUser := None,
chownGroup := None,
Comment on lines +330 to +331
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
chownUser := None,
chownGroup := None,
dockerChownUser := None,
dockerChownGroup := None,

See comment in the Keys.scala.

Also move up to the settings starting with docker*

defaultLinuxInstallLocation := "/opt/docker",
validatePackage := Validation
.runAndThrow(validatePackageValidators.value, streams.value.log),
Expand Down
4 changes: 4 additions & 0 deletions src/main/scala/com/typesafe/sbt/packager/docker/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Comment on lines +71 to +74
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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")
val dockerChownUser =
SettingKey[Option[String]]("docker-chown-user", "Optional alternative user to use in chown in COPY command")
val dockerChownGroup =
SettingKey[Option[String]]("docker-chown-group", "Optional alternative group to use in chown in COPY command")

If the setting is specific to a packaging format it's prefixed with that format. In this case docker<SettingKey>. The configuration scoping is not necessary, so you can move it in the plugins definition to the other settings starting with docker.

}
6 changes: 6 additions & 0 deletions src/sphinx/formats/docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
``chownUser in Docker``
``dockerChownUser``

Optionally overrides user value used for applying to ``chown`` in ``COPY`` commands.

``chownGroup in Docker``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
``chownGroup in Docker``
``dockerChownGroup``

Optionally overrides group value used for applying to ``chown`` in ``COPY`` commands.

``dockerExposedPorts``
A list of TCP ports to expose from the Docker image.

Expand Down