Skip to content

Commit

Permalink
Fix windows build (mostly) (opensearch-project#1412)
Browse files Browse the repository at this point in the history
* Updated developer guide with Windows specifics.

Signed-off-by: dblock <dblock@dblock.org>

* Correct windows task name.

Signed-off-by: dblock <dblock@dblock.org>

* Use Docker desktop installation on Windows.

Signed-off-by: dblock <dblock@dblock.org>

* Locate docker-compose on Windows.

Signed-off-by: dblock <dblock@dblock.org>

* Default docker-compose location.

Signed-off-by: dblock <dblock@dblock.org>
  • Loading branch information
dblock committed Oct 22, 2021
1 parent 06a123b commit 843c116
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
21 changes: 18 additions & 3 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ So you want to contribute code to OpenSearch? Excellent! We're glad you're here.
- [Git Clone OpenSearch Repo](#git-clone-opensearch-repo)
- [Install Prerequisites](#install-prerequisites)
- [JDK 14](#jdk-14)
- [JDK 8 and 11](#jdk-8-and-11)
- [Runtime JDK](#runtime-jdk)
- [Windows](#windows)
- [Docker](#docker)
- [Run Tests](#run-tests)
- [Run OpenSearch](#run-opensearch)
Expand Down Expand Up @@ -57,13 +60,25 @@ sdk install java 14.0.2-open
sdk use java 14.0.2-open
```

By default, the test tasks use bundled JDK runtime, configured in `buildSrc/version.properties` and set to JDK 15. Other kind of test tasks (integration, cluster, ... ) use the same runtime as `JAVA_HOME`. However, since OpenSearch supports JDK 8 as the runtime, the build supports compiling with JDK 14 and testing on a different version of JDK runtime. To do this, set `RUNTIME_JAVA_HOME` pointing to the Java home of another JDK installation, e.g. `RUNTIME_JAVA_HOME=/usr/lib/jvm/jdk-8`. Alternatively, the runtime JDK version could be provided as the command line argument, using combination of `runtime.java=<major JDK version>` property and `JAVA<major JDK version>_HOME` environment variable, for example `./gradlew -Druntime.java=17 ...` (in this case, the tooling expects `JAVA17_HOME` environment variable to be set).
Download Java 14 from [here](https://adoptium.net/releases.html?variant=openjdk14).

To run the full suite of tests you will also need `JAVA8_HOME` and `JAVA14_HOME`. They are required by the [backwards compatibility test](./TESTING.md#testing-backwards-compatibility).
#### JDK 8 and 11

To run the full suite of tests, download and install [JDK 8](https://adoptium.net/releases.html?variant=openjdk8) and [11](https://adoptium.net/releases.html?variant=openjdk11) and set `JAVA8_HOME`, `JAVA11_HOME`, and `JAVA14_HOME`. They are required by the [backwards compatibility test](./TESTING.md#testing-backwards-compatibility).

#### Runtime JDK

By default, the test tasks use bundled JDK runtime, configured in `buildSrc/version.properties` and set to JDK 17 (LTS). Other kind of test tasks (integration, cluster, ... ) use the same runtime as `JAVA_HOME`. However, since OpenSearch supports JDK 8 as the runtime, the build supports compiling with JDK 11 and testing on a different version of JDK runtime. To do this, set `RUNTIME_JAVA_HOME` pointing to the Java home of another JDK installation, e.g. `RUNTIME_JAVA_HOME=/usr/lib/jvm/jdk-8`. Alternatively, the runtime JDK version could be provided as the command line argument, using combination of `runtime.java=<major JDK version>` property and `JAVA<major JDK version>_HOME` environment variable, for example `./gradlew -Druntime.java=17 ...` (in this case, the tooling expects `JAVA17_HOME` environment variable to be set).

#### Windows

On Windows, set `_JAVA_OPTIONS: -Xmx4096M`. You may also need to set `LongPathsEnabled=0x1` under `Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem`.

#### Docker

[Docker](https://docs.docker.com/install/) is required for building some OpenSearch artifacts and executing certain test suites.
Download and install [Docker](https://docs.docker.com/install/), required for building OpenSearch artifacts, and executing certain test suites.

On Windows, uncheck support for Hyper-V during installation, run `"C:\Program Files\Docker\Docker\DockerCli.exe" -SwitchDaemon` to fix the ` In the default daemon configuration on Windows, the docker client must be run with elevated privileges to connect.` error, run Docker Desktop once, review and accept license agreement, and ensure that the Docker daemon is running.

### Run Tests

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.gradle.api.services.BuildServiceParameters;
import org.gradle.process.ExecOperations;
import org.gradle.process.ExecResult;
import org.apache.tools.ant.taskdefs.condition.Os;

import javax.inject.Inject;
import java.io.ByteArrayOutputStream;
Expand All @@ -64,8 +65,21 @@ public abstract class DockerSupportService implements BuildService<DockerSupport

private static Logger LOGGER = Logging.getLogger(DockerSupportService.class);
// Defines the possible locations of the Docker CLI. These will be searched in order.
private static String[] DOCKER_BINARIES = { "/usr/bin/docker", "/usr/local/bin/docker" };
private static String[] DOCKER_COMPOSE_BINARIES = { "/usr/local/bin/docker-compose", "/usr/bin/docker-compose" };
private static String[] DOCKER_BINARIES_UNIX = { "/usr/bin/docker", "/usr/local/bin/docker" };

private static String[] DOCKER_BINARIES_WINDOWS = { System.getenv("PROGRAMFILES") + "\\Docker\\Docker\\resources\\bin\\docker.exe" };

private static String[] DOCKER_BINARIES = Os.isFamily(Os.FAMILY_WINDOWS) ? DOCKER_BINARIES_WINDOWS : DOCKER_BINARIES_UNIX;

private static String[] DOCKER_COMPOSE_BINARIES_UNIX = { "/usr/local/bin/docker-compose", "/usr/bin/docker-compose" };

private static String[] DOCKER_COMPOSE_BINARIES_WINDOWS = {
System.getenv("PROGRAMFILES") + "\\Docker\\Docker\\resources\\bin\\docker-compose.exe" };

private static String[] DOCKER_COMPOSE_BINARIES = Os.isFamily(Os.FAMILY_WINDOWS)
? DOCKER_COMPOSE_BINARIES_WINDOWS
: DOCKER_COMPOSE_BINARIES_UNIX;

private static final Version MINIMUM_DOCKER_VERSION = Version.fromString("17.05.0");

private final ExecOperations execOperations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private static List<DistributionProject> resolveArchiveProjects(File checkoutDir
projects.addAll(asList("deb", "rpm"));

if (bwcVersion.onOrAfter("7.0.0")) { // starting with 7.0 we bundle a jdk which means we have platform-specific archives
projects.addAll(asList("darwin-tar", "linux-tar", "windows-tar"));
projects.addAll(asList("darwin-tar", "linux-tar", "windows-zip"));
} else { // prior to 7.0 we published only a single zip and tar archives
projects.addAll(asList("zip", "tar"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.testing.Test;
import org.apache.tools.ant.taskdefs.condition.Os;

import javax.inject.Inject;
import java.io.File;
Expand All @@ -65,13 +66,24 @@
import java.nio.file.Files;
import java.util.Collections;
import java.util.function.BiConsumer;
import java.util.List;
import java.util.Optional;

public class TestFixturesPlugin implements Plugin<Project> {

private static final Logger LOGGER = Logging.getLogger(TestFixturesPlugin.class);
private static final String DOCKER_COMPOSE_THROTTLE = "dockerComposeThrottle";
static final String DOCKER_COMPOSE_YML = "docker-compose.yml";

private static String[] DOCKER_COMPOSE_BINARIES_UNIX = { "/usr/local/bin/docker-compose", "/usr/bin/docker-compose" };

private static String[] DOCKER_COMPOSE_BINARIES_WINDOWS = {
System.getenv("PROGRAMFILES") + "\\Docker\\Docker\\resources\\bin\\docker-compose.exe" };

private static String[] DOCKER_COMPOSE_BINARIES = Os.isFamily(Os.FAMILY_WINDOWS)
? DOCKER_COMPOSE_BINARIES_WINDOWS
: DOCKER_COMPOSE_BINARIES_UNIX;

@Inject
protected FileSystemOperations getFileSystemOperations() {
throw new UnsupportedOperationException();
Expand Down Expand Up @@ -130,9 +142,13 @@ public void apply(Project project) {
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"
);

Optional<String> dockerCompose = List.of(DOCKER_COMPOSE_BINARIES)
.stream()
.filter(path -> project.file(path).exists())
.findFirst();

composeExtension.setExecutable(dockerCompose.isPresent() ? dockerCompose.get() : "/usr/bin/docker");

tasks.named("composeUp").configure(t -> {
// Avoid running docker-compose tasks in parallel in CI due to some issues on certain Linux distributions
Expand Down

0 comments on commit 843c116

Please sign in to comment.