sffc
sffc

Reputation: 6424

How to select x86_64 vs aarch64 in Google Cloud Build?

I'm using Google Cloud Build to generate binary artifacts that I deploy to N1 series VMs. For years, I've done this by setting my cloudbuild.yaml to gcr.io/cloud-builders/docker and then, in the Dockerfile, selecting the base image corresponding to the OS of my VM, such as FROM rockylinux:9.

Currently, both Google Cloud Build and my VMs are x86_64, so the artifacts can be deployed without issue. However, many of the new GCP machine types, such as C4A, use ARM architecture.

In my cloudbuild.yaml, I currently set machineType to N1_HIGHCPU_8. However, there is no option to select an ARM-based machine. The only other option is for E2 machines, where the platform is unspecified.

I could probably figure out how to cross-compile by setting flags in gcc, etc, but it is a complicated build across multiple build systems, and I would prefer to just build on the target architecture.

So, how can I run Google Cloud Build jobs in an aarch64 environment?

Upvotes: 0

Views: 123

Answers (1)

KikoZam
KikoZam

Reputation: 419

As of the moment, Google Cloud Build does not directly support builds on ARM-based machines (aarch64 architecture), but you can use Docker’s buildx to create ARM-based images to build your artifacts.

Here’s how you can set this up:

  • Use QEMU for ARM Architecture

    • Install QEMU in your build process to emulate ARM architecture.

    • Add --platform=linux/arm64 to your Docker build command to build for ARM. Ensure your Docker daemon is set up to use QEMU for multi-platform builds.

steps:
- name: 'gcr.io/cloud-builders/docker'
  args: ['buildx', 'create', '--use']
- name: 'gcr.io/cloud-builders/docker'
  args: ['buildx', 'build', '--platform=linux/arm64', '-t', 'gcr.io/$PROJECT_ID/your-image', '.']
options:
  machineType: 'N1_HIGHCPU_8'

I hope this suggestion works!

Upvotes: 1

Related Questions