Skip to content

Commit

Permalink
Refactor build workflows to run mult-architecture build via matrix (#674
Browse files Browse the repository at this point in the history
)

* Refactor build workflows to run mult-architecture build via matrix

* split build cache based on architecture
  • Loading branch information
d4mr authored Sep 26, 2024
1 parent bb8b756 commit 0ed46cc
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 18 deletions.
39 changes: 30 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Main Branch Build Workflow for Docker Image supporting multiple architectures
name: Build on Main Merge
name: Build Nightly on Main Merge

on:
push:
Expand All @@ -8,13 +7,14 @@ on:

jobs:
build:
runs-on: ubuntu-latest-32
runs-on: ubuntu-latest
strategy:
matrix:
platform: [linux/amd64, linux/arm64]

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: main # checkout the main branch to build nightly

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand All @@ -30,10 +30,31 @@ jobs:
with:
context: .
target: prod
platforms: linux/amd64,linux/arm64
platforms: ${{ matrix.platform }}
push: true
tags: thirdweb/engine:nightly
cache-from: type=gha
cache-to: type=gha,mode=max
cache-from: |
type=gha,scope=${{ matrix.platform }}
type=registry,ref=thirdweb/engine:buildcache-${{ matrix.platform }}
cache-to: |
type=gha,scope=${{ matrix.platform }},mode=max
type=registry,ref=thirdweb/engine:buildcache-${{ matrix.platform }},mode=max
tags: thirdweb/engine:nightly-${{ matrix.platform }}
build-args: |
ENGINE_VERSION=nightly
merge-manifests:
needs: build
runs-on: ubuntu-latest
steps:
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Create and Push Multi-arch Manifest (nightly)
run: |
docker manifest create thirdweb/engine:nightly \
thirdweb/engine:nightly-linux/amd64 \
thirdweb/engine:nightly-linux/arm64
docker manifest push thirdweb/engine:nightly
48 changes: 39 additions & 9 deletions .github/workflows/tagBasedImageBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ on:

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

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

- name: Set up Docker Buildx
Expand All @@ -32,12 +33,41 @@ jobs:
with:
context: .
target: prod
platforms: linux/amd64,linux/arm64
platforms: ${{ matrix.platform }}
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
thirdweb/engine:${{ github.event.release.tag_name }}
${{ env.LATEST_TAG }}
cache-from: |
type=gha,scope=${{ matrix.platform }}
type=registry,ref=thirdweb/engine:buildcache-${{ matrix.platform }}
cache-to: |
type=gha,scope=${{ matrix.platform }},mode=max
type=registry,ref=thirdweb/engine:buildcache-${{ matrix.platform }},mode=max
tags: thirdweb/engine:${{ github.event.release.tag_name }}-${{ matrix.platform }}
build-args: |
ENGINE_VERSION=${{ github.event.release.tag_name }}
merge-manifests:
needs: buildImageForNewTag
runs-on: ubuntu-latest
env:
LATEST_TAG: ${{ (github.event.release.target_commitish == 'main') && 'thirdweb/engine:latest' || '' }}
steps:
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Create and Push Multi-arch Manifest
run: |
docker manifest create thirdweb/engine:${{ github.event.release.tag_name }} \
thirdweb/engine:${{ github.event.release.tag_name }}-linux/amd64 \
thirdweb/engine:${{ github.event.release.tag_name }}-linux/arm64
docker manifest push thirdweb/engine:${{ github.event.release.tag_name }}
- name: Create and Push Latest Tag (if applicable)
if: ${{ env.LATEST_TAG != '' }}
run: |
docker manifest create thirdweb/engine:latest \
thirdweb/engine:${{ github.event.release.tag_name }}-linux/amd64 \
thirdweb/engine:${{ github.event.release.tag_name }}-linux/arm64
docker manifest push thirdweb/engine:latest

0 comments on commit 0ed46cc

Please sign in to comment.