Skip to content

Commit

Permalink
Merge branch 'JENKINS-48674' of https://github.com/denisa/docker-comm…
Browse files Browse the repository at this point in the history
…ons-plugin into installer-JENKINS-48674
  • Loading branch information
jglick committed Jan 4, 2018
2 parents ed97b74 + a433acf commit ca19d3c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
Expand Up @@ -147,14 +147,12 @@ public FilePath performInstallation(ToolInstallation toolInstallation, @Nonnull
}

static URL getDockerImageUrl(String os, String version) throws MalformedURLException {
if (parseVersion(version).isNewerThan(parseVersion("17.05.0-ce")))
return new URL("https://download.docker.com/" + os + "/docker-" + version);

String osName="";
if (os.startsWith("linux")) osName = "Linux";
if (os.startsWith("win")) osName = "Windows";
if (os.startsWith("mac")) osName = "Darwin";
return new URL("https://get.docker.com/builds/" + osName + os.substring(os.lastIndexOf("/")) + "/docker-" + version);
final int i = os.indexOf("/");
if (parseVersion(version).isNewerThan(parseVersion("17.05.0-ce"))) {
return new URL("https://download.docker.com/" + os.substring(0, i) + "/static/edge/"+ os.substring(i + 1) + "/docker-" + version);
}

return new URL("https://get.docker.com/builds/" + FindArch.asGetDockerArchName(os) + os.substring(i +1) + "/docker-" + version);
}

private static VersionNumber parseVersion(String version) {
Expand Down Expand Up @@ -183,16 +181,22 @@ public boolean isApplicable(Class<? extends ToolInstallation> toolType) {

private static class FindArch extends MasterToSlaveCallable<String,IOException> {

private static String asGetDockerArchName(String os) {
if (os.startsWith("linux")) return "Linux/";
if (os.startsWith("win")) return "Windows/";
if (os.startsWith("mac")) return "Darwin/";
throw new IllegalArgumentException("Failed to recognize OS architecture " + os );
}

@Override
public String call() throws IOException {
String os = System.getProperty("os.name").toLowerCase();
String arch = System.getProperty("os.arch").contains("64") ? "x86_64" : "i386";
if (os.contains("linux")) return "linux/static/stable/" + arch;
if (os.contains("windows")) return "win/static/stable/" + arch;
if (os.contains("mac")) return "mac/static/stable/" + arch;
if (os.contains("linux")) return "linux/" + arch;
if (os.contains("windows")) return "win/" + arch;
if (os.contains("mac")) return "mac/" + arch;
throw new IOException("Failed to determine OS architecture " + os + ":" + arch);
}

}

}
Expand Up @@ -56,18 +56,18 @@ public class DockerToolInstallerTest {
@WithoutJenkins
@Test
public void testImageUrl() throws MalformedURLException {
assertEquals(new URL("https://get.docker.com/builds/Linux/x86_64/docker-1.10.0"), DockerToolInstaller.getDockerImageUrl("linux/static/stable/x86_64", "1.10.0"));
assertEquals(new URL("https://get.docker.com/builds/Windows/x86_64/docker-1.10.0"), DockerToolInstaller.getDockerImageUrl("win/static/stable/x86_64","1.10.0"));
assertEquals(new URL("https://get.docker.com/builds/Darwin/x86_64/docker-1.10.0"), DockerToolInstaller.getDockerImageUrl("mac/static/stable/x86_64","1.10.0"));
assertEquals(new URL("https://get.docker.com/builds/Linux/x86_64/docker-17.05.0-ce"), DockerToolInstaller.getDockerImageUrl("linux/static/stable/x86_64", "17.05.0-ce"));
assertEquals(new URL("https://get.docker.com/builds/Windows/x86_64/docker-17.05.0-ce"), DockerToolInstaller.getDockerImageUrl("win/static/stable/x86_64","17.05.0-ce"));
assertEquals(new URL("https://get.docker.com/builds/Darwin/x86_64/docker-17.05.0-ce"), DockerToolInstaller.getDockerImageUrl("mac/static/stable/x86_64","17.05.0-ce"));
assertEquals(new URL("https://get.docker.com/builds/Linux/x86_64/docker-latest"), DockerToolInstaller.getDockerImageUrl("linux/static/stable/x86_64", "latest"));
assertEquals(new URL("https://get.docker.com/builds/Windows/x86_64/docker-latest"), DockerToolInstaller.getDockerImageUrl("win/static/stable/x86_64","latest"));
assertEquals(new URL("https://get.docker.com/builds/Darwin/x86_64/docker-latest"), DockerToolInstaller.getDockerImageUrl("mac/static/stable/x86_64","latest"));
assertEquals(new URL("https://download.docker.com/linux/static/stable/x86_64/docker-17.09.0-ce"), DockerToolInstaller.getDockerImageUrl("linux/static/stable/x86_64", "17.09.0-ce"));
assertEquals(new URL("https://download.docker.com/win/static/stable/x86_64/docker-17.09.0-ce"), DockerToolInstaller.getDockerImageUrl("win/static/stable/x86_64","17.09.0-ce"));
assertEquals(new URL("https://download.docker.com/mac/static/stable/x86_64/docker-17.09.0-ce"), DockerToolInstaller.getDockerImageUrl("mac/static/stable/x86_64","17.09.0-ce"));
assertEquals(new URL("https://get.docker.com/builds/Linux/x86_64/docker-1.10.0"), DockerToolInstaller.getDockerImageUrl("linux/x86_64", "1.10.0"));
assertEquals(new URL("https://get.docker.com/builds/Windows/x86_64/docker-1.10.0"), DockerToolInstaller.getDockerImageUrl("win/x86_64","1.10.0"));
assertEquals(new URL("https://get.docker.com/builds/Darwin/x86_64/docker-1.10.0"), DockerToolInstaller.getDockerImageUrl("mac/x86_64","1.10.0"));
assertEquals(new URL("https://get.docker.com/builds/Linux/x86_64/docker-17.05.0-ce"), DockerToolInstaller.getDockerImageUrl("linux/x86_64", "17.05.0-ce"));
assertEquals(new URL("https://get.docker.com/builds/Windows/x86_64/docker-17.05.0-ce"), DockerToolInstaller.getDockerImageUrl("win/x86_64","17.05.0-ce"));
assertEquals(new URL("https://get.docker.com/builds/Darwin/x86_64/docker-17.05.0-ce"), DockerToolInstaller.getDockerImageUrl("mac/x86_64","17.05.0-ce"));
assertEquals(new URL("https://get.docker.com/builds/Linux/x86_64/docker-latest"), DockerToolInstaller.getDockerImageUrl("linux/x86_64", "latest"));
assertEquals(new URL("https://get.docker.com/builds/Windows/x86_64/docker-latest"), DockerToolInstaller.getDockerImageUrl("win/x86_64","latest"));
assertEquals(new URL("https://get.docker.com/builds/Darwin/x86_64/docker-latest"), DockerToolInstaller.getDockerImageUrl("mac/x86_64","latest"));
assertEquals(new URL("https://download.docker.com/linux/static/edge/x86_64/docker-17.09.0-ce"), DockerToolInstaller.getDockerImageUrl("linux/x86_64", "17.09.0-ce"));
assertEquals(new URL("https://download.docker.com/win/static/edge/x86_64/docker-17.09.0-ce"), DockerToolInstaller.getDockerImageUrl("win/x86_64","17.09.0-ce"));
assertEquals(new URL("https://download.docker.com/mac/static/edge/x86_64/docker-17.09.0-ce"), DockerToolInstaller.getDockerImageUrl("mac/x86_64","17.09.0-ce"));
}

@Issue({"JENKINS-36082", "JENKINS-32790", "JENKINS-48674"})
Expand Down

0 comments on commit ca19d3c

Please sign in to comment.