Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for docker compose v2 in TestFixturesPlugin #16049

Merged
merged 5 commits into from
Sep 24, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Update protobuf from 3.25.4 to 3.25.5 ([#16011](https://github.com/opensearch-project/OpenSearch/pull/16011))

### Changed
- Add support for docker compose v2 in TestFixturesPlugin ([#16049](https://github.com/opensearch-project/OpenSearch/pull/16049))


### Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
Version version = null;
boolean isVersionHighEnough = false;
boolean isComposeAvailable = false;
boolean isComposeV2Available = false;

Check warning on line 109 in buildSrc/src/main/java/org/opensearch/gradle/docker/DockerSupportService.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/docker/DockerSupportService.java#L109

Added line #L109 was not covered by tests

// Check if the Docker binary exists
final Optional<String> dockerBinary = getDockerPath();
Expand All @@ -129,6 +130,8 @@
if (lastResult.isSuccess() && composePath.isPresent()) {
isComposeAvailable = runCommand(composePath.get(), "version").isSuccess();
}

isComposeV2Available = runCommand(dockerPath, "compose", "version").isSuccess();

Check warning on line 134 in buildSrc/src/main/java/org/opensearch/gradle/docker/DockerSupportService.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/docker/DockerSupportService.java#L134

Added line #L134 was not covered by tests
}
}
}
Expand All @@ -138,6 +141,7 @@
this.dockerAvailability = new DockerAvailability(
isAvailable,
isComposeAvailable,
isComposeV2Available,
isVersionHighEnough,
dockerPath,
version,
Expand Down Expand Up @@ -356,6 +360,11 @@
*/
public final boolean isComposeAvailable;

/**
* True if docker compose is available.
*/
public final boolean isComposeV2Available;

/**
* True if the installed Docker version is &gt;= 17.05
*/
Expand All @@ -379,13 +388,15 @@
DockerAvailability(
boolean isAvailable,
boolean isComposeAvailable,
boolean isComposeV2Available,
boolean isVersionHighEnough,
String path,
Version version,
Result lastCommand
) {
this.isAvailable = isAvailable;
this.isComposeAvailable = isComposeAvailable;
this.isComposeV2Available = isComposeV2Available;

Check warning on line 399 in buildSrc/src/main/java/org/opensearch/gradle/docker/DockerSupportService.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/docker/DockerSupportService.java#L399

Added line #L399 was not covered by tests
this.isVersionHighEnough = isVersionHighEnough;
this.path = path;
this.version = version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@
.findFirst();

composeExtension.getExecutable().set(dockerCompose.isPresent() ? dockerCompose.get() : "/usr/bin/docker");
composeExtension.getUseDockerComposeV2().set(false);
if (dockerSupport.get().getDockerAvailability().isComposeV2Available) {
composeExtension.getUseDockerComposeV2().set(true);

Check warning on line 175 in buildSrc/src/main/java/org/opensearch/gradle/testfixtures/TestFixturesPlugin.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/testfixtures/TestFixturesPlugin.java#L175

Added line #L175 was not covered by tests
} else if (dockerSupport.get().getDockerAvailability().isComposeAvailable) {
composeExtension.getUseDockerComposeV2().set(false);

Check warning on line 177 in buildSrc/src/main/java/org/opensearch/gradle/testfixtures/TestFixturesPlugin.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/testfixtures/TestFixturesPlugin.java#L177

Added line #L177 was not covered by tests
}

tasks.named("composeUp").configure(t -> {
// Avoid running docker-compose tasks in parallel in CI due to some issues on certain Linux distributions
Expand Down Expand Up @@ -228,7 +232,8 @@

private void maybeSkipTask(Provider<DockerSupportService> dockerSupport, Task task) {
task.onlyIf(spec -> {
boolean isComposeAvailable = dockerSupport.get().getDockerAvailability().isComposeAvailable;
boolean isComposeAvailable = dockerSupport.get().getDockerAvailability().isComposeV2Available
|| dockerSupport.get().getDockerAvailability().isComposeAvailable;
if (isComposeAvailable == false) {
LOGGER.info("Task {} requires docker-compose but it is unavailable. Task will be skipped.", task.getPath());
}
Expand Down
Loading