2525 types : [ published ]
2626
2727jobs :
28- build :
29- if : github.event_name != 'release'
30- runs-on : ubuntu-latest
31- steps :
32- - &checkout-step
33- name : Check out repository
34- uses : actions/checkout@v4
35-
36- - &setup-qemu-step
37- name : Set up QEMU
38- uses : docker/setup-qemu-action@v3
39-
40- - &login-step
41- name : Login to Docker Hub
42- uses : docker/login-action@v3
43- with :
44- username : ${{ secrets.DOCKERHUB_USERNAME }}
45- password : ${{ secrets.DOCKERHUB_TOKEN }}
46-
47- - &setup-buildx-step
48- name : Set up Docker Buildx
49- uses : docker/setup-buildx-action@v3
50-
51- - name : Build and push
52- uses : docker/build-push-action@v6
53- with :
54- context : .
55- push : true
56- platforms : linux/amd64
57- cache-from : type=gha
58- cache-to : type=gha,mode=max
59- tags : |
60- ${{ env.IMAGE_NAME }}:latest-${{ github.ref_name }}
61-
6228 build-matrix :
63- if : github.event_name == 'release'
29+ if : github.event_name != 'pull_request'
30+ outputs :
31+ safe_ref : ${{ steps.ref.outputs.safe_ref }}
6432 runs-on : ${{ matrix.runner }}
6533 strategy :
6634 matrix :
6735 include :
6836 - arch : amd64
69- platform : linux/amd64
70- runner : ubuntu-latest
37+ runner : ubuntu-22.04
7138 - arch : arm64
72- platform : linux/arm64
73- runner : ubuntu-latest-arm64
39+ runner : ubuntu-22.04-arm
7440 steps :
7541 - name : Check out repository
7642 uses : actions/checkout@v4
7743
44+ - name : Prepare ref name
45+ id : ref
46+ run : echo "safe_ref=${GITHUB_REF_NAME//\//-}" >> "$GITHUB_OUTPUT"
47+
7848 - name : Login to Docker Hub
7949 uses : docker/login-action@v3
8050 with :
@@ -84,19 +54,48 @@ jobs:
8454 - name : Set up Docker Buildx
8555 uses : docker/setup-buildx-action@v3
8656
87- - name : Build and push architecture-specific image
57+ - name : Build and push branch images
58+ if : github.event_name == 'push'
59+ uses : docker/build-push-action@v6
60+ with :
61+ context : .
62+ push : true
63+ cache-from : type=gha
64+ cache-to : type=gha,mode=max
65+ tags : |
66+ ${{ env.IMAGE_NAME }}:latest-${{ steps.ref.outputs.safe_ref }}-${{ matrix.arch }}
67+
68+ - name : Build and push release images
69+ if : github.event_name == 'release'
8870 uses : docker/build-push-action@v6
8971 with :
9072 context : .
9173 push : true
92- platforms : ${{ matrix.platform }}
9374 cache-from : type=gha
9475 cache-to : type=gha,mode=max
9576 tags : |
96- ${{ env.IMAGE_NAME }}:${{ github.event.release.tag_name }}-${{ matrix.arch }}
77+ ${{ env.IMAGE_NAME }}:${{ steps.ref.outputs.safe_ref }}-${{ matrix.arch }}
9778 ${{ env.IMAGE_NAME }}:latest-${{ matrix.arch }}
9879
99- create-manifest :
80+ create-branch-manifest :
81+ if : github.event_name == 'push'
82+ needs : build-matrix
83+ runs-on : ubuntu-latest
84+ steps :
85+ - name : Login to Docker Hub
86+ uses : docker/login-action@v3
87+ with :
88+ username : ${{ secrets.DOCKERHUB_USERNAME }}
89+ password : ${{ secrets.DOCKERHUB_TOKEN }}
90+
91+ - name : Create and push multi-arch manifest for branch tip
92+ run : |
93+ docker manifest create ${{ env.IMAGE_NAME }}:latest-${{ needs.build-matrix.outputs.safe_ref }} \
94+ --amend ${{ env.IMAGE_NAME }}:latest-${{ needs.build-matrix.outputs.safe_ref }}-amd64 \
95+ --amend ${{ env.IMAGE_NAME }}:latest-${{ needs.build-matrix.outputs.safe_ref }}-arm64
96+ docker manifest push ${{ env.IMAGE_NAME }}:latest-${{ needs.build-matrix.outputs.safe_ref }}
97+
98+ create-release-manifest :
10099 if : github.event_name == 'release'
101100 needs : build-matrix
102101 runs-on : ubuntu-latest
0 commit comments