/** * Checks if Docker Machine is installed by running docker-machine and inspect the result. * * @return true if it is installed, false otherwise. */ public boolean isDockerMachineInstalled() { return isDockerMachineInstalled(null); }
/** * Checks if Docker Machine is installed by running docker-machine and inspect the result. * * @return true if it is installed, false otherwise. */ public boolean isDockerMachineInstalled() { return isDockerMachineInstalled(null); }
private Map<String, String> resolveAutoStartDockerMachine(Map<String, String> config) { final String cliPathExec = config.get(CubeDockerConfiguration.DOCKER_MACHINE_PATH); if (dockerMachine.isDockerMachineInstalled(cliPathExec)) { final Set<Machine> allMachines = dockerMachine.list(cliPathExec); Optional<Machine> machine = Optional.empty(); if (config.containsKey(CubeDockerConfiguration.DOCKER_MACHINE_NAME)) { String configuredMachineName = config.get(CubeDockerConfiguration.DOCKER_MACHINE_NAME); machine = allMachines.stream() .filter(m -> configuredMachineName.equals(m.getName())) .filter(m -> "Stopped".equalsIgnoreCase(m.getState())) .findFirst(); } else { if (allMachines.size() == 1 && "Stopped".equalsIgnoreCase(allMachines.iterator().next().getState())) { machine = Optional.of(allMachines.iterator().next()); } } machine.ifPresent(m -> dockerMachine.startDockerMachine(cliPathExec, m.getName())); } return config; }
private Map<String, String> resolveAutoStartDockerMachine(Map<String, String> config) { final String cliPathExec = config.get(CubeDockerConfiguration.DOCKER_MACHINE_PATH); if (dockerMachine.isDockerMachineInstalled(cliPathExec)) { final Set<Machine> allMachines = dockerMachine.list(cliPathExec); Optional<Machine> machine = Optional.empty(); if (config.containsKey(CubeDockerConfiguration.DOCKER_MACHINE_NAME)) { String configuredMachineName = config.get(CubeDockerConfiguration.DOCKER_MACHINE_NAME); machine = allMachines.stream() .filter(m -> configuredMachineName.equals(m.getName())) .filter(m -> "Stopped".equalsIgnoreCase(m.getState())) .findFirst(); } else { if (allMachines.size() == 1 && "Stopped".equalsIgnoreCase(allMachines.iterator().next().getState())) { machine = Optional.of(allMachines.iterator().next()); } } machine.ifPresent(m -> dockerMachine.startDockerMachine(cliPathExec, m.getName())); } return config; }
private Map<String, String> resolveDefaultDockerMachine(Map<String, String> config) { // if user has not specified Docker URI host not a docker machine // setting DOCKER_URI to avoid using docker machine although it is installed if (!config.containsKey(CubeDockerConfiguration.DOCKER_URI) && !config.containsKey( CubeDockerConfiguration.DOCKER_MACHINE_NAME)) { log.fine( "No DockerUri or DockerMachine has been set, let's see if there is only one Docker Machine Running."); if (dockerMachine.isDockerMachineInstalled(config.get(CubeDockerConfiguration.DOCKER_MACHINE_PATH))) { // we can inspect if docker machine has one and only one docker machine running, which means that would like to use that one Set<Machine> machines = this.dockerMachine.list(config.get(CubeDockerConfiguration.DOCKER_MACHINE_PATH), "state", "Running"); // if there is only one machine running we can use that one. // if not Cube will resolve the default URI depending on OS (linux socket, boot2docker, ...) if (machines.size() == 1) { log.fine(String.format("One Docker Machine is running (%s) and it is going to be used for tests", machines.iterator().next().getName())); config.put(CubeDockerConfiguration.DOCKER_MACHINE_NAME, getFirstMachine(machines).getName()); } } } return config; }
private Map<String, String> resolveDefaultDockerMachine(Map<String, String> config) { // if user has not specified Docker URI host not a docker machine // setting DOCKER_URI to avoid using docker machine although it is installed if (!config.containsKey(CubeDockerConfiguration.DOCKER_URI) && !config.containsKey( CubeDockerConfiguration.DOCKER_MACHINE_NAME)) { log.fine( "No DockerUri or DockerMachine has been set, let's see if there is only one Docker Machine Running."); if (dockerMachine.isDockerMachineInstalled(config.get(CubeDockerConfiguration.DOCKER_MACHINE_PATH))) { // we can inspect if docker machine has one and only one docker machine running, which means that would like to use that one Set<Machine> machines = this.dockerMachine.list(config.get(CubeDockerConfiguration.DOCKER_MACHINE_PATH), "state", "Running"); // if there is only one machine running we can use that one. // if not Cube will resolve the default URI depending on OS (linux socket, boot2docker, ...) if (machines.size() == 1) { log.fine(String.format("One Docker Machine is running (%s) and it is going to be used for tests", machines.iterator().next().getName())); config.put(CubeDockerConfiguration.DOCKER_MACHINE_NAME, getFirstMachine(machines).getName()); } } } return config; }
private Map<String, String> resolveDownloadDockerMachine(Map<String, String> config) { if (config.containsKey(CubeDockerConfiguration.DOCKER_MACHINE_NAME)) { final String cliPathExec = config.get(CubeDockerConfiguration.DOCKER_MACHINE_PATH); if (!dockerMachine.isDockerMachineInstalled(cliPathExec)) { String machineVersion = GitHubUtil.getDockerMachineLatestVersion(); String machineCustomPath = config.get(CubeDockerConfiguration.DOCKER_MACHINE_CUSTOM_PATH); File dockerMachineFile = CubeDockerConfiguration.resolveMachinePath(machineCustomPath, machineVersion); String dockerMachinePath = dockerMachineFile.getPath(); boolean dockerMachineFileExist = dockerMachineFile != null && dockerMachineFile.exists(); String machineName = config.get(CubeDockerConfiguration.DOCKER_MACHINE_NAME); String machineUrl = CubeDockerConfiguration.resolveUrl(machineVersion); if (!dockerMachineFileExist) { dockerMachineFile.getParentFile().mkdirs(); Spacelift.task(DownloadTool.class) .from(machineUrl) .to(dockerMachineFile) .execute() .await(); config.put(CubeDockerConfiguration.DOCKER_MACHINE_PATH, dockerMachinePath); dockerMachine.grantPermissionToDockerMachine(dockerMachinePath); String machineDriver = config.get(CubeDockerConfiguration.DOCKER_MACHINE_DRIVER); dockerMachine.createMachine(dockerMachinePath, machineDriver, machineName); } else { config.put(CubeDockerConfiguration.DOCKER_MACHINE_PATH, dockerMachinePath); } } } return config; }
private Map<String, String> resolveDownloadDockerMachine(Map<String, String> config) { if (config.containsKey(CubeDockerConfiguration.DOCKER_MACHINE_NAME)) { final String cliPathExec = config.get(CubeDockerConfiguration.DOCKER_MACHINE_PATH); if (!dockerMachine.isDockerMachineInstalled(cliPathExec)) { String machineVersion = GitHubUtil.getDockerMachineLatestVersion(); String machineCustomPath = config.get(CubeDockerConfiguration.DOCKER_MACHINE_CUSTOM_PATH); File dockerMachineFile = CubeDockerConfiguration.resolveMachinePath(machineCustomPath, machineVersion); String dockerMachinePath = dockerMachineFile.getPath(); boolean dockerMachineFileExist = dockerMachineFile != null && dockerMachineFile.exists(); String machineName = config.get(CubeDockerConfiguration.DOCKER_MACHINE_NAME); String machineUrl = CubeDockerConfiguration.resolveUrl(machineVersion); if (!dockerMachineFileExist) { dockerMachineFile.getParentFile().mkdirs(); Spacelift.task(DownloadTool.class) .from(machineUrl) .to(dockerMachineFile) .execute() .await(); config.put(CubeDockerConfiguration.DOCKER_MACHINE_PATH, dockerMachinePath); dockerMachine.grantPermissionToDockerMachine(dockerMachinePath); String machineDriver = config.get(CubeDockerConfiguration.DOCKER_MACHINE_DRIVER); dockerMachine.createMachine(dockerMachinePath, machineDriver, machineName); } else { config.put(CubeDockerConfiguration.DOCKER_MACHINE_PATH, dockerMachinePath); } } } return config; }