@@ -12,6 +12,13 @@ permissions:
12
12
id-token : write
13
13
discussions : write
14
14
15
+ concurrency :
16
+ group : ${{ github.workflow }}-${{ github.ref }}
17
+ cancel-in-progress : true
18
+
19
+ env :
20
+ REGISTRY_IMAGE : ghcr.io/akashrajpurohit/git-sync
21
+
15
22
jobs :
16
23
test :
17
24
name : Test
@@ -55,33 +62,34 @@ jobs:
55
62
env :
56
63
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
57
64
58
- docker_build_and_push :
59
- name : Docker Build & Push
65
+ docker_build :
66
+ name : Docker Build
60
67
runs-on : ubuntu-latest
61
- needs : [test]
62
-
68
+ needs :
69
+ - test
70
+ timeout-minutes : 15
71
+ strategy :
72
+ fail-fast : false
73
+ matrix :
74
+ platform :
75
+ - linux/amd64
76
+ - linux/arm64
77
+ - linux/arm/v7
63
78
steps :
64
- - name : Checkout code
65
- uses : actions/checkout@v4
66
- with :
67
- fetch-depth : 0
68
-
69
- - name : Set env
79
+ - name : Prepare
70
80
run : |
71
- echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
72
- echo "NOW=$(date --utc +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_ENV
73
-
74
- - name : Cache Docker layers
75
- uses : actions/cache@v3
81
+ platform=${{ matrix.platform }}
82
+ echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
83
+
84
+ - name : Docker meta
85
+ id : meta
86
+ uses : docker/metadata-action@v5
76
87
with :
77
- path : /tmp/.buildx-cache
78
- key : ${{ runner.os }}-buildx-${{ github.sha }}
79
- restore-keys : |
80
- ${{ runner.os }}-buildx-
81
-
88
+ images : ${{ env.REGISTRY_IMAGE }}
89
+
82
90
- name : Set up QEMU
83
91
uses : docker/setup-qemu-action@v3
84
-
92
+
85
93
- name : Set up Docker Buildx
86
94
uses : docker/setup-buildx-action@v3
87
95
@@ -91,24 +99,68 @@ jobs:
91
99
registry : ghcr.io
92
100
username : ${{ github.actor }}
93
101
password : ${{ secrets.GITHUB_TOKEN }}
94
-
95
- - name : Build & push Docker image to ghcr.io
96
- uses : docker/build-push-action@v4
102
+
103
+ - name : Build and push by digest
104
+ id : build
105
+ uses : docker/build-push-action@v6
106
+ with :
107
+ platforms : ${{ matrix.platform }}
108
+ labels : ${{ steps.meta.outputs.labels }}
109
+ outputs : type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
110
+ cache-from : type=gha
111
+ cache-to : type=gha,mode=max
112
+
113
+ - name : Export digest
114
+ run : |
115
+ mkdir -p /tmp/digests
116
+ digest="${{ steps.build.outputs.digest }}"
117
+ touch "/tmp/digests/${digest#sha256:}"
118
+
119
+ - name : Upload digest
120
+ uses : actions/upload-artifact@v4
97
121
with :
98
- context : .
99
- push : true
100
- tags : |
101
- - ghcr.io/${{ github.repository }}:${{ env.RELEASE_VERSION }}
102
- - ghcr.io/${{ github.repository }}:latest
103
- platforms : |
104
- - linux/amd64
105
- - linux/arm64
106
- - linux/arm/v7
107
- build-args : |
108
- VERSION=${{ env.RELEASE_VERSION }}
109
- BUILD_DATE=${{ env.NOW }}
110
- cache-from : type=local,src=/tmp/.buildx-cache
111
- cache-to : type=local,dest=/tmp/.buildx-cache-new,mode=max
122
+ name : digests-${{ env.PLATFORM_PAIR }}
123
+ path : /tmp/digests/*
124
+ if-no-files-found : error
125
+ retention-days : 1
112
126
113
- - name : Move new cache to old cache
114
- run : mv /tmp/.buildx-cache-new /tmp/.buildx-cache
127
+ docker_merge :
128
+ name : Docker Merge and Push
129
+ runs-on : ubuntu-latest
130
+ needs :
131
+ - test
132
+ - docker_build
133
+ timeout-minutes : 15
134
+ steps :
135
+ - name : Download digests
136
+ uses : actions/download-artifact@v4
137
+ with :
138
+ path : /tmp/digests
139
+ pattern : digests-*
140
+ merge-multiple : true
141
+
142
+ - name : Set up Docker Buildx
143
+ uses : docker/setup-buildx-action@v3
144
+
145
+ - name : Docker meta
146
+ id : meta
147
+ uses : docker/metadata-action@v5
148
+ with :
149
+ images : ${{ env.REGISTRY_IMAGE }}
150
+
151
+ - name : Login to GitHub Container Registry
152
+ uses : docker/login-action@v3
153
+ with :
154
+ registry : ghcr.io
155
+ username : ${{ github.actor }}
156
+ password : ${{ secrets.GITHUB_TOKEN }}
157
+
158
+ - name : Create manifest list and push
159
+ working-directory : /tmp/digests
160
+ run : |
161
+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
162
+ $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
163
+
164
+ - name : Inspect image
165
+ run : |
166
+ docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
0 commit comments