Skip to content

Commit

Permalink
GEODE-3556: Add support for setting the user inside docker containers
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeppe-pivotal committed Sep 6, 2017
1 parent 6d32e28 commit e330ee0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ nexusSignArchives = true
# Control how many concurrent dunit (using docker) tests will be run
dunitParallelForks = 8
# This is the name of the Docker image for running parallel dunits
dunitDockerImage = openjdk:8
dunitDockerImage = apachegeode/geode-build
# Docker user for parallel dunit tests
dunitDockerUser = root
16 changes: 15 additions & 1 deletion gradle/docker.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ def dockerConfig = {
// Add volumes configured by top-level build script
volumes << project.dunitDockerVolumes

// specify the user for starting Gradle test worker within the container.
user = dunitDockerUser

beforeContainerCreate = { cmd, client ->
def javaHomeIdx = -1
def pathIdx = -1
def tmpEnv = cmd.getEnv()
def tmpEnv = []
cmd.getEnv().each { tmpEnv << it }

tmpEnv.eachWithIndex { x, j ->
if (x.startsWith('JAVA_HOME')) {
Expand All @@ -75,6 +79,16 @@ def dockerConfig = {
tmpEnv[pathIdx] = 'PATH_REMOVED='
}

// Unfortunately this snippet of code is here and is required by dev-tools/docker/base/entrypoint.sh.
// This allows preserving the outer user inside the running container. Required for Jenkins
// and other environments. There doesn't seem to be a way to pass this environment variable
// in from a Jenkins Gradle job.
if (System.env['LOCAL_USER_ID'] == null) {
def username = System.getProperty("user.name")
def uid = ['id', '-u', username].execute().text.trim()
tmpEnv << ("LOCAL_USER_ID=${uid}" as String)
}

cmd.withEnv(tmpEnv)

// Infer the index of this invocation
Expand Down

0 comments on commit e330ee0

Please sign in to comment.