Skip to content

Commit fff0ea2

Browse files
committed
Merge remote-tracking branch 'origin/master' into deprecate-security-xpack
2 parents 8d1496b + 10feb75 commit fff0ea2

File tree

284 files changed

+4926
-2351
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

284 files changed

+4926
-2351
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

Lines changed: 90 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import org.gradle.api.tasks.compile.JavaCompile
5151
import org.gradle.api.tasks.javadoc.Javadoc
5252
import org.gradle.internal.jvm.Jvm
5353
import org.gradle.process.ExecResult
54+
import org.gradle.process.ExecSpec
5455
import org.gradle.util.GradleVersion
5556

5657
import java.nio.charset.StandardCharsets
@@ -232,6 +233,95 @@ class BuildPlugin implements Plugin<Project> {
232233
project.ext.java9Home = project.rootProject.ext.java9Home
233234
}
234235

236+
static void requireDocker(final Task task) {
237+
final Project rootProject = task.project.rootProject
238+
if (rootProject.hasProperty('requiresDocker') == false) {
239+
/*
240+
* This is our first time encountering a task that requires Docker. We will add an extension that will let us track the tasks
241+
* that register as requiring Docker. We will add a delayed execution that when the task graph is ready if any such tasks are
242+
* in the task graph, then we check two things:
243+
* - the Docker binary is available
244+
* - we can execute a Docker command that requires privileges
245+
*
246+
* If either of these fail, we fail the build.
247+
*/
248+
final boolean buildDocker
249+
final String buildDockerProperty = System.getProperty("build.docker")
250+
if (buildDockerProperty == null || buildDockerProperty == "true") {
251+
buildDocker = true
252+
} else if (buildDockerProperty == "false") {
253+
buildDocker = false
254+
} else {
255+
throw new IllegalArgumentException(
256+
"expected build.docker to be unset or one of \"true\" or \"false\" but was [" + buildDockerProperty + "]")
257+
}
258+
rootProject.rootProject.ext.buildDocker = buildDocker
259+
rootProject.rootProject.ext.requiresDocker = []
260+
rootProject.gradle.taskGraph.whenReady { TaskExecutionGraph taskGraph ->
261+
// check if the Docker binary exists and record its path
262+
final List<String> maybeDockerBinaries = ['/usr/bin/docker', '/usr/local/bin/docker']
263+
final String dockerBinary = maybeDockerBinaries.find { it -> new File(it).exists() }
264+
265+
int exitCode
266+
String dockerErrorOutput
267+
if (dockerBinary == null) {
268+
exitCode = -1
269+
dockerErrorOutput = null
270+
} else {
271+
// the Docker binary executes, check that we can execute a privileged command
272+
final ByteArrayOutputStream output = new ByteArrayOutputStream()
273+
final ExecResult result = LoggedExec.exec(rootProject, { ExecSpec it ->
274+
it.commandLine dockerBinary, "images"
275+
it.errorOutput = output
276+
it.ignoreExitValue = true
277+
})
278+
if (result.exitValue == 0) {
279+
return
280+
}
281+
exitCode = result.exitValue
282+
dockerErrorOutput = output.toString()
283+
}
284+
final List<String> tasks =
285+
((List<Task>)rootProject.requiresDocker).findAll { taskGraph.hasTask(it) }.collect { " ${it.path}".toString()}
286+
if (tasks.isEmpty() == false) {
287+
/*
288+
* There are tasks in the task graph that require Docker. Now we are failing because either the Docker binary does not
289+
* exist or because execution of a privileged Docker command failed.
290+
*/
291+
String message
292+
if (dockerBinary == null) {
293+
message = String.format(
294+
Locale.ROOT,
295+
"Docker (checked [%s]) is required to run the following task%s: \n%s",
296+
maybeDockerBinaries.join(","),
297+
tasks.size() > 1 ? "s" : "",
298+
tasks.join('\n'))
299+
} else {
300+
assert exitCode > 0 && dockerErrorOutput != null
301+
message = String.format(
302+
Locale.ROOT,
303+
"a problem occurred running Docker from [%s] yet it is required to run the following task%s: \n%s\n" +
304+
"the problem is that Docker exited with exit code [%d] with standard error output [%s]",
305+
dockerBinary,
306+
tasks.size() > 1 ? "s" : "",
307+
tasks.join('\n'),
308+
exitCode,
309+
dockerErrorOutput.trim())
310+
}
311+
throw new GradleException(
312+
message + "\nyou can address this by attending to the reported issue, "
313+
+ "removing the offending tasks from being executed, "
314+
+ "or by passing -Dbuild.docker=false")
315+
}
316+
}
317+
}
318+
if (rootProject.buildDocker) {
319+
rootProject.requiresDocker.add(task)
320+
} else {
321+
task.enabled = false
322+
}
323+
}
324+
235325
private static String findCompilerJavaHome() {
236326
String compilerJavaHome = System.getenv('JAVA_HOME')
237327
final String compilerJavaProperty = System.getProperty('compiler.java')
@@ -785,10 +875,6 @@ class BuildPlugin implements Plugin<Project> {
785875
task.shouldRunAfter testTask
786876
}
787877
}
788-
// no loose ends: check has to depend on all test tasks
789-
project.tasks.matching {it.name == "check"}.all {
790-
dependsOn(task)
791-
}
792878

793879
// TODO: why are we not passing maxmemory to junit4?
794880
jvmArg '-Xmx' + System.getProperty('tests.heap.size', '512m')

buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public class PluginBuildPlugin extends BuildPlugin {
129129
RestIntegTestTask integTest = project.tasks.create('integTest', RestIntegTestTask.class)
130130
integTest.mustRunAfter(project.precommit, project.test)
131131
project.integTestCluster.distribution = System.getProperty('tests.distribution', 'integ-test-zip')
132+
project.check.dependsOn(integTest)
132133
}
133134

134135
/**

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@
1919
package org.elasticsearch.gradle.test
2020

2121
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
22-
import org.elasticsearch.gradle.BuildPlugin
2322
import org.elasticsearch.gradle.VersionProperties
2423
import org.gradle.api.DefaultTask
25-
import org.gradle.api.Project
2624
import org.gradle.api.Task
2725
import org.gradle.api.execution.TaskExecutionAdapter
28-
import org.gradle.api.provider.Property
29-
import org.gradle.api.provider.Provider
3026
import org.gradle.api.tasks.Copy
3127
import org.gradle.api.tasks.Input
3228
import org.gradle.api.tasks.TaskState
@@ -36,7 +32,6 @@ import org.gradle.plugins.ide.idea.IdeaPlugin
3632
import java.nio.charset.StandardCharsets
3733
import java.nio.file.Files
3834
import java.util.stream.Stream
39-
4035
/**
4136
* A wrapper task around setting up a cluster and running rest tests.
4237
*/

0 commit comments

Comments
 (0)