Merge branch '2.7.x'

pull/28887/head
Scott Frederick 3 years ago
commit 1f838bf2ee

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -73,7 +73,7 @@ final class ApiVersion {
* the same version number. A 1.x or higher release matches when the versions have the * the same version number. A 1.x or higher release matches when the versions have the
* same major version and a minor that is equal or greater. * same major version and a minor that is equal or greater.
* @param other the version to check against * @param other the version to check against
* @return if the specified API is supported * @return if the specified API version is supported
* @see #assertSupports(ApiVersion) * @see #assertSupports(ApiVersion)
*/ */
boolean supports(ApiVersion other) { boolean supports(ApiVersion other) {
@ -86,6 +86,21 @@ final class ApiVersion {
return this.minor >= other.minor; return this.minor >= other.minor;
} }
/**
* Returns if this API version supports any of the given versions.
* @param others the versions to check against
* @return if any of the specified API versions are supported
* @see #supports(ApiVersion)
*/
boolean supportsAny(ApiVersion... others) {
for (ApiVersion other : others) {
if (supports(other)) {
return true;
}
}
return false;
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) { if (this == obj) {

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,7 +32,8 @@ final class ApiVersions {
/** /**
* The platform API versions supported by this release. * The platform API versions supported by this release.
*/ */
static final ApiVersions SUPPORTED_PLATFORMS = new ApiVersions(ApiVersion.of(0, 3), ApiVersion.of(0, 4)); static final ApiVersions SUPPORTED_PLATFORMS = new ApiVersions(ApiVersion.of(0, 3), ApiVersion.of(0, 4),
ApiVersion.of(0, 5), ApiVersion.of(0, 6), ApiVersion.of(0, 7), ApiVersion.of(0, 8));
private final ApiVersion[] apiVersions; private final ApiVersion[] apiVersions;

@ -181,7 +181,7 @@ class Lifecycle implements Closeable {
} }
private boolean requiresProcessTypeDefault() { private boolean requiresProcessTypeDefault() {
return this.platformVersion.supports(ApiVersion.of(0, 4)); return this.platformVersion.supportsAny(ApiVersion.of(0, 4), ApiVersion.of(0, 5));
} }
private void run(Phase phase) throws IOException { private void run(Phase phase) throws IOException {

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,6 +16,8 @@
package org.springframework.boot.buildpack.platform.build; package org.springframework.boot.buildpack.platform.build;
import java.util.Arrays;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -68,7 +70,7 @@ class ApiVersionTests {
} }
@Test @Test
void supportWhenSame() { void supportsWhenSame() {
assertThat(supports("0.0", "0.0")).isTrue(); assertThat(supports("0.0", "0.0")).isTrue();
assertThat(supports("0.1", "0.1")).isTrue(); assertThat(supports("0.1", "0.1")).isTrue();
assertThat(supports("1.0", "1.0")).isTrue(); assertThat(supports("1.0", "1.0")).isTrue();
@ -92,11 +94,21 @@ class ApiVersionTests {
} }
@Test @Test
void supportWhenMajorZeroAndDifferentMinor() { void supportsWhenMajorZeroAndDifferentMinor() {
assertThat(supports("0.2", "0.1")).isFalse(); assertThat(supports("0.2", "0.1")).isFalse();
assertThat(supports("0.2", "0.3")).isFalse(); assertThat(supports("0.2", "0.3")).isFalse();
} }
@Test
void supportsAnyWhenOneMatches() {
assertThat(supportsAny("0.2", "0.1", "0.2")).isTrue();
}
@Test
void supportsAnyWhenNoneMatch() {
assertThat(supportsAny("0.2", "0.3", "0.4")).isFalse();
}
@Test @Test
void toStringReturnsString() { void toStringReturnsString() {
assertThat(ApiVersion.parse("1.2").toString()).isEqualTo("1.2"); assertThat(ApiVersion.parse("1.2").toString()).isEqualTo("1.2");
@ -115,4 +127,9 @@ class ApiVersionTests {
return ApiVersion.parse(v1).supports(ApiVersion.parse(v2)); return ApiVersion.parse(v1).supports(ApiVersion.parse(v2));
} }
private boolean supportsAny(String v1, String... others) {
return ApiVersion.parse(v1)
.supportsAny(Arrays.stream(others).map(ApiVersion::parse).toArray(ApiVersion[]::new));
}
} }

@ -92,7 +92,7 @@ class BuilderMetadataTests extends AbstractJsonTests {
assertThat(metadata.getStack().getRunImage().getMirrors()).isEmpty(); assertThat(metadata.getStack().getRunImage().getMirrors()).isEmpty();
assertThat(metadata.getLifecycle().getVersion()).isEqualTo("0.7.2"); assertThat(metadata.getLifecycle().getVersion()).isEqualTo("0.7.2");
assertThat(metadata.getLifecycle().getApi().getBuildpack()).isEqualTo("0.2"); assertThat(metadata.getLifecycle().getApi().getBuildpack()).isEqualTo("0.2");
assertThat(metadata.getLifecycle().getApi().getPlatform()).isEqualTo("0.4"); assertThat(metadata.getLifecycle().getApi().getPlatform()).isEqualTo("0.8");
assertThat(metadata.getLifecycle().getApis().getBuildpack()).isNull(); assertThat(metadata.getLifecycle().getApis().getBuildpack()).isNull();
assertThat(metadata.getLifecycle().getApis().getPlatform()).isNull(); assertThat(metadata.getLifecycle().getApis().getPlatform()).isNull();
} }
@ -102,9 +102,10 @@ class BuilderMetadataTests extends AbstractJsonTests {
BuilderMetadata metadata = BuilderMetadata.fromJson(getContentAsString("builder-metadata-supported-apis.json")); BuilderMetadata metadata = BuilderMetadata.fromJson(getContentAsString("builder-metadata-supported-apis.json"));
assertThat(metadata.getLifecycle().getVersion()).isEqualTo("0.7.2"); assertThat(metadata.getLifecycle().getVersion()).isEqualTo("0.7.2");
assertThat(metadata.getLifecycle().getApi().getBuildpack()).isEqualTo("0.2"); assertThat(metadata.getLifecycle().getApi().getBuildpack()).isEqualTo("0.2");
assertThat(metadata.getLifecycle().getApi().getPlatform()).isEqualTo("0.4"); assertThat(metadata.getLifecycle().getApi().getPlatform()).isEqualTo("0.8");
assertThat(metadata.getLifecycle().getApis().getBuildpack()).containsExactly("0.1", "0.2", "0.3"); assertThat(metadata.getLifecycle().getApis().getBuildpack()).containsExactly("0.1", "0.2", "0.3");
assertThat(metadata.getLifecycle().getApis().getPlatform()).containsExactly("0.3", "0.4"); assertThat(metadata.getLifecycle().getApis().getPlatform()).containsExactly("0.3", "0.4", "0.5", "0.6", "0.7",
"0.8");
} }
@Test @Test

@ -159,8 +159,8 @@ class LifecycleTests {
given(this.docker.container().create(any(), any())).willAnswer(answerWithGeneratedContainerId()); given(this.docker.container().create(any(), any())).willAnswer(answerWithGeneratedContainerId());
given(this.docker.container().wait(any())).willReturn(ContainerStatus.of(0, null)); given(this.docker.container().wait(any())).willReturn(ContainerStatus.of(0, null));
assertThatIllegalStateException() assertThatIllegalStateException()
.isThrownBy(() -> createLifecycle("builder-metadata-unsupported-api.json").execute()) .isThrownBy(() -> createLifecycle("builder-metadata-unsupported-api.json").execute()).withMessage(
.withMessage("Detected platform API versions '0.2' are not included in supported versions '0.3,0.4'"); "Detected platform API versions '0.2' are not included in supported versions '0.3,0.4,0.5,0.6,0.7,0.8'");
} }
@Test @Test
@ -170,7 +170,7 @@ class LifecycleTests {
given(this.docker.container().wait(any())).willReturn(ContainerStatus.of(0, null)); given(this.docker.container().wait(any())).willReturn(ContainerStatus.of(0, null));
assertThatIllegalStateException() assertThatIllegalStateException()
.isThrownBy(() -> createLifecycle("builder-metadata-unsupported-apis.json").execute()).withMessage( .isThrownBy(() -> createLifecycle("builder-metadata-unsupported-apis.json").execute()).withMessage(
"Detected platform API versions '0.5,0.6' are not included in supported versions '0.3,0.4'"); "Detected platform API versions '0.1,0.2' are not included in supported versions '0.3,0.4,0.5,0.6,0.7,0.8'");
} }
@Test @Test

@ -16,7 +16,7 @@
"version": "0.7.2", "version": "0.7.2",
"api": { "api": {
"buildpack": "0.2", "buildpack": "0.2",
"platform": "0.4" "platform": "0.8"
}, },
"apis": { "apis": {
"buildpack": { "buildpack": {
@ -30,9 +30,13 @@
"platform": { "platform": {
"deprecated": [], "deprecated": [],
"supported": [ "supported": [
"0.3", "0.3",
"0.4" "0.4",
] "0.5",
"0.6",
"0.7",
"0.8"
]
} }
} }
}, },

@ -30,9 +30,9 @@
"platform": { "platform": {
"deprecated": [], "deprecated": [],
"supported": [ "supported": [
"0.5", "0.1",
"0.6" "0.2"
] ]
} }
} }
}, },

@ -182,7 +182,7 @@
"version": "0.7.2", "version": "0.7.2",
"api": { "api": {
"buildpack": "0.2", "buildpack": "0.2",
"platform": "0.4" "platform": "0.8"
} }
}, },
"createdBy": { "createdBy": {

@ -1,12 +1,38 @@
{ {
"User" : "root", "User": "root",
"Image" : "pack.local/ephemeral-builder", "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" ], "Cmd": [
"Env" : [ "CNB_PLATFORM_API=0.4" ], "/cnb/lifecycle/creator",
"Labels" : { "-app",
"author" : "spring-boot" "/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"
],
"Env": [
"CNB_PLATFORM_API=0.8"
],
"Labels": {
"author": "spring-boot"
}, },
"HostConfig" : { "HostConfig": {
"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", "/host/src/path:/container/dest/path:ro", "volume-name:/container/volume/path:rw" ] "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",
"/host/src/path:/container/dest/path:ro",
"volume-name:/container/volume/path:rw"
]
} }
} }

@ -16,11 +16,10 @@
"-launch-cache", "-launch-cache",
"/launch-cache", "/launch-cache",
"-daemon", "-daemon",
"-process-type=web",
"docker.io/library/my-application:latest" "docker.io/library/my-application:latest"
], ],
"Env": [ "Env": [
"CNB_PLATFORM_API=0.4" "CNB_PLATFORM_API=0.8"
], ],
"Labels": { "Labels": {
"author": "spring-boot" "author": "spring-boot"

@ -1,12 +1,37 @@
{ {
"User" : "root", "User": "root",
"Image" : "pack.local/ephemeral-builder", "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", "-skip-restore", "-process-type=web", "docker.io/library/my-application:latest" ], "Cmd": [
"Env" : [ "CNB_PLATFORM_API=0.4" ], "/cnb/lifecycle/creator",
"Labels" : { "-app",
"author" : "spring-boot" "/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"
],
"Env": [
"CNB_PLATFORM_API=0.8"
],
"Labels": {
"author": "spring-boot"
}, },
"HostConfig" : { "HostConfig": {
"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" ] "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"
]
} }
} }

@ -1,13 +1,37 @@
{ {
"User" : "root", "User": "root",
"Image" : "pack.local/ephemeral-builder", "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" ], "Cmd": [
"Env" : [ "CNB_PLATFORM_API=0.4" ], "/cnb/lifecycle/creator",
"Labels" : { "-app",
"author" : "spring-boot" "/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"
],
"Env": [
"CNB_PLATFORM_API=0.8"
],
"Labels": {
"author": "spring-boot"
}, },
"HostConfig" : { "HostConfig": {
"NetworkMode" : "test", "NetworkMode": "test",
"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" ] "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"
]
} }
} }

@ -1,12 +1,36 @@
{ {
"User" : "root", "User": "root",
"Image" : "pack.local/ephemeral-builder", "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" ], "Cmd": [
"Env" : [ "CNB_PLATFORM_API=0.4" ], "/cnb/lifecycle/creator",
"Labels" : { "-app",
"author" : "spring-boot" "/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"
],
"Env": [
"CNB_PLATFORM_API=0.8"
],
"Labels": {
"author": "spring-boot"
}, },
"HostConfig" : { "HostConfig": {
"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" ] "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"
]
} }
} }
Loading…
Cancel
Save