Skip to content

Commit

Permalink
fix: Reduce multi container build action - segment arm64 and amd64 bu…
Browse files Browse the repository at this point in the history
…ilds
  • Loading branch information
epociask committed Dec 16, 2024
1 parent 454f8cd commit 928c57d
Showing 1 changed file with 95 additions and 22 deletions.
117 changes: 95 additions & 22 deletions .github/workflows/docker-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,80 @@ on:
workflow_dispatch:

jobs:
docker:
docker-amd64:
runs-on: linux-2xl

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
install: true

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('Dockerfile') }}
restore-keys: ${{ runner.os }}-buildx-

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/nitro-eigenda
tags: |
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
type=ref,event=tag,suffix={{sha}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=,format=short,enable=true
type=raw,value=latest,enable={{is_default_branch}}
type=match,pattern=^(v\d+\.\d+\.\d+-\w*)\..*$,value=$1,enable={{is_default_branch}}
- name: "Build and push amd64"
uses: docker/[email protected]
with:
target: nitro-node-dev
context: .
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Clear cache on failure
if: failure()
run: |
keys=(${{ runner.os }}-buildx- ${{ runner.os }}-buildx-${{ hashFiles('Dockerfile') }})
for key in "${keys[@]}"; do
curl -X DELETE -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/actions/caches/$key"
done
docker-arm64:
runs-on: linux-xl-arm

steps:
Expand All @@ -20,12 +93,12 @@ jobs:
with:
install: true

# - name: Cache Docker layers
# uses: actions/cache@v3
# with:
# path: /tmp/.buildx-cache
# key: ${{ runner.os }}-buildx-${{ hashFiles('Dockerfile') }}
# restore-keys: ${{ runner.os }}-buildx-
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('Dockerfile') }}
restore-keys: ${{ runner.os }}-buildx-

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
Expand Down Expand Up @@ -60,18 +133,18 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# cache-from: type=local,src=/tmp/.buildx-cache
# cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

# - name: Move cache
# run: |
# rm -rf /tmp/.buildx-cache
# mv /tmp/.buildx-cache-new /tmp/.buildx-cache

# - name: Clear cache on failure
# if: failure()
# run: |
# keys=(${{ runner.os }}-buildx- ${{ runner.os }}-buildx-${{ hashFiles('Dockerfile') }})
# for key in "${keys[@]}"; do
# curl -X DELETE -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/actions/caches/$key"
# done
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Clear cache on failure
if: failure()
run: |
keys=(${{ runner.os }}-buildx- ${{ runner.os }}-buildx-${{ hashFiles('Dockerfile') }})
for key in "${keys[@]}"; do
curl -X DELETE -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/actions/caches/$key"
done

0 comments on commit 928c57d

Please sign in to comment.