我该如何在Github Actions中指定体系结构(例如x86
或arm64
)?
我该如何在Github Actions中指定体系结构(例如x86
或arm64
)?
不,您不能设置GitHub托管的runner架构。这些虚拟机运行x64。目前没有办法指定或请求其他结构。
如果您需要在arm64或x86上使用runner,则需要设置自己的主机/虚拟机并将runner与构建过程需要的任何其他工具一起安装。
您可以使用GitHub/virtual-environments存储库借用设置脚本,但需要进行适当的调整以支持您选择的架构。
我相信你可以将架构指定为环境变量。
- name: Set up Python 3.8.5
uses: actions/setup-python@v3
with:
architecture: 'x64'
python-version: 3.8.5
正如@jessehouwing所说,您需要使用自托管的运行程序。GitHub托管的运行程序尚不支持arm64。您可以通过启动一个arm64虚拟机并安装actions/runner来创建运行程序。您还可以使用一个更完整的分离式解决方案,在 fly 上创建这些运行程序。您有三个可靠的选择:
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: [自托管, codebuild, arm64]
。
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
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"
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 .