2018-12-06 17:06:13 -05:00
|
|
|
import org.elasticsearch.gradle.BuildPlugin
|
|
|
|
import org.elasticsearch.gradle.LoggedExec
|
|
|
|
import org.elasticsearch.gradle.VersionProperties
|
2019-08-08 20:07:41 -04:00
|
|
|
import org.elasticsearch.gradle.testfixtures.TestFixturesPlugin
|
2018-12-06 17:06:13 -05:00
|
|
|
|
2019-07-11 08:04:25 -04:00
|
|
|
apply plugin: 'elasticsearch.standalone-rest-test'
|
2019-01-24 10:26:42 -05:00
|
|
|
apply plugin: 'elasticsearch.test.fixtures'
|
2018-12-06 17:06:13 -05:00
|
|
|
|
|
|
|
configurations {
|
|
|
|
dockerPlugins
|
|
|
|
dockerSource
|
|
|
|
ossDockerSource
|
2019-07-11 08:04:25 -04:00
|
|
|
restSpec
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
2019-01-29 14:18:30 -05:00
|
|
|
dockerSource project(path: ":distribution:archives:linux-tar")
|
|
|
|
ossDockerSource project(path: ":distribution:archives:oss-linux-tar")
|
2019-07-11 08:04:25 -04:00
|
|
|
restSpec project(':rest-api-spec')
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
2019-05-06 21:04:13 -04:00
|
|
|
ext.expansions = { oss, local ->
|
2019-02-08 13:01:59 -05:00
|
|
|
final String classifier = 'linux-x86_64'
|
|
|
|
final String elasticsearch = oss ? "elasticsearch-oss-${VersionProperties.elasticsearch}-${classifier}.tar.gz" : "elasticsearch-${VersionProperties.elasticsearch}-${classifier}.tar.gz"
|
2018-12-06 17:06:13 -05:00
|
|
|
return [
|
2019-08-04 13:50:26 -04:00
|
|
|
'build_date' : project.ext.buildDate,
|
2019-02-08 13:01:59 -05:00
|
|
|
'elasticsearch' : elasticsearch,
|
2019-08-04 13:50:26 -04:00
|
|
|
'git_revision' : project.ext.gitRevision,
|
|
|
|
'license' : oss ? 'Apache-2.0' : 'Elastic-License',
|
2019-05-06 21:04:13 -04:00
|
|
|
'source_elasticsearch': local ? "COPY $elasticsearch /opt/" : "RUN cd /opt && curl --retry 8 -s -L -O https://artifacts.elastic.co/downloads/elasticsearch/${elasticsearch} && cd -",
|
2019-02-08 13:01:59 -05:00
|
|
|
'version' : VersionProperties.elasticsearch
|
2018-12-06 17:06:13 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String files(final boolean oss) {
|
|
|
|
return "build/${ oss ? 'oss-' : ''}docker"
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String taskName(final String prefix, final boolean oss, final String suffix) {
|
|
|
|
return "${prefix}${oss ? 'Oss' : ''}${suffix}"
|
|
|
|
}
|
|
|
|
|
2019-05-06 21:04:13 -04:00
|
|
|
project.ext {
|
|
|
|
dockerBuildContext = { boolean oss, boolean local ->
|
|
|
|
copySpec {
|
|
|
|
into('bin') {
|
|
|
|
from project.projectDir.toPath().resolve("src/docker/bin")
|
|
|
|
}
|
2018-12-06 17:06:13 -05:00
|
|
|
|
2019-05-06 21:04:13 -04:00
|
|
|
into('config') {
|
2019-06-05 11:15:37 -04:00
|
|
|
/*
|
|
|
|
* Oss and default distribution can have different configuration, therefore we want to allow overriding the default configuration
|
|
|
|
* by creating config files in oss or default build-context sub-modules.
|
|
|
|
*/
|
2019-05-06 21:04:13 -04:00
|
|
|
from project.projectDir.toPath().resolve("src/docker/config")
|
2019-06-05 11:15:37 -04:00
|
|
|
from project.projectDir.toPath().resolve(oss ? "oss-docker-build-context" : "docker-build-context").resolve("src/docker/config")
|
2019-02-08 13:01:59 -05:00
|
|
|
}
|
2018-12-06 17:06:13 -05:00
|
|
|
|
2019-05-06 21:04:13 -04:00
|
|
|
from(project.projectDir.toPath().resolve("src/docker/Dockerfile")) {
|
2019-08-08 20:07:41 -04:00
|
|
|
expand(expansions(oss, local))
|
2019-05-06 21:04:13 -04:00
|
|
|
}
|
2019-02-08 13:01:59 -05:00
|
|
|
}
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-06 21:04:13 -04:00
|
|
|
void addCopyDockerContextTask(final boolean oss) {
|
|
|
|
task(taskName("copy", oss, "DockerContext"), type: Sync) {
|
2019-08-08 20:07:41 -04:00
|
|
|
expansions(oss, true).each { k, v ->
|
|
|
|
inputs.property(k, { v.toString() })
|
|
|
|
}
|
2018-12-06 17:06:13 -05:00
|
|
|
into files(oss)
|
|
|
|
|
2019-05-06 21:04:13 -04:00
|
|
|
with dockerBuildContext(oss, true)
|
|
|
|
|
|
|
|
if (oss) {
|
|
|
|
from configurations.ossDockerSource
|
|
|
|
} else {
|
|
|
|
from configurations.dockerSource
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
2019-05-06 21:04:13 -04:00
|
|
|
|
|
|
|
from configurations.dockerPlugins
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-11 08:04:25 -04:00
|
|
|
def createAndSetWritable (Object... locations) {
|
|
|
|
locations.each { location ->
|
|
|
|
File file = file(location)
|
|
|
|
file.mkdirs()
|
|
|
|
file.setWritable(true, false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
task copyKeystore(type: Sync) {
|
|
|
|
from project(':x-pack:plugin:core')
|
|
|
|
.file('src/test/resources/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.jks')
|
|
|
|
into "${buildDir}/certs"
|
|
|
|
doLast {
|
|
|
|
file("${buildDir}/certs").setReadable(true, false)
|
|
|
|
file("${buildDir}/certs/testnode.jks").setReadable(true, false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-24 10:26:42 -05:00
|
|
|
preProcessFixture {
|
2019-07-11 08:04:25 -04:00
|
|
|
if (TestFixturesPlugin.dockerComposeSupported()) {
|
|
|
|
dependsOn assemble
|
|
|
|
}
|
|
|
|
dependsOn copyKeystore
|
|
|
|
doLast {
|
|
|
|
// tests expect to have an empty repo
|
|
|
|
project.delete(
|
|
|
|
"${buildDir}/repo",
|
|
|
|
"${buildDir}/oss-repo"
|
|
|
|
)
|
|
|
|
createAndSetWritable(
|
|
|
|
"${buildDir}/repo",
|
|
|
|
"${buildDir}/oss-repo",
|
|
|
|
"${buildDir}/logs/default-1",
|
|
|
|
"${buildDir}/logs/default-2",
|
|
|
|
"${buildDir}/logs/oss-1",
|
|
|
|
"${buildDir}/logs/oss-2"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
processTestResources {
|
|
|
|
from ({ zipTree(configurations.restSpec.singleFile) }) {
|
|
|
|
include 'rest-api-spec/api/**'
|
|
|
|
}
|
|
|
|
from project(':x-pack:plugin:core')
|
|
|
|
.file('src/test/resources/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.jks')
|
|
|
|
dependsOn configurations.restSpec
|
2019-01-24 10:26:42 -05:00
|
|
|
}
|
|
|
|
|
2019-07-11 08:04:25 -04:00
|
|
|
task integTest(type: Test) {
|
|
|
|
maxParallelForks = '1'
|
|
|
|
include '**/*IT.class'
|
2019-08-06 12:00:25 -04:00
|
|
|
// don't add the tasks to build the docker images if we have no way of testing them
|
|
|
|
if (TestFixturesPlugin.dockerComposeSupported()) {
|
|
|
|
dependsOn assemble
|
|
|
|
}
|
2019-01-24 10:26:42 -05:00
|
|
|
}
|
|
|
|
|
2019-07-11 08:04:25 -04:00
|
|
|
check.dependsOn integTest
|
2019-01-24 10:26:42 -05:00
|
|
|
|
2018-12-06 17:06:13 -05:00
|
|
|
void addBuildDockerImage(final boolean oss) {
|
|
|
|
final Task buildDockerImageTask = task(taskName("build", oss, "DockerImage"), type: LoggedExec) {
|
|
|
|
dependsOn taskName("copy", oss, "DockerContext")
|
|
|
|
List<String> tags
|
|
|
|
if (oss) {
|
2019-04-12 05:31:30 -04:00
|
|
|
tags = [
|
|
|
|
"docker.elastic.co/elasticsearch/elasticsearch-oss:${VersionProperties.elasticsearch}",
|
|
|
|
"elasticsearch-oss:test"
|
|
|
|
]
|
2018-12-06 17:06:13 -05:00
|
|
|
} else {
|
|
|
|
tags = [
|
|
|
|
"elasticsearch:${VersionProperties.elasticsearch}",
|
|
|
|
"docker.elastic.co/elasticsearch/elasticsearch:${VersionProperties.elasticsearch}",
|
2019-04-12 05:31:30 -04:00
|
|
|
"docker.elastic.co/elasticsearch/elasticsearch-full:${VersionProperties.elasticsearch}",
|
|
|
|
"elasticsearch:test",
|
2018-12-06 17:06:13 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
executable 'docker'
|
2019-01-18 20:01:35 -05:00
|
|
|
final List<String> dockerArgs = ['build', files(oss), '--pull', '--no-cache']
|
2018-12-06 17:06:13 -05:00
|
|
|
for (final String tag : tags) {
|
|
|
|
dockerArgs.add('--tag')
|
|
|
|
dockerArgs.add(tag)
|
|
|
|
}
|
|
|
|
args dockerArgs.toArray()
|
|
|
|
}
|
|
|
|
BuildPlugin.requireDocker(buildDockerImageTask)
|
|
|
|
}
|
|
|
|
|
|
|
|
for (final boolean oss : [false, true]) {
|
|
|
|
addCopyDockerContextTask(oss)
|
|
|
|
addBuildDockerImage(oss)
|
|
|
|
}
|
|
|
|
|
|
|
|
assemble.dependsOn "buildOssDockerImage"
|
|
|
|
assemble.dependsOn "buildDockerImage"
|
2019-04-17 01:58:11 -04:00
|
|
|
|
|
|
|
// We build the images used in compose locally, but the pull command insists on using a repository
|
|
|
|
// thus we must disable it to prevent it from doing so.
|
|
|
|
// Everything will still be pulled since we will build the local images on a pull
|
2019-04-23 07:54:57 -04:00
|
|
|
if (tasks.findByName("composePull")) {
|
|
|
|
tasks.composePull.enabled = false
|
|
|
|
}
|