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()); }
public static LocalBuilder localMachine(DockerType dockerType) { return new LocalBuilder(dockerType, System.getenv()); }
@Test public void docker_compose_gets_environment_variables_from_docker_machine_and_passes_it_into_a_test_container() throws Exception { DockerMachine dockerMachine = DockerMachine.localMachine() .withAdditionalEnvironmentVariable("SOME_VARIABLE", "SOME_VALUE") .build(); DockerComposeRule dockerComposition = DockerComposeRule.builder() .file("src/test/resources/environment/docker-compose.yaml") .machine(dockerMachine) .waitingForService("env-test", toHaveAllPortsOpen()) .saveLogsTo(temporaryFolder.getRoot().getAbsolutePath()) .build(); try { dockerComposition.before(); } finally { dockerComposition.after(); } Path logLocation = temporaryFolder.getRoot() .toPath() .resolve("env-test.log"); assertThat(logLocation.toFile(), is(fileContainingString("SOME_VARIABLE=SOME_VALUE"))); } }
@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 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 have_invalid_variables_daemon() { Map<String, String> invalidDockerVariables = ImmutableMap.<String, String>builder() .put(DOCKER_HOST, "tcp://192.168.99.100:2376") .put(DOCKER_TLS_VERIFY, "1") .put(DOCKER_CERT_PATH, "/path/to/certs") .build(); exception.expect(IllegalStateException.class); exception.expectMessage("These variables were set"); exception.expectMessage(DOCKER_HOST); exception.expectMessage(DOCKER_CERT_PATH); exception.expectMessage(DOCKER_TLS_VERIFY); exception.expectMessage("They cannot be set when connecting to a local docker daemon"); new LocalBuilder(DAEMON, invalidDockerVariables).build(); }
public static LocalBuilder localMachine(DockerType dockerType) { return new LocalBuilder(dockerType, System.getenv()); }
@Value.Default public DockerMachine machine() { return DockerMachine.localMachine().build(); }
@Test public void have_invalid_additional_variables_remote() { Map<String, String> dockerVariables = ImmutableMap.<String, String>builder() .put(DOCKER_HOST, "tcp://192.168.99.100:2376") .put(DOCKER_TLS_VERIFY, "1") .put(DOCKER_CERT_PATH, "/path/to/certs") .build(); exception.expect(IllegalStateException.class); exception.expectMessage("The following variables"); exception.expectMessage(DOCKER_HOST); exception.expectMessage("cannot exist in your additional environment variable block"); new LocalBuilder(REMOTE, dockerVariables).withAdditionalEnvironmentVariable(DOCKER_HOST, "tcp://192.168.99.101:2376") .build(); }
@Value.Default public DockerMachine machine() { return DockerMachine.localMachine().build(); }
public static LocalBuilder localMachine(DockerType dockerType) { return new LocalBuilder(dockerType, System.getenv()); }
public static Version version() throws IOException, InterruptedException { return new Docker(DockerExecutable.builder().dockerConfiguration(DockerMachine.localMachine().build()).build()) .configuredVersion(); }
private DockerMachine dockerMachine(ExtensionContext.Store store, Compose compose) { return getOrBuild(DockerMachine.class, store, compose, () -> DockerMachine.localMachine().build()); }
@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 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)); }
private DockerMachine machine() { if (machine == null) { if (Strings.isEmpty(hostIp)) { machine = DockerMachine.localMachine().build(); } else { LOG.INFO("Using hostIp: %s", hostIp); machine = new DockerMachine(hostIp, System.getenv()); } } return machine; }
public static LocalBuilder localMachine() { Map<String, String> systemEnv = System.getenv(); Optional<DockerType> dockerType = DockerType.getFirstValidDockerTypeForEnvironment(systemEnv); if (!dockerType.isPresent()) { log.debug( "Failed to determine Docker type (daemon or remote) based on current environment. " + "Proceeding with {} as the type.", FALLBACK_DOCKER_TYPE); } return new LocalBuilder(dockerType.orElse(FALLBACK_DOCKER_TYPE), systemEnv); }
@Test public void have_missing_cert_path_remote() { Map<String, String> dockerVariables = ImmutableMap.<String, String>builder() .put(DOCKER_HOST, "tcp://192.168.99.100:2376") .put(DOCKER_TLS_VERIFY, "1") .build(); exception.expect(IllegalStateException.class); exception.expectMessage("Missing required environment variables: "); exception.expectMessage(DOCKER_CERT_PATH); new LocalBuilder(REMOTE, dockerVariables).build(); }
@Test public void have_missing_docker_host_remote() { exception.expect(IllegalStateException.class); exception.expectMessage("Missing required environment variables: "); exception.expectMessage(DOCKER_HOST); new LocalBuilder(REMOTE, newHashMap()).build(); }
public static LocalBuilder localMachine() { Map<String, String> systemEnv = System.getenv(); Optional<DockerType> dockerType = DockerType.getFirstValidDockerTypeForEnvironment(systemEnv); if (!dockerType.isPresent()) { log.debug( "Failed to determine Docker type (daemon or remote) based on current environment. " + "Proceeding with {} as the type.", FALLBACK_DOCKER_TYPE); } return new LocalBuilder(dockerType.orElse(FALLBACK_DOCKER_TYPE), systemEnv); }