public static String getDockerMachineLatestVersion() { try { URL url = new URL(DOCKER_MACHINE_LATEST_URL); LatestRepository latestRepository = consumeHttp(url); return latestRepository.getTagName(); } catch (MalformedURLException e) { log.log(Level.WARNING, e.getMessage()); } return ""; }
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; }
public static String getDockerMachineLatestVersion() { try { URL url = new URL(DOCKER_MACHINE_LATEST_URL); LatestRepository latestRepository = consumeHttp(url); return latestRepository.getTagName(); } catch (MalformedURLException e) { log.log(Level.WARNING, e.getMessage()); } return ""; }
@Test public void test_download_docker_machine() throws IOException { HttpURLConnection connection = mock(HttpURLConnection.class); URL url = mockUrl(connection); String content = "{\"id\":\"1\", \"name\":\"v0.5.5\", \"tag_name\":\"v0.5.5\"}"; when(connection.getInputStream()).thenReturn(new ByteArrayInputStream(content.getBytes())); assertThat(GitHubUtil.consumeHttp(url).getTagName(), is("v0.5.5")); }