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
|
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
|
|
|
aarch64OssDockerSource
|
2018-12-06 17:06:13 -05:00
|
|
|
ossDockerSource
|
|
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
2020-09-10 02:08:50 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-02-22 18:08:15 -05:00
|
|
|
ext.expansions = { Architecture architecture, 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
|
|
|
|
2021-02-22 18:08:15 -05:00
|
|
|
final String elasticsearch = "elasticsearch-oss-${VersionProperties.elasticsearch}-${classifier}.tar.gz"
|
2020-05-12 06:10:05 -04:00
|
|
|
|
|
|
|
/* 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,
|
2021-01-30 01:23:18 -05:00
|
|
|
'license' : 'Apache-2.0',
|
2021-02-22 18:08:15 -05:00
|
|
|
'package_manager' : '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
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2021-02-22 18:08:15 -05:00
|
|
|
private static String buildPath(Architecture architecture, DockerBase base) {
|
2020-08-18 04:27:23 -04:00
|
|
|
return 'build/' +
|
|
|
|
(architecture == Architecture.AARCH64 ? 'aarch64-' : '') +
|
2021-02-22 18:08:15 -05:00
|
|
|
'oss-' +
|
2020-08-18 04:27:23 -04:00
|
|
|
'docker'
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
2021-02-22 18:08:15 -05:00
|
|
|
private static String taskName(String prefix, Architecture architecture, DockerBase base, String suffix) {
|
2020-08-18 04:27:23 -04:00
|
|
|
return prefix +
|
|
|
|
(architecture == Architecture.AARCH64 ? 'Aarch64' : '') +
|
2021-02-22 18:08:15 -05:00
|
|
|
'Oss' +
|
2020-08-18 04:27:23 -04:00
|
|
|
suffix
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
2019-05-06 21:04:13 -04:00
|
|
|
project.ext {
|
2021-02-22 18:08:15 -05:00
|
|
|
dockerBuildContext = { Architecture architecture, 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') {
|
2021-02-22 18:08:15 -05:00
|
|
|
from project.projectDir.toPath().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")) {
|
2021-02-22 18:08:15 -05:00
|
|
|
expand(expansions(architecture, 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-22 18:08:15 -05:00
|
|
|
void addCopyDockerContextTask(Architecture architecture, DockerBase base) {
|
|
|
|
if (base != DockerBase.CENTOS) {
|
2020-08-18 04:27:23 -04:00
|
|
|
throw new GradleException("The only allowed docker base image for OSS builds is CENTOS")
|
|
|
|
}
|
|
|
|
|
2021-02-22 18:08:15 -05:00
|
|
|
tasks.register(taskName("copy", architecture, base, "DockerContext"), Sync) {
|
|
|
|
expansions(architecture, base, true).findAll { it.key != 'build_date' }.each { k, v ->
|
2019-08-08 20:07:41 -04:00
|
|
|
inputs.property(k, { v.toString() })
|
|
|
|
}
|
2021-02-22 18:08:15 -05:00
|
|
|
into buildPath(architecture, base)
|
2018-12-06 17:06:13 -05:00
|
|
|
|
2021-02-22 18:08:15 -05:00
|
|
|
with dockerBuildContext(architecture, base, true)
|
2019-05-06 21:04:13 -04:00
|
|
|
|
2020-08-18 04:27:23 -04:00
|
|
|
if (architecture == Architecture.AARCH64) {
|
2021-02-22 18:08:15 -05:00
|
|
|
from configurations.aarch64OssDockerSource
|
2019-05-06 21:04:13 -04:00
|
|
|
} else {
|
2021-02-22 18:08:15 -05:00
|
|
|
from configurations.ossDockerSource
|
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-02-21 18:24:05 -05:00
|
|
|
elasticsearch_distributions {
|
2020-04-15 08:39:18 -04:00
|
|
|
Architecture.values().each { eachArchitecture ->
|
2021-02-22 18:08:15 -05:00
|
|
|
"docker${ eachArchitecture == Architecture.AARCH64 ? '_aarch64' : '' }" {
|
|
|
|
architecture = eachArchitecture
|
|
|
|
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 {
|
2021-02-22 18:08:15 -05:00
|
|
|
dependsOn elasticsearch_distributions.docker
|
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}/oss-repo"
|
2019-07-11 08:04:25 -04:00
|
|
|
)
|
|
|
|
createAndSetWritable(
|
2019-11-14 06:01:23 -05:00
|
|
|
"${buildDir}/oss-repo",
|
|
|
|
"${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.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
|
|
|
|
2021-02-22 18:08:15 -05:00
|
|
|
void addBuildDockerImage(Architecture architecture, DockerBase base) {
|
|
|
|
if (base != DockerBase.CENTOS) {
|
2020-08-18 04:27:23 -04:00
|
|
|
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 =
|
2021-02-22 18:08:15 -05:00
|
|
|
tasks.register(taskName("build", architecture, base, "DockerImage"), DockerBuildTask) {
|
2020-08-18 04:27:23 -04:00
|
|
|
onlyIf { Architecture.current() == architecture }
|
2021-02-22 18:08:15 -05:00
|
|
|
TaskProvider<Sync> copyContextTask = tasks.named(taskName("copy", architecture, base, "DockerContext"))
|
2020-02-27 22:18:53 -05:00
|
|
|
dependsOn(copyContextTask)
|
|
|
|
dockerContext.fileProvider(copyContextTask.map { it.destinationDir })
|
2020-10-21 08:31:32 -04:00
|
|
|
baseImages = [ base.getImage() ]
|
2020-02-27 22:18:53 -05:00
|
|
|
|
2020-08-18 04:27:23 -04:00
|
|
|
String version = VersionProperties.elasticsearch
|
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
|
|
|
}
|
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()) {
|
2021-02-22 18:08:15 -05:00
|
|
|
// We only create Docker images for the OSS distribution on CentOS.
|
2020-08-18 04:27:23 -04:00
|
|
|
for (final DockerBase base : DockerBase.values()) {
|
2021-02-22 18:08:15 -05:00
|
|
|
if (base == DockerBase.CENTOS) {
|
|
|
|
addCopyDockerContextTask(architecture, base)
|
|
|
|
addBuildDockerImage(architecture, base)
|
2020-08-18 04:27:23 -04:00
|
|
|
}
|
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
|
2021-02-22 18:08:15 -05:00
|
|
|
final DockerBase base = DockerBase.CENTOS
|
2020-08-18 04:27:23 -04:00
|
|
|
|
|
|
|
final String arch = architecture == Architecture.AARCH64 ? '-aarch64' : ''
|
2021-02-22 18:08:15 -05:00
|
|
|
final String suffix = '-oss'
|
|
|
|
final String extension = 'docker.tar'
|
2020-08-18 04:27:23 -04:00
|
|
|
final String artifactName = "elasticsearch${arch}${suffix}_test"
|
2019-11-05 10:17:59 -05:00
|
|
|
|
2021-02-22 18:08:15 -05:00
|
|
|
final String exportTaskName = taskName("export", architecture, base, "DockerImage")
|
|
|
|
final String buildTaskName = taskName("build", architecture, base, "DockerImage")
|
2020-08-18 04:27:23 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|