2020-03-23 14:49:42 -04:00
|
|
|
import org.elasticsearch.gradle.Architecture
|
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
|
2020-02-27 22:18:53 -05:00
|
|
|
import org.elasticsearch.gradle.docker.DockerBuildTask
|
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'
|
2020-07-06 15:16:26 -04:00
|
|
|
apply plugin: 'elasticsearch.rest-resources'
|
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
|
2020-03-23 14:49:42 -04:00
|
|
|
aarch64DockerSource
|
2018-12-06 17:06:13 -05:00
|
|
|
dockerSource
|
2020-03-23 14:49:42 -04:00
|
|
|
aarch64OssDockerSource
|
2018-12-06 17:06:13 -05:00
|
|
|
ossDockerSource
|
|
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
2020-03-23 14:49:42 -04:00
|
|
|
aarch64DockerSource project(path: ":distribution:archives:linux-aarch64-tar")
|
2019-01-29 14:18:30 -05:00
|
|
|
dockerSource project(path: ":distribution:archives:linux-tar")
|
2020-03-23 14:49:42 -04:00
|
|
|
aarch64OssDockerSource project(path: ":distribution:archives:oss-linux-aarch64-tar")
|
2019-01-29 14:18:30 -05:00
|
|
|
ossDockerSource project(path: ":distribution:archives:oss-linux-tar")
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
2020-03-23 14:49:42 -04:00
|
|
|
ext.expansions = { architecture, oss, local ->
|
2020-05-12 06:10:05 -04:00
|
|
|
String classifier
|
|
|
|
if (local) {
|
|
|
|
switch (architecture) {
|
|
|
|
case "aarch64":
|
|
|
|
classifier = "linux-aarch64"
|
|
|
|
break
|
|
|
|
case "x64":
|
|
|
|
classifier = "linux-x86_64"
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
throw new IllegalArgumentException("Unrecognized architecture [" + architecture + "], must be one of (aarch64|x64)")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* When sourcing the Elasticsearch build remotely, the same Dockerfile needs
|
|
|
|
* to be able to fetch the artifact for any supported platform. We can't make
|
|
|
|
* the decision here. Bash will interpolate the `arch` command for us. */
|
|
|
|
classifier = "linux-\$(arch)"
|
2020-03-23 14:49:42 -04:00
|
|
|
}
|
2020-05-12 06:10:05 -04:00
|
|
|
|
|
|
|
final String elasticsearch = "elasticsearch-${oss ? 'oss-' : ''}${VersionProperties.elasticsearch}-${classifier}.tar.gz"
|
|
|
|
|
|
|
|
/* Both the following Dockerfile commands put the resulting artifact at
|
|
|
|
* the same location, regardless of classifier, so that the commands that
|
|
|
|
* follow in the Dockerfile don't have to know about the runtime
|
|
|
|
* architecture. */
|
|
|
|
String sourceElasticsearch
|
|
|
|
if (local) {
|
|
|
|
sourceElasticsearch = "COPY $elasticsearch /opt/elasticsearch.tar.gz"
|
|
|
|
} else {
|
|
|
|
sourceElasticsearch = """
|
|
|
|
RUN curl --retry 8 -S -L \\
|
|
|
|
--output /opt/elasticsearch.tar.gz \\
|
|
|
|
https://artifacts.elastic.co/downloads/elasticsearch/$elasticsearch
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
|
2018-12-06 17:06:13 -05:00
|
|
|
return [
|
2019-11-01 14:33:11 -04:00
|
|
|
'build_date' : BuildParams.buildDate,
|
|
|
|
'git_revision' : BuildParams.gitRevision,
|
2019-08-04 13:50:26 -04:00
|
|
|
'license' : oss ? 'Apache-2.0' : 'Elastic-License',
|
2020-05-12 06:10:05 -04:00
|
|
|
'source_elasticsearch': sourceElasticsearch,
|
2019-02-08 13:01:59 -05:00
|
|
|
'version' : VersionProperties.elasticsearch
|
2018-12-06 17:06:13 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2020-03-23 14:49:42 -04:00
|
|
|
private static String buildPath(final String architecture, final boolean oss) {
|
|
|
|
return "build/${"aarch64".equals(architecture) ? 'aarch64-' : ''}${oss ? 'oss-' : ''}docker"
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
2020-03-23 14:49:42 -04:00
|
|
|
private static String taskName(final String prefix, final String architecture, final boolean oss, final String suffix) {
|
|
|
|
return "${prefix}${"aarch64".equals(architecture) ? 'Aarch64' : ''}${oss ? 'Oss' : ''}${suffix}"
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
2019-05-06 21:04:13 -04:00
|
|
|
project.ext {
|
2020-03-23 14:49:42 -04:00
|
|
|
dockerBuildContext = { String architecture, 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
|
|
|
*/
|
2020-07-07 07:45:36 -04:00
|
|
|
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
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-03-23 14:49:42 -04:00
|
|
|
expand(expansions(architecture, 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-03-23 14:49:42 -04:00
|
|
|
void addCopyDockerContextTask(final String architecture, final boolean oss) {
|
|
|
|
task(taskName("copy", architecture, oss, "DockerContext"), type: Sync) {
|
|
|
|
expansions(architecture, oss, true).findAll { it.key != 'build_date' }.each { k, v ->
|
2019-08-08 20:07:41 -04:00
|
|
|
inputs.property(k, { v.toString() })
|
|
|
|
}
|
2020-03-23 14:49:42 -04:00
|
|
|
into buildPath(architecture, oss)
|
2018-12-06 17:06:13 -05:00
|
|
|
|
2020-03-23 14:49:42 -04:00
|
|
|
with dockerBuildContext(architecture, oss, true)
|
2019-05-06 21:04:13 -04:00
|
|
|
|
2020-03-23 14:49:42 -04:00
|
|
|
if ("aarch64".equals(architecture)) {
|
|
|
|
if (oss) {
|
|
|
|
from configurations.aarch64OssDockerSource
|
|
|
|
} else {
|
|
|
|
from configurations.aarch64DockerSource
|
|
|
|
}
|
2019-05-06 21:04:13 -04:00
|
|
|
} else {
|
2020-03-23 14:49:42 -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 {
|
2020-04-15 08:39:18 -04:00
|
|
|
Architecture.values().each { eachArchitecture ->
|
|
|
|
Flavor.values().each { distroFlavor ->
|
|
|
|
"docker_$distroFlavor${ eachArchitecture == Architecture.AARCH64 ? '_aarch64' : '' }" {
|
|
|
|
architecture = eachArchitecture
|
|
|
|
flavor = distroFlavor
|
|
|
|
type = 'docker'
|
|
|
|
version = VersionProperties.getElasticsearch()
|
|
|
|
failIfUnavailable = false // This ensures we don't attempt to build images if docker is unavailable
|
|
|
|
}
|
2020-02-21 18:24:05 -05:00
|
|
|
}
|
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 {
|
|
|
|
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-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-03-23 14:49:42 -04:00
|
|
|
void addBuildDockerImage(final String architecture, final boolean oss) {
|
|
|
|
final Task buildDockerImageTask = task(taskName("build", architecture, oss, "DockerImage"), type: DockerBuildTask) {
|
|
|
|
TaskProvider<Sync> copyContextTask = tasks.named(taskName("copy", architecture, oss, "DockerContext"))
|
2020-02-27 22:18:53 -05:00
|
|
|
dependsOn(copyContextTask)
|
|
|
|
dockerContext.fileProvider(copyContextTask.map { it.destinationDir })
|
|
|
|
|
2018-12-06 17:06:13 -05:00
|
|
|
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
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2020-03-23 22:50:43 -04:00
|
|
|
buildDockerImageTask.onlyIf { Architecture.current().name().toLowerCase().equals(architecture) }
|
2019-10-30 19:04:40 -04:00
|
|
|
assemble.dependsOn(buildDockerImageTask)
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
2020-03-23 14:49:42 -04:00
|
|
|
for (final String architecture : ["aarch64", "x64"]) {
|
|
|
|
for (final boolean oss : [false, true]) {
|
|
|
|
addCopyDockerContextTask(architecture, oss)
|
|
|
|
addBuildDockerImage(architecture, 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 ->
|
2020-04-15 08:39:18 -04:00
|
|
|
if (subProject.name.endsWith('-export')) {
|
2019-11-05 10:17:59 -05:00
|
|
|
apply plugin: 'distribution'
|
|
|
|
|
2020-03-23 14:49:42 -04:00
|
|
|
final String architecture = subProject.name.contains('aarch64-') ? 'aarch64' : 'x64'
|
2019-11-05 10:17:59 -05:00
|
|
|
final boolean oss = subProject.name.contains('oss-')
|
|
|
|
|
2020-03-23 14:49:42 -04:00
|
|
|
def exportTaskName = taskName("export", architecture, oss, "DockerImage")
|
|
|
|
def buildTaskName = taskName("build", architecture, oss, "DockerImage")
|
|
|
|
def tarFile = "${parent.projectDir}/build/elasticsearch${"aarch64".equals(architecture) ? '-aarch64' : ''}${oss ? '-oss' : ''}_test.${VersionProperties.elasticsearch}.docker.tar"
|
2019-11-05 10:17:59 -05:00
|
|
|
|
|
|
|
final Task exportDockerImageTask = task(exportTaskName, type: LoggedExec) {
|
2020-04-24 11:47:24 -04:00
|
|
|
inputs.file("${parent.projectDir}/build/markers/${buildTaskName}.marker")
|
2019-11-05 10:17:59 -05:00
|
|
|
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))
|
|
|
|
|
2020-04-15 08:39:18 -04:00
|
|
|
exportDockerImageTask.onlyIf { Architecture.current().name().toLowerCase().equals(architecture) }
|
|
|
|
|
2019-11-05 10:17:59 -05:00
|
|
|
artifacts.add('default', file(tarFile)) {
|
2019-11-14 06:01:23 -05:00
|
|
|
type 'tar'
|
2020-03-23 14:49:42 -04:00
|
|
|
name "elasticsearch${"aarch64".equals(architecture) ? '-aarch64' : ''}${oss ? '-oss' : ''}"
|
2019-11-14 06:01:23 -05:00
|
|
|
builtBy exportTaskName
|
2019-11-05 10:17:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
assemble.dependsOn exportTaskName
|
|
|
|
}
|
|
|
|
}
|