2018-12-06 17:06:13 -05:00
|
|
|
import org.elasticsearch.gradle.BuildPlugin
|
|
|
|
import org.elasticsearch.gradle.LoggedExec
|
|
|
|
import org.elasticsearch.gradle.MavenFilteringHack
|
|
|
|
import org.elasticsearch.gradle.VersionProperties
|
|
|
|
|
|
|
|
apply plugin: 'base'
|
2019-01-24 10:26:42 -05:00
|
|
|
apply plugin: 'elasticsearch.test.fixtures'
|
2018-12-06 17:06:13 -05:00
|
|
|
|
|
|
|
configurations {
|
|
|
|
dockerPlugins
|
|
|
|
dockerSource
|
|
|
|
ossDockerSource
|
|
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
2019-01-29 14:18:30 -05:00
|
|
|
dockerSource project(path: ":distribution:archives:linux-tar")
|
|
|
|
ossDockerSource project(path: ":distribution:archives:oss-linux-tar")
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ext.expansions = { oss ->
|
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-02-08 13:01:59 -05:00
|
|
|
'elasticsearch' : elasticsearch,
|
|
|
|
'jdkUrl' : 'https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz',
|
|
|
|
'jdkVersion' : '11.0.2',
|
|
|
|
'license' : oss ? 'Apache-2.0' : 'Elastic License',
|
|
|
|
'source_elasticsearch': local() ? "COPY $elasticsearch /opt/" : "RUN curl --retry 8 -s -L -O https://artifacts.elastic.co/downloads/elasticsearch/${elasticsearch}",
|
|
|
|
'version' : VersionProperties.elasticsearch
|
2018-12-06 17:06:13 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2019-02-08 13:01:59 -05:00
|
|
|
/*
|
|
|
|
* We need to be able to render a Dockerfile that references the official artifacts on https://artifacts.elastic.co. For this, we use a
|
|
|
|
* substitution in the Dockerfile template where we can either replace source_elasticsearch with a COPY from the Docker build context, or
|
|
|
|
* a RUN curl command to retrieve the artifact from https://artifacts.elastic.co. The system property build.docker.source, which can be
|
|
|
|
* either "local" (default) or "remote" controls which version of the Dockerfile is produced.
|
|
|
|
*/
|
|
|
|
private static boolean local() {
|
|
|
|
final String buildDockerSource = System.getProperty("build.docker.source")
|
|
|
|
if (buildDockerSource == null || "local".equals(buildDockerSource)) {
|
|
|
|
return true
|
|
|
|
} else if ("remote".equals(buildDockerSource)) {
|
|
|
|
return false
|
|
|
|
} else {
|
|
|
|
throw new IllegalArgumentException("expected build.docker.source to be [local] or [remote] but was [" + buildDockerSource + "]")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 17:06:13 -05:00
|
|
|
private static String files(final boolean oss) {
|
|
|
|
return "build/${ oss ? 'oss-' : ''}docker"
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String taskName(final String prefix, final boolean oss, final String suffix) {
|
|
|
|
return "${prefix}${oss ? 'Oss' : ''}${suffix}"
|
|
|
|
}
|
|
|
|
|
|
|
|
void addCopyDockerContextTask(final boolean oss) {
|
|
|
|
task(taskName("copy", oss, "DockerContext"), type: Sync) {
|
|
|
|
into files(oss)
|
|
|
|
|
|
|
|
into('bin') {
|
|
|
|
from 'src/docker/bin'
|
|
|
|
}
|
|
|
|
|
|
|
|
into('config') {
|
|
|
|
from 'src/docker/config'
|
|
|
|
}
|
|
|
|
|
2019-02-08 13:01:59 -05:00
|
|
|
if (local()) {
|
|
|
|
if (oss) {
|
|
|
|
from configurations.ossDockerSource
|
|
|
|
} else {
|
|
|
|
from configurations.dockerSource
|
|
|
|
}
|
2018-12-06 17:06:13 -05:00
|
|
|
|
2019-02-08 13:01:59 -05:00
|
|
|
from configurations.dockerPlugins
|
|
|
|
}
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void addCopyDockerfileTask(final boolean oss) {
|
|
|
|
task(taskName("copy", oss, "Dockerfile"), type: Copy) {
|
2019-02-08 13:01:59 -05:00
|
|
|
dependsOn taskName("copy", oss, "DockerContext")
|
2019-01-18 20:01:35 -05:00
|
|
|
inputs.properties(expansions(oss)) // ensure task is run when ext.expansions is changed
|
2018-12-06 17:06:13 -05:00
|
|
|
into files(oss)
|
|
|
|
|
|
|
|
from('src/docker/Dockerfile') {
|
|
|
|
MavenFilteringHack.filter(it, expansions(oss))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-24 10:26:42 -05:00
|
|
|
preProcessFixture {
|
|
|
|
dependsOn taskName("copy", true, "DockerContext")
|
|
|
|
dependsOn taskName("copy", true, "Dockerfile")
|
|
|
|
dependsOn taskName("copy", false, "DockerContext")
|
|
|
|
dependsOn taskName("copy", false, "Dockerfile")
|
|
|
|
}
|
|
|
|
|
|
|
|
postProcessFixture.doLast {
|
|
|
|
println "docker default distro is on port: ${ext."test.fixtures.elasticsearch-default.tcp.9200"}, " +
|
|
|
|
"oss is on: ${ext."test.fixtures.elasticsearch-oss.tcp.9200"}"
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Add some actual tests, this will just check that the TPC port in the container is up
|
|
|
|
check.dependsOn postProcessFixture
|
|
|
|
|
2018-12-06 17:06:13 -05:00
|
|
|
void addBuildDockerImage(final boolean oss) {
|
|
|
|
final Task buildDockerImageTask = task(taskName("build", oss, "DockerImage"), type: LoggedExec) {
|
|
|
|
dependsOn taskName("copy", oss, "DockerContext")
|
|
|
|
dependsOn taskName("copy", oss, "Dockerfile")
|
|
|
|
List<String> tags
|
|
|
|
if (oss) {
|
|
|
|
tags = [ "docker.elastic.co/elasticsearch/elasticsearch-oss:${VersionProperties.elasticsearch}" ]
|
|
|
|
} else {
|
|
|
|
tags = [
|
|
|
|
"elasticsearch:${VersionProperties.elasticsearch}",
|
|
|
|
"docker.elastic.co/elasticsearch/elasticsearch:${VersionProperties.elasticsearch}",
|
|
|
|
"docker.elastic.co/elasticsearch/elasticsearch-full:${VersionProperties.elasticsearch}"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
executable 'docker'
|
2019-01-18 20:01:35 -05:00
|
|
|
final List<String> dockerArgs = ['build', files(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()
|
|
|
|
}
|
|
|
|
BuildPlugin.requireDocker(buildDockerImageTask)
|
|
|
|
}
|
|
|
|
|
|
|
|
for (final boolean oss : [false, true]) {
|
|
|
|
addCopyDockerContextTask(oss)
|
|
|
|
addCopyDockerfileTask(oss)
|
|
|
|
addBuildDockerImage(oss)
|
|
|
|
}
|
|
|
|
|
|
|
|
assemble.dependsOn "buildOssDockerImage"
|
|
|
|
assemble.dependsOn "buildDockerImage"
|