Correct grouping of custom buildpacks

This commit corrects the order.toml file that is generated and added
to the builder when building an image using custom buildpacks with the
Maven or Gradle plugin in order to support buildpacks that depend on
detection as a group.

Fixes gh-25378
pull/25409/head
Scott Frederick 4 years ago
parent 9c24ca06ae
commit 76e42ff96f

@ -63,6 +63,7 @@ final class Buildpacks {
private String getOrderToml() {
StringBuilder builder = new StringBuilder();
builder.append("[[order]]\n\n");
for (Buildpack buildpack : this.buildpacks) {
appendToOrderToml(builder, buildpack.getCoordinates());
}
@ -70,15 +71,12 @@ final class Buildpacks {
}
private void appendToOrderToml(StringBuilder builder, BuildpackCoordinates coordinates) {
builder.append("[[order]]\n");
builder.append("group = [\n");
builder.append(" { ");
builder.append("id = \"" + coordinates.getId() + "\"");
builder.append(" [[order.group]]\n");
builder.append(" id = \"" + coordinates.getId() + "\"\n");
if (StringUtils.hasText(coordinates.getVersion())) {
builder.append(", version = \"" + coordinates.getVersion() + "\"");
builder.append(" version = \"" + coordinates.getVersion() + "\"\n");
}
builder.append(" }\n");
builder.append("]\n\n");
builder.append("\n");
}
static Buildpacks of(List<Buildpack> buildpacks) {

@ -94,17 +94,18 @@ class BuildpacksTests {
private String getExpectedToml() {
StringBuilder toml = new StringBuilder();
toml.append("[[order]]\n");
toml.append("group = [\n");
toml.append(" { id = \"example/buildpack1\", version = \"0.0.1\" }\n");
toml.append("]\n\n");
toml.append("[[order]]\n");
toml.append("group = [\n");
toml.append(" { id = \"example/buildpack2\", version = \"0.0.2\" }\n");
toml.append("]\n\n");
toml.append("[[order]]\n");
toml.append("group = [\n");
toml.append(" { id = \"example/buildpack3\" }\n");
toml.append("]\n\n");
toml.append("\n");
toml.append(" [[order.group]]\n");
toml.append(" id = \"example/buildpack1\"\n");
toml.append(" version = \"0.0.1\"\n");
toml.append("\n");
toml.append(" [[order.group]]\n");
toml.append(" id = \"example/buildpack2\"\n");
toml.append(" version = \"0.0.2\"\n");
toml.append("\n");
toml.append(" [[order.group]]\n");
toml.append(" id = \"example/buildpack3\"\n");
toml.append("\n");
return toml.toString();
}

@ -146,7 +146,7 @@ class EphemeralBuilderTests extends AbstractJsonTests {
assertBuildpackLayerContent(builder, 2, "/cnb/buildpacks/example_buildpack3/0.0.3/buildpack.toml");
File orderDirectory = unpack(getLayer(builder.getArchive(), 3), "order");
assertThat(new File(orderDirectory, "cnb/order.toml")).usingCharset(StandardCharsets.UTF_8)
.hasContent(content("order-versions.toml"));
.hasContent(content("order.toml"));
}
private void assertBuildpackLayerContent(EphemeralBuilder builder, int index, String s) throws Exception {

@ -1,15 +0,0 @@
[[order]]
group = [
{ id = "example/buildpack1", version = "0.0.1" }
]
[[order]]
group = [
{ id = "example/buildpack2", version = "0.0.2" }
]
[[order]]
group = [
{ id = "example/buildpack3", version = "0.0.3" }
]

@ -1,15 +1,14 @@
[[order]]
group = [
{ id = "example/buildpack1" }
]
[[order]]
group = [
{ id = "example/buildpack2" }
]
[[order.group]]
id = "example/buildpack1"
version = "0.0.1"
[[order]]
group = [
{ id = "example/buildpack3" }
]
[[order.group]]
id = "example/buildpack2"
version = "0.0.2"
[[order.group]]
id = "example/buildpack3"
version = "0.0.3"

@ -203,7 +203,7 @@ class BootBuildImageIntegrationTests {
}
@TestTemplate
void buildsImageWithBuildpackFromImage() throws IOException {
void buildsImageWithBuildpacksFromImages() throws IOException {
writeMainClass();
writeLongNameResource();
BuildResult result = this.gradleBuild.build("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT");

@ -1,11 +0,0 @@
plugins {
id 'java'
id 'org.springframework.boot' version '{version}'
}
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
bootBuildImage {
buildpacks = [ "gcr.io/paketo-buildpacks/java:latest" ]
}

@ -0,0 +1,13 @@
plugins {
id 'java'
id 'org.springframework.boot' version '{version}'
}
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
bootBuildImage {
buildpacks = ["gcr.io/paketo-buildpacks/bellsoft-liberica:latest",
"gcr.io/paketo-buildpacks/executable-jar:latest",
"gcr.io/paketo-buildpacks/spring-boot:latest"]
}

@ -24,7 +24,9 @@
<configuration>
<image>
<buildpacks>
<buildpack>paketo-buildpacks/java</buildpack>
<buildpack>gcr.io/paketo-buildpacks/bellsoft-liberica:latest</buildpack>
<buildpack>gcr.io/paketo-buildpacks/executable-jar:latest</buildpack>
<buildpack>gcr.io/paketo-buildpacks/spring-boot:latest</buildpack>
</buildpacks>
</image>
</configuration>

Loading…
Cancel
Save