in plugins/docker/component-image/src/main/java/co/elastic/gradle/dockercomponent/ComponentBuildTask.java [176:242]
protected void buildComponentImages() throws IOException {
getProject().sync(spec -> {
spec.into(getProjectLayout().getBuildDirectory().file(getName() + "/" + LAYERS_DIR).get().getAsFile());
spec.with(rootCopySpec);
}
);
JibActions actions = new JibActions();
final ComponentLockfile lockFile;
if (isStaticFrom()) {
final Path lockfilePath = RegularFileUtils.toPath(getLockFileLocation());
if (!Files.exists(lockfilePath)) {
throw new GradleException("A lockfile does not exist, run the `" +
DockerComponentPlugin.LOCK_FILE_TASK_NAME + "` task to generate it."
);
}
lockFile = ComponentLockfile.parse(
Files.newBufferedReader(lockfilePath)
);
} else {
lockFile = null;
}
for (Map.Entry<Architecture, List<ContainerImageBuildInstruction>> entry : getInstructions().get().entrySet()) {
final Architecture architecture = entry.getKey();
actions.buildArchive(
entry.getKey(),
getImageArchive().get().get(architecture),
getImageIdFile().get().get(architecture),
getCreatedAtFile().get().get(architecture),
entry.getValue().stream()
.map(instruction -> {
if (instruction instanceof From from) {
if (lockFile != null) {
return actions.addDigestFromLockfile(
lockFile.images().get(entry.getKey()), from, getProviderFactory()
);
} else {
return instruction;
}
} else {
return instruction;
}
})
.toList()
);
}
if (getMaxOutputSizeMB().get() > 0) {
GradleCacheUtilities.assertOutputSize(
getPath(),
getImageArchive().get().values().stream()
.map(RegularFile::getAsFile)
.map(File::toPath)
.filter(Files::exists) // Not all of them will exist locally
.map(path -> {
try {
return Files.size(path);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
})
.reduce(0L, Long::sum),
getMaxOutputSizeMB().get()
);
}
}