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 RuleChain setup( Class<?> eteClass, String composeFile, List<String> availableClientNames, Map<String, String> environment) { availableClients = ImmutableList.copyOf(availableClientNames); DockerMachine machine = DockerMachine.localMachine().withEnvironment(environment).build(); String logDirectory = EteSetup.class.getSimpleName() + "-" + eteClass.getSimpleName(); docker = DockerComposeRule.builder() .file(composeFile) .machine(machine) .saveLogsTo(LogDirectory.circleAwareLogDirectory(logDirectory)) .shutdownStrategy(ShutdownStrategy.AGGRESSIVE_WITH_NETWORK_CLEANUP) .build(); DockerProxyRule dockerProxyRule = DockerProxyRule.fromProjectName(docker.projectName(), eteClass); return RuleChain .outerRule(GRADLE_PREPARE_TASK) .around(docker) .around(dockerProxyRule) .around(waitForServersToBeReady()); }
@Test public void override_system_environment_with_additional_environment() { Map<String, String> systemEnv = ImmutableMap.<String, String>builder() .put("ENV_1", "VAL_1") .build(); Map<String, String> overrideEnv = ImmutableMap.<String, String>builder() .put("ENV_1", "DIFFERENT_VALUE") .build(); DockerMachine localMachine = new LocalBuilder(DAEMON, systemEnv) .withEnvironment(overrideEnv) .build(); assertThat(localMachine, not(containsEnvironment(systemEnv))); assertThat(localMachine, containsEnvironment(overrideEnv)); }
@Test public void get_variable_overriden_with_additional_environment() { Map<String, String> environment = ImmutableMap.<String, String>builder() .put("ENV_1", "VAL_1") .put("ENV_2", "VAL_2") .build(); DockerMachine localMachine = new LocalBuilder(DAEMON, newHashMap()).withEnvironment(environment) .withAdditionalEnvironmentVariable("ENV_2", "DIFFERENT_VALUE") .build(); Map<String, String> expected = ImmutableMap.<String, String>builder() .put("ENV_1", "VAL_1") .put("ENV_2", "DIFFERENT_VALUE") .build(); assertThat(localMachine, not(containsEnvironment(environment))); assertThat(localMachine, containsEnvironment(expected)); }
@Test public void be_union_of_additional_environment_and_individual_environment_when_both_set_remote() { Map<String, String> dockerVariables = ImmutableMap.<String, String>builder() .put(DOCKER_HOST, "tcp://192.168.99.100:2376") .build(); Map<String, String> environment = ImmutableMap.<String, String>builder() .put("ENV_1", "VAL_1") .put("ENV_2", "VAL_2") .build(); DockerMachine localMachine = new LocalBuilder(REMOTE, dockerVariables).withEnvironment(environment) .withAdditionalEnvironmentVariable("ENV_3", "VAL_3") .build(); assertThat(localMachine, containsEnvironment(environment)); assertThat(localMachine, containsEnvironment(ImmutableMap.of("ENV_3", "VAL_3"))); }
@Test public void override_previous_environment_with_additional_environment_set_twice_remote() { Map<String, String> dockerVariables = ImmutableMap.<String, String>builder() .put(DOCKER_HOST, "tcp://192.168.99.100:2376") .build(); Map<String, String> environment1 = ImmutableMap.of("ENV_1", "VAL_1"); Map<String, String> environment2 = ImmutableMap.of("ENV_2", "VAL_2"); DockerMachine localMachine = new LocalBuilder(REMOTE, dockerVariables).withEnvironment(environment1) .withEnvironment(environment2) .build(); assertThat(localMachine, not(containsEnvironment(environment1))); assertThat(localMachine, containsEnvironment(environment2)); }
@Test public void override_previous_environment_when_additional_environment_set_twice_daemon() { Map<String, String> environment1 = ImmutableMap.of("ENV_1", "VAL_1"); Map<String, String> environment2 = ImmutableMap.of("ENV_2", "VAL_2"); DockerMachine localMachine = new LocalBuilder(DAEMON, newHashMap()).withEnvironment(environment1) .withEnvironment(environment2) .build(); assertThat(localMachine, not(containsEnvironment(environment1))); assertThat(localMachine, containsEnvironment(environment2)); }
@Test public void be_union_of_additional_environment_and_individual_environment_when_both_set_daemon() { Map<String, String> environment = ImmutableMap.<String, String>builder() .put("ENV_1", "VAL_1") .put("ENV_2", "VAL_2") .build(); DockerMachine localMachine = new LocalBuilder(DAEMON, newHashMap()).withEnvironment(environment) .withAdditionalEnvironmentVariable("ENV_3", "VAL_3") .build(); assertThat(localMachine, containsEnvironment(environment)); assertThat(localMachine, containsEnvironment(ImmutableMap.of("ENV_3", "VAL_3"))); }
private DockerMachine createDockerMachine() { return DockerMachine.localMachine() .withEnvironment(getEnvironment()) .build(); }