Allow to specify additional groups in DockerCreateContainer
MODIFY
src/functTest/groovy/com/bmuschko/gradle/docker/tasks/container/DockerCreateContainerFunctionalTest.groovy
src/functTest/groovy/com/bmuschko/gradle/docker/tasks/container/DockerCreateContainerFunctionalTest.groovy
@@ -21,6 +21,27 @@ import org.gradle.testkit.runner.TaskOutcome
class DockerCreateContainerFunctionalTest extends AbstractGroovyDslFunctionalTest {
+ def "can setup additional user groups"() {
+ given:
+ String containerCreationTask = """
+ task createContainer(type: DockerCreateContainer) {
+ dependsOn pullImage
+ targetImageId pullImage.getImageId()
+ cmd = ['groups']
+ groups = ['postgres']
+ }
+ """
+ buildFile <<
+ containerStart(containerCreationTask) <<
+ containerLogAndRemove()
+
+ when:
+ BuildResult result = build('logContainer')
+
+ then:
+ result.output.contains("postgres")
+ }
+
def "can override default MAC address"() {
given:
String containerCreationTask = """

MODIFY
src/main/groovy/com/bmuschko/gradle/docker/tasks/container/DockerCreateContainer.groovy
src/main/groovy/com/bmuschko/gradle/docker/tasks/container/DockerCreateContainer.groovy
@@ -48,6 +48,13 @@ class DockerCreateContainer extends DockerExistingImage {
@Optional
final Property<String> user = project.objects.property(String)
+ /**
+ * A list of additional groups that the container process will run as.
+ */
+ @Input
+ @Optional
+ final ListProperty<String> groups = project.objects.listProperty(String)
+
@Input
@Optional
final Property<Boolean> stdinOpen = project.objects.property(Boolean)
@@ -215,6 +222,7 @@ class DockerCreateContainer extends DockerExistingImage {
tty.set(false)
devices.set([])
autoRemove.set(false)
+ groups.set([])
}
@Override
@@ -271,6 +279,10 @@ class DockerCreateContainer extends DockerExistingImage {
containerCommand.withUser(user.get())
}
+ if(groups.getOrNull()) {
+ containerCommand.hostConfig.withGroupAdd(groups.get())
+ }
+
if(stdinOpen.getOrNull()) {
containerCommand.withStdinOpen(stdinOpen.get())
}

Allow to specify additional groups in DockerCreateContainer