forked from apache/geode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker.gradle
155 lines (127 loc) · 5.56 KB
/
docker.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Configuration for running (dunit) tests in parallel in Docker containers.
* The container used must hava JAVA_HOME set in it's environment and must
* have 'java' defined on the path. For example, the relevant Dockerfile
* content could be:
*
* ENV JAVA_HOME=/opt/jdk1.8.0_u101
* ENV PATH=$PATH:$JAVA_HOME/bin
*
* In addition, the container must have docker installed.
*
* The plugin can be activated with the Gradle property 'parallelDunit'.
* Additional properties that can be set are:
*
* dunitDockerImage - The docker image used for running parallel dunits. The
* default image is 'bellsoft/liberica-openjdk-debian:8'. The image is required to
* have 'JAVA_HOME' set as an environment variable.
* dunitParallelForks - The number of parallel containers that will be
* launched. The default is 8.
* dunitDockerUser - The user used within the docker container to run tests.
* The default is 'root'.
*/
apply plugin: 'com.github.pedjak.dockerized-test'
if (project.hasProperty('parallelDunit')) {
def pwd = System.getenv('PWD')
def geodeDir = new File(pwd).getCanonicalPath()
project.ext.dunitDockerVolumes = ["${geodeDir}":geodeDir]
}
project.ext.dockerConfig = {
maxParallelForks = dunitParallelForks.toInteger()
docker {
// base image for creating docker containers that execute the tests
image = dunitDockerImage
// volumes mounted to the containers
// in a form: host_dir : container_dir
def gradleHome = System.getenv('GRADLE_USER_HOME') ?: "${System.getenv('HOME')}/.gradle"
volumes = ["${gradleHome}":gradleHome]
// 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().each { tmpEnv << it }
tmpEnv.eachWithIndex { x, j ->
if (x.startsWith('JAVA_HOME')) {
javaHomeIdx = j
}
if (x.startsWith('PATH')) {
pathIdx = j
}
}
// Remove JAVA_HOME and PATH env variables - they might not be the same as the container needs
if (javaHomeIdx >= 0) {
tmpEnv[javaHomeIdx] = 'JAVA_HOME_REMOVED='
}
if (pathIdx >= 0) {
tmpEnv[pathIdx] = 'PATH_REMOVED='
}
if (project.hasProperty('testJVM') && !testJVM.trim().isEmpty()) {
// Docker command is just 'java' so set to full path
tmpEnv << ("JAVA_HOME=${project.testJVM}" as String)
}
// 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
def cmdList = cmd.getCmd()
if (project.hasProperty('testJVM') && !testJVM.trim().isEmpty()) {
// Docker command is just 'java' so set to full path
cmdList[0] = ("${project.testJVM}/bin/java" as String)
}
def matcher = (cmdList[cmdList.length - 1] =~ /.*Executor (\d*).*/)
def workdir = new File(cmd.getWorkingDir() + matcher[0][1])
workdir.mkdirs()
cmd.withWorkingDir(workdir.toString())
// copy the classpath file to the working dir
def classPathFileIndex = cmdList.findIndexOf { it =~ /^@.*gradle-worker-classpath.*txt$/ }
if (classPathFileIndex > 0) {
def dst = new File(workdir, "gradle-worker-classpath.txt")
if (!dst.exists()) {
def src = new File(cmdList[classPathFileIndex].substring(1))
dst.write(src.text)
}
cmdList[classPathFileIndex] = '@'+dst.toString()
}
//println cmd
}
}
}
if (project.hasProperty('parallelDunit')) {
uiTest.configure(project.ext.dockerConfig)
repeatUnitTest.configure(project.ext.dockerConfig)
integrationTest.configure(project.ext.dockerConfig)
repeatIntegrationTest.configure(project.ext.dockerConfig)
distributedTest.configure(project.ext.dockerConfig)
repeatDistributedTest.configure(project.ext.dockerConfig)
upgradeTest.configure(project.ext.dockerConfig)
repeatUpgradeTest.configure(project.ext.dockerConfig)
acceptanceTest.configure(project.ext.dockerConfig)
repeatAcceptanceTest.configure(project.ext.dockerConfig)
}