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
|
|
|
}
|
|
|
|
|
2019-05-06 21:04:13 -04:00
|
|
|
ext.expansions = { oss, 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-02-08 13:01:59 -05:00
|
|
|
'elasticsearch' : elasticsearch,
|
|
|
|
'license' : oss ? 'Apache-2.0' : 'Elastic License',
|
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
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
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}"
|
|
|
|
}
|
|
|
|
|
2019-05-06 21:04:13 -04:00
|
|
|
project.ext {
|
|
|
|
dockerBuildContext = { boolean oss, boolean local ->
|
|
|
|
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-06-05 11:15:37 -04:00
|
|
|
from project.projectDir.toPath().resolve(oss ? "oss-docker-build-context" : "docker-build-context").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")) {
|
|
|
|
MavenFilteringHack.filter(it, expansions(oss, local))
|
|
|
|
}
|
2019-02-08 13:01:59 -05:00
|
|
|
}
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-06 21:04:13 -04:00
|
|
|
void addCopyDockerContextTask(final boolean oss) {
|
|
|
|
task(taskName("copy", oss, "DockerContext"), type: Sync) {
|
|
|
|
inputs.properties(expansions(oss, true))
|
2018-12-06 17:06:13 -05:00
|
|
|
into files(oss)
|
|
|
|
|
2019-05-06 21:04:13 -04:00
|
|
|
with dockerBuildContext(oss, true)
|
|
|
|
|
|
|
|
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-01-24 10:26:42 -05:00
|
|
|
preProcessFixture {
|
2019-04-12 05:31:30 -04:00
|
|
|
dependsOn assemble
|
2019-01-24 10:26:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
|
|
|
List<String> tags
|
|
|
|
if (oss) {
|
2019-04-12 05:31:30 -04:00
|
|
|
tags = [
|
|
|
|
"docker.elastic.co/elasticsearch/elasticsearch-oss:${VersionProperties.elasticsearch}",
|
|
|
|
"elasticsearch-oss:test"
|
|
|
|
]
|
2018-12-06 17:06:13 -05:00
|
|
|
} else {
|
|
|
|
tags = [
|
|
|
|
"elasticsearch:${VersionProperties.elasticsearch}",
|
|
|
|
"docker.elastic.co/elasticsearch/elasticsearch:${VersionProperties.elasticsearch}",
|
2019-04-12 05:31:30 -04:00
|
|
|
"docker.elastic.co/elasticsearch/elasticsearch-full:${VersionProperties.elasticsearch}",
|
|
|
|
"elasticsearch:test",
|
2018-12-06 17:06:13 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
addBuildDockerImage(oss)
|
|
|
|
}
|
|
|
|
|
|
|
|
assemble.dependsOn "buildOssDockerImage"
|
|
|
|
assemble.dependsOn "buildDockerImage"
|
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
|
|
|
|
}
|