Skip to content

Commit e84c1ab

Browse files
Prevent Docker volume name clashes in tests during parallel builds
See gh-28292
1 parent e25f216 commit e84c1ab

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ void buildsImageWithVolumeCaches() throws IOException {
290290
assertThat(result.getOutput()).contains("---> Test Info buildpack building");
291291
assertThat(result.getOutput()).contains("---> Test Info buildpack done");
292292
removeImages(projectName);
293-
deleteVolumes("build-cache-volume", "launch-cache-volume");
293+
deleteVolumes("cache-" + projectName + ".build", "cache-" + projectName + ".launch");
294294
}
295295

296296
@TestTemplate

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithVolumeCaches.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ bootBuildImage {
1010
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
1111
buildCache {
1212
volume {
13-
name = "build-cache-volume"
13+
name = "cache-${rootProject.name}.build"
1414
}
1515
}
1616
launchCache {
1717
volume {
18-
name = "launch-cache-volume"
18+
name = "cache-${rootProject.name}.launch"
1919
}
2020
}
2121
}

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildImageTests.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.nio.file.Path;
2323
import java.nio.file.Paths;
2424
import java.util.Random;
25+
import java.util.stream.IntStream;
2526

2627
import org.junit.jupiter.api.TestTemplate;
2728
import org.junit.jupiter.api.extension.ExtendWith;
@@ -310,13 +311,15 @@ void whenBuildImageIsInvokedWithTags(MavenBuild mavenBuild) {
310311

311312
@TestTemplate
312313
void whenBuildImageIsInvokedWithVolumeCaches(MavenBuild mavenBuild) {
314+
String testBuildId = randomString();
313315
mavenBuild.project("build-image-caches").goals("package")
314-
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT").execute((project) -> {
316+
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
317+
.systemProperty("test-build-id", testBuildId).execute((project) -> {
315318
assertThat(buildLog(project)).contains("Building image")
316319
.contains("docker.io/library/build-image-caches:0.0.1.BUILD-SNAPSHOT")
317320
.contains("Successfully built image");
318321
removeImage("build-image-caches", "0.0.1.BUILD-SNAPSHOT");
319-
deleteVolumes("build-cache-volume", "launch-cache-volume");
322+
deleteVolumes("cache-" + testBuildId + ".build", "cache-" + testBuildId + ".launch");
320323
});
321324
}
322325

@@ -394,4 +397,9 @@ private void deleteVolumes(String... names) throws IOException {
394397
}
395398
}
396399

400+
private String randomString() {
401+
IntStream chars = new Random().ints('a', 'z' + 1).limit(10);
402+
return chars.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append).toString();
403+
}
404+
397405
}

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-image-caches/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
2727
<buildCache>
2828
<volume>
29-
<name>build-cache-volume</name>
29+
<name>cache-${test-build-id}.build</name>
3030
</volume>
3131
</buildCache>
3232
<launchCache>
3333
<volume>
34-
<name>launch-cache-volume</name>
34+
<name>cache-${test-build-id}.launch</name>
3535
</volume>
3636
</launchCache>
3737
</image>

0 commit comments

Comments
 (0)