如何在 Github Actions 中指定架构?

发布于 2025-01-09 09:30:09 字数 74 浏览 0 评论 0原文

如何在 Github Actions 中指定架构(例如 x86arm64)?

How can I specify the architecture (something like x86 or arm64) in Github Actions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

各自安好 2025-01-16 09:30:09

不,您无法设置 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.

墟烟 2025-01-16 09:30:09

正如 @jessehouwing 所说,您将需要使用自托管运行器。 GitHub 托管的运行器尚不支持arm64。您可以通过启动arm64虚拟机并安装actions/runner来自己创建运行程序。您还可以使用单独的更完整的解决方案来动态创建这些跑步者。您有三个可靠的选择:

import { aws_codebuild as codebuild } from 'aws-cdk-lib';
import { Architecture, CodeBuildRunnerProvider } from '@cloudsnorkel/cdk-github-runners';

new GitHubRunners(this, 'runners', {
  providers: [
    new CodeBuildRunnerProvider(this, 'CodeBuild ARM64', {
      labels: ['codebuild', 'arm64'],
      computeType: codebuild.ComputeType.SMALL,
      imageBuilder: CodeBuildRunnerProvider.imageBuilder(this, 'Runner Image Builder', {
        architecture: Architecture.ARM64,
      }),
    }),
  ],
});

然后您的工作流程应该使用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:

import { aws_codebuild as codebuild } from 'aws-cdk-lib';
import { Architecture, CodeBuildRunnerProvider } from '@cloudsnorkel/cdk-github-runners';

new GitHubRunners(this, 'runners', {
  providers: [
    new CodeBuildRunnerProvider(this, 'CodeBuild ARM64', {
      labels: ['codebuild', 'arm64'],
      computeType: codebuild.ComputeType.SMALL,
      imageBuilder: CodeBuildRunnerProvider.imageBuilder(this, 'Runner Image Builder', {
        architecture: Architecture.ARM64,
      }),
    }),
  ],
});

Your workflows should then use runs-on: [self-hosted, codebuild, arm64].

说谎友 2025-01-16 09:30:09

您可以结合使用 qemu 和跨平台 docker 映像来实现结果。有一个 GH 工作流程操作尝试为您打包此操作,称为 run-on-architecture

您还可以将构建操作打包到 dockerfile 中,构建该 dockerfile 并(如有必要)将输出复制到主机运行程序。我将尝试提供一个小例子:

Dockerfile:

FROM debian:bullseye

ENV project myproject
ENV DEBIAN_FRONTEND noninteractive
ENV LC_ALL en_US.UTF-8
ENV LANG ${LC_ALL}

RUN echo "#log: ${project}: Setup system" \
  && set -x \
  && apt-get update -y \
  && apt-get install -y \
    build-essential \
    python3 \
  && apt-get clean \
  && sync

ADD . /usr/local/opt/${project}
WORKDIR /usr/local/opt/${project}

RUN echo "#log: ${project}: Running build" \
  && set -x \
  && ./configure \
  && make \
  && make dist

CMD /bin/bash -l

到目前为止,这都是普通的 dockerfile。现在的技巧是在 quemu-user 的帮助下在多个架构上运行它。 github 上有一个操作也可以进行此设置。

对于初学者来说,以下是如何在本地跨平台运行此程序:

docker build --name --tag my-builder --platform linux/arm64
docker build --name --tag my-builder --platform linux/arm

然后您可以使用 docker create 和 docker cp 复制工件:

CONTAINER=$docker create --platform "linux/arm64" my-builder)
docker cp "$CONTAINER:/usr/local/opt/myproject/*.tar.gz" .
docker rm "$CONTAINER"

CONTAINER=$docker create --platform "linux/arm" my-builder)
docker cp "$CONTAINER:/usr/local/opt/myproject/*.tar.gz" .
docker rm "$CONTAINER"

从这里,有几个在 github 操作中运行它的方法。一种是使用 setup-qemu-action。然后在工作流程中运行构建和复制步骤。像这样的东西:

jobs:
  build:
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        platform: [linux/amd64, linux/arm64, linux/arm]
    steps:
      - uses: actions/checkout@v4
      - uses: docker/setup-qemu-action@v3
        with:
          image: tonistiigi/binfmt:latest
          platforms: arm,arm64
      - run: >
          docker build .
          --tag my-builder
          --platform ${{ matrix.platform }}
      - run: >
          docker create
          --name node-bcryptjs-builder
          --platform ${{ matrix.platform }}
          my-builder
      - run: docker cp "my-builder:/usr/local/opt/myproject/*.tar.gz .

另请参阅:

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:

FROM debian:bullseye

ENV project myproject
ENV DEBIAN_FRONTEND noninteractive
ENV LC_ALL en_US.UTF-8
ENV LANG ${LC_ALL}

RUN echo "#log: ${project}: Setup system" \
  && set -x \
  && apt-get update -y \
  && apt-get install -y \
    build-essential \
    python3 \
  && apt-get clean \
  && sync

ADD . /usr/local/opt/${project}
WORKDIR /usr/local/opt/${project}

RUN echo "#log: ${project}: Running build" \
  && set -x \
  && ./configure \
  && make \
  && make dist

CMD /bin/bash -l

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:

docker build --name --tag my-builder --platform linux/arm64
docker build --name --tag my-builder --platform linux/arm

Then you can copy the artifacts using docker create and docker cp:

CONTAINER=$docker create --platform "linux/arm64" my-builder)
docker cp "$CONTAINER:/usr/local/opt/myproject/*.tar.gz" .
docker rm "$CONTAINER"

CONTAINER=$docker create --platform "linux/arm" my-builder)
docker cp "$CONTAINER:/usr/local/opt/myproject/*.tar.gz" .
docker rm "$CONTAINER"

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:

jobs:
  build:
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        platform: [linux/amd64, linux/arm64, linux/arm]
    steps:
      - uses: actions/checkout@v4
      - uses: docker/setup-qemu-action@v3
        with:
          image: tonistiigi/binfmt:latest
          platforms: arm,arm64
      - run: >
          docker build .
          --tag my-builder
          --platform ${{ matrix.platform }}
      - run: >
          docker create
          --name node-bcryptjs-builder
          --platform ${{ matrix.platform }}
          my-builder
      - run: docker cp "my-builder:/usr/local/opt/myproject/*.tar.gz .

See also:

海螺姑娘 2025-01-16 09:30:09

如果您有 Github Teams 或 Enterprise,则可以使用 runs-on

这是一个示例,文档为 此处

我看到的唯一 Arm 类型是 XLarge arm64 (M1)

name: learn-github-actions-testing
on: [push]
jobs:
  build:
    runs-on: macos-13-xlarge
    steps:
      - uses: actions/checkout@v4
      - name: Build
        run: swift build
      - name: Run tests
        run: swift test

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)

name: learn-github-actions-testing
on: [push]
jobs:
  build:
    runs-on: macos-13-xlarge
    steps:
      - uses: actions/checkout@v4
      - name: Build
        run: swift build
      - name: Run tests
        run: swift test
山色无中 2025-01-16 09:30:09

我相信您可以将架构指定为环境变量。

- name: Set up Python 3.8.5
  uses: actions/setup-python@v3
  with:
    architecture: 'x64'
    python-version: 3.8.5

I believe you can specify architecture as an environment variable.

- name: Set up Python 3.8.5
  uses: actions/setup-python@v3
  with:
    architecture: 'x64'
    python-version: 3.8.5
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文