2020-02-21 18:24:05 -05:00
|
|
|
import org.elasticsearch.gradle.ElasticsearchDistribution.Flavor
|
2018-12-06 17:06:13 -05:00
|
|
|
import org.elasticsearch.gradle.LoggedExec
|
|
|
|
import org.elasticsearch.gradle.VersionProperties
|
2019-11-01 14:33:11 -04:00
|
|
|
import org.elasticsearch.gradle.info.BuildParams
|
|
|
|
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'
|
2020-02-21 18:24:05 -05:00
|
|
|
apply plugin: 'elasticsearch.distribution-download'
|
2018-12-06 17:06:13 -05:00
|
|
|
|
2019-09-23 05:48:47 -04:00
|
|
|
testFixtures.useFixture()
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-01-08 16:51:41 -05:00
|
|
|
ext.expansions = { oss, local ->
|
2019-11-14 06:01:23 -05:00
|
|
|
final String classifier = 'linux-x86_64'
|
2019-02-08 13:01:59 -05:00
|
|
|
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-11-01 14:33:11 -04:00
|
|
|
'build_date' : BuildParams.buildDate,
|
2019-02-08 13:01:59 -05:00
|
|
|
'elasticsearch' : elasticsearch,
|
2019-11-01 14:33:11 -04:00
|
|
|
'git_revision' : BuildParams.gitRevision,
|
2019-08-04 13:50:26 -04:00
|
|
|
'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
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2020-01-08 16:51:41 -05:00
|
|
|
private static String buildPath(final boolean oss) {
|
|
|
|
return "build/${oss ? 'oss-' : ''}docker"
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
2020-01-08 16:51:41 -05:00
|
|
|
private static String taskName(final String prefix, final boolean oss, final String suffix) {
|
|
|
|
return "${prefix}${oss ? 'Oss' : ''}${suffix}"
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
2019-05-06 21:04:13 -04:00
|
|
|
project.ext {
|
2020-01-08 16:51:41 -05:00
|
|
|
dockerBuildContext = { boolean oss, boolean local ->
|
2019-05-06 21:04:13 -04:00
|
|
|
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
|
2019-11-14 06:01:23 -05:00
|
|
|
* by creating config files in oss or default build-context sub-modules.
|
2019-06-05 11:15:37 -04:00
|
|
|
*/
|
2019-05-06 21:04:13 -04:00
|
|
|
from project.projectDir.toPath().resolve("src/docker/config")
|
2019-10-30 19:04:40 -04:00
|
|
|
if (oss) {
|
|
|
|
from project.projectDir.toPath().resolve("src/docker/config/oss")
|
|
|
|
}
|
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")) {
|
2020-01-08 16:51:41 -05: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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-08 16:51:41 -05:00
|
|
|
void addCopyDockerContextTask(final boolean oss) {
|
|
|
|
task(taskName("copy", oss, "DockerContext"), type: Sync) {
|
|
|
|
expansions(oss, true).findAll { it.key != 'build_date' }.each { k, v ->
|
2019-08-08 20:07:41 -04:00
|
|
|
inputs.property(k, { v.toString() })
|
|
|
|
}
|
2020-01-08 16:51:41 -05:00
|
|
|
into buildPath(oss)
|
2018-12-06 17:06:13 -05:00
|
|
|
|
2020-01-08 16:51:41 -05:00
|
|
|
with dockerBuildContext(oss, true)
|
2019-05-06 21:04:13 -04:00
|
|
|
|
|
|
|
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-11-14 06:01:23 -05:00
|
|
|
def createAndSetWritable(Object... locations) {
|
2019-07-11 08:04:25 -04:00
|
|
|
locations.each { location ->
|
|
|
|
File file = file(location)
|
|
|
|
file.mkdirs()
|
|
|
|
file.setWritable(true, false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
task copyKeystore(type: Sync) {
|
|
|
|
from project(':x-pack:plugin:core')
|
2019-11-14 06:01:23 -05:00
|
|
|
.file('src/test/resources/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.jks')
|
2019-07-11 08:04:25 -04:00
|
|
|
into "${buildDir}/certs"
|
|
|
|
doLast {
|
|
|
|
file("${buildDir}/certs").setReadable(true, false)
|
|
|
|
file("${buildDir}/certs/testnode.jks").setReadable(true, false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-21 18:24:05 -05:00
|
|
|
elasticsearch_distributions {
|
|
|
|
Flavor.values().each { distroFlavor ->
|
|
|
|
"docker_$distroFlavor" {
|
|
|
|
flavor = distroFlavor
|
|
|
|
type = 'docker'
|
|
|
|
version = VersionProperties.getElasticsearch()
|
|
|
|
failIfUnavailable = false // This ensures we don't attempt to build images if docker is unavailable
|
|
|
|
}
|
2019-07-11 08:04:25 -04:00
|
|
|
}
|
2020-02-21 18:24:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
preProcessFixture {
|
|
|
|
dependsOn elasticsearch_distributions.docker_default, elasticsearch_distributions.docker_oss
|
2019-07-11 08:04:25 -04:00
|
|
|
dependsOn copyKeystore
|
|
|
|
doLast {
|
|
|
|
// tests expect to have an empty repo
|
|
|
|
project.delete(
|
2019-11-14 06:01:23 -05:00
|
|
|
"${buildDir}/repo",
|
|
|
|
"${buildDir}/oss-repo"
|
2019-07-11 08:04:25 -04:00
|
|
|
)
|
|
|
|
createAndSetWritable(
|
2019-11-14 06:01:23 -05:00
|
|
|
"${buildDir}/repo",
|
|
|
|
"${buildDir}/oss-repo",
|
|
|
|
"${buildDir}/logs/default-1",
|
|
|
|
"${buildDir}/logs/default-2",
|
|
|
|
"${buildDir}/logs/oss-1",
|
|
|
|
"${buildDir}/logs/oss-2"
|
2019-07-11 08:04:25 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
processTestResources {
|
2019-11-14 06:01:23 -05:00
|
|
|
from({ zipTree(configurations.restSpec.singleFile) }) {
|
2019-07-11 08:04:25 -04:00
|
|
|
include 'rest-api-spec/api/**'
|
|
|
|
}
|
|
|
|
from project(':x-pack:plugin:core')
|
2019-11-14 06:01:23 -05:00
|
|
|
.file('src/test/resources/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.jks')
|
2019-07-11 08:04:25 -04:00
|
|
|
dependsOn configurations.restSpec
|
2019-01-24 10:26:42 -05:00
|
|
|
}
|
|
|
|
|
2019-07-11 08:04:25 -04:00
|
|
|
task integTest(type: Test) {
|
2020-01-30 20:23:23 -05:00
|
|
|
outputs.doNotCacheIf('Build cache is disabled for Docker tests') { true }
|
2019-07-11 08:04:25 -04:00
|
|
|
maxParallelForks = '1'
|
|
|
|
include '**/*IT.class'
|
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
|
|
|
|
2020-01-08 16:51:41 -05:00
|
|
|
void addBuildDockerImage(final boolean oss) {
|
|
|
|
final Task buildDockerImageTask = task(taskName("build", oss, "DockerImage"), type: LoggedExec) {
|
2020-02-21 18:24:05 -05:00
|
|
|
ext.requiresDocker = true // mark this task as requiring docker to execute
|
2020-01-08 16:51:41 -05:00
|
|
|
inputs.files(tasks.named(taskName("copy", oss, "DockerContext")))
|
2018-12-06 17:06:13 -05:00
|
|
|
List<String> tags
|
|
|
|
if (oss) {
|
2019-11-14 06:01:23 -05:00
|
|
|
tags = [
|
2020-01-08 16:51:41 -05:00
|
|
|
"docker.elastic.co/elasticsearch/elasticsearch-oss:${VersionProperties.elasticsearch}",
|
|
|
|
"elasticsearch-oss:test"
|
2019-04-12 05:31:30 -04:00
|
|
|
]
|
2018-12-06 17:06:13 -05:00
|
|
|
} else {
|
|
|
|
tags = [
|
2020-01-08 16:51:41 -05:00
|
|
|
"elasticsearch:${VersionProperties.elasticsearch}",
|
|
|
|
"docker.elastic.co/elasticsearch/elasticsearch:${VersionProperties.elasticsearch}",
|
|
|
|
"docker.elastic.co/elasticsearch/elasticsearch-full:${VersionProperties.elasticsearch}",
|
|
|
|
"elasticsearch:test",
|
2018-12-06 17:06:13 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
executable 'docker'
|
2020-01-08 16:51:41 -05:00
|
|
|
final List<String> dockerArgs = ['build', buildPath(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()
|
2019-11-27 14:19:34 -05:00
|
|
|
File markerFile = file("build/markers/${it.name}.marker")
|
|
|
|
outputs.file(markerFile)
|
|
|
|
doLast {
|
|
|
|
markerFile.setText('', 'UTF-8')
|
|
|
|
}
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
2019-10-30 19:04:40 -04:00
|
|
|
assemble.dependsOn(buildDockerImageTask)
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for (final boolean oss : [false, true]) {
|
2020-01-08 16:51:41 -05:00
|
|
|
addCopyDockerContextTask(oss)
|
|
|
|
addBuildDockerImage(oss)
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
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
|
2019-11-14 06:01:23 -05:00
|
|
|
// thus we must disable it to prevent it from doing so.
|
2019-04-17 01:58:11 -04:00
|
|
|
// 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")) {
|
2019-11-14 06:01:23 -05:00
|
|
|
tasks.composePull.enabled = false
|
2019-04-23 07:54:57 -04:00
|
|
|
}
|
2019-11-05 10:17:59 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The export subprojects write out the generated Docker images to disk, so
|
|
|
|
* that they can be easily reloaded, for example into a VM.
|
|
|
|
*/
|
|
|
|
subprojects { Project subProject ->
|
|
|
|
if (subProject.name.contains('docker-export')) {
|
|
|
|
apply plugin: 'distribution'
|
|
|
|
|
|
|
|
final boolean oss = subProject.name.contains('oss-')
|
|
|
|
|
2020-01-08 16:51:41 -05:00
|
|
|
def exportTaskName = taskName("export", oss, "DockerImage")
|
|
|
|
def buildTaskName = taskName("build", oss, "DockerImage")
|
|
|
|
def tarFile = "${parent.projectDir}/build/elasticsearch${oss ? '-oss' : ''}_test.${VersionProperties.elasticsearch}.docker.tar"
|
2019-11-05 10:17:59 -05:00
|
|
|
|
|
|
|
final Task exportDockerImageTask = task(exportTaskName, type: LoggedExec) {
|
|
|
|
executable 'docker'
|
2019-11-27 14:19:34 -05:00
|
|
|
outputs.file(tarFile)
|
2019-11-05 10:17:59 -05:00
|
|
|
args "save",
|
|
|
|
"-o",
|
|
|
|
tarFile,
|
2020-01-08 16:51:41 -05:00
|
|
|
"elasticsearch${oss ? '-oss' : ''}:test"
|
2019-11-05 10:17:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
exportDockerImageTask.dependsOn(parent.tasks.getByName(buildTaskName))
|
|
|
|
|
|
|
|
artifacts.add('default', file(tarFile)) {
|
2019-11-14 06:01:23 -05:00
|
|
|
type 'tar'
|
2020-01-08 16:51:41 -05:00
|
|
|
name "elasticsearch${oss ? '-oss' : ''}"
|
2019-11-14 06:01:23 -05:00
|
|
|
builtBy exportTaskName
|
2019-11-05 10:17:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
assemble.dependsOn exportTaskName
|
|
|
|
}
|
|
|
|
}
|