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 static DockerComposeFiles from(String... dockerComposeFilenames) { List<File> dockerComposeFiles = newArrayList(dockerComposeFilenames).stream() .map(File::new) .collect(toList()); validateAtLeastOneComposeFileSpecified(dockerComposeFiles); validateComposeFilesExist(dockerComposeFiles); return new DockerComposeFiles(dockerComposeFiles); }
@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())); }
@Override public Process execute(String... commands) throws IOException { List<String> args = ImmutableList.<String>builder() .add(dockerComposePath()) .addAll(projectName().constructComposeFileCommand()) .addAll(dockerComposeFiles().constructComposeFileCommand()) .add(commands) .build(); return dockerConfiguration().configuredDockerComposeProcess() .command(args) .redirectErrorStream(true) .start(); }
@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())); }
@Override public Process execute(String... commands) throws IOException { List<String> args = ImmutableList.<String>builder() .add(dockerComposePath()) .addAll(projectName().constructComposeFileCommand()) .addAll(dockerComposeFiles().constructComposeFileCommand()) .add(commands) .build(); return dockerConfiguration().configuredDockerComposeProcess() .command(args) .redirectErrorStream(true) .start(); }
public Builder file(String dockerComposeYmlFile) { return files(DockerComposeFiles.from(dockerComposeYmlFile)); }
public static DockerComposeFiles from(String... dockerComposeFilenames) { List<File> dockerComposeFiles = newArrayList(dockerComposeFilenames).stream() .map(File::new) .collect(toList()); validateAtLeastOneComposeFileSpecified(dockerComposeFiles); validateComposeFilesExist(dockerComposeFiles); return new DockerComposeFiles(dockerComposeFiles); }
@Override public Process execute(String... commands) throws IOException { DockerForMacHostsIssue.issueWarning(); List<String> args = ImmutableList.<String>builder() .add(dockerComposePath()) .addAll(projectName().constructComposeFileCommand()) .addAll(dockerComposeFiles().constructComposeFileCommand()) .add(commands) .build(); return dockerConfiguration().configuredDockerComposeProcess() .command(args) .redirectErrorStream(true) .start(); }
public Builder file(String dockerComposeYmlFile) { return files(DockerComposeFiles.from(dockerComposeYmlFile)); }
public static DockerComposeFiles from(String... dockerComposeFilenames) { List<File> dockerComposeFiles = newArrayList(dockerComposeFilenames).stream() .map(File::new) .collect(toList()); validateAtLeastOneComposeFileSpecified(dockerComposeFiles); validateComposeFilesExist(dockerComposeFiles); return new DockerComposeFiles(dockerComposeFiles); }
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 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(); }); }
private DockerComposeExecutable dockerComposeExecutable() { return DockerComposeExecutable.builder() .dockerComposeFiles(DockerComposeFiles.from(dockerfile)) .dockerConfiguration(this.machine()) .projectName(projectName()) .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()); }