Polish "Add option to customize cache volume names when building an image"
See gh-28292
This commit is contained in:
@@ -210,11 +210,11 @@ class BuildRequestTests {
|
||||
@Test
|
||||
void withTagsAddsTags() throws IOException {
|
||||
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar"));
|
||||
BuildRequest witTags = request.withTags(ImageReference.of("docker.io/library/my-app:latest"),
|
||||
BuildRequest withTags = request.withTags(ImageReference.of("docker.io/library/my-app:latest"),
|
||||
ImageReference.of("example.com/custom/my-app:0.0.1"),
|
||||
ImageReference.of("example.com/custom/my-app:latest"));
|
||||
assertThat(request.getTags()).isEmpty();
|
||||
assertThat(witTags.getTags()).containsExactly(ImageReference.of("docker.io/library/my-app:latest"),
|
||||
assertThat(withTags.getTags()).containsExactly(ImageReference.of("docker.io/library/my-app:latest"),
|
||||
ImageReference.of("example.com/custom/my-app:0.0.1"),
|
||||
ImageReference.of("example.com/custom/my-app:latest"));
|
||||
}
|
||||
@@ -226,6 +226,36 @@ class BuildRequestTests {
|
||||
.withMessage("Tags must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void withBuildVolumeCacheAddsCache() throws IOException {
|
||||
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar"));
|
||||
BuildRequest withCache = request.withBuildCache(Cache.volume("build-volume"));
|
||||
assertThat(request.getBuildCache()).isNull();
|
||||
assertThat(withCache.getBuildCache()).isEqualTo(Cache.volume("build-volume"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void withBuildVolumeCacheWhenCacheIsNullThrowsException() throws IOException {
|
||||
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar"));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> request.withBuildCache(null))
|
||||
.withMessage("BuildCache must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void withLaunchVolumeCacheAddsCache() throws IOException {
|
||||
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar"));
|
||||
BuildRequest withCache = request.withLaunchCache(Cache.volume("launch-volume"));
|
||||
assertThat(request.getLaunchCache()).isNull();
|
||||
assertThat(withCache.getLaunchCache()).isEqualTo(Cache.volume("launch-volume"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void withLaunchVolumeCacheWhenCacheIsNullThrowsException() throws IOException {
|
||||
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar"));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> request.withLaunchCache(null))
|
||||
.withMessage("LaunchCache must not be null");
|
||||
}
|
||||
|
||||
private void hasExpectedJarContent(TarArchive archive) {
|
||||
try {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
|
||||
@@ -200,6 +200,18 @@ class LifecycleTests {
|
||||
assertThat(this.out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
|
||||
}
|
||||
|
||||
@Test
|
||||
void executeWithCacheVolumeNamesExecutesPhases() throws Exception {
|
||||
given(this.docker.container().create(any())).willAnswer(answerWithGeneratedContainerId());
|
||||
given(this.docker.container().create(any(), any())).willAnswer(answerWithGeneratedContainerId());
|
||||
given(this.docker.container().wait(any())).willReturn(ContainerStatus.of(0, null));
|
||||
BuildRequest request = getTestRequest().withBuildCache(Cache.volume("build-volume"))
|
||||
.withLaunchCache(Cache.volume("launch-volume"));
|
||||
createLifecycle(request).execute();
|
||||
assertPhaseWasRun("creator", withExpectedConfig("lifecycle-creator-cache-volumes.json"));
|
||||
assertThat(this.out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
|
||||
}
|
||||
|
||||
private DockerApi mockDockerApi() {
|
||||
DockerApi docker = mock(DockerApi.class);
|
||||
ImageApi imageApi = mock(ImageApi.class);
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"User": "root",
|
||||
"Image": "pack.local/ephemeral-builder",
|
||||
"Cmd": [
|
||||
"/cnb/lifecycle/creator",
|
||||
"-app",
|
||||
"/workspace",
|
||||
"-platform",
|
||||
"/platform",
|
||||
"-run-image",
|
||||
"docker.io/cloudfoundry/run:latest",
|
||||
"-layers",
|
||||
"/layers",
|
||||
"-cache-dir",
|
||||
"/cache",
|
||||
"-launch-cache",
|
||||
"/launch-cache",
|
||||
"-daemon",
|
||||
"-process-type=web",
|
||||
"docker.io/library/my-application:latest"
|
||||
],
|
||||
"Env": [
|
||||
"CNB_PLATFORM_API=0.4"
|
||||
],
|
||||
"Labels": {
|
||||
"author": "spring-boot"
|
||||
},
|
||||
"HostConfig": {
|
||||
"Binds": [
|
||||
"/var/run/docker.sock:/var/run/docker.sock",
|
||||
"pack-layers-aaaaaaaaaa:/layers",
|
||||
"pack-app-aaaaaaaaaa:/workspace",
|
||||
"build-volume:/cache",
|
||||
"launch-volume:/launch-cache"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user