private void setupDockerComposeRule() throws InterruptedException, IOException { Set<String> containerDockerComposeFiles = containersToStart.stream() .map(Container::getDockerComposeFile) .map(dockerComposeFilesToTemporaryCopies::getUnchecked) .collect(Collectors.toSet()); Map<String, String> environment = containersToStart.stream() .flatMap(container -> container.getEnvironment().entrySet().stream()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (fst, snd) -> snd)); DockerMachine machine = DockerMachine.localMachine() .withEnvironment(environment) .build(); dockerComposeRule = DockerComposeRule.builder() .files(DockerComposeFiles.from(containerDockerComposeFiles.toArray(new String[0]))) .projectName(PROJECT_NAME) .machine(machine) .logCollector(currentLogCollector) .shutdownStrategy(ShutdownStrategy.AGGRESSIVE_WITH_NETWORK_CLEANUP) .build(); dockerComposeRule.before(); }
public Builder file(String dockerComposeYmlFile) { return files(DockerComposeFiles.from(dockerComposeYmlFile)); }
public Builder file(String dockerComposeYmlFile) { return files(DockerComposeFiles.from(dockerComposeYmlFile)); }
public Builder file(String dockerComposeYmlFile) { return files(DockerComposeFiles.from(dockerComposeYmlFile)); }
public static DockerCompositionBuilder of(String dockerComposeFile) { return new DockerCompositionBuilder() .files(DockerComposeFiles.from(dockerComposeFile)); }
public static DockerCompositionBuilder of(String dockerComposeFile, DockerMachine dockerMachine) { return new DockerCompositionBuilder() .files(DockerComposeFiles.from(dockerComposeFile)) .machine(dockerMachine); }
@Test public void generate_docker_compose_file_command_correctly_for_single_compose_file() throws Exception { File composeFile = tempFolder.newFile("docker-compose.yaml"); DockerComposeFiles dockerComposeFiles = DockerComposeFiles.from(composeFile.getAbsolutePath()); assertThat(dockerComposeFiles.constructComposeFileCommand(), contains("--file", composeFile.getAbsolutePath())); }
@Test public void generate_docker_compose_file_command_correctly_for_multiple_compose_files() throws Exception { File composeFile1 = tempFolder.newFile("docker-compose1.yaml"); File composeFile2 = tempFolder.newFile("docker-compose2.yaml"); DockerComposeFiles dockerComposeFiles = DockerComposeFiles.from(composeFile1.getAbsolutePath(), composeFile2.getAbsolutePath()); assertThat(dockerComposeFiles.constructComposeFileCommand(), contains( "--file", composeFile1.getAbsolutePath(), "--file", composeFile2.getAbsolutePath())); }
private DockerComposeExecutable dockerComposeExecutable() { return DockerComposeExecutable.builder() .dockerComposeFiles(DockerComposeFiles.from(dockerfile)) .dockerConfiguration(this.machine()) .projectName(projectName()) .build(); }
@Test public void throw_exception_when_compose_file_is_not_specified() { exception.expect(IllegalArgumentException.class); exception.expectMessage("A docker compose file must be specified."); DockerComposeFiles.from(); }
private DockerComposeExecutable dockerComposeExecutable(ExtensionContext.Store store, Compose compose) { return getOrBuild(DockerComposeExecutable.class, store, compose, () -> { DockerMachine dockerMachine = dockerMachine(store, compose); return DockerComposeExecutable.builder() .dockerConfiguration(dockerMachine) .dockerComposeFiles(DockerComposeFiles.from(compose.dockerComposePath())) .build(); }); }
@Test public void throw_correct_exception_when_there_is_a_single_missing_compose_file_with_an_existing_compose_file() throws Exception { exception.expect(IllegalStateException.class); exception.expectMessage("The following docker-compose files:"); exception.expectMessage("does-not-exist.yaml"); exception.expectMessage("do not exist."); exception.expectMessage(not(containsString("docker-compose.yaml"))); File composeFile = tempFolder.newFile("docker-compose.yaml"); DockerComposeFiles.from("does-not-exist.yaml", composeFile.getAbsolutePath()); }
@Test public void throw_exception_when_compose_file_does_not_exist() { exception.expect(IllegalStateException.class); exception.expectMessage("The following docker-compose files:"); exception.expectMessage("does-not-exist.yaml"); exception.expectMessage("do not exist."); DockerComposeFiles.from("does-not-exist.yaml"); }
@Test public void testStateChanges_withoutHealthCheck() throws IOException, InterruptedException { DockerCompose dockerCompose = new DefaultDockerCompose( DockerComposeFiles.from("src/test/resources/no-healthcheck.yaml"), dockerMachine, ProjectName.random()); // The noHealthcheck service has no healthcheck specified; it should be immediately healthy Container container = new Container("noHealthcheck", docker, dockerCompose); assertEquals(State.DOWN, container.state()); container.up(); assertEquals(State.HEALTHY, container.state()); container.kill(); assertEquals(State.DOWN, container.state()); }
/** * This test is not currently enabled in Circle as it does not provide a sufficiently recent version of docker-compose. * * @see <a href="https://github.com/palantir/docker-compose-rule/issues/156">Issue #156</a> */ @Test public void testStateChanges_withHealthCheck() throws IOException, InterruptedException { assumeThat("docker version", Docker.version(), new GreaterOrEqual<>(Version.forIntegers(1, 12, 0))); assumeThat("docker-compose version", DockerCompose.version(), new GreaterOrEqual<>(Version.forIntegers(1, 10, 0))); DockerCompose dockerCompose = new DefaultDockerCompose( DockerComposeFiles.from("src/test/resources/native-healthcheck.yaml"), dockerMachine, ProjectName.random()); // The withHealthcheck service's healthcheck checks every 100ms whether the file "healthy" exists Container container = new Container("withHealthcheck", docker, dockerCompose); assertEquals(State.DOWN, container.state()); container.up(); assertEquals(State.UNHEALTHY, container.state()); dockerCompose.exec(noOptions(), "withHealthcheck", arguments("touch", "healthy")); wait.until(container::state, equalTo(State.HEALTHY)); dockerCompose.exec(noOptions(), "withHealthcheck", arguments("rm", "healthy")); wait.until(container::state, equalTo(State.UNHEALTHY)); container.kill(); assertEquals(State.DOWN, container.state()); } }