Skip to content

#1181: UrlUpdater fetches every defined version for Docker #1117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
60bb713
https://github.com/devonfw/IDEasy/issues/692 : "Latest" version of Do…
mbilda Mar 7, 2025
c638a15
Merge branch 'main' into fix/692-fixing-url-updater-for-docker
jan-vcapgemini Mar 10, 2025
ebc9908
Merge branch 'main' into fix/692-fixing-url-updater-for-docker
jan-vcapgemini Mar 11, 2025
1c3b98e
Merge branch 'main' into fix/692-fixing-url-updater-for-docker
jan-vcapgemini Mar 11, 2025
3310471
https://github.com/devonfw/IDEasy/issues/692 : "Latest" version of Do…
mbilda Mar 11, 2025
2037ae2
https://github.com/devonfw/IDEasy/issues/692 : "Latest" version of Do…
mbilda Mar 11, 2025
be49cea
https://github.com/devonfw/IDEasy/issues/692 : "Latest" version of Do…
mbilda Mar 12, 2025
56f1c73
https://github.com/devonfw/IDEasy/issues/692 : "Latest" version of Do…
mbilda Mar 13, 2025
a45edbc
Merge branch 'main' into fix/692-fixing-url-updater-for-docker
mbilda Mar 13, 2025
a1046cc
https://github.com/devonfw/IDEasy/issues/692 : "Latest" version of Do…
mbilda Mar 13, 2025
ff8fe15
https://github.com/devonfw/IDEasy/issues/692 : "Latest" version of Do…
mbilda Mar 13, 2025
1d76b49
Merge branch 'main' into fix/692-fixing-url-updater-for-docker
mbilda Mar 17, 2025
c2d0e2b
https://github.com/devonfw/IDEasy/issues/692 : "Latest" version of Do…
mbilda Mar 17, 2025
9394d51
Merge branch 'main' into fix/692-fixing-url-updater-for-docker
jan-vcapgemini Mar 26, 2025
20652d3
https://github.com/devonfw/IDEasy/issues/1181 : Improve url updater f…
mbilda Mar 27, 2025
d954a5a
https://github.com/devonfw/IDEasy/issues/1181 : Improve url updater f…
mbilda Mar 27, 2025
340a149
https://github.com/devonfw/IDEasy/issues/1181 : Improve url updater f…
mbilda Mar 27, 2025
97f4083
https://github.com/devonfw/IDEasy/issues/1181 : Improve url updater f…
mbilda Mar 27, 2025
0af8fa2
https://github.com/devonfw/IDEasy/issues/1181 : Improve url updater f…
mbilda Mar 27, 2025
33c07dd
Merge branch 'main' into fix/692-fixing-url-updater-for-docker
jan-vcapgemini Mar 31, 2025
2d97315
https://github.com/devonfw/IDEasy/issues/1181 : Improve url updater f…
mbilda Apr 7, 2025
74ee70a
Merge branch 'main' into fix/692-fixing-url-updater-for-docker
mbilda Apr 7, 2025
51f7f7e
Merge branch 'main' into fix/692-fixing-url-updater-for-docker
jan-vcapgemini Apr 7, 2025
3fa4236
Merge branch 'main' into fix/692-fixing-url-updater-for-docker
jan-vcapgemini Apr 28, 2025
76a93a8
Merge branch 'main' into fix/692-fixing-url-updater-for-docker
jan-vcapgemini May 12, 2025
55dbbfe
#692: fixed checksum detection
jan-vcapgemini May 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.devonfw.tools.ide.url.tool.docker;

import static java.lang.String.format;

import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -17,6 +19,33 @@ public class DockerDesktopUrlUpdater extends WebsiteUrlUpdater {
VersionIdentifier.of("4.4.3"), VersionIdentifier.of("4.4.4"), VersionIdentifier.of("4.17.1"),
VersionIdentifier.of("4.5.1"));

private final static String DOCKER_RELEASE_NOTES_URL = "https://docs.docker.com/desktop/release-notes/";
private final static String AMD_ARCH_TYPE = "amd64";
private final static String ARM_ARCH_TYPE = "arm64";
private final static String CHECKSUM_FILE = "checksums.txt";

private final static String WIN_VERSION = "win";
private final static String WIN_FILE = "Docker%20Desktop%20Installer.exe";
private final static String WIN_BASE_URL = "https://desktop.docker.com/win/main/";
private final static String WIN_AMD_URL = WIN_BASE_URL + AMD_ARCH_TYPE + "/";
private final static String WIN_ARM_URL = WIN_BASE_URL + ARM_ARCH_TYPE + "/";

private final static String MAC_VERSION = "mac";
private final static String MAC_FILE = "Docker.dmg";
private final static String MAC_BASE_URL = "https://desktop.docker.com/mac/main/";
private final static String MAC_AMD_URL = MAC_BASE_URL + AMD_ARCH_TYPE + "/";
private final static String MAC_ARM_URL = MAC_BASE_URL + ARM_ARCH_TYPE + "/";

private final static String REGEX_FOR_DOWNLOAD_URLS = "https://desktop.docker.com/%s/main/%s/%s/";
private final static String REGEX_FOR_DOCKER_VERSION =
"href=#%s" // Find the href with the readable version - %s provided by urlVersion
+ ".{0,300}" // We have to look in close range for the next part (docker lists a summary at top. If this range is to big
// we'll find the latest listed version with download links that doesn't match the version we are looking for
+ "href=https://desktop\\.docker\\.com" // Start of download link
+ ".*?" // We don't care if its windows or mac - match as least as possible characters
+ "(\\d{5,6})"; // Associated docker-version to readable version we are looking for


@Override
protected String getTool() {

Expand All @@ -29,31 +58,95 @@ protected void addVersion(UrlVersion urlVersion) {
VersionIdentifier vid = VersionIdentifier.of(urlVersion.getName());
String version = urlVersion.getName().replaceAll("\\.", "");
// get Code for version
String body = doGetResponseBodyAsString("https://docs.docker.com/desktop/release-notes/");
String regex = "href=#" + version
// .......1.........................................................2.................
+ ".{8,12}(\r\n|\r|\n).{0,350}href=https://desktop\\.docker\\.com.*?(\\d{5,6}).*\\.exe";
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
Matcher matcher = pattern.matcher(body);
String body = doGetResponseBodyAsString(DOCKER_RELEASE_NOTES_URL);
String regexForDockerVersion = format(REGEX_FOR_DOCKER_VERSION, version);
Pattern patternForDockerVersion = Pattern.compile(regexForDockerVersion, Pattern.DOTALL);
Matcher matcherForDockerVersion = patternForDockerVersion.matcher(body);
String code;
if (matcher.find()) {
code = matcher.group(2);
boolean success = doAddVersion(urlVersion,
"https://desktop.docker.com/win/main/amd64/" + code + "/Docker%20Desktop%20Installer.exe", WINDOWS);
if (!success) {
return;
}
if (matcherForDockerVersion.find()) {
code = matcherForDockerVersion.group(1);
addVersionsForWindows(urlVersion, code, body);
if (!WINDOWS_ONLY_VERSIONS.stream().anyMatch(i -> vid.compareVersion(i).isEqual())) {
doAddVersion(urlVersion, "https://desktop.docker.com/mac/main/amd64/" + code + "/Docker.dmg", MAC, X64);
doAddVersion(urlVersion, "https://desktop.docker.com/mac/main/arm64/" + code + "/Docker.dmg", MAC, ARM64);
addVersionsForMac(urlVersion, code, body);
}
}
}

/**
* Adds the windows versions for docker if they exist
*
* @param urlVersion the readable version e.g. 4332 (4.33.2)
* @param dockerVersion the associated docker version to readable version e.g. 179689
* @param body the html body to search in
*/
private void addVersionsForWindows(UrlVersion urlVersion, String dockerVersion, String body) {
boolean versionExists = checkIfVersionExists(dockerVersion, body, WIN_VERSION, AMD_ARCH_TYPE);
if (versionExists) {
String cs = getChecksum(WIN_AMD_URL + dockerVersion + "/" + CHECKSUM_FILE);
doAddVersion(urlVersion, WIN_AMD_URL + dockerVersion + "/" + WIN_FILE, WINDOWS, X64, cs);
}
versionExists = checkIfVersionExists(dockerVersion, body, WIN_VERSION, ARM_ARCH_TYPE);
if (versionExists) {
String cs = getChecksum(WIN_ARM_URL + dockerVersion + "/" + CHECKSUM_FILE);
doAddVersion(urlVersion, WIN_ARM_URL + dockerVersion + "/" + WIN_FILE, WINDOWS, ARM64, cs);
}
}

/**
* Adds the mac versions for docker if they exist
*
* @param urlVersion the readable version e.g. 4332 (4.33.2)
* @param dockerVersion the associated docker version to readable version e.g. 179689
* @param body the html body to search in
*/
private void addVersionsForMac(UrlVersion urlVersion, String dockerVersion, String body) {
boolean versionExists = checkIfVersionExists(dockerVersion, body, MAC_VERSION, AMD_ARCH_TYPE);
if (versionExists) {
String cs = getChecksum(MAC_AMD_URL + dockerVersion + "/" + CHECKSUM_FILE);
doAddVersion(urlVersion, MAC_AMD_URL + dockerVersion + "/" + MAC_FILE, MAC, X64, cs);
}
versionExists = checkIfVersionExists(dockerVersion, body, MAC_VERSION, ARM_ARCH_TYPE);
if (versionExists) {
String cs = getChecksum(MAC_ARM_URL + dockerVersion + "/" + CHECKSUM_FILE);
doAddVersion(urlVersion, MAC_ARM_URL + dockerVersion + "/" + MAC_FILE, MAC, ARM64, cs);
}
}

/**
* As docker is very inconsistent by releasing versions we have to check every single one if the download link exists to prevent failing downloads
* (403-errors) E.g. for only amd64 windows download link provided- <a href="https://docs.docker.com/desktop/release-notes/#4241">4.24.1</a> E.g. for no
* download links provided - <a href="https://docs.docker.com/desktop/release-notes/#4242">4.24.2</a> E.g. for only mac download links provided - <a
* href="https://docs.docker.com/desktop/release-notes/#4361">4.36.1</a>
*
* @param dockerVersion the associated docker version to readable version e.g. 179689 (4.33.2)
* @param body the html body to search in
* @param osVersion the os versions - win or mac
* @param archType the archType - amd64 or arm64
* @return true if the version exists - false if not
*/
private boolean checkIfVersionExists(String dockerVersion, String body, String osVersion, String archType) {
String regexForDownloadUrlS = format(REGEX_FOR_DOWNLOAD_URLS, osVersion, archType, dockerVersion);
Pattern patternForDownloadUrls = Pattern.compile(regexForDownloadUrlS, Pattern.DOTALL);
Matcher matcherForDownloadUrls = patternForDownloadUrls.matcher(body);
return matcherForDownloadUrls.find();
}

/**
* Retrieves the checksum for the passed url
*
* @param url url for specific version to download
* @return the checksum in string format
*/
private String getChecksum(String url) {
String checksumAsString = doGetResponseBodyAsString(url);
// Example checksum response: e832d4c2c99300436096b2e990220068e69ede845137a9dd63eff0a51e8a14e9 *Docker Desktop Installer.exe
return checksumAsString.split(" ")[0];
}

@Override
protected String getVersionUrl() {

return "https://docs.docker.com/desktop/release-notes/";
return DOCKER_RELEASE_NOTES_URL;
}

@Override
Expand Down