Prevent Docker volume name clashes in tests during parallel builds

See gh-28292
pull/28436/head
Scott Frederick 3 years ago
parent e25f216eab
commit e84c1abb0f

@ -290,7 +290,7 @@ class BootBuildImageIntegrationTests {
assertThat(result.getOutput()).contains("---> Test Info buildpack building");
assertThat(result.getOutput()).contains("---> Test Info buildpack done");
removeImages(projectName);
deleteVolumes("build-cache-volume", "launch-cache-volume");
deleteVolumes("cache-" + projectName + ".build", "cache-" + projectName + ".launch");
}
@TestTemplate

@ -10,12 +10,12 @@ bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
buildCache {
volume {
name = "build-cache-volume"
name = "cache-${rootProject.name}.build"
}
}
launchCache {
volume {
name = "launch-cache-volume"
name = "cache-${rootProject.name}.launch"
}
}
}

@ -22,6 +22,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Random;
import java.util.stream.IntStream;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
@ -310,13 +311,15 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithVolumeCaches(MavenBuild mavenBuild) {
String testBuildId = randomString();
mavenBuild.project("build-image-caches").goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT").execute((project) -> {
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.systemProperty("test-build-id", testBuildId).execute((project) -> {
assertThat(buildLog(project)).contains("Building image")
.contains("docker.io/library/build-image-caches:0.0.1.BUILD-SNAPSHOT")
.contains("Successfully built image");
removeImage("build-image-caches", "0.0.1.BUILD-SNAPSHOT");
deleteVolumes("build-cache-volume", "launch-cache-volume");
deleteVolumes("cache-" + testBuildId + ".build", "cache-" + testBuildId + ".launch");
});
}
@ -394,4 +397,9 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
}
}
private String randomString() {
IntStream chars = new Random().ints('a', 'z' + 1).limit(10);
return chars.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append).toString();
}
}

@ -26,12 +26,12 @@
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<buildCache>
<volume>
<name>build-cache-volume</name>
<name>cache-${test-build-id}.build</name>
</volume>
</buildCache>
<launchCache>
<volume>
<name>launch-cache-volume</name>
<name>cache-${test-build-id}.launch</name>
</volume>
</launchCache>
</image>

Loading…
Cancel
Save