in plugins/docker/component-image/src/main/java/co/elastic/gradle/dockercomponent/ComponentLockfileTask.java [72:115]
public void generateLockFile() throws IOException {
if (getInstructions().get().values().stream()
.flatMap(Collection::stream)
.noneMatch(each -> each instanceof From)) {
throw new StopExecutionException("No static images in image definition");
}
final String reference = getDockerReferenceFromInstructions();
// TODO: latest versions of jib-core seems to have the infrastructure to pull and push manifests, we could use that instead of the manifest-tool
final String output = getManifestToolInspectRawJason(reference);
getLogger().info("Reading manifest list with manifest-tool --raw:\n{}", output);
final JsonNode root = new ObjectMapper().readTree(output);
final Map<Architecture, String> result = new HashMap<>();
final String digest = root.get("digest").asText();
if (digest == null || digest.equals("")) {
throw new GradleException("manifest-tool did not return the expected digest");
}
for (Architecture arch : Architecture.values()) {
result.put(arch, digest);
}
try (Writer writer = Files.newBufferedWriter(RegularFileUtils.toPath(getLockFileLocation()))) {
ComponentLockfile.write(
new ComponentLockfile(
result.entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
entry -> {
final String[] splitRef = reference.split(":", 2);
return new UnchangingContainerReference(
splitRef[0],
splitRef[1],
entry.getValue()
);
}
))
),
writer
);
}
}