mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-06 21:18:31 +00:00
We initially added `requireDocker` for a way for tasks to say that they absolutely must have it, like the build docker image tasks. Projects using the test fixtures plugin are not in this both, as the intent with these is that they will be skipped if docker and docker-compose is not available. Before this change we were lenient, the docker image build would succeed but produce nothing. The implementation was also confusing as it was not immediately obvious this was the case due to all the indirection in the code. The reason we have this leniency is that when we added the docker image build, docker was a fairly new requirement for us, and we didn't have it deployed in CI widely enough nor had CI configured to prefer workers with docker when possible. We are in a much better position now. The other reason was other stack teams running `./gradlew assemble` in their respective CI and the possibility of breaking them if docker is not installed. We have been advocating for building specific distros for some time now and I will also send out an additional notice The PR also removes the use of `requireDocker` from tests that actually use test fixtures and are ok without it, and fixes a bug in test fixtures that would cause incorrect configuration and allow some tasks to run when docker was not available and they shouldn't have. Closes #42680 and #42829 see also #42719
137 lines
4.6 KiB
Groovy
137 lines
4.6 KiB
Groovy
import org.elasticsearch.gradle.BuildPlugin
|
|
import org.elasticsearch.gradle.LoggedExec
|
|
import org.elasticsearch.gradle.MavenFilteringHack
|
|
import org.elasticsearch.gradle.VersionProperties
|
|
import org.elasticsearch.gradle.testfixtures.TestFixturesPlugin
|
|
|
|
apply plugin: 'base'
|
|
apply plugin: 'elasticsearch.test.fixtures'
|
|
|
|
configurations {
|
|
dockerPlugins
|
|
dockerSource
|
|
ossDockerSource
|
|
}
|
|
|
|
dependencies {
|
|
dockerSource project(path: ":distribution:archives:linux-tar")
|
|
ossDockerSource project(path: ":distribution:archives:oss-linux-tar")
|
|
}
|
|
|
|
ext.expansions = { oss, local ->
|
|
final String classifier = 'linux-x86_64'
|
|
final String elasticsearch = oss ? "elasticsearch-oss-${VersionProperties.elasticsearch}-${classifier}.tar.gz" : "elasticsearch-${VersionProperties.elasticsearch}-${classifier}.tar.gz"
|
|
return [
|
|
'elasticsearch' : elasticsearch,
|
|
'license' : oss ? 'Apache-2.0' : 'Elastic License',
|
|
'source_elasticsearch': local ? "COPY $elasticsearch /opt/" : "RUN cd /opt && curl --retry 8 -s -L -O https://artifacts.elastic.co/downloads/elasticsearch/${elasticsearch} && cd -",
|
|
'version' : VersionProperties.elasticsearch
|
|
]
|
|
}
|
|
|
|
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}"
|
|
}
|
|
|
|
project.ext {
|
|
dockerBuildContext = { boolean oss, boolean local ->
|
|
copySpec {
|
|
into('bin') {
|
|
from project.projectDir.toPath().resolve("src/docker/bin")
|
|
}
|
|
|
|
into('config') {
|
|
/*
|
|
* 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.
|
|
*/
|
|
from project.projectDir.toPath().resolve("src/docker/config")
|
|
from project.projectDir.toPath().resolve(oss ? "oss-docker-build-context" : "docker-build-context").resolve("src/docker/config")
|
|
}
|
|
|
|
from(project.projectDir.toPath().resolve("src/docker/Dockerfile")) {
|
|
MavenFilteringHack.filter(it, expansions(oss, local))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void addCopyDockerContextTask(final boolean oss) {
|
|
task(taskName("copy", oss, "DockerContext"), type: Sync) {
|
|
inputs.properties(expansions(oss, true))
|
|
into files(oss)
|
|
|
|
with dockerBuildContext(oss, true)
|
|
|
|
if (oss) {
|
|
from configurations.ossDockerSource
|
|
} else {
|
|
from configurations.dockerSource
|
|
}
|
|
|
|
from configurations.dockerPlugins
|
|
}
|
|
}
|
|
|
|
preProcessFixture {
|
|
// don't add the tasks to build the docker images if we have no way of testing them
|
|
if (TestFixturesPlugin.dockerComposeSupported()) {
|
|
dependsOn assemble
|
|
}
|
|
}
|
|
|
|
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
|
|
|
|
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) {
|
|
tags = [
|
|
"docker.elastic.co/elasticsearch/elasticsearch-oss:${VersionProperties.elasticsearch}",
|
|
"elasticsearch-oss:test"
|
|
]
|
|
} else {
|
|
tags = [
|
|
"elasticsearch:${VersionProperties.elasticsearch}",
|
|
"docker.elastic.co/elasticsearch/elasticsearch:${VersionProperties.elasticsearch}",
|
|
"docker.elastic.co/elasticsearch/elasticsearch-full:${VersionProperties.elasticsearch}",
|
|
"elasticsearch:test",
|
|
]
|
|
}
|
|
executable 'docker'
|
|
final List<String> dockerArgs = ['build', files(oss), '--pull', '--no-cache']
|
|
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"
|
|
|
|
// 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
|
|
if (tasks.findByName("composePull")) {
|
|
tasks.composePull.enabled = false
|
|
}
|