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 building");
assertThat(result.getOutput()).contains("---> Test Info buildpack done"); assertThat(result.getOutput()).contains("---> Test Info buildpack done");
removeImages(projectName); removeImages(projectName);
deleteVolumes("build-cache-volume", "launch-cache-volume"); deleteVolumes("cache-" + projectName + ".build", "cache-" + projectName + ".launch");
} }
@TestTemplate @TestTemplate

@ -10,12 +10,12 @@ bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1" builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
buildCache { buildCache {
volume { volume {
name = "build-cache-volume" name = "cache-${rootProject.name}.build"
} }
} }
launchCache { launchCache {
volume { 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.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Random; import java.util.Random;
import java.util.stream.IntStream;
import org.junit.jupiter.api.TestTemplate; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
@ -310,13 +311,15 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate @TestTemplate
void whenBuildImageIsInvokedWithVolumeCaches(MavenBuild mavenBuild) { void whenBuildImageIsInvokedWithVolumeCaches(MavenBuild mavenBuild) {
String testBuildId = randomString();
mavenBuild.project("build-image-caches").goals("package") 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") assertThat(buildLog(project)).contains("Building image")
.contains("docker.io/library/build-image-caches:0.0.1.BUILD-SNAPSHOT") .contains("docker.io/library/build-image-caches:0.0.1.BUILD-SNAPSHOT")
.contains("Successfully built image"); .contains("Successfully built image");
removeImage("build-image-caches", "0.0.1.BUILD-SNAPSHOT"); 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> <builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<buildCache> <buildCache>
<volume> <volume>
<name>build-cache-volume</name> <name>cache-${test-build-id}.build</name>
</volume> </volume>
</buildCache> </buildCache>
<launchCache> <launchCache>
<volume> <volume>
<name>launch-cache-volume</name> <name>cache-${test-build-id}.launch</name>
</volume> </volume>
</launchCache> </launchCache>
</image> </image>

Loading…
Cancel
Save