From a48ca6e8b803e1ce22f8b76e071d956d4aee202e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Clerget?= Date: Fri, 26 Jan 2024 15:33:44 +0100 Subject: [PATCH] Temporary QEMU fix for CI beskar-ostree image build --- .github/workflows/release.yml | 2 ++ build/mage/build.go | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5e3b9de..8768056 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -79,6 +79,8 @@ jobs: - uses: actions/setup-go@v3 with: go-version: '1.21' + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 - uses: actions/checkout@v3 - name: Release beskar-ostree image run: ./scripts/mage ci:image ghcr.io/ctrliq/beskar-ostree:${{ github.ref_name }} "${{ github.actor }}" "${{ secrets.GITHUB_TOKEN }}" diff --git a/build/mage/build.go b/build/mage/build.go index c2e4a2d..520bfed 100644 --- a/build/mage/build.go +++ b/build/mage/build.go @@ -49,6 +49,7 @@ type genAPI struct { type binaryConfig struct { configFiles map[string]string excludedPlatforms map[dagger.Platform]struct{} + useQEMUForCIImage bool execStmts [][]string useProto bool genAPI *genAPI @@ -171,6 +172,7 @@ var binaries = map[string]binaryConfig{ "linux/arm/v6": {}, "linux/arm/v7": {}, }, + useQEMUForCIImage: true, }, } @@ -290,7 +292,8 @@ func (b Build) build(ctx context.Context, name string) error { } binary := name - if string(platform) != currentPlatform { + nativePlatform := string(platform) == currentPlatform + if !nativePlatform { binary += "-" + getPlatformBinarySuffix(string(platform)) } @@ -298,7 +301,15 @@ func (b Build) build(ctx context.Context, name string) error { src := getSource(client) - golang := client.Container().From(GoImage) + var opts []dagger.ContainerOpts + + if binaryConfig.useQEMUForCIImage && buildOpts.publishOptions != nil && !nativePlatform { + opts = append(opts, dagger.ContainerOpts{ + Platform: platform, + }) + } + + golang := client.Container(opts...).From(GoImage) golang = golang. WithMountedDirectory("/src", src).