@Override protected boolean isApplicable() { return DockerMachineClient.instance().isInstalled(); }
/** * {@inheritDoc} */ @Override public String getTestHostIpAddress() { if (DockerMachineClient.instance().isInstalled()) { try { Optional<String> defaultMachine = DockerMachineClient.instance().getDefaultMachine(); if (!defaultMachine.isPresent()) { throw new IllegalStateException("Could not find a default docker-machine instance"); } String sshConnectionString = runShellCommand("docker-machine", "ssh", defaultMachine.get(), "echo $SSH_CONNECTION").trim(); if (Strings.isNullOrEmpty(sshConnectionString)) { throw new IllegalStateException("Could not obtain SSH_CONNECTION environment variable for docker machine " + defaultMachine.get()); } String[] sshConnectionParts = sshConnectionString.split("\\s"); if (sshConnectionParts.length != 4) { throw new IllegalStateException("Unexpected pattern for SSH_CONNECTION for docker machine - expected 'IP PORT IP PORT' pattern but found '" + sshConnectionString + "'"); } return sshConnectionParts[0]; } catch (Exception e) { throw new RuntimeException(e); } } else { throw new UnsupportedOperationException("getTestHostIpAddress() is only implemented for docker-machine right now"); } }
@Override public void test() throws InvalidConfigurationException { try { boolean installed = DockerMachineClient.instance().isInstalled(); checkArgument(installed, "docker-machine executable was not found on PATH (" + Arrays.toString(CommandLine.getSystemPath()) + ")"); Optional<String> machineNameOptional = DockerMachineClient.instance().getDefaultMachine(); checkArgument(machineNameOptional.isPresent(), "docker-machine is installed but no default machine could be found"); String machineName = machineNameOptional.get(); log.info("Found docker-machine, and will use machine named {}", machineName); DockerMachineClient.instance().ensureMachineRunning(machineName); String dockerDaemonIpAddress = DockerMachineClient.instance().getDockerDaemonIpAddress(machineName); log.info("Docker daemon IP address for docker machine {} is {}", machineName, dockerDaemonIpAddress); config = DefaultDockerClientConfig.createDefaultConfigBuilder() .withDockerHost("tcp://" + dockerDaemonIpAddress + ":2376") .withDockerTlsVerify(true) .withDockerCertPath(Paths.get(System.getProperty("user.home") + "/.docker/machine/certs/").toString()) .build(); client = getClientForConfig(config); } catch (Exception e) { throw new InvalidConfigurationException(e.getMessage()); } // If the docker-machine VM has started, the docker daemon may still not be ready. Retry pinging until it works. final int timeout = Integer.parseInt(System.getProperty(PING_TIMEOUT_PROPERTY_NAME, PING_TIMEOUT_DEFAULT)); ping(client, timeout); }
@Override protected boolean isApplicable() { return DockerMachineClient.instance().isInstalled(); }
@Override public void test() throws InvalidConfigurationException { try { boolean installed = DockerMachineClient.instance().isInstalled(); checkArgument(installed, "docker-machine executable was not found on PATH (" + Arrays.toString(CommandLine.getSystemPath()) + ")"); Optional<String> machineNameOptional = DockerMachineClient.instance().getDefaultMachine(); checkArgument(machineNameOptional.isPresent(), "docker-machine is installed but no default machine could be found"); String machineName = machineNameOptional.get(); log.info("Found docker-machine, and will use machine named {}", machineName); DockerMachineClient.instance().ensureMachineRunning(machineName); String dockerDaemonIpAddress = DockerMachineClient.instance().getDockerDaemonIpAddress(machineName); log.info("Docker daemon IP address for docker machine {} is {}", machineName, dockerDaemonIpAddress); config = DefaultDockerClientConfig.createDefaultConfigBuilder().withDockerHost("tcp://" + dockerDaemonIpAddress + ":2376").withDockerTlsVerify(true).withDockerCertPath(Paths.get(System.getProperty("user.home") + "/.docker/machine/certs/").toString()).build(); client = getClientForConfig(config); } catch (Exception e) { throw new InvalidConfigurationException(e.getMessage()); } // If the docker-machine VM has started, the docker daemon may still not be ready. Retry pinging until it works. final int timeout = Integer.parseInt(System.getProperty(PING_TIMEOUT_PROPERTY_NAME, PING_TIMEOUT_DEFAULT)); ping(client, timeout); }