Skip to content

Commit

Permalink
JENKINS-48674: (1) use the edge instead of the stable channel, it con…
Browse files Browse the repository at this point in the history
…tains every available binaries

(2) refactor the string manipulations: findArch concerned only with architecture, getDockerImageUrl with the url path
  • Loading branch information
denisa committed Jan 4, 2018
1 parent 00a18c2 commit a433acf
Show file tree
Hide file tree
Showing 2 changed files with 30 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 @@ -42,27 +42,29 @@
import org.junit.Rule;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.WithoutJenkins;

public class DockerToolInstallerTest {

@Rule
public JenkinsRule r = new JenkinsRule();

@Issue({"JENKINS-48674"})
@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 a433acf

Please sign in to comment.