Skip to content

Commit b62905b

Browse files
Merge branch '2.4.x'
Closes spring-projectsgh-25840
2 parents c257f28 + 8ac297d commit b62905b

File tree

40 files changed

+364
-229
lines changed

40 files changed

+364
-229
lines changed

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

+56-84
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
import org.junit.jupiter.api.TestTemplate;
3939
import org.junit.jupiter.api.condition.DisabledOnOs;
4040
import org.junit.jupiter.api.condition.OS;
41-
import org.testcontainers.containers.GenericContainer;
42-
import org.testcontainers.containers.wait.strategy.Wait;
4341

4442
import org.springframework.boot.buildpack.platform.docker.DockerApi;
4543
import org.springframework.boot.buildpack.platform.docker.type.ImageName;
@@ -70,13 +68,10 @@ void buildsImageWithDefaultBuilder() throws IOException {
7068
String projectName = this.gradleBuild.getProjectDir().getName();
7169
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
7270
assertThat(result.getOutput()).contains("docker.io/library/" + projectName);
73-
ImageReference imageReference = ImageReference.of(ImageName.of(projectName));
74-
try (GenericContainer<?> container = new GenericContainer<>(imageReference.toString())) {
75-
container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start();
76-
}
77-
finally {
78-
new DockerApi().image().remove(imageReference, false);
79-
}
71+
assertThat(result.getOutput()).contains("---> Test Info buildpack building");
72+
assertThat(result.getOutput()).contains("env: BP_JVM_VERSION=8.*");
73+
assertThat(result.getOutput()).contains("---> Test Info buildpack done");
74+
removeImage(projectName);
8075
}
8176

8277
@TestTemplate
@@ -88,16 +83,13 @@ void buildsImageWithWarPackaging() throws IOException {
8883
String projectName = this.gradleBuild.getProjectDir().getName();
8984
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
9085
assertThat(result.getOutput()).contains("docker.io/library/" + projectName);
86+
assertThat(result.getOutput()).contains("---> Test Info buildpack building");
87+
assertThat(result.getOutput()).contains("env: BP_JVM_VERSION=8.*");
88+
assertThat(result.getOutput()).contains("---> Test Info buildpack done");
9189
File buildLibs = new File(this.gradleBuild.getProjectDir(), "build/libs");
9290
assertThat(buildLibs.listFiles())
9391
.containsExactly(new File(buildLibs, this.gradleBuild.getProjectDir().getName() + ".war"));
94-
ImageReference imageReference = ImageReference.of(ImageName.of(projectName));
95-
try (GenericContainer<?> container = new GenericContainer<>(imageReference.toString())) {
96-
container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start();
97-
}
98-
finally {
99-
new DockerApi().image().remove(imageReference, false);
100-
}
92+
removeImage(projectName);
10193
}
10294

10395
@TestTemplate
@@ -108,16 +100,12 @@ void buildsImageWithWarPackagingAndJarConfiguration() throws IOException {
108100
String projectName = this.gradleBuild.getProjectDir().getName();
109101
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
110102
assertThat(result.getOutput()).contains("docker.io/library/" + projectName);
103+
assertThat(result.getOutput()).contains("---> Test Info buildpack building");
104+
assertThat(result.getOutput()).contains("---> Test Info buildpack done");
111105
File buildLibs = new File(this.gradleBuild.getProjectDir(), "build/libs");
112106
assertThat(buildLibs.listFiles())
113107
.containsExactly(new File(buildLibs, this.gradleBuild.getProjectDir().getName() + ".war"));
114-
ImageReference imageReference = ImageReference.of(ImageName.of(projectName));
115-
try (GenericContainer<?> container = new GenericContainer<>(imageReference.toString())) {
116-
container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start();
117-
}
118-
finally {
119-
new DockerApi().image().remove(imageReference, false);
120-
}
108+
removeImage(projectName);
121109
}
122110

123111
@TestTemplate
@@ -127,13 +115,9 @@ void buildsImageWithCustomName() throws IOException {
127115
BuildResult result = this.gradleBuild.build("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT");
128116
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
129117
assertThat(result.getOutput()).contains("example/test-image-name");
130-
ImageReference imageReference = ImageReference.of(ImageName.of("example/test-image-name"));
131-
try (GenericContainer<?> container = new GenericContainer<>(imageReference.toString())) {
132-
container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start();
133-
}
134-
finally {
135-
new DockerApi().image().remove(imageReference, false);
136-
}
118+
assertThat(result.getOutput()).contains("---> Test Info buildpack building");
119+
assertThat(result.getOutput()).contains("---> Test Info buildpack done");
120+
removeImage("example/test-image-name");
137121
}
138122

139123
@TestTemplate
@@ -143,56 +127,38 @@ void buildsImageWithCustomBuilderAndRunImage() throws IOException {
143127
BuildResult result = this.gradleBuild.build("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT");
144128
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
145129
assertThat(result.getOutput()).contains("example/test-image-custom");
146-
ImageReference imageReference = ImageReference.of(ImageName.of("example/test-image-custom"));
147-
try (GenericContainer<?> container = new GenericContainer<>(imageReference.toString())) {
148-
container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start();
149-
}
150-
finally {
151-
new DockerApi().image().remove(imageReference, false);
152-
}
130+
assertThat(result.getOutput()).contains("---> Test Info buildpack building");
131+
assertThat(result.getOutput()).contains("---> Test Info buildpack done");
132+
removeImage("example/test-image-custom");
153133
}
154134

155135
@TestTemplate
156136
void buildsImageWithCommandLineOptions() throws IOException {
157137
writeMainClass();
158138
writeLongNameResource();
159139
BuildResult result = this.gradleBuild.build("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT",
160-
"--imageName=example/test-image-cmd", "--builder=paketobuildpacks/builder:full",
161-
"--runImage=paketobuildpacks/run:full-cnb");
140+
"--imageName=example/test-image-cmd",
141+
"--builder=projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1",
142+
"--runImage=projects.registry.vmware.com/springboot/run:tiny-cnb");
162143
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
163144
assertThat(result.getOutput()).contains("example/test-image-cmd");
164-
ImageReference imageReference = ImageReference.of(ImageName.of("example/test-image-cmd"));
165-
try (GenericContainer<?> container = new GenericContainer<>(imageReference.toString())) {
166-
container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start();
167-
}
168-
finally {
169-
new DockerApi().image().remove(imageReference, false);
170-
}
145+
assertThat(result.getOutput()).contains("---> Test Info buildpack building");
146+
assertThat(result.getOutput()).contains("---> Test Info buildpack done");
147+
removeImage("example/test-image-cmd");
171148
}
172149

173150
@TestTemplate
174151
void buildsImageWithPullPolicy() throws IOException {
175152
writeMainClass();
176153
writeLongNameResource();
177154
String projectName = this.gradleBuild.getProjectDir().getName();
178-
ImageReference imageReference = ImageReference.of(ImageName.of(projectName));
179-
180155
BuildResult result = this.gradleBuild.build("bootBuildImage", "--pullPolicy=ALWAYS");
181156
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
182157
assertThat(result.getOutput()).contains("Pulled builder image").contains("Pulled run image");
183-
try (GenericContainer<?> container = new GenericContainer<>(imageReference.toString())) {
184-
container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start();
185-
}
186-
187158
result = this.gradleBuild.build("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT");
188159
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
189160
assertThat(result.getOutput()).doesNotContain("Pulled builder image").doesNotContain("Pulled run image");
190-
try (GenericContainer<?> container = new GenericContainer<>(imageReference.toString())) {
191-
container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start();
192-
}
193-
finally {
194-
new DockerApi().image().remove(imageReference, false);
195-
}
161+
removeImage(projectName);
196162
}
197163

198164
@TestTemplate
@@ -203,13 +169,9 @@ void buildsImageWithBuildpackFromBuilder() throws IOException {
203169
String projectName = this.gradleBuild.getProjectDir().getName();
204170
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
205171
assertThat(result.getOutput()).contains("docker.io/library/" + projectName);
206-
ImageReference imageReference = ImageReference.of(ImageName.of(projectName));
207-
try (GenericContainer<?> container = new GenericContainer<>(imageReference.toString())) {
208-
container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start();
209-
}
210-
finally {
211-
new DockerApi().image().remove(imageReference, false);
212-
}
172+
assertThat(result.getOutput()).contains("---> Test Info buildpack building")
173+
.contains("---> Test Info buildpack done");
174+
removeImage(projectName);
213175
}
214176

215177
@TestTemplate
@@ -220,11 +182,10 @@ void buildsImageWithBuildpackFromDirectory() throws IOException {
220182
writeBuildpackContent();
221183
BuildResult result = this.gradleBuild.build("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT");
222184
String projectName = this.gradleBuild.getProjectDir().getName();
223-
ImageReference imageReference = ImageReference.of(ImageName.of(projectName));
224185
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
225186
assertThat(result.getOutput()).contains("docker.io/library/" + projectName);
226187
assertThat(result.getOutput()).contains("---> Hello World buildpack");
227-
new DockerApi().image().remove(imageReference, false);
188+
removeImage(projectName);
228189
}
229190

230191
@TestTemplate
@@ -236,11 +197,10 @@ void buildsImageWithBuildpackFromTarGzip() throws IOException {
236197
tarGzipBuildpackContent();
237198
BuildResult result = this.gradleBuild.build("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT");
238199
String projectName = this.gradleBuild.getProjectDir().getName();
239-
ImageReference imageReference = ImageReference.of(ImageName.of(projectName));
240200
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
241201
assertThat(result.getOutput()).contains("docker.io/library/" + projectName);
242202
assertThat(result.getOutput()).contains("---> Hello World buildpack");
243-
new DockerApi().image().remove(imageReference, false);
203+
removeImage(projectName);
244204
}
245205

246206
@TestTemplate
@@ -251,24 +211,26 @@ void buildsImageWithBuildpacksFromImages() throws IOException {
251211
String projectName = this.gradleBuild.getProjectDir().getName();
252212
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
253213
assertThat(result.getOutput()).contains("docker.io/library/" + projectName);
254-
ImageReference imageReference = ImageReference.of(ImageName.of(projectName));
255-
try (GenericContainer<?> container = new GenericContainer<>(imageReference.toString())) {
256-
container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start();
257-
}
258-
finally {
259-
new DockerApi().image().remove(imageReference, false);
260-
}
214+
assertThat(result.getOutput()).contains("---> Test Info buildpack building")
215+
.contains("---> Test Info buildpack done");
216+
removeImage(projectName);
261217
}
262218

263219
@TestTemplate
264-
void failsWithBindingContainingInvalidCertificate() throws IOException {
220+
void buildsImageWithBinding() throws IOException {
265221
writeMainClass();
266222
writeLongNameResource();
267223
writeCertificateBindingFiles();
268-
BuildResult result = this.gradleBuild.buildAndFail("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT");
269-
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.FAILED);
270-
assertThat(result.getOutput()).contains("failed to decode certificate")
271-
.contains("/platform/bindings/certificates/test.crt");
224+
BuildResult result = this.gradleBuild.build("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT");
225+
String projectName = this.gradleBuild.getProjectDir().getName();
226+
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
227+
assertThat(result.getOutput()).contains("docker.io/library/" + projectName);
228+
assertThat(result.getOutput()).contains("---> Test Info buildpack building");
229+
assertThat(result.getOutput()).contains("binding: certificates/type=ca-certificates");
230+
assertThat(result.getOutput()).contains("binding: certificates/test1.crt=---certificate one---");
231+
assertThat(result.getOutput()).contains("binding: certificates/test2.crt=---certificate two---");
232+
assertThat(result.getOutput()).contains("---> Test Info buildpack done");
233+
removeImage(projectName);
272234
}
273235

274236
@TestTemplate
@@ -286,6 +248,7 @@ void failsWithBuilderError() throws IOException {
286248
writeLongNameResource();
287249
BuildResult result = this.gradleBuild.buildAndFail("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT");
288250
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.FAILED);
251+
assertThat(result.getOutput()).contains("Forced builder failure");
289252
assertThat(result.getOutput()).containsPattern("Builder lifecycle '.*' failed with status code");
290253
}
291254

@@ -410,10 +373,19 @@ private void writeCertificateBindingFiles() throws IOException {
410373
try (PrintWriter writer = new PrintWriter(new FileWriter(type))) {
411374
writer.print("ca-certificates");
412375
}
413-
File cert = new File(bindingDir, "test.crt");
414-
try (PrintWriter writer = new PrintWriter(new FileWriter(cert))) {
415-
writer.println("not a valid certificate");
376+
File cert1 = new File(bindingDir, "test1.crt");
377+
try (PrintWriter writer = new PrintWriter(new FileWriter(cert1))) {
378+
writer.println("---certificate one---");
416379
}
380+
File cert2 = new File(bindingDir, "test2.crt");
381+
try (PrintWriter writer = new PrintWriter(new FileWriter(cert2))) {
382+
writer.println("---certificate two---");
383+
}
384+
}
385+
386+
private void removeImage(String name) throws IOException {
387+
ImageReference imageReference = ImageReference.of(ImageName.of(name));
388+
new DockerApi().image().remove(imageReference, false);
417389
}
418390

419391
}
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ sourceCompatibility = '1.8'
77
targetCompatibility = '1.8'
88

99
bootBuildImage {
10+
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
1011
bindings = [ "${projectDir}/bindings/ca-certificates:/platform/bindings/certificates" ]
1112
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ sourceCompatibility = '1.8'
77
targetCompatibility = '1.8'
88

99
bootBuildImage {
10-
buildpacks = [ "paketo-buildpacks/java" ]
10+
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
11+
buildpacks = [ "spring-boot/test-info" ]
1112
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ sourceCompatibility = '1.8'
77
targetCompatibility = '1.8'
88

99
bootBuildImage {
10+
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
1011
buildpacks = [ "file://${projectDir}/buildpack/hello-world" ]
1112
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ sourceCompatibility = '1.8'
77
targetCompatibility = '1.8'
88

99
bootBuildImage {
10+
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
1011
buildpacks = [ "file://${projectDir}/hello-world.tgz" ]
1112
}

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ sourceCompatibility = '1.8'
77
targetCompatibility = '1.8'
88

99
bootBuildImage {
10-
buildpacks = ["gcr.io/paketo-buildpacks/bellsoft-liberica:latest",
11-
"gcr.io/paketo-buildpacks/executable-jar:latest",
12-
"gcr.io/paketo-buildpacks/spring-boot:latest"]
10+
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
11+
buildpacks = ["projects.registry.vmware.com/springboot/test-info:latest"]
1312
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
id 'java'
3+
id 'org.springframework.boot' version '{version}'
4+
}
5+
6+
sourceCompatibility = '1.8'
7+
targetCompatibility = '1.8'

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ targetCompatibility = '1.8'
88

99
bootBuildImage {
1010
imageName = "example/test-image-custom"
11-
builder = "paketobuildpacks/builder:full"
12-
runImage = "paketobuildpacks/run:full-cnb"
11+
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
12+
runImage = "projects.registry.vmware.com/springboot/run:tiny-cnb"
1313
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ targetCompatibility = '1.8'
88

99
bootBuildImage {
1010
imageName = "example/test-image-name"
11+
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
1112
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ bootBuildImage {
99

1010
sourceCompatibility = '1.8'
1111
targetCompatibility = '1.8'
12+
13+
bootBuildImage {
14+
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
15+
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ sourceCompatibility = '1.8'
77
targetCompatibility = '1.8'
88

99
bootBuildImage {
10-
environment = ["BP_JVM_VERSION": "13.9.9"]
10+
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
11+
environment = ["FORCE_FAILURE": "true"]
1112
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ sourceCompatibility = '1.8'
77
targetCompatibility = '1.8'
88

99
bootBuildImage {
10+
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
1011
buildpacks = [ "urn:cnb:builder:example/does-not-exist:0.0.1" ]
1112
}

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ targetCompatibility = '1.8'
88

99
bootJar {
1010
launchScript()
11-
}
11+
}
12+
13+
bootBuildImage {
14+
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
15+
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ if (project.hasProperty('applyWarPlugin')) {
99

1010
sourceCompatibility = '1.8'
1111
targetCompatibility = '1.8'
12+
13+
bootBuildImage {
14+
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
15+
}

0 commit comments

Comments
 (0)