springboot 3 GraalVM本地映像永远卡住:Mac M1

huangapple go评论69阅读模式
英文:

springboot 3 graalvm native image stuck forever: mac m1

问题

我正在使用Spring Boot 3.0.2,并且正在使用native-maven-plugin。

<plugin>
    <groupId>org.graalvm.buildtools</groupId>
    <artifactId>native-maven-plugin</artifactId>
    <version>0.9.19</version>
</plugin>

当我尝试使用以下命令构建GraalVM本地镜像时:

./mvnw -Pnative spring-boot:build-image

该过程运行了一段时间,然后永远停在此阶段:

[INFO]     [creator]         执行native-image -H:+StaticExecutableWithDynamicLibC @/workspace/META-INF/native-image/argfile -H:Name=/layers/paketo-buildpacks_native-image/native-image/com.example.spring6.Spring6Application -cp /workspace:/workspace/BOOT-INF/classes:/workspace/BOOT-INF/lib/spring-boot-3.0.2.jar:/workspace/BOOT-INF/lib/spring-boot-autoconfigure-3.0.2.jar:/workspace/BOOT-INF/lib/logback-classic-1.4.5.jar:/workspace/BOOT-INF/lib/logback-core-1.4.5.jar:/workspace/BOOT-INF/lib/log4j-to-slf4j-2.19.0.jar:/workspace/BOOT-INF/lib/log4j-api-2.19.0.jar:/workspace/BOOT-INF/lib/jul-to-slf4j-2.0.6.jar:/workspace/BOOT-INF/lib/jakarta.annotation-api-2.1.1.jar:/workspace/BOOT-INF/lib/snakeyaml-1.33.jar:/workspace/BOOT-INF/lib/jackson-databind-2.14.1.jar:/workspace/BOOT-INF/lib/jackson-annotations-2.14.1.jar:/workspace/BOOT-INF/lib/jackson-core-2.14.1.jar:/workspace/BOOT-INF/lib/jackson-datatype-jdk8-2.14.1.jar:/workspace/BOOT-INF/lib/jackson-datatype-jsr310-2.14.1.jar:/workspace/BOOT-INF/lib/jackson-module-parameter-names-2.14.1.jar:/workspace/BOOT-INF/lib/tomcat-embed-core-10.1.5.jar:/workspace/BOOT-INF/lib/tomcat-embed-el-10.1.5.jar:/workspace/BOOT-INF/lib/tomcat-embed-websocket-10.1.5.jar:/workspace/BOOT-INF/lib/spring-web-6.0.4.jar:/workspace/BOOT-INF/lib/spring-beans-6.0.4.jar:/workspace/BOOT-INF/lib/micrometer-observation-1.10.3.jar:/workspace/BOOT-INF/lib/micrometer-commons-1.10.3.jar:/workspace/BOOT-INF/lib/spring-webmvc-6.0.4.jar:/workspace/BOOT-INF/lib/spring-aop-6.0.4.jar:/workspace/BOOT-INF/lib/spring-context-6.0.4.jar:/workspace/BOOT-INF/lib/spring-expression-6.0.4.jar:/workspace/BOOT-INF/lib/reactor-netty-http-1.1.2.jar:/workspace/BOOT-INF/lib/netty-codec-http-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-common-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-buffer-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-transport-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-codec-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-handler-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-codec-http2-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-resolver-dns-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-resolver-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-codec-dns-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-resolver-dns-native-macos-4.1.87.Final-osx-x86_64.jar:/workspace/BOOT-INF/lib/netty-resolver-dns-classes-macos-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-transport-native-epoll-4.1.87.Final-linux-x86_64.jar:/workspace/BOOT-INF/lib/netty-transport-native-unix-common-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-transport-classes-epoll-4.1.87.Final.jar:/workspace/BOOT-INF/lib/reactor-netty-core-1.1.2.jar:/workspace/BOOT-INF/lib/netty-handler-proxy-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-codec-socks-4.1.87.Final.jar:/workspace/BOOT-INF/lib/spring-webflux-6.0.4.jar:/workspace/BOOT-INF/lib/reactor-core-3.5.2.jar:/workspace/BOOT-INF/lib/reactive-streams-1.0.4.jar:/workspace/BOOT-INF/lib/slf4j-api-2.0.6.jar:/workspace/BOOT-INF/lib/spring-core-6.0.4.jar:/workspace/BOOT-INF/lib/spring-jcl-6.0.4.jar:/workspace/BOOT-INF/lib/spring-boot-jarmode-layertools-3.0.2.jar com.example.spring6.Spring6Application

我正在使用MacBook Pro M1。我的Java版本:

openjdk版本 "17.0.6" 2023-01-17
OpenJDK运行时环境GraalVM CE 22.3.1(构建17.0.6+10-jvmci-22.3-b13)
OpenJDK 64位服务器VM GraalVM CE 22.3.1(构建17.0.6+10-jvmci-22.3-b13,混合模式,共享)
英文:

I am using spring boot 3.0.2 and I am using native-maven-plugin.

 &lt;plugin&gt;
       &lt;groupId&gt;org.graalvm.buildtools&lt;/groupId&gt;
       &lt;artifactId&gt;native-maven-plugin&lt;/artifactId&gt;
       &lt;version&gt;0.9.19&lt;/version&gt;
 &lt;/plugin&gt;

when I try to build a graalvm native image with this command

./mvnw -Pnative spring-boot:build-image

The process runs for a while and then it is just waiting at this stage forever.

[INFO]     [creator]         Executing native-image -H:+StaticExecutableWithDynamicLibC @/workspace/META-INF/native-image/argfile -H:Name=/layers/paketo-buildpacks_native-image/native-image/com.example.spring6.Spring6Application -cp /workspace:/workspace/BOOT-INF/classes:/workspace/BOOT-INF/lib/spring-boot-3.0.2.jar:/workspace/BOOT-INF/lib/spring-boot-autoconfigure-3.0.2.jar:/workspace/BOOT-INF/lib/logback-classic-1.4.5.jar:/workspace/BOOT-INF/lib/logback-core-1.4.5.jar:/workspace/BOOT-INF/lib/log4j-to-slf4j-2.19.0.jar:/workspace/BOOT-INF/lib/log4j-api-2.19.0.jar:/workspace/BOOT-INF/lib/jul-to-slf4j-2.0.6.jar:/workspace/BOOT-INF/lib/jakarta.annotation-api-2.1.1.jar:/workspace/BOOT-INF/lib/snakeyaml-1.33.jar:/workspace/BOOT-INF/lib/jackson-databind-2.14.1.jar:/workspace/BOOT-INF/lib/jackson-annotations-2.14.1.jar:/workspace/BOOT-INF/lib/jackson-core-2.14.1.jar:/workspace/BOOT-INF/lib/jackson-datatype-jdk8-2.14.1.jar:/workspace/BOOT-INF/lib/jackson-datatype-jsr310-2.14.1.jar:/workspace/BOOT-INF/lib/jackson-module-parameter-names-2.14.1.jar:/workspace/BOOT-INF/lib/tomcat-embed-core-10.1.5.jar:/workspace/BOOT-INF/lib/tomcat-embed-el-10.1.5.jar:/workspace/BOOT-INF/lib/tomcat-embed-websocket-10.1.5.jar:/workspace/BOOT-INF/lib/spring-web-6.0.4.jar:/workspace/BOOT-INF/lib/spring-beans-6.0.4.jar:/workspace/BOOT-INF/lib/micrometer-observation-1.10.3.jar:/workspace/BOOT-INF/lib/micrometer-commons-1.10.3.jar:/workspace/BOOT-INF/lib/spring-webmvc-6.0.4.jar:/workspace/BOOT-INF/lib/spring-aop-6.0.4.jar:/workspace/BOOT-INF/lib/spring-context-6.0.4.jar:/workspace/BOOT-INF/lib/spring-expression-6.0.4.jar:/workspace/BOOT-INF/lib/reactor-netty-http-1.1.2.jar:/workspace/BOOT-INF/lib/netty-codec-http-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-common-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-buffer-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-transport-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-codec-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-handler-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-codec-http2-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-resolver-dns-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-resolver-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-codec-dns-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-resolver-dns-native-macos-4.1.87.Final-osx-x86_64.jar:/workspace/BOOT-INF/lib/netty-resolver-dns-classes-macos-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-transport-native-epoll-4.1.87.Final-linux-x86_64.jar:/workspace/BOOT-INF/lib/netty-transport-native-unix-common-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-transport-classes-epoll-4.1.87.Final.jar:/workspace/BOOT-INF/lib/reactor-netty-core-1.1.2.jar:/workspace/BOOT-INF/lib/netty-handler-proxy-4.1.87.Final.jar:/workspace/BOOT-INF/lib/netty-codec-socks-4.1.87.Final.jar:/workspace/BOOT-INF/lib/spring-webflux-6.0.4.jar:/workspace/BOOT-INF/lib/reactor-core-3.5.2.jar:/workspace/BOOT-INF/lib/reactive-streams-1.0.4.jar:/workspace/BOOT-INF/lib/slf4j-api-2.0.6.jar:/workspace/BOOT-INF/lib/spring-core-6.0.4.jar:/workspace/BOOT-INF/lib/spring-jcl-6.0.4.jar:/workspace/BOOT-INF/lib/spring-boot-jarmode-layertools-3.0.2.jar com.example.spring6.Spring6Application

I am using macbook pro m1. My java version

openjdk version &quot;17.0.6&quot; 2023-01-17
OpenJDK Runtime Environment GraalVM CE 22.3.1 (build 17.0.6+10-jvmci-22.3-b13)
OpenJDK 64-Bit Server VM GraalVM CE 22.3.1 (build 17.0.6+10-jvmci-22.3-b13, mixed mode, sharing)

答案1

得分: 3

更新你的pom.xml文件以使用一个正确支持ARM64架构的Buildpacks镜像:

<plugin>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-maven-plugin</artifactId>
	<configuration>
		<image>
			<builder>dashaun/builder:tiny</builder>
		</image>
	</configuration>
</plugin>

另一个回答正确解释了如何构建本地镜像,但如果你想将应用程序容器化,它不会解决你的问题 - 因为本地镜像是为你的本地主机架构创建的,如果只是复制到标准基础镜像中,它将无法工作。它还需要本地安装GraalVM构建工具。

Spring Boot插件通过在容器中构建项目来解决这个问题,使用Buildpacks。不幸的是,默认的Packeto Buildpacks镜像不支持Mac M1架构(来源)。取而代之,使用这个基础镜像,应该可以解决你的问题。

英文:

tl;dr - update your pom.xml to use a different Buildpacks image that properly supports ARM64:

&lt;plugin&gt;
	&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
	&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
	&lt;configuration&gt;
		&lt;image&gt;
			&lt;builder&gt;dashaun/builder:tiny&lt;/builder&gt;
		&lt;/image&gt;
	&lt;/configuration&gt;
&lt;/plugin&gt;

The other answer correctly explains how to build a native image, but it does not solve your problem if you wanted to containerize your application - tricky to do as the native image is created for your local host architecture, and would not work if you just copy it to a standard base image. It also requires a local installation of the GraalVM build tools.

The Spring Boot plugin is solving this problem by building your project in a container, using Buildpacks. Unfortunately, the default Packeto Buildpacks image does not support the Mac M1 architecture (source). Instead, use this base image and it should solve your problem.

答案2

得分: 2

以下是您要的翻译:

The answer of Itay Polack-Gadassi worked perfectly for me which is why I want to expand on it to include the Gradle version.
Itay Polack-Gadassi的答案对我非常有效,这就是我想要扩展它以包括Gradle版本的原因。

To build a native image with Gradle, the task bootBuildImage is used.
要使用Gradle构建本机映像,需要使用bootBuildImage任务。

However, the default buildpack image used does not support ARM architectures, resulting in builds running forever with no real error message.
然而,使用的默认构建包映像不支持ARM架构,导致构建永远运行,没有实际的错误消息。

To solve this problem, another buildpack image has to be configured as described in this repo.
要解决这个问题,必须配置另一个构建包映像,如此存储库中所述。

For Groovy build.gradle:
对于Groovy的build.gradle

tasks.named(&quot;bootBuildImage&quot;) {
    builder = &quot;dashaun/builder:tiny&quot;
    environment = [&quot;BP_NATIVE_IMAGE&quot; : &quot;true&quot;]
}

For Kotlin build.gradle.kts (including OS & CPU check):
对于Kotlin的build.gradle.kts(包括操作系统和CPU检查):

tasks.withType&lt;BootBuildImage&gt; {
	val osName = System.getProperty(&quot;os.name&quot;).toLowerCase()
	val arch = System.getProperty(&quot;os.arch&quot;)

	val runningOnM1Mac = &quot;mac&quot; in osName &amp;&amp; arch == &quot;aarch64&quot;
	if (runningOnM1Mac) {
		builder.set(&quot;dashaun/builder:tiny&quot;)
		environment.set(mapOf(&quot;BP_NATIVE_IMAGE&quot; to &quot;true&quot;))
	}
}
英文:

The answer of Itay Polack-Gadassi worked perfectly for me which is why I want to expand on it to include the Gradle version.

To build a native image with Gradle, the task bootBuildImage is used.
However, the default buildpack image used does not support ARM architectures, resulting in builds running forever with no real error message.

To solve this problem, another buildpack image has to be configured as described in this repo.

For Groovy build.gradle:

tasks.named(&quot;bootBuildImage&quot;) {
    builder = &quot;dashaun/builder:tiny&quot;
    environment = [&quot;BP_NATIVE_IMAGE&quot; : &quot;true&quot;]
}

For Kotlin build.gradle.kts (including OS & CPU check):

tasks.withType&lt;BootBuildImage&gt; {
	val osName = System.getProperty(&quot;os.name&quot;).toLowerCase()
	val arch = System.getProperty(&quot;os.arch&quot;)

	val runningOnM1Mac = &quot;mac&quot; in osName &amp;&amp; arch == &quot;aarch64&quot;
	if (runningOnM1Mac) {
		builder.set(&quot;dashaun/builder:tiny&quot;)
		environment.set(mapOf(&quot;BP_NATIVE_IMAGE&quot; to &quot;true&quot;))
	}
}

答案3

得分: 1

对于原生镜像命令是mvn -Pnative native:compile

当激活本机配置文件时,您可以调用本机:编译目标来触发本机映像编译:

$ mvn -Pnative native:compile

本机映像可在目标目录中找到。

来源

您使用的命令是spring-boot:build-image,它用于生成Docker映像并在Docker中运行本机映像。如果该命令在某个点上停滞不前,这意味着Docker没有响应或某些地方出现了冻结。请查看此文档以获取更多详细信息。

最后请不要在本机maven插件插件中使用版本号。POM应该像这样这样

      &lt;plugin&gt;
        &lt;groupId&gt;org.graalvm.buildtools&lt;/groupId&gt;
        &lt;artifactId&gt;native-maven-plugin&lt;/artifactId&gt;
      &lt;/plugin&gt;
英文:

For native image command is mvn -Pnative native:compile

> With the native profile active, you can invoke the native:compile goal to trigger native-image compilation:

> $ mvn -Pnative native:compile

> The native image executable can be found in the target directory.

Source

The command you used is spring-boot:build-image which is generating docker image and running the native image under docker. if that command is stucking at some point it means docker is not responding or something freezing that side. Check this doc for further details.

Last note please do not use version number in native-maven-plugin plugin. pom should look like this

      &lt;plugin&gt;
        &lt;groupId&gt;org.graalvm.buildtools&lt;/groupId&gt;
        &lt;artifactId&gt;native-maven-plugin&lt;/artifactId&gt;
      &lt;/plugin&gt;

huangapple
  • 本文由 发表于 2023年2月6日 05:05:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75355506.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定