Throw exception if pulled image platform doesn't match the requested platform

Closes gh-44059
This commit is contained in:
Moritz Halbritter
2025-03-07 09:28:17 +01:00
parent 282571ae1e
commit d93f4f5554
3 changed files with 44 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -513,6 +513,14 @@ class BootBuildImageIntegrationTests {
assertThat(result.getOutput()).containsPattern("Each image building cache can be configured only once");
}
@TestTemplate
void failsWithIncompatiblePlatform() throws IOException {
writeMainClass();
BuildResult result = this.gradleBuild.buildAndFail("bootBuildImage");
assertThat(result.getOutput()).contains(
"Image platform mismatch detected. The configured platform 'invalid/platform' is not supported by the image 'ghcr.io/spring-io/spring-boot-cnb-test-builder:0.0.1'. Requested platform 'invalid/platform' but got 'linux/amd64'");
}
private void writeMainClass() throws IOException {
File examplePackage = new File(this.gradleBuild.getProjectDir(), "src/main/java/example");
examplePackage.mkdirs();

View File

@@ -0,0 +1,11 @@
plugins {
id 'java'
id 'org.springframework.boot' version '{version}'
}
bootBuildImage {
builder = "ghcr.io/spring-io/spring-boot-cnb-test-builder:0.0.1"
runImage = "paketobuildpacks/run-jammy-tiny"
buildpacks = ["ghcr.io/spring-io/spring-boot-test-info:0.0.1"]
imagePlatform = "invalid/platform"
}