简体   繁体   English

在 M1 Mac 上使用 quarkus 构建原生镜像失败

[英]Building native image using quarkus on a M1 Mac fails

From my project's root directory, I issued the following command to create a native executable that will be specific to my operating system.从我的项目的根目录中,我发出以下命令来创建一个特定于我的操作系统的本机可执行文件。 See the following guide for details 有关详细信息,请参阅以下指南

mvn package -Pnative -Dquarkus.native.container-build=true

and here is the output.这是输出。

[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< com.example:quarkus-spring >---------------------
[INFO] Building quarkus-spring 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- quarkus-maven-plugin:1.13.7.Final:generate-code (default) @ quarkus-spring ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ quarkus-spring ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ quarkus-spring ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- quarkus-maven-plugin:1.13.7.Final:generate-code-tests (default) @ quarkus-spring ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ quarkus-spring ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ quarkus-spring ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) @ quarkus-spring ---
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.controller.GreetingControllerTest
2021-06-22 21:17:05,339 WARN  [io.qua.dat.dep.dev.DevServicesDatasourceProcessor] (build-10) Unable to determine a database type for default datasource
2021-06-22 21:17:05,340 WARN  [io.qua.agr.dep.AgroalProcessor] (build-16) The Agroal dependency is present but no JDBC datasources have been defined.
2021-06-22 21:17:06,080 INFO  [io.quarkus] (main) Quarkus 1.13.7.Final on JVM started in 1.004s. Listening on: http://localhost:8081
2021-06-22 21:17:06,081 INFO  [io.quarkus] (main) Profile test activated.
2021-06-22 21:17:06,081 INFO  [io.quarkus] (main) Installed features: [agroal, cdi, hibernate-orm, hibernate-orm-panache, mongodb-client, mutiny, narayana-jta, resteasy, smallrye-context-propagation, spring-boot-properties, spring-data-jpa, spring-data-rest, spring-di]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.755 s - in com.example.controller.GreetingControllerTest
2021-06-22 21:17:06,699 INFO  [io.quarkus] (main) Quarkus stopped in 0.020s
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ quarkus-spring ---
[INFO]
[INFO] --- quarkus-maven-plugin:1.13.7.Final:build (default) @ quarkus-spring ---
[INFO] [org.jboss.threads] JBoss Threads version 3.2.0.Final
[WARNING] [io.quarkus.agroal.deployment.AgroalProcessor] The Agroal dependency is present but no JDBC datasources have been defined.
[INFO] [org.hibernate.Version] HHH000412: Hibernate ORM core version 5.4.29.Final
[INFO] [io.quarkus.deployment.pkg.steps.JarResultBuildStep] Building native image source jar: /Users/viswanath/projects/quarkus-spring/target/quarkus-spring-1.0-SNAPSHOT-native-image-source-jar/quarkus-spring-1.0-SNAPSHOT-runner.jar
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] Building native image from /Users/viswanath/projects/quarkus-spring/target/quarkus-spring-1.0-SNAPSHOT-native-image-source-jar/quarkus-spring-1.0-SNAPSHOT-runner.jar
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildContainerRunner] Using docker to run the native image builder
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildContainerRunner] Checking image status quay.io/quarkus/ubi-quarkus-native-image:21.0-java11
21.0-java11: Pulling from quarkus/ubi-quarkus-native-image
Digest: sha256:356624049da5f564e14acbaf167a341a01b332569db83e9967b1e72cfdf06653
Status: Image is up to date for quay.io/quarkus/ubi-quarkus-native-image:21.0-java11
quay.io/quarkus/ubi-quarkus-native-image:21.0-java11
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] Running Quarkus native-image plugin on GraalVM Version 21.0.0.2 (Java Version 11.0.10+8-jvmci-21.0-b06)
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildRunner] docker run --env LANG=C --rm -v /Users/viswanath/projects/quarkus-spring/target/quarkus-spring-1.0-SNAPSHOT-native-image-source-jar:/project:z quay.io/quarkus/ubi-quarkus-native-image:21.0-java11 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dsun.nio.ch.maxUpdateArraySize=100 -J-DCoordinatorEnvironmentBean.transactionStatusManagerEnable=false -J-Dvertx.logger-delegate-factory-class-name=io.quarkus.vertx.core.runtime.VertxLogDelegateFactory -J-Dvertx.disableDnsResolver=true -J-Dio.netty.leakDetection.level=DISABLED -J-Dio.netty.allocator.maxOrder=1 -J-Duser.language=en -J-Duser.country=GB -J-Dfile.encoding=UTF-8 --initialize-at-build-time= -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy\$BySpaceAndTime -H:+JNI -H:+AllowFoldMethods -jar quarkus-spring-1.0-SNAPSHOT-runner.jar -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -J-Xmx8192m -H:-AddAllCharsets -H:EnableURLProtocols=http,https --enable-all-security-services --no-server -H:-UseServiceLoaderFeature -H:+StackTrace quarkus-spring-1.0-SNAPSHOT-runner
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
^C%

Native image generation fails as the build just hangs.由于构建挂起,本机映像生成失败。


I chose to install Graal VM on my host and opt for the non-container based approach as shown below.我选择在我的主机上安装 Graal VM 并选择基于非容器的方法,如下所示。

  • Install Graal VM on M1 Mac using the following command使用以下命令在 M1 Mac 上安装 Graal VM

    ❯ brew install --cask graalvm/tap/graalvm-ce-lts-java11 ❯ brew install --cask graalvm/tap/graalvm-ce-lts-java11

  • Add Graal VM to JEnv managed versions of Java将 Graal VM 添加到 JEnv 托管的 Java 版本

    ❯ jenv add /Library/Java/JavaVirtualMachines/graalvm-ce-lts-java11-20.3.1/Contents/Home graalvm64-11.0.10 added ❯ jenv 添加 /Library/Java/JavaVirtualMachines/graalvm-ce-lts-java11-20.3.1/Contents/Home graalvm64-11.0.10

  • For the project, set Graal VM's Java 11. From the project's directory, issue the following command对于项目,设置 Graal VM 的 Java 11。在项目目录中,发出以下命令

    ❯ jenv local graalvm64-11.0.10 ❯ jenv 本地 graalvm64-11.0.10

  • Set GRAALVM_HOME environment variable to the GraalVM installation directory.将 GRAALVM_HOME 环境变量设置为 GraalVM 安装目录。 Add the following to ~/.zshrc将以下内容添加到 ~/.zshrc

    ❯ export GRAALVM_HOME=/Library/Java/JavaVirtualMachines/graalvm-ce-lts-java11-20.3.1/Contents/Home ❯ 导出 GRAALVM_HOME=/Library/Java/JavaVirtualMachines/graalvm-ce-lts-java11-20.3.1/Contents/Home

and reload changes made to .zshrc by issuing the command并通过发出命令重新加载对 .zshrc 所做的更改

❯ source ~/.zshrc
  • Install the native-image tool using the following command.使用以下命令安装本机映像工具。 Some previous releases of GraalVM included the native-image tool by default. GraalVM 的一些早期版本默认包含原生镜像工具。 This is no longer the case;这已不再是这种情况; it must be installed as a second step after GraalVM itself is installed.它必须在安装 GraalVM 本身之后作为第二步安装。

    ❯ ${GRAALVM_HOME}/bin/gu install native-image ❯ ${GRAALVM_HOME}/bin/gu 安装原生镜像

  • Install binutils and add it to the path安装 binutils 并将其添加到路径中

    ❯ brew install binutils ❯ 酿造安装 binutils

    ❯ echo 'export PATH="/opt/homebrew/opt/binutils/bin:$PATH"' >> ~/.zshrc ❯ source ~/.zshrc ❯ echo 'export PATH="/opt/homebrew/opt/binutils/bin:$PATH"' >> ~/.zshrc ❯ source ~/.zshrc

  • Create a native executable using the following caommand from project's root directory使用项目根目录中的以下命令创建本机可执行文件

    ❯ mvn clean install -Pnative -Dnative-image.docker-build=true -Dquarkus.native.native-image-xmx=4g ❯ mvn clean install -Pnative -Dnative-image.docker-build=true -Dquarkus.native.native-image-xmx=4g

Finally when I ran the native image, it failed.最后,当我运行本机映像时,它失败了。

❯ ~/projects/quarkus-spring/target ./quarkus-spring-1.0-SNAPSHOT-runner                                      
[1]    11638 killed     ./quarkus-spring-1.0-SNAPSHOT-runner

Any help?有什么帮助吗?

The documentation explains that -Dquarkus.native.container-build=true option means that you want to build a Linux executable and that the build should happen in a container.文档解释说-Dquarkus.native.container-build=true选项意味着您想要构建Linux可执行文件并且构建应该在容器中进行。 You can even control the runtime for that Docker/Podman with:您甚至可以通过以下方式控制 Docker/Podman 的运行时:

# Docker
./mvnw package -Pnative -Dquarkus.native.container-build=true -Dquarkus.native.container-runtime=docker
# Podman
./mvnw package -Pnative -Dquarkus.native.container-build=true -Dquarkus.native.container-runtime=podman

It's likely the reason why the executable doesn't work on MacOS after your last command since it's a Linux binary.这可能是可执行文件在您最后一个命令后无法在 MacOS 上运行的原因,因为它是 Linux 二进制文件。 You can check that with:您可以通过以下方式检查:

file ./quarkus-spring-1.0-SNAPSHOT-runner

Though in the command line you're using "-Dquarkus.native.docker-build=true" instead of "-Dquarkus.native.container-build.true", and I don't know if has any relevance.尽管在命令行中您使用的是“-Dquarkus.native.docker-build=true”而不是“-Dquarkus.native.container-build.true”,但我不知道是否有任何相关性。

This Answer from another similar question worked for me . This Answer from another similar question对我有用 Basically you just need to build base graalvm image on your M1 laptop and reference that image (eg here the image is tagged as graalvm ) using -Dquarkus.native.builder-image=graalvm基本上你只需要在你的 M1 笔记本电脑上构建基础 graalvm 图像并使用-Dquarkus.native.builder-image=graalvm引用该图像(例如,这里的图像被标记为graalvm

If you are using macOS Catalina and later you may need to remove the quarantine attribute from the bits before you can use them To do this, run the following:如果您使用的是 macOS Catalina 及更高版本,您可能需要先从这些位中删除隔离属性,然后才能使用它们。为此,请运行以下命令:

$ sudo xattr -r -d com.apple.quarantine path/to/graalvm/folder/

Based on Graal commit: https://github.com/oracle/graal/tree/vm-22.1.0基于 Graal 提交: https ://github.com/oracle/graal/tree/vm-22.1.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM