Skip to content

Commit 0ed46cc

Browse files
authored
Refactor build workflows to run mult-architecture build via matrix (#674)
* Refactor build workflows to run mult-architecture build via matrix * split build cache based on architecture
1 parent bb8b756 commit 0ed46cc

File tree

2 files changed

+69
-18
lines changed

2 files changed

+69
-18
lines changed

.github/workflows/main.yml

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# Main Branch Build Workflow for Docker Image supporting multiple architectures
2-
name: Build on Main Merge
1+
name: Build Nightly on Main Merge
32

43
on:
54
push:
@@ -8,13 +7,14 @@ on:
87

98
jobs:
109
build:
11-
runs-on: ubuntu-latest-32
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
platform: [linux/amd64, linux/arm64]
1214

1315
steps:
1416
- name: Checkout code
1517
uses: actions/checkout@v2
16-
with:
17-
ref: main # checkout the main branch to build nightly
1818

1919
- name: Set up Docker Buildx
2020
uses: docker/setup-buildx-action@v3
@@ -30,10 +30,31 @@ jobs:
3030
with:
3131
context: .
3232
target: prod
33-
platforms: linux/amd64,linux/arm64
33+
platforms: ${{ matrix.platform }}
3434
push: true
35-
tags: thirdweb/engine:nightly
36-
cache-from: type=gha
37-
cache-to: type=gha,mode=max
35+
cache-from: |
36+
type=gha,scope=${{ matrix.platform }}
37+
type=registry,ref=thirdweb/engine:buildcache-${{ matrix.platform }}
38+
cache-to: |
39+
type=gha,scope=${{ matrix.platform }},mode=max
40+
type=registry,ref=thirdweb/engine:buildcache-${{ matrix.platform }},mode=max
41+
tags: thirdweb/engine:nightly-${{ matrix.platform }}
3842
build-args: |
3943
ENGINE_VERSION=nightly
44+
45+
merge-manifests:
46+
needs: build
47+
runs-on: ubuntu-latest
48+
steps:
49+
- name: Login to DockerHub
50+
uses: docker/login-action@v1
51+
with:
52+
username: ${{ secrets.DOCKER_USERNAME }}
53+
password: ${{ secrets.DOCKER_PASSWORD }}
54+
55+
- name: Create and Push Multi-arch Manifest (nightly)
56+
run: |
57+
docker manifest create thirdweb/engine:nightly \
58+
thirdweb/engine:nightly-linux/amd64 \
59+
thirdweb/engine:nightly-linux/arm64
60+
docker manifest push thirdweb/engine:nightly

.github/workflows/tagBasedImageBuild.yml

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ on:
66

77
jobs:
88
buildImageForNewTag:
9-
runs-on: ubuntu-latest-32
10-
# Set environment variables
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
platform: [linux/amd64, linux/arm64]
1113
env:
1214
LATEST_TAG: ${{ (github.event.release.target_commitish == 'main') && 'thirdweb/engine:latest' || '' }}
1315

1416
steps:
1517
- name: Checkout code
1618
uses: actions/checkout@v2
1719
with:
18-
# Fetches the branch at which the release was made
1920
ref: ${{ github.event.release.target_commitish }}
2021

2122
- name: Set up Docker Buildx
@@ -32,12 +33,41 @@ jobs:
3233
with:
3334
context: .
3435
target: prod
35-
platforms: linux/amd64,linux/arm64
36+
platforms: ${{ matrix.platform }}
3637
push: true
37-
cache-from: type=gha
38-
cache-to: type=gha,mode=max
39-
tags: |
40-
thirdweb/engine:${{ github.event.release.tag_name }}
41-
${{ env.LATEST_TAG }}
38+
cache-from: |
39+
type=gha,scope=${{ matrix.platform }}
40+
type=registry,ref=thirdweb/engine:buildcache-${{ matrix.platform }}
41+
cache-to: |
42+
type=gha,scope=${{ matrix.platform }},mode=max
43+
type=registry,ref=thirdweb/engine:buildcache-${{ matrix.platform }},mode=max
44+
tags: thirdweb/engine:${{ github.event.release.tag_name }}-${{ matrix.platform }}
4245
build-args: |
4346
ENGINE_VERSION=${{ github.event.release.tag_name }}
47+
48+
merge-manifests:
49+
needs: buildImageForNewTag
50+
runs-on: ubuntu-latest
51+
env:
52+
LATEST_TAG: ${{ (github.event.release.target_commitish == 'main') && 'thirdweb/engine:latest' || '' }}
53+
steps:
54+
- name: Login to DockerHub
55+
uses: docker/login-action@v1
56+
with:
57+
username: ${{ secrets.DOCKER_USERNAME }}
58+
password: ${{ secrets.DOCKER_PASSWORD }}
59+
60+
- name: Create and Push Multi-arch Manifest
61+
run: |
62+
docker manifest create thirdweb/engine:${{ github.event.release.tag_name }} \
63+
thirdweb/engine:${{ github.event.release.tag_name }}-linux/amd64 \
64+
thirdweb/engine:${{ github.event.release.tag_name }}-linux/arm64
65+
docker manifest push thirdweb/engine:${{ github.event.release.tag_name }}
66+
67+
- name: Create and Push Latest Tag (if applicable)
68+
if: ${{ env.LATEST_TAG != '' }}
69+
run: |
70+
docker manifest create thirdweb/engine:latest \
71+
thirdweb/engine:${{ github.event.release.tag_name }}-linux/amd64 \
72+
thirdweb/engine:${{ github.event.release.tag_name }}-linux/arm64
73+
docker manifest push thirdweb/engine:latest

0 commit comments

Comments
 (0)