@@ -2,12 +2,22 @@ name: Build and Push Docker image to GHCR
22
33on :
44 push :
5- branches : [dev]
5+ branches : [dev, main ]
66 workflow_dispatch :
77
88jobs :
9- build-and-push :
10- runs-on : ubuntu-latest
9+ build :
10+ strategy :
11+ matrix :
12+ include :
13+ - arch : amd64
14+ runner : ubuntu-latest
15+ platform : linux/amd64
16+ - arch : arm64
17+ runner : ubuntu-24.04-arm
18+ platform : linux/arm64
19+
20+ runs-on : ${{ matrix.runner }}
1121 permissions :
1222 contents : read
1323 packages : write
1626 - name : Checkout code
1727 uses : actions/checkout@v4
1828
19- - name : Set up QEMU
20- uses : docker/setup-qemu-action@v3
21-
2229 - name : Set up Docker Buildx
2330 uses : docker/setup-buildx-action@v3
2431
@@ -32,13 +39,60 @@ jobs:
3239 - name : Set lowercase image name
3340 id : meta
3441 run : |
35- IMAGE_NAME="ghcr.io/${GITHUB_REPOSITORY,,}:latest"
42+ IMAGE_NAME="ghcr.io/${GITHUB_REPOSITORY,,}"
43+ BRANCH_TAG="${GITHUB_REF_NAME}"
3644 echo "image=$IMAGE_NAME" >> $GITHUB_OUTPUT
45+ echo "branch_tag=$BRANCH_TAG" >> $GITHUB_OUTPUT
3746
38- - name : Build and push Docker image
47+ - name : Build and push image (${{ matrix.arch }})
3948 uses : docker/build-push-action@v5
4049 with :
4150 context : .
4251 push : true
43- platforms : linux/amd64,linux/arm64
44- tags : ${{ steps.meta.outputs.image }}
52+ platforms : ${{ matrix.platform }}
53+ tags : |
54+ ${{ steps.meta.outputs.image }}:${{ github.sha }}-${{ matrix.arch }}
55+ ${{ steps.meta.outputs.image }}:${{ steps.meta.outputs.branch_tag }}-${{ matrix.arch }}
56+ cache-from : type=gha
57+ cache-to : type=gha,mode=max
58+
59+ merge-manifest :
60+ runs-on : ubuntu-latest
61+ needs : build
62+ steps :
63+ - name : Log in to GHCR
64+ uses : docker/login-action@v3
65+ with :
66+ registry : ghcr.io
67+ username : ${{ github.actor }}
68+ password : ${{ secrets.GITHUB_TOKEN }}
69+
70+ - name : Set lowercase image name
71+ id : meta
72+ run : |
73+ IMAGE_NAME="ghcr.io/${GITHUB_REPOSITORY,,}"
74+ BRANCH_TAG="${GITHUB_REF_NAME}"
75+ echo "image=$IMAGE_NAME" >> $GITHUB_OUTPUT
76+ echo "branch_tag=$BRANCH_TAG" >> $GITHUB_OUTPUT
77+
78+ - name : Create and push multi-arch manifests
79+ run : |
80+ # SHA tag
81+ docker manifest create ${{ steps.meta.outputs.image }}:${{ github.sha }} \
82+ --amend ${{ steps.meta.outputs.image }}:${{ github.sha }}-amd64 \
83+ --amend ${{ steps.meta.outputs.image }}:${{ github.sha }}-arm64
84+ docker manifest push ${{ steps.meta.outputs.image }}:${{ github.sha }}
85+
86+ # Branch tag
87+ docker manifest create ${{ steps.meta.outputs.image }}:${{ steps.meta.outputs.branch_tag }} \
88+ --amend ${{ steps.meta.outputs.image }}:${{ steps.meta.outputs.branch_tag }}-amd64 \
89+ --amend ${{ steps.meta.outputs.image }}:${{ steps.meta.outputs.branch_tag }}-arm64
90+ docker manifest push ${{ steps.meta.outputs.image }}:${{ steps.meta.outputs.branch_tag }}
91+
92+ # Dev branch gets latest
93+ if [ "${{ github.ref_name }}" = "dev" ]; then
94+ docker manifest create ${{ steps.meta.outputs.image }}:latest \
95+ --amend ${{ steps.meta.outputs.image }}:${{ github.sha }}-amd64 \
96+ --amend ${{ steps.meta.outputs.image }}:${{ github.sha }}-arm64
97+ docker manifest push ${{ steps.meta.outputs.image }}:latest
98+ fi
0 commit comments