Skip to content

Commit 3898498

Browse files
Add support for CNB platform API 0.4
This commit adds support for platform API 0.4 when invoking a CNB builder in the Maven and Gradle plugins. If the builder advertises that it supports platform API 0.4 then that version will be requested when invoking lifecycle phases. Otherwise the plugins will fall back to requesting platform API 0.3. Requesting platform API 0.4 when invoking builder lifecycle phases has the primary benefit of making it easier to pass command-line arguments to the default process in the generated image. Fixes gh-23692
1 parent 38b1954 commit 3898498

File tree

10 files changed

+183
-12
lines changed

10 files changed

+183
-12
lines changed

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/ApiVersions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ final class ApiVersions {
3232
/**
3333
* The platform API versions supported by this release.
3434
*/
35-
static final ApiVersions SUPPORTED_PLATFORMS = new ApiVersions(ApiVersion.of(0, 3));
35+
static final ApiVersions SUPPORTED_PLATFORMS = new ApiVersions(ApiVersion.of(0, 3), ApiVersion.of(0, 4));
3636

3737
private final ApiVersion[] apiVersions;
3838

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/Lifecycle.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ private Phase createPhase() {
134134
if (this.request.isCleanCache()) {
135135
phase.withArgs("-skip-restore");
136136
}
137+
if (requiresProcessTypeDefault()) {
138+
phase.withArgs("-process-type=web");
139+
}
137140
phase.withArgs(this.request.getName());
138141
phase.withBinds(this.layersVolume, Directory.LAYERS);
139142
phase.withBinds(this.applicationVolume, Directory.APPLICATION);
@@ -147,6 +150,10 @@ private boolean isVerboseLogging() {
147150
return this.request.isVerboseLogging() && this.lifecycleVersion.isEqualOrGreaterThan(LOGGING_MINIMUM_VERSION);
148151
}
149152

153+
private boolean requiresProcessTypeDefault() {
154+
return this.platformVersion.supports(ApiVersion.of(0, 4));
155+
}
156+
150157
private void run(Phase phase) throws IOException {
151158
Consumer<LogUpdateEvent> logConsumer = this.log.runningPhase(this.request, phase.getName());
152159
ContainerConfig containerConfig = ContainerConfig.of(this.builder.getName(), phase::apply);

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderMetadataTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void fromJsonLoadsMetadataWithoutSupportedApis() throws IOException {
8787
assertThat(metadata.getStack().getRunImage().getMirrors()).isEmpty();
8888
assertThat(metadata.getLifecycle().getVersion()).isEqualTo("0.7.2");
8989
assertThat(metadata.getLifecycle().getApi().getBuildpack()).isEqualTo("0.2");
90-
assertThat(metadata.getLifecycle().getApi().getPlatform()).isEqualTo("0.3");
90+
assertThat(metadata.getLifecycle().getApi().getPlatform()).isEqualTo("0.4");
9191
assertThat(metadata.getLifecycle().getApis().getBuildpack()).isNull();
9292
assertThat(metadata.getLifecycle().getApis().getPlatform()).isNull();
9393
}

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/LifecycleTests.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ void executeExecutesPhases() throws Exception {
8888
assertThat(this.out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
8989
}
9090

91+
@Test
92+
void executeExecutesPhasesWithPlatformApi03() throws Exception {
93+
given(this.docker.container().create(any())).willAnswer(answerWithGeneratedContainerId());
94+
given(this.docker.container().create(any(), any())).willAnswer(answerWithGeneratedContainerId());
95+
given(this.docker.container().wait(any())).willReturn(ContainerStatus.of(0, null));
96+
createLifecycle("builder-metadata-platform-api-0.3.json").execute();
97+
assertPhaseWasRun("creator", withExpectedConfig("lifecycle-creator-platform-api-0.3.json"));
98+
assertThat(this.out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
99+
}
100+
91101
@Test
92102
void executeOnlyUploadsContentOnce() throws Exception {
93103
given(this.docker.container().create(any())).willAnswer(answerWithGeneratedContainerId());
@@ -136,7 +146,7 @@ void executeWhenPlatformApiNotSupportedThrowsException() throws Exception {
136146
given(this.docker.container().wait(any())).willReturn(ContainerStatus.of(0, null));
137147
assertThatIllegalStateException()
138148
.isThrownBy(() -> createLifecycle("builder-metadata-unsupported-api.json").execute())
139-
.withMessage("Detected platform API versions '0.2' are not included in supported versions '0.3'");
149+
.withMessage("Detected platform API versions '0.2' are not included in supported versions '0.3,0.4'");
140150
}
141151

142152
@Test
@@ -145,8 +155,8 @@ void executeWhenMultiplePlatformApisNotSupportedThrowsException() throws Excepti
145155
given(this.docker.container().create(any(), any())).willAnswer(answerWithGeneratedContainerId());
146156
given(this.docker.container().wait(any())).willReturn(ContainerStatus.of(0, null));
147157
assertThatIllegalStateException()
148-
.isThrownBy(() -> createLifecycle("builder-metadata-unsupported-apis.json").execute())
149-
.withMessage("Detected platform API versions '0.4,0.5' are not included in supported versions '0.3'");
158+
.isThrownBy(() -> createLifecycle("builder-metadata-unsupported-apis.json").execute()).withMessage(
159+
"Detected platform API versions '0.5,0.6' are not included in supported versions '0.3,0.4'");
150160
}
151161

152162
@Test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
{
2+
"description": "Ubuntu bionic base image with buildpacks for Java, NodeJS and Golang",
3+
"buildpacks": [
4+
{
5+
"id": "org.cloudfoundry.googlestackdriver",
6+
"version": "v1.1.11"
7+
},
8+
{
9+
"id": "org.cloudfoundry.springboot",
10+
"version": "v1.2.13"
11+
},
12+
{
13+
"id": "org.cloudfoundry.debug",
14+
"version": "v1.2.11"
15+
},
16+
{
17+
"id": "org.cloudfoundry.tomcat",
18+
"version": "v1.3.18"
19+
},
20+
{
21+
"id": "org.cloudfoundry.go",
22+
"version": "v0.0.4"
23+
},
24+
{
25+
"id": "org.cloudfoundry.openjdk",
26+
"version": "v1.2.14"
27+
},
28+
{
29+
"id": "org.cloudfoundry.buildsystem",
30+
"version": "v1.2.15"
31+
},
32+
{
33+
"id": "org.cloudfoundry.jvmapplication",
34+
"version": "v1.1.12"
35+
},
36+
{
37+
"id": "org.cloudfoundry.springautoreconfiguration",
38+
"version": "v1.1.11"
39+
},
40+
{
41+
"id": "org.cloudfoundry.archiveexpanding",
42+
"version": "v1.0.102"
43+
},
44+
{
45+
"id": "org.cloudfoundry.jmx",
46+
"version": "v1.1.12"
47+
},
48+
{
49+
"id": "org.cloudfoundry.nodejs",
50+
"version": "v2.0.8"
51+
},
52+
{
53+
"id": "org.cloudfoundry.jdbc",
54+
"version": "v1.1.14"
55+
},
56+
{
57+
"id": "org.cloudfoundry.procfile",
58+
"version": "v1.1.12"
59+
},
60+
{
61+
"id": "org.cloudfoundry.dotnet-core",
62+
"version": "v0.0.6"
63+
},
64+
{
65+
"id": "org.cloudfoundry.azureapplicationinsights",
66+
"version": "v1.1.12"
67+
},
68+
{
69+
"id": "org.cloudfoundry.distzip",
70+
"version": "v1.1.12"
71+
},
72+
{
73+
"id": "org.cloudfoundry.dep",
74+
"version": "0.0.101"
75+
},
76+
{
77+
"id": "org.cloudfoundry.go-compiler",
78+
"version": "0.0.105"
79+
},
80+
{
81+
"id": "org.cloudfoundry.go-mod",
82+
"version": "0.0.89"
83+
},
84+
{
85+
"id": "org.cloudfoundry.node-engine",
86+
"version": "0.0.163"
87+
},
88+
{
89+
"id": "org.cloudfoundry.npm",
90+
"version": "0.1.3"
91+
},
92+
{
93+
"id": "org.cloudfoundry.yarn-install",
94+
"version": "0.1.10"
95+
},
96+
{
97+
"id": "org.cloudfoundry.dotnet-core-aspnet",
98+
"version": "0.0.118"
99+
},
100+
{
101+
"id": "org.cloudfoundry.dotnet-core-build",
102+
"version": "0.0.68"
103+
},
104+
{
105+
"id": "org.cloudfoundry.dotnet-core-conf",
106+
"version": "0.0.115"
107+
},
108+
{
109+
"id": "org.cloudfoundry.dotnet-core-runtime",
110+
"version": "0.0.127"
111+
},
112+
{
113+
"id": "org.cloudfoundry.dotnet-core-sdk",
114+
"version": "0.0.122"
115+
},
116+
{
117+
"id": "org.cloudfoundry.icu",
118+
"version": "0.0.43"
119+
},
120+
{
121+
"id": "org.cloudfoundry.node-engine",
122+
"version": "0.0.158"
123+
}
124+
],
125+
"stack": {
126+
"runImage": {
127+
"image": "cloudfoundry/run:base-cnb",
128+
"mirrors": null
129+
}
130+
},
131+
"lifecycle": {
132+
"version": "0.7.2",
133+
"api": {
134+
"buildpack": "0.2",
135+
"platform": "0.3"
136+
}
137+
},
138+
"createdBy": {
139+
"name": "Pack CLI",
140+
"version": "v0.9.0 (git sha: d42c384a39f367588f2653f2a99702db910e5ad7)"
141+
}
142+
}

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/resources/org/springframework/boot/buildpack/platform/build/builder-metadata-unsupported-apis.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"platform": {
3131
"deprecated": [],
3232
"supported": [
33-
"0.4",
34-
"0.5"
33+
"0.5",
34+
"0.6"
3535
]
3636
}
3737
}

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/resources/org/springframework/boot/buildpack/platform/build/builder-metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
"version": "0.7.2",
133133
"api": {
134134
"buildpack": "0.2",
135-
"platform": "0.3"
135+
"platform": "0.4"
136136
}
137137
},
138138
"createdBy": {

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/resources/org/springframework/boot/buildpack/platform/build/lifecycle-creator-clean-cache.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"User" : "root",
33
"Image" : "pack.local/ephemeral-builder",
4-
"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", "-skip-restore", "docker.io/library/my-application:latest" ],
5-
"Env" : [ "CNB_PLATFORM_API=0.3" ],
4+
"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", "-skip-restore", "-process-type=web", "docker.io/library/my-application:latest" ],
5+
"Env" : [ "CNB_PLATFORM_API=0.4" ],
66
"Labels" : {
77
"author" : "spring-boot"
88
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"User" : "root",
3+
"Image" : "pack.local/ephemeral-builder",
4+
"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", "docker.io/library/my-application:latest" ],
5+
"Env" : [ "CNB_PLATFORM_API=0.3" ],
6+
"Labels" : {
7+
"author" : "spring-boot"
8+
},
9+
"HostConfig" : {
10+
"Binds" : [ "/var/run/docker.sock:/var/run/docker.sock", "pack-layers-aaaaaaaaaa:/layers", "pack-app-aaaaaaaaaa:/workspace", "pack-cache-b35197ac41ea.build:/cache", "pack-cache-b35197ac41ea.launch:/launch-cache" ]
11+
}
12+
}

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/resources/org/springframework/boot/buildpack/platform/build/lifecycle-creator.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"User" : "root",
33
"Image" : "pack.local/ephemeral-builder",
4-
"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", "docker.io/library/my-application:latest" ],
5-
"Env" : [ "CNB_PLATFORM_API=0.3" ],
4+
"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" ],
5+
"Env" : [ "CNB_PLATFORM_API=0.4" ],
66
"Labels" : {
77
"author" : "spring-boot"
88
},

0 commit comments

Comments
 (0)