Skip to content

Commit 2b139ba

Browse files
committed
run separately on amd64 and arm64
1 parent 6dc9d09 commit 2b139ba

1 file changed

Lines changed: 48 additions & 31 deletions

File tree

.github/workflows/docker-publish.yml

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,68 @@ name: Build and Push to Docker Hub
33
on:
44
push:
55
branches: [ "main" ]
6-
pull_request:
7-
branches: [ "main" ]
86

97
jobs:
10-
build-and-push:
11-
runs-on: ubuntu-latest
8+
build:
9+
runs-on: ${{ matrix.arch == 'amd64' && 'ubuntu-latest' || 'ubuntu-24.04-arm64' }}
10+
strategy:
11+
matrix:
12+
arch: [amd64, arm64]
13+
1214
steps:
1315
- name: Checkout code
1416
uses: actions/checkout@v4
1517

16-
# 1. Set up QEMU (Required for multi-platform builds)
17-
- name: Set up QEMU
18-
uses: docker/setup-qemu-action@v3
19-
20-
# 2. Set up Docker Buildx
2118
- name: Set up Docker Buildx
2219
uses: docker/setup-buildx-action@v3
2320

24-
# 3. Login to Docker Hub
2521
- name: Login to Docker Hub
2622
uses: docker/login-action@v3
2723
with:
2824
username: ${{ secrets.DOCKERHUB_USERNAME }}
2925
password: ${{ secrets.DOCKERHUB_API_KEY }}
3026

31-
# 4. Extract metadata
32-
- name: Extract metadata
33-
id: meta
34-
uses: docker/metadata-action@v5
35-
with:
36-
images: cdrl/3podr_container
37-
tags: |
38-
type=ref,event=branch
39-
type=sha,format=short
40-
latest
41-
42-
# 5. Build and Push with Multi-Platform Support
43-
- name: Build and push
44-
uses: docker/build-push-action@v5
27+
- name: Build and push by digest
28+
id: build
29+
uses: docker/build-push-action@v6
4530
with:
4631
context: .
47-
push: true
48-
# This creates a "Manifest List" containing both versions
49-
platforms: linux/amd64, linux/arm64
50-
tags: ${{ steps.meta.outputs.tags }}
51-
labels: ${{ steps.meta.outputs.labels }}
52-
cache-from: type=gha
53-
cache-to: type=gha,mode=max
32+
platforms: linux/${{ matrix.arch }}
33+
outputs: type=image,name=cdrl/3podr_container,push-by-digest=true,name-canonical=true,push=true
34+
35+
- name: Export digest
36+
run: |
37+
mkdir -p /tmp/digests
38+
digest="${{ steps.build.outputs.digest }}"
39+
touch "/tmp/digests/${digest#sha256:}"
40+
41+
- name: Upload digest
42+
uses: actions/upload-artifact@v4
43+
with:
44+
name: digests-${{ matrix.arch }}
45+
path: /tmp/digests/*
46+
if-no-files-found: error
47+
retention-days: 1
48+
49+
merge:
50+
runs-on: ubuntu-latest
51+
needs: build
52+
steps:
53+
- name: Download digests
54+
uses: actions/download-artifact@v4
55+
with:
56+
path: /tmp/digests
57+
pattern: digests-*
58+
merge-multiple: true
59+
60+
- name: Login to Docker Hub
61+
uses: docker/login-action@v3
62+
with:
63+
username: ${{ secrets.DOCKERHUB_USERNAME }}
64+
password: ${{ secrets.DOCKERHUB_API_KEY }}
65+
66+
- name: Create manifest list and push
67+
working-directory: /tmp/digests
68+
run: |
69+
docker buildx imagetools create -t cdrl/3podr_container:latest \
70+
$(printf 'cdrl/3podr_container@sha256:%s ' *)

0 commit comments

Comments
 (0)