Skip to content

Commit

Permalink
Merge branch '3.2.x'
Browse files Browse the repository at this point in the history
Closes gh-40799
  • Loading branch information
scottfrederick committed May 16, 2024
2 parents 85acdf5 + cd44113 commit 5f4d7f4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ public void taggedImage(ImageReference tag) {
log();
}

@Override
public void failedCleaningWorkDir(Cache cache, Exception exception) {
StringBuilder message = new StringBuilder("Warning: Working location " + cache + " could not be cleaned");
if (exception != null) {
message.append(": ").append(exception.getMessage());
}
log();
log(message.toString());
log();
}

private String getDigest(Image image) {
List<String> digests = image.getDigests();
return (digests.isEmpty() ? "" : digests.get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ public interface BuildLog {
*/
void taggedImage(ImageReference tag);

/**
* Log that a cache cleanup step was not completed successfully.
* @param cache the cache
* @param exception any exception that caused the failure
*/
void failedCleaningWorkDir(Cache cache, Exception exception);

/**
* Factory method that returns a {@link BuildLog} the outputs to {@link System#out}.
* @return a build log instance that logs to system out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,20 +311,20 @@ private void deleteCache(Cache cache) throws IOException {
deleteVolume(cache.getVolume().getVolumeName());
}
if (cache.getBind() != null) {
deleteBind(cache.getBind().getSource());
deleteBind(cache.getBind());
}
}

private void deleteVolume(VolumeName name) throws IOException {
this.docker.volume().delete(name, true);
}

private void deleteBind(String source) {
private void deleteBind(Cache.Bind bind) {
try {
FileSystemUtils.deleteRecursively(Path.of(source));
FileSystemUtils.deleteRecursively(Path.of(bind.getSource()));
}
catch (IOException ex) {
throw new IllegalStateException("Error cleaning bind mount directory '" + source + "'", ex);
this.log.failedCleaningWorkDir(bind, ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.apache.commons.compress.utils.IOUtils;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.TaskOutcome;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
Expand Down Expand Up @@ -301,10 +300,8 @@ void buildsImageWithVolumeCaches() throws IOException {
}

@TestTemplate
@EnabledOnOs(value = OS.LINUX,
disabledReason = "Works with Docker Engine on Linux but is not reliable with "
+ "Docker Desktop on other OSs")
@Disabled("gh-40760")
@EnabledOnOs(value = OS.LINUX, disabledReason = "Works with Docker Engine on Linux but is not reliable with "
+ "Docker Desktop on other OSs")
void buildsImageWithBindCaches() throws IOException {
writeMainClass();
writeLongNameResource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Random;
import java.util.stream.IntStream;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
Expand Down Expand Up @@ -402,10 +401,8 @@ void whenBuildImageIsInvokedWithVolumeCaches(MavenBuild mavenBuild) {
}

@TestTemplate
@EnabledOnOs(value = OS.LINUX,
disabledReason = "Works with Docker Engine on Linux but is not reliable with "
+ "Docker Desktop on other OSs")
@Disabled("gh-40760")
@EnabledOnOs(value = OS.LINUX, disabledReason = "Works with Docker Engine on Linux but is not reliable with "
+ "Docker Desktop on other OSs")
void whenBuildImageIsInvokedWithBindCaches(MavenBuild mavenBuild) {
String testBuildId = randomString();
mavenBuild.project("build-image-bind-caches")
Expand Down

0 comments on commit 5f4d7f4

Please sign in to comment.