-
Notifications
You must be signed in to change notification settings - Fork 41.4k
Description
If I run gradlew bootBuildImage
the image is built every time as this task has no outputs
> Task :bootBuildImage
Caching disabled for task ':bootBuildImage' because:
Caching has been disabled for the task
Task ':bootBuildImage' is not up-to-date because:
Task has not declared any outputs despite executing actions.
Building image ...
The rebuilding of the image takes 8 seconds vene if nothing has changed. So it is worth caching. If i run tests against the image and I am only changing some tests, I don't want the image to be rebuild every time.
I doesn't help to add a fixed timestamp to get a repeatable build
springBoot {
buildInfo {
properties {
time = "1895-01-01T18:00:00.0Z"
}
}
}
What does help in gradle is to add
tasks.bootBuildImage {
onlyIf {
!tasks.bootJar.get().state.skipped
}
}
credits to gyoder at Stackoverflow
But this does not take into account the following changes:
- changing the task configuration of bootBuildImage itself does not trigger a rebuild
- deleting the image from the docker daemon
I don't know if it is wise to ask the docker daemon if the image is already available, but the gradle docker plugin does exactly that. It saves the imageId to the build/.docker Directory, looking up this ID in the docker daemon and does not rebuilt the image if the image is already available:
As the task bootBuildImage
does connect to the Docker daemon anyway, it might be worth asking the daemon if the image is already available.
private final Spec<Task> upToDateWhenSpec = new Spec<Task>() {
@Override
public boolean isSatisfiedBy(Task element) {
File file = getImageIdFile().get().getAsFile();
if (file.exists()) {
try {
String fileImageId;
try {
fileImageId = Files.readString(file.toPath());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
List<String> repoTags = getDockerClient().inspectImageCmd(fileImageId).exec().getRepoTags();
if (!getImages().isPresent() || repoTags.containsAll(getImages().get())) {
return true;
}
} catch (DockerException ignored) {
}
}
return false;
}
};