SpringBoot Native异常排查处理No.1
报错:The current machine does not support all of the following CPU features that are required by the image: [CX8, CMOV, FXSR, MMX, SSE, SSE2, SSE3, SSSE3, SSE4_1, SSE4_2, POPCNT, LZCNT, AVX, AVX2, BMI1, BMI2, FMA, F16C].
解决方案:
https://github.com/spring-projects/spring-boot/issues/36576#issuecomment-1651093475
Can you try to pass in -march=compatibility
in the BP_NATIVE_IMAGE_BUILD_ARGUMENTS
buildpack configuration? This disables the CPU optimizations.
如何设置BP_NATIVE_IMAGE_BUILD_ARGUMENTS
?
Spring Native 中文文档[^1]
bootBuildImage {
builder = "paketobuildpacks/builder:tiny"
environment = [
"BP_NATIVE_IMAGE" : "true",
"BP_NATIVE_IMAGE_BUILD_ARGUMENTS" : "-march=compatibility"
]
}
但是又报错了啊!!!
* What went wrong:
Execution failed for task ':bootBuildImage'.
> Builder lifecycle 'restorer' failed with status code 2
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':bootBuildImage'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambdaexecuteIfValid1(ExecuteActionsTaskExecuter.java:148)
at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:146)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:134)
at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
......
Caused by: org.springframework.boot.buildpack.platform.build.BuilderException: Builder lifecycle 'restorer' failed with status code 2
at org.springframework.boot.buildpack.platform.build.Lifecycle.run(Lifecycle.java:357)
at org.springframework.boot.buildpack.platform.build.Lifecycle.execute(Lifecycle.java:172)
at org.springframework.boot.buildpack.platform.build.Builder.executeLifecycle(Builder.java:177)
at org.springframework.boot.buildpack.platform.build.Builder.build(Builder.java:119)
......
发现是builder写错了,原本使用的是builder = "paketobuildpacks/builder-jammy-java-tiny:latest"
这个是从加参数前构建日志中找到的:
> Pulling builder image 'docker.io/paketobuildpacks/builder-jammy-java-tiny:latest' ..................................................
> Pulled builder image 'paketobuildpacks/builder-jammy-java-tiny@sha256:640a64ee00b8e629b8d1b4cc8a4d1a178951bec4704568b936e94929dccd2687'
> Pulling run image 'docker.io/paketobuildpacks/run-jammy-tiny:latest' for platform 'linux/amd64' ..................................................
> Pulled run image 'paketobuildpacks/run-jammy-tiny@sha256:0c5ac79d549c4b077a7d857631f817f8b573f5da2c109a51f320ee584d44d3f2'
> Executing lifecycle version v0.20.5
> Using build cache volume 'pack-cache-a5ce21949f73.build'
更改正确的builder后,再次构建,日志中可以看到增加的参数:
[creator] Build Configuration:
[creator] $BP_BINARY_COMPRESSION_METHOD Compression mechanism used to reduce binary size. Options: none
(default), upx
or gzexe
[creator] BP_NATIVE_IMAGE true enable native image build
[creator]BP_NATIVE_IMAGE_BUILD_ARGUMENTS -march=compatibility arguments to pass to the native-image command
[creator] BP_NATIVE_IMAGE_BUILD_ARGUMENTS_FILE a file with arguments to pass to the native-image command
[creator]BP_NATIVE_IMAGE_BUILT_ARTIFACT the built application artifact explicitly, required if building from a JAR
可以看出配置已经生效,并且构建也成功了!测试一下镜像是否能使用了
成功启动了