Browse Source

Polish

pull/41957/head
Phillip Webb 1 year ago
parent
commit
c30a5572f3
  1. 13
      spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/AbstractBuildLog.java
  2. 52
      spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/DockerApi.java
  3. 13
      spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/ImagePlatform.java

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

@ -46,15 +46,10 @@ public abstract class AbstractBuildLog implements BuildLog {
@Override @Override
public Consumer<TotalProgressEvent> pullingImage(ImageReference imageReference, ImagePlatform platform, public Consumer<TotalProgressEvent> pullingImage(ImageReference imageReference, ImagePlatform platform,
ImageType imageType) { ImageType imageType) {
String message; return (platform != null)
if (platform != null) { ? getProgressConsumer(" > Pulling %s '%s' for platform '%s'".formatted(imageType.getDescription(),
message = String.format(" > Pulling %s '%s' for platform '%s'", imageType.getDescription(), imageReference, imageReference, platform))
platform); : getProgressConsumer(" > Pulling %s '%s'".formatted(imageType.getDescription(), imageReference));
}
else {
message = String.format(" > Pulling %s '%s'", imageType.getDescription(), imageReference);
}
return getProgressConsumer(message);
} }
@Override @Override

52
spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/DockerApi.java

@ -64,7 +64,9 @@ public class DockerApi {
private static final List<String> FORCE_PARAMS = Collections.unmodifiableList(Arrays.asList("force", "1")); private static final List<String> FORCE_PARAMS = Collections.unmodifiableList(Arrays.asList("force", "1"));
static final ApiVersion MINIMUM_API_VERSION = ApiVersion.parse("1.24"); static final ApiVersion MINIMUM_API_VERSION = ApiVersion.of(1, 24);
static final ApiVersion MINIMUM_PLATFORM_API_VERSION = ApiVersion.of(1, 41);
static final String API_VERSION_HEADER_NAME = "API-Version"; static final String API_VERSION_HEADER_NAME = "API-Version";
@ -80,7 +82,7 @@ public class DockerApi {
private final SystemApi system; private final SystemApi system;
private ApiVersion apiVersion = null; private volatile ApiVersion apiVersion = null;
/** /**
* Create a new {@link DockerApi} instance. * Create a new {@link DockerApi} instance.
@ -126,10 +128,7 @@ public class DockerApi {
private URI buildUrl(String path, Object... params) { private URI buildUrl(String path, Object... params) {
try { try {
if (this.apiVersion == null) { URIBuilder builder = new URIBuilder("/v" + getApiVersion() + path);
this.apiVersion = this.system.getApiVersion();
}
URIBuilder builder = new URIBuilder("/v" + this.apiVersion + path);
int param = 0; int param = 0;
while (param < params.length) { while (param < params.length) {
builder.addParameter(Objects.toString(params[param++]), Objects.toString(params[param++])); builder.addParameter(Objects.toString(params[param++]), Objects.toString(params[param++]));
@ -141,11 +140,19 @@ public class DockerApi {
} }
} }
private void verifyApiVersionForPlatform() { private void verifyApiVersionForPlatform(ImagePlatform platform) {
ApiVersion minimumPlatformApiVersion = ApiVersion.of(1, 41); Assert.isTrue(platform == null || getApiVersion().supports(MINIMUM_PLATFORM_API_VERSION),
Assert.isTrue(this.apiVersion.supports(minimumPlatformApiVersion), () -> "Docker API version must be at least " + MINIMUM_PLATFORM_API_VERSION
"Docker API version must be at least " + minimumPlatformApiVersion + " to support the 'imagePlatform' option, but current API version is " + getApiVersion());
+ " to support the 'imagePlatform' option, but current API version is " + this.apiVersion); }
private ApiVersion getApiVersion() {
ApiVersion apiVersion = this.apiVersion;
if (this.apiVersion == null) {
apiVersion = this.system.getApiVersion();
this.apiVersion = apiVersion;
}
return apiVersion;
} }
/** /**
@ -206,14 +213,10 @@ public class DockerApi {
UpdateListener<PullImageUpdateEvent> listener, String registryAuth) throws IOException { UpdateListener<PullImageUpdateEvent> listener, String registryAuth) throws IOException {
Assert.notNull(reference, "Reference must not be null"); Assert.notNull(reference, "Reference must not be null");
Assert.notNull(listener, "Listener must not be null"); Assert.notNull(listener, "Listener must not be null");
URI createUri; verifyApiVersionForPlatform(platform);
if (platform != null) { URI createUri = (platform != null)
createUri = buildUrl("/images/create", "fromImage", reference, "platform", platform); ? buildUrl("/images/create", "fromImage", reference, "platform", platform)
verifyApiVersionForPlatform(); : buildUrl("/images/create", "fromImage", reference);
}
else {
createUri = buildUrl("/images/create", "fromImage", reference);
}
DigestCaptureUpdateListener digestCapture = new DigestCaptureUpdateListener(); DigestCaptureUpdateListener digestCapture = new DigestCaptureUpdateListener();
listener.onStart(); listener.onStart();
try { try {
@ -400,14 +403,9 @@ public class DockerApi {
} }
private ContainerReference createContainer(ContainerConfig config, ImagePlatform platform) throws IOException { private ContainerReference createContainer(ContainerConfig config, ImagePlatform platform) throws IOException {
URI createUri; verifyApiVersionForPlatform(platform);
if (platform != null) { URI createUri = (platform != null) ? buildUrl("/containers/create", "platform", platform)
createUri = buildUrl("/containers/create", "platform", platform); : buildUrl("/containers/create");
verifyApiVersionForPlatform();
}
else {
createUri = buildUrl("/containers/create");
}
try (Response response = http().post(createUri, "application/json", config::writeTo)) { try (Response response = http().post(createUri, "application/json", config::writeTo)) {
return ContainerReference return ContainerReference
.of(SharedObjectMapper.get().readTree(response.getContent()).at("/Id").asText()); .of(SharedObjectMapper.get().readTree(response.getContent()).at("/Id").asText());

13
spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/ImagePlatform.java

@ -42,20 +42,21 @@ public class ImagePlatform {
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object obj) {
if (this == o) { if (this == obj) {
return true; return true;
} }
if (!(o instanceof ImagePlatform that)) { if (obj == null || getClass() != obj.getClass()) {
return false; return false;
} }
return Objects.equals(this.os, that.os) && Objects.equals(this.architecture, that.architecture) ImagePlatform other = (ImagePlatform) obj;
&& Objects.equals(this.variant, that.variant); return Objects.equals(this.architecture, other.architecture) && Objects.equals(this.os, other.os)
&& Objects.equals(this.variant, other.variant);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(this.os, this.architecture, this.variant); return Objects.hash(this.architecture, this.os, this.variant);
} }
@Override @Override

Loading…
Cancel
Save