Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,7 @@ class BuildPlugin implements Plugin<Project> {
}
}

if (ext.get('buildDocker')) {
(ext.get('requiresDocker') as List<Task>).add(task)
} else {
task.onlyIf { false }
}
(ext.get('requiresDocker') as List<Task>).add(task)
}

protected static void checkDockerVersionRecent(String dockerVersion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,7 @@ default void waitForConditions(
} catch (TestClustersException e) {
throw e;
} catch (Exception e) {
if (lastException == null) {
lastException = e;
} else {
lastException = e;
}
throw e;
}
}
if (conditionMet == false) {
Expand All @@ -135,7 +131,7 @@ default void waitForConditions(
if (lastException == null) {
throw new TestClustersException(message);
} else {
throw new TestClustersException(message, lastException);
throw new TestClustersException(message + message, lastException);
}
}
logger.info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.testing.Test;

import java.io.File;
import java.util.Collections;
import java.util.function.BiConsumer;

Expand All @@ -58,46 +59,47 @@ public void apply(Project project) {
disableTaskByType(tasks, ThirdPartyAuditTask.class);
disableTaskByType(tasks, JarHellTask.class);

// the project that defined a test fixture can also use it
extension.fixtures.add(project);

Task buildFixture = project.getTasks().create("buildFixture");
Task pullFixture = project.getTasks().create("pullFixture");
Task preProcessFixture = project.getTasks().create("preProcessFixture");
buildFixture.dependsOn(preProcessFixture);
pullFixture.dependsOn(preProcessFixture);
Task postProcessFixture = project.getTasks().create("postProcessFixture");
postProcessFixture.dependsOn(buildFixture);
preProcessFixture.onlyIf(spec -> buildFixture.getEnabled());
postProcessFixture.onlyIf(spec -> buildFixture.getEnabled());

if (dockerComposeSupported(project) == false) {
if (dockerComposeSupported() == false) {
preProcessFixture.setEnabled(false);
postProcessFixture.setEnabled(false);
buildFixture.setEnabled(false);
pullFixture.setEnabled(false);
return;
}
preProcessFixture.onlyIf(spec -> buildFixture.getEnabled());
postProcessFixture.onlyIf(spec -> buildFixture.getEnabled());

project.apply(spec -> spec.plugin(BasePlugin.class));
project.apply(spec -> spec.plugin(DockerComposePlugin.class));
ComposeExtension composeExtension = project.getExtensions().getByType(ComposeExtension.class);
composeExtension.setUseComposeFiles(Collections.singletonList(DOCKER_COMPOSE_YML));
composeExtension.setRemoveContainers(true);
composeExtension.setExecutable(
project.file("/usr/local/bin/docker-compose").exists() ?
"/usr/local/bin/docker-compose" : "/usr/bin/docker-compose"
);
} else {
project.apply(spec -> spec.plugin(BasePlugin.class));
project.apply(spec -> spec.plugin(DockerComposePlugin.class));
ComposeExtension composeExtension = project.getExtensions().getByType(ComposeExtension.class);
composeExtension.setUseComposeFiles(Collections.singletonList(DOCKER_COMPOSE_YML));
composeExtension.setRemoveContainers(true);
composeExtension.setExecutable(
project.file("/usr/local/bin/docker-compose").exists() ?
"/usr/local/bin/docker-compose" : "/usr/bin/docker-compose"
);

buildFixture.dependsOn(tasks.getByName("composeUp"));
pullFixture.dependsOn(tasks.getByName("composePull"));
tasks.getByName("composeUp").mustRunAfter(preProcessFixture);
tasks.getByName("composePull").mustRunAfter(preProcessFixture);
postProcessFixture.dependsOn(buildFixture);
buildFixture.dependsOn(tasks.getByName("composeUp"));
pullFixture.dependsOn(tasks.getByName("composePull"));
tasks.getByName("composeUp").mustRunAfter(preProcessFixture);
tasks.getByName("composePull").mustRunAfter(preProcessFixture);

configureServiceInfoForTask(
postProcessFixture,
project,
(name, port) -> postProcessFixture.getExtensions()
.getByType(ExtraPropertiesExtension.class).set(name, port)
);
extension.fixtures.add(project);
configureServiceInfoForTask(
postProcessFixture,
project,
(name, port) -> postProcessFixture.getExtensions()
.getByType(ExtraPropertiesExtension.class).set(name, port)
);
}
}

extension.fixtures
Expand All @@ -109,7 +111,7 @@ public void apply(Project project) {
conditionTaskByType(tasks, extension, TestingConventionsTasks.class);
conditionTaskByType(tasks, extension, ComposeUp.class);

if (dockerComposeSupported(project) == false) {
if (dockerComposeSupported() == false) {
project.getLogger().warn(
"Tests for {} require docker-compose at /usr/local/bin/docker-compose or /usr/bin/docker-compose " +
"but none could be found so these will be skipped", project.getPath()
Expand Down Expand Up @@ -138,7 +140,9 @@ private void conditionTaskByType(TaskContainer tasks, TestFixtureExtension exten
taskClass,
task -> task.onlyIf(spec ->
extension.fixtures.stream()
.anyMatch(fixtureProject -> fixtureProject.getTasks().getByName("buildFixture").getEnabled() == false) == false
.anyMatch(fixtureProject ->
fixtureProject.getTasks().getByName("buildFixture").getEnabled() == false
) == false
)
);
}
Expand Down Expand Up @@ -175,12 +179,12 @@ public void execute(Task theTask) {
);
}

public boolean dockerComposeSupported(Project project) {
public static boolean dockerComposeSupported() {
if (OS.current().equals(OS.WINDOWS)) {
return false;
}
final boolean hasDockerCompose = project.file("/usr/local/bin/docker-compose").exists() ||
project.file("/usr/bin/docker-compose").exists();
final boolean hasDockerCompose = (new File("/usr/local/bin/docker-compose")).exists() ||
(new File("/usr/bin/docker-compose").exists());
return hasDockerCompose && Boolean.parseBoolean(System.getProperty("tests.fixture.enabled", "true"));
}

Expand Down
6 changes: 5 additions & 1 deletion distribution/docker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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'
Expand Down Expand Up @@ -77,7 +78,10 @@ void addCopyDockerContextTask(final boolean oss) {
}

preProcessFixture {
dependsOn assemble
// 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 {
Expand Down
15 changes: 4 additions & 11 deletions plugins/repository-s3/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,16 @@ if (useFixture) {

File minioAddressFile = new File(project.buildDir, 'generated-resources/s3Fixture.address')

// We can't lazy evaluate a system property for the Minio address passed to JUnit so we write it to a resource file
// and pass its name instead.
task writeMinioAddress {
thirdPartyTest {
dependsOn tasks.bundlePlugin, tasks.postProcessFixture
doLast {
outputs.file(minioAddressFile)
doFirst {
file(minioAddressFile).text = "${ -> minioAddress.call() }"
}
}

thirdPartyTest {
dependsOn writeMinioAddress
// TODO: this could be a nonInputProperties.systemProperty so we don't need a file
systemProperty 'test.s3.endpoint', minioAddressFile.name
}

BuildPlugin.requireDocker(tasks.thirdPartyTest)

task integTestMinio(type: RestIntegTestTask) {
description = "Runs REST tests using the Minio repository."
dependsOn tasks.bundlePlugin, tasks.postProcessFixture
Expand All @@ -198,7 +192,6 @@ if (useFixture) {
}
}
check.dependsOn(integTestMinio)
BuildPlugin.requireDocker(tasks.integTestMinio)

testClusters.integTestMinio {
keystore 's3.client.integration_test_permanent.access_key', s3PermanentAccessKey
Expand Down