mingpepe
mingpepe

Reputation: 559

How can i specify the architecture in Github Actions?

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

Upvotes: 11

Views: 11537

Answers (6)

ReenigneArcher
ReenigneArcher

Reputation: 137

You can only specify architectures by specifying the runner labels. If you are using GitHub provided runners then only one label should be provided. If you are using self hosted runners you can apply multiple labels to your runners such as linux, x86_64, arm64 and then whichever labels you select in your workflow must find a runner that has all of those labels, e.g. linux and arm64. Of course you would need to provide an arm64 runner yourself in that scenario. For free options keep reading.

As of January 16, 2025, GitHub now has arm64 runners available for Ubuntu images. https://github.blog/changelog/2025-01-16-linux-arm64-hosted-runners-now-available-for-free-in-public-repositories-public-preview/

Additionally, Windows images are available to GitHub Team or Enterprise customers. This will probably come to the free tier soon as they announced the goal was by the end of 2024. https://github.blog/changelog/2024-06-03-actions-arm-based-linux-and-windows-runners-are-now-in-public-beta/

For macOS you can use macos-14 or macos-15 to get arm64, while macos-13 is x86_64.

For more information on GitHub hosted runners I recommend checking out the official runner repository here: https://github.com/actions/runner-images?tab=readme-ov-file#available-images

Another option to run things under a different architecture is to use QEMU in an ubuntu runner.

Upvotes: 0

Michael Warner
Michael Warner

Reputation: 4217

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

Upvotes: 0

thom_nic
thom_nic

Reputation: 8143

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:

Upvotes: 0

kichik
kichik

Reputation: 34704

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].

Upvotes: 0

Tasawer Nawaz
Tasawer Nawaz

Reputation: 925

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

Upvotes: -1

jessehouwing
jessehouwing

Reputation: 114641

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.

Upvotes: 8

Related Questions