如何在 Github Actions 中指定架构?
如何在 Github Actions 中指定架构(例如 x86
或 arm64
)?
How can I specify the architecture (something like x86
or arm64
) in Github Actions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不,您无法设置 GitHub 托管运行器的架构。这些虚拟机运行 x64。目前无法指定或请求其他架构。
如果您需要 arm64 或 x86 上的运行程序,则需要设置自己的主机/虚拟机,并将运行程序以及构建过程所需的任何其他工具安装到其中。
您可以使用 GitHub/virtual-environments 存储库借用设置脚本,但您需要进行适当的调整以支持您选择的架构。
No you cannot set the architecture for the GitHub hosted runner. These VMs run x64. There is currently no way to specify or request another architecture.
If you need runners on arm64 or x86 you'll need to setup your own host/ VM and install the runner into it along with any other tools your build process needs.
You can use the GitHub/virtual-environments repo to borrow the setup scripts, but you'll need to make the proper adjustments to support the architecture of your choice.
正如 @jessehouwing 所说,您将需要使用自托管运行器。 GitHub 托管的运行器尚不支持arm64。您可以通过启动arm64虚拟机并安装actions/runner来自己创建运行程序。您还可以使用单独的更完整的解决方案来动态创建这些跑步者。您有三个可靠的选择:
然后您的工作流程应该使用runs-on:[self-hosted,codebuild,arm64]。
As @jessehouwing said, you will need to use self-hosted runners. GitHub hosted runners don't support arm64 yet. You can create the runner yourself by spinning up an arm64 VM and installing actions/runner. You can also use a separate more complete solution that would create those runners on the fly. You have three solid options:
Your workflows should then use
runs-on: [self-hosted, codebuild, arm64]
.您可以结合使用 qemu 和跨平台 docker 映像来实现结果。有一个 GH 工作流程操作尝试为您打包此操作,称为 run-on-architecture 。
您还可以将构建操作打包到 dockerfile 中,构建该 dockerfile 并(如有必要)将输出复制到主机运行程序。我将尝试提供一个小例子:
Dockerfile:
到目前为止,这都是普通的 dockerfile。现在的技巧是在 quemu-user 的帮助下在多个架构上运行它。 github 上有一个操作也可以进行此设置。
对于初学者来说,以下是如何在本地跨平台运行此程序:
然后您可以使用 docker create 和 docker cp 复制工件:
从这里,有几个在 github 操作中运行它的方法。一种是使用 setup-qemu-action。然后在工作流程中运行构建和复制步骤。像这样的东西:
另请参阅:
You can use a combination of qemu and cross-platform docker images to achieve the result. There is a GH workflow action that attempts to package this up for you called run-on-architecture.
You can also package the build actions into a dockerfile, build that dockerfile and (if necessary) copy the output to the host runner. I'll try to provide a small example:
Dockerfile:
This is all vanilla dockerfile so far. The trick now is to run this on several architectures with the help of quemu-user. There's a github action that sets this up as well.
For starters, here is how you would run this locally, cross-platform:
Then you can copy the artifacts using
docker create
anddocker cp
:From here, there are a couple ways to run this inside a github action. One would be to use the setup-qemu-action. Then run the build and copy steps in your workflow. Something like this:
See also:
如果您有 Github Teams 或 Enterprise,则可以使用
runs-on
。这是一个示例,文档为 此处
我看到的唯一 Arm 类型是
XLarge
arm64 (M1)If you have Github Teams or Enterprise you can with
runs-on
.Here is an example and the docs are here
The only Arm type I see is the
XLarge
arm64 (M1)我相信您可以将架构指定为环境变量。
I believe you can specify architecture as an environment variable.