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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-10-30 19:04:40 -04:00
|
|
|
ext.expansions = { oss, ubi, 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-10-30 19:04:40 -04:00
|
|
|
'base_image' : ubi ? 'registry.access.redhat.com/ubi7/ubi-minimal:7.7' : 'centos:7',
|
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-10-30 19:04:40 -04:00
|
|
|
'package_manager' : ubi ? 'microdnf' : 'yum',
|
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
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2019-10-30 19:04:40 -04:00
|
|
|
private static String buildPath(final boolean oss, final boolean ubi) {
|
|
|
|
return "build/${ oss ? 'oss-' : ''}${ ubi ? 'ubi-' : ''}docker"
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
2019-10-30 19:04:40 -04:00
|
|
|
private static String taskName(final String prefix, final boolean oss, final boolean ubi, final String suffix) {
|
|
|
|
return "${prefix}${oss ? 'Oss' : ''}${ubi ? 'Ubi': ''}${suffix}"
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
2019-05-06 21:04:13 -04:00
|
|
|
project.ext {
|
2019-10-30 19:04:40 -04:00
|
|
|
dockerBuildContext = { boolean oss, boolean ubi, 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
|
|
|
|
* 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-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")) {
|
2019-10-30 19:04:40 -04:00
|
|
|
expand(expansions(oss, ubi, 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-10-30 19:04:40 -04:00
|
|
|
void addCopyDockerContextTask(final boolean oss, final boolean ubi) {
|
|
|
|
task(taskName("copy", oss, ubi, "DockerContext"), type: Sync) {
|
|
|
|
expansions(oss, ubi, true).each { k, v ->
|
2019-08-08 20:07:41 -04:00
|
|
|
inputs.property(k, { v.toString() })
|
|
|
|
}
|
2019-10-30 19:04:40 -04:00
|
|
|
into buildPath(oss, ubi)
|
2018-12-06 17:06:13 -05:00
|
|
|
|
2019-10-30 19:04:40 -04:00
|
|
|
with dockerBuildContext(oss, ubi, 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-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
|
|
|
|
2019-10-30 19:04:40 -04:00
|
|
|
void addBuildDockerImage(final boolean oss, final boolean ubi) {
|
|
|
|
final Task buildDockerImageTask = task(taskName("build", oss, ubi, "DockerImage"), type: LoggedExec) {
|
|
|
|
dependsOn taskName("copy", oss, ubi, "DockerContext")
|
2018-12-06 17:06:13 -05:00
|
|
|
List<String> tags
|
|
|
|
if (oss) {
|
2019-04-12 05:31:30 -04:00
|
|
|
tags = [
|
2019-10-30 23:48:06 -04:00
|
|
|
"docker.elastic.co/elasticsearch/elasticsearch-oss${ubi ? '-ubi7' : ''}:${VersionProperties.elasticsearch}",
|
|
|
|
"elasticsearch-oss${ubi ? '-ubi7' : ''}:test"
|
2019-04-12 05:31:30 -04:00
|
|
|
]
|
2018-12-06 17:06:13 -05:00
|
|
|
} else {
|
|
|
|
tags = [
|
2019-10-30 23:48:06 -04:00
|
|
|
"elasticsearch${ubi ? '-ubi7' : ''}:${VersionProperties.elasticsearch}",
|
|
|
|
"docker.elastic.co/elasticsearch/elasticsearch${ubi ? '-ubi7' : ''}:${VersionProperties.elasticsearch}",
|
|
|
|
"docker.elastic.co/elasticsearch/elasticsearch${ubi ? '-ubi7' : ''}-full:${VersionProperties.elasticsearch}",
|
|
|
|
"elasticsearch${ubi ? '-ubi7' : ''}:test",
|
2018-12-06 17:06:13 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
executable 'docker'
|
2019-10-30 19:04:40 -04:00
|
|
|
final List<String> dockerArgs = ['build', buildPath(oss, ubi), '--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-10-30 19:04:40 -04:00
|
|
|
assemble.dependsOn(buildDockerImageTask)
|
2018-12-06 17:06:13 -05:00
|
|
|
BuildPlugin.requireDocker(buildDockerImageTask)
|
|
|
|
}
|
|
|
|
|
|
|
|
for (final boolean oss : [false, true]) {
|
2019-10-30 19:04:40 -04:00
|
|
|
for (final boolean ubi : [false, true]) {
|
|
|
|
addCopyDockerContextTask(oss, ubi)
|
|
|
|
addBuildDockerImage(oss, ubi)
|
|
|
|
}
|
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
|
|
|
|
// 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
|
|
|
|
}
|