in plugins/docker/base-image/src/main/java/co/elastic/gradle/dockerbase/DockerLockfileTask.java [329:369]
private String getManifestDigest(String image) {
if (manifestDigest != null) {
return manifestDigest;
}
DockerUtils daemonActions = new DockerUtils(getExecOperations());
return RetryUtils.retry(() -> {
try (ByteArrayOutputStream stdout = new ByteArrayOutputStream()) {
daemonActions.exec(spec -> {
spec.setStandardOutput(stdout);
spec.commandLine("docker", "manifest", "inspect", image);
});
try (InputStreamReader reader = new InputStreamReader(new ByteArrayInputStream(stdout.toByteArray()))) {
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(reader);
String digest = null;
Iterator<JsonNode> manifests = root.path("manifests").elements();
while (manifests.hasNext()) {
JsonNode manifest = manifests.next();
if (getArchitecture().get().dockerName().equals(manifest.path("platform").path("architecture").asText())) {
digest = manifest.path("digest").asText(null);
break;
}
}
if (digest == null) {
// Happens when the tag does not point to a manifest list
// We could make this work for a single platform if we really wanted to, for now it's an error
throw new GradleException("Can't find manifest digest from docker output. " +
"Does the image have a manifest?\n" + stdout
);
}
manifestDigest = digest;
return digest;
}
} catch (IOException e) {
throw new UncheckedIOException("Failed to read the image manifest", e);
}
})
.maxAttempt(3)
.exponentialBackoff(1000, 100000)
.execute();
}