2020-03-23 14:49:42 -04:00
|
|
|
import org.elasticsearch.gradle.Architecture
|
2020-08-18 04:27:23 -04:00
|
|
|
import org.elasticsearch.gradle.DockerBase
|
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
|
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-07-31 03:30:21 -04:00
|
|
|
apply plugin: 'elasticsearch.internal-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 {
|
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-09-10 02:08:50 -04:00
|
|
|
aarch64DockerSource project(path: ":distribution:archives:linux-aarch64-tar", configuration:"default")
|
|
|
|
dockerSource project(path: ":distribution:archives:linux-tar", configuration:"default")
|
|
|
|
aarch64OssDockerSource project(path: ":distribution:archives:oss-linux-aarch64-tar", configuration:"default")
|
|
|
|
ossDockerSource project(path: ":distribution:archives:oss-linux-tar", configuration:"default")
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
2020-08-18 04:27:23 -04:00
|
|
|
ext.expansions = { Architecture architecture, boolean oss, DockerBase base, boolean local ->
|
2020-05-12 06:10:05 -04:00
|
|
|
String classifier
|
|
|
|
if (local) {
|
2020-08-18 04:27:23 -04:00
|
|
|
if (architecture == Architecture.AARCH64) {
|
|
|
|
classifier = "linux-aarch64"
|
|
|
|
} else if (architecture == Architecture.X64) {
|
|
|
|
classifier = "linux-x86_64"
|
|
|
|
} else {
|
|
|
|
throw new IllegalArgumentException("Unsupported architecture [" + architecture + "]")
|
2020-05-12 06:10:05 -04:00
|
|
|
}
|
|
|
|
} 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 \\
|
2020-11-07 14:27:58 -05:00
|
|
|
https://artifacts-no-kpi.elastic.co/downloads/elasticsearch/$elasticsearch
|
2020-05-12 06:10:05 -04:00
|
|
|
"""
|
|
|
|
}
|
|
|
|
|
2018-12-06 17:06:13 -05:00
|
|
|
return [
|
2020-08-18 04:27:23 -04:00
|
|
|
'base_image' : base.getImage(),
|
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-08-18 04:27:23 -04:00
|
|
|
'package_manager' : base == DockerBase.UBI ? 'microdnf' : 'yum',
|
2020-05-12 06:10:05 -04:00
|
|
|
'source_elasticsearch': sourceElasticsearch,
|
2020-08-18 04:27:23 -04:00
|
|
|
'docker_base' : base.name().toLowerCase(),
|
2019-02-08 13:01:59 -05:00
|
|
|
'version' : VersionProperties.elasticsearch
|
2018-12-06 17:06:13 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2020-08-18 04:27:23 -04:00
|
|
|
private static String buildPath(Architecture architecture, boolean oss, DockerBase base) {
|
|
|
|
return 'build/' +
|
|
|
|
(architecture == Architecture.AARCH64 ? 'aarch64-' : '') +
|
|
|
|
(oss ? 'oss-' : '') +
|
|
|
|
(base == DockerBase.UBI ? 'ubi-' : '') +
|
|
|
|
'docker'
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
2020-08-18 04:27:23 -04:00
|
|
|
private static String taskName(String prefix, Architecture architecture, boolean oss, DockerBase base, String suffix) {
|
|
|
|
return prefix +
|
|
|
|
(architecture == Architecture.AARCH64 ? 'Aarch64' : '') +
|
|
|
|
(oss ? 'Oss' : '') +
|
|
|
|
(base == DockerBase.UBI ? 'Ubi' : '') +
|
|
|
|
suffix
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
2019-05-06 21:04:13 -04:00
|
|
|
project.ext {
|
2020-08-18 04:27:23 -04:00
|
|
|
dockerBuildContext = { Architecture architecture, boolean oss, DockerBase base, 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
|
|
|
/*
|
2020-08-18 04:27:23 -04:00
|
|
|
* The OSS and default distributions have different configurations, therefore we want to allow overriding the default configuration
|
|
|
|
* from files in the 'oss' sub-directory. We don't want the 'oss' sub-directory to appear in the final build context, however.
|
2019-06-05 11:15:37 -04:00
|
|
|
*/
|
2020-08-18 04:27:23 -04:00
|
|
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
|
|
|
from(project.projectDir.toPath().resolve("src/docker/config")) {
|
|
|
|
exclude 'oss'
|
|
|
|
}
|
2019-10-30 19:04:40 -04:00
|
|
|
if (oss) {
|
2020-08-18 04:27:23 -04:00
|
|
|
// Overlay the config file
|
2019-10-30 19:04:40 -04:00
|
|
|
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-08-18 04:27:23 -04:00
|
|
|
expand(expansions(architecture, oss, base, 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-08-18 04:27:23 -04:00
|
|
|
void addCopyDockerContextTask(Architecture architecture, boolean oss, DockerBase base) {
|
|
|
|
if (oss && base != DockerBase.CENTOS) {
|
|
|
|
throw new GradleException("The only allowed docker base image for OSS builds is CENTOS")
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.register(taskName("copy", architecture, oss, base, "DockerContext"), Sync) {
|
|
|
|
expansions(architecture, oss, base, true).findAll { it.key != 'build_date' }.each { k, v ->
|
2019-08-08 20:07:41 -04:00
|
|
|
inputs.property(k, { v.toString() })
|
|
|
|
}
|
2020-08-18 04:27:23 -04:00
|
|
|
into buildPath(architecture, oss, base)
|
2018-12-06 17:06:13 -05:00
|
|
|
|
2020-08-18 04:27:23 -04:00
|
|
|
with dockerBuildContext(architecture, oss, base, true)
|
2019-05-06 21:04:13 -04:00
|
|
|
|
2020-08-18 04:27:23 -04:00
|
|
|
if (architecture == Architecture.AARCH64) {
|
2020-03-23 14:49:42 -04:00
|
|
|
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-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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.register("copyKeystore", Sync) {
|
2019-07-11 08:04:25 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.named("preProcessFixture").configure {
|
2020-02-21 18:24:05 -05:00
|
|
|
dependsOn elasticsearch_distributions.docker_default, elasticsearch_distributions.docker_oss
|
2020-07-31 07:09:04 -04:00
|
|
|
dependsOn "copyKeystore"
|
2019-07-11 08:04:25 -04:00
|
|
|
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
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.named("processTestResources").configure {
|
2019-07-11 08:04:25 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.register("integTest", 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
|
|
|
}
|
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.named("check").configure {
|
|
|
|
dependsOn "integTest"
|
|
|
|
}
|
2019-01-24 10:26:42 -05:00
|
|
|
|
2020-08-18 04:27:23 -04:00
|
|
|
void addBuildDockerImage(Architecture architecture, boolean oss, DockerBase base) {
|
|
|
|
if (oss && base != DockerBase.CENTOS) {
|
|
|
|
throw new GradleException("The only allowed docker base image for OSS builds is CENTOS")
|
|
|
|
}
|
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
final TaskProvider<DockerBuildTask> buildDockerImageTask =
|
2020-08-18 04:27:23 -04:00
|
|
|
tasks.register(taskName("build", architecture, oss, base, "DockerImage"), DockerBuildTask) {
|
|
|
|
onlyIf { Architecture.current() == architecture }
|
|
|
|
TaskProvider<Sync> copyContextTask = tasks.named(taskName("copy", architecture, oss, base, "DockerContext"))
|
2020-02-27 22:18:53 -05:00
|
|
|
dependsOn(copyContextTask)
|
|
|
|
dockerContext.fileProvider(copyContextTask.map { it.destinationDir })
|
|
|
|
|
2020-08-18 04:27:23 -04:00
|
|
|
String version = VersionProperties.elasticsearch
|
2018-12-06 17:06:13 -05:00
|
|
|
if (oss) {
|
2019-11-14 06:01:23 -05:00
|
|
|
tags = [
|
2020-08-18 04:27:23 -04:00
|
|
|
"docker.elastic.co/elasticsearch/elasticsearch-oss:${version}",
|
2020-01-08 16:51:41 -05:00
|
|
|
"elasticsearch-oss:test"
|
2019-04-12 05:31:30 -04:00
|
|
|
]
|
2018-12-06 17:06:13 -05:00
|
|
|
} else {
|
2020-08-18 04:27:23 -04:00
|
|
|
String suffix = base == DockerBase.UBI ? '-ubi8' : ''
|
2018-12-06 17:06:13 -05:00
|
|
|
tags = [
|
2020-08-18 04:27:23 -04:00
|
|
|
"elasticsearch${suffix}:${version}",
|
|
|
|
"docker.elastic.co/elasticsearch/elasticsearch${suffix}:${version}",
|
|
|
|
"docker.elastic.co/elasticsearch/elasticsearch-full${suffix}:${version}",
|
|
|
|
"elasticsearch${suffix}:test",
|
2018-12-06 17:06:13 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.named("assemble").configure {
|
|
|
|
dependsOn(buildDockerImageTask)
|
|
|
|
}
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
2020-08-18 04:27:23 -04:00
|
|
|
for (final Architecture architecture : Architecture.values()) {
|
|
|
|
for (final DockerBase base : DockerBase.values()) {
|
|
|
|
for (final boolean oss : [false, true]) {
|
|
|
|
if (oss && base != DockerBase.CENTOS) {
|
|
|
|
// We only create Docker images for the OSS distribution on CentOS.
|
|
|
|
// Other bases only use the default distribution.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
addCopyDockerContextTask(architecture, oss, base)
|
|
|
|
addBuildDockerImage(architecture, oss, base)
|
|
|
|
}
|
2020-03-23 14:49:42 -04:00
|
|
|
}
|
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
|
2020-08-18 04:27:23 -04:00
|
|
|
* that they can be easily reloaded, for example into a VM for distribution testing
|
2019-11-05 10:17:59 -05:00
|
|
|
*/
|
|
|
|
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-08-18 04:27:23 -04:00
|
|
|
final Architecture architecture = subProject.name.contains('aarch64-') ? Architecture.AARCH64 : Architecture.X64
|
2019-11-05 10:17:59 -05:00
|
|
|
final boolean oss = subProject.name.contains('oss-')
|
2020-08-18 04:27:23 -04:00
|
|
|
final DockerBase base = subProject.name.contains('ubi-') ? DockerBase.UBI : DockerBase.CENTOS
|
|
|
|
|
|
|
|
final String arch = architecture == Architecture.AARCH64 ? '-aarch64' : ''
|
|
|
|
final String suffix = oss ? '-oss' : base == DockerBase.UBI ? '-ubi8' : ''
|
|
|
|
final String extension = base == DockerBase.UBI ? 'ubi.tar' : 'docker.tar'
|
|
|
|
final String artifactName = "elasticsearch${arch}${suffix}_test"
|
2019-11-05 10:17:59 -05:00
|
|
|
|
2020-08-18 04:27:23 -04:00
|
|
|
final String exportTaskName = taskName("export", architecture, oss, base, "DockerImage")
|
|
|
|
final String buildTaskName = taskName("build", architecture, oss, base, "DockerImage")
|
|
|
|
final String tarFile = "${parent.projectDir}/build/${artifactName}_${VersionProperties.elasticsearch}.${extension}"
|
2019-11-05 10:17:59 -05:00
|
|
|
|
2020-08-18 04:27:23 -04:00
|
|
|
tasks.register(exportTaskName, 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-08-18 04:27:23 -04:00
|
|
|
"elasticsearch${suffix}:test"
|
2019-11-05 10:17:59 -05:00
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
dependsOn(parent.path + ":" + buildTaskName)
|
2020-08-18 04:27:23 -04:00
|
|
|
onlyIf { Architecture.current() == architecture }
|
2020-07-31 07:09:04 -04:00
|
|
|
}
|
2020-04-15 08:39:18 -04:00
|
|
|
|
2019-11-05 10:17:59 -05:00
|
|
|
artifacts.add('default', file(tarFile)) {
|
2019-11-14 06:01:23 -05:00
|
|
|
type 'tar'
|
2020-08-18 04:27:23 -04:00
|
|
|
name artifactName
|
2019-11-14 06:01:23 -05:00
|
|
|
builtBy exportTaskName
|
2019-11-05 10:17:59 -05:00
|
|
|
}
|
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.named("assemble").configure {
|
|
|
|
dependsOn(exportTaskName)
|
|
|
|
}
|
2019-11-05 10:17:59 -05:00
|
|
|
}
|
|
|
|
}
|