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,23 +54,58 @@ 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'
8859 uses : docker/build-push-action@v6
8960 with :
9061 context : .
9162 push : true
92- platforms : ${{ matrix.platform }}
9363 cache-from : type=gha
9464 cache-to : type=gha,mode=max
9565 tags : |
96- ${{ env.IMAGE_NAME }}:${{ github.event.release.tag_name }}-${{ matrix.arch }}
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'
70+ uses : docker/build-push-action@v6
71+ with :
72+ context : .
73+ push : true
74+ cache-from : type=gha
75+ cache-to : type=gha,mode=max
76+ tags : |
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 : Set up Docker Buildx
86+ uses : docker/setup-buildx-action@v3
87+
88+ - name : Login to Docker Hub
89+ uses : docker/login-action@v3
90+ with :
91+ username : ${{ secrets.DOCKERHUB_USERNAME }}
92+ password : ${{ secrets.DOCKERHUB_TOKEN }}
93+
94+ - name : Create and push multi-arch manifest for branch tip
95+ run : |
96+ docker buildx imagetools create \
97+ -t ${{ env.IMAGE_NAME }}:latest-${{ needs.build-matrix.outputs.safe_ref }} \
98+ ${{ env.IMAGE_NAME }}:latest-${{ needs.build-matrix.outputs.safe_ref }}-amd64 \
99+ ${{ env.IMAGE_NAME }}:latest-${{ needs.build-matrix.outputs.safe_ref }}-arm64
100+
101+ create-release-manifest :
100102 if : github.event_name == 'release'
101103 needs : build-matrix
102104 runs-on : ubuntu-latest
103105 steps :
106+ - name : Set up Docker Buildx
107+ uses : docker/setup-buildx-action@v3
108+
104109 - name : Login to Docker Hub
105110 uses : docker/login-action@v3
106111 with :
@@ -109,14 +114,14 @@ jobs:
109114
110115 - name : Create and push multi-arch manifest for release tag
111116 run : |
112- docker manifest create ${{ env.IMAGE_NAME }}:${{ github.event.release.tag_name }} \
113- --amend ${{ env.IMAGE_NAME }}:${{ github.event.release.tag_name }}-amd64 \
114- --amend ${{ env.IMAGE_NAME }}:${{ github.event.release.tag_name }}-arm64
115- docker manifest push ${{ env.IMAGE_NAME }}:${{ github.event.release.tag_name }}
117+ docker buildx imagetools create \
118+ -t ${{ env.IMAGE_NAME }}:${{ github.event.release.tag_name }} \
119+ ${{ env.IMAGE_NAME }}:${{ github.event.release.tag_name }}-amd64 \
120+ ${{ env.IMAGE_NAME }}:${{ github.event.release.tag_name }}-arm64
116121
117122 - name : Create and push multi-arch manifest for latest tag
118123 run : |
119- docker manifest create ${{ env.IMAGE_NAME }}:latest \
120- --amend ${{ env.IMAGE_NAME }}:latest-amd64 \
121- --amend ${{ env.IMAGE_NAME }}:latest-arm64
122- docker manifest push ${{ env.IMAGE_NAME }}:latest
124+ docker buildx imagetools create \
125+ -t ${{ env.IMAGE_NAME }}:latest \
126+ ${{ env.IMAGE_NAME }}:latest-amd64 \
127+ ${{ env.IMAGE_NAME }}:latest-arm64
0 commit comments