@@ -3,16 +3,15 @@ name: publish
33on :
44 push :
55 branches : ['main']
6- release :
7- types : ['published']
6+ tags : ['v*.*.*']
87
98concurrency : ${{ github.ref }}
109
1110env :
12- REGISTRY : ghcr.io
1311 IMAGE_NAME : cloudstruct/cardano-db-sync
1412
1513jobs :
14+
1615 build-amd64 :
1716 runs-on : ubuntu-latest
1817 permissions :
@@ -21,32 +20,56 @@ jobs:
2120 steps :
2221 - uses : actions/checkout@v2
2322 - uses : docker/setup-buildx-action@v1
24- - name : login
23+ - name : Login to Docker Hub
24+ uses : docker/login-action@v1
25+ with :
26+ username : cloudstruct
27+ password : ${{ secrets.DOCKER_PASSWORD }} # uses token
28+ - name : Login to GHCR
2529 uses : docker/login-action@v1
2630 with :
27- registry : ${{ env.REGISTRY }}
31+ registry : ghcr.io
2832 username : ${{ github.actor }}
2933 password : ${{ secrets.GITHUB_TOKEN }}
34+ - uses : actions/cache@v3
35+ with :
36+ path : /tmp/.buildx-cache
37+ key : ${{ runner.os }}-${{ runner.arch }}-buildx-${{ github.sha }}
38+ restore-keys : |
39+ ${{ runner.os }}-${{ runner.arch }}-buildx-
3040 - id : meta
3141 uses : docker/metadata-action@v3
3242 with :
33- images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
43+ images : |
44+ ${{ env.IMAGE_NAME }}
45+ ghcr.io/${{ env.IMAGE_NAME }}
3446 flavor : |
3547 latest=false
48+ suffix=-amd64
3649 tags : |
37- type=schedule,suffix=-amd64
38- type=ref,event=branch,suffix=-amd64
39- type=ref,event=tag,suffix=-amd64
40- type=ref,event=pr,suffix=-amd64
50+ # Only version, no revision
51+ type=match,pattern=v(.*)-(.*),group=1
52+ # branch
53+ type=ref,event=branch
54+ # semver
55+ type=semver,pattern={{version}}
4156 - name : push
4257 uses : docker/build-push-action@v2
4358 with :
4459 context : .
4560 push : true
4661 tags : ${{ steps.meta.outputs.tags }}
4762 labels : ${{ steps.meta.outputs.labels }}
48- cache-from : type=gha
49- cache-to : type=gha,mode=max
63+ cache-from : type=local,src=/tmp/.buildx-cache
64+ cache-to : type=local,dest=/tmp/.buildx-cache-new,mode=max
65+ # TEMP fix
66+ # https://github.com/docker/build-push-action/issues/252
67+ # https://github.com/moby/buildkit/issues/1896
68+ - name : cache
69+ run : |
70+ rm -rf /tmp/.buildx-cache
71+ mv /tmp/.buildx-cache-new /tmp/.buildx-cache
72+
5073 build-arm64 :
5174 runs-on : self-hosted
5275 permissions :
@@ -55,32 +78,56 @@ jobs:
5578 steps :
5679 - uses : actions/checkout@v2
5780 - uses : docker/setup-buildx-action@v1
58- - name : login
81+ - name : Login to Docker Hub
82+ uses : docker/login-action@v1
83+ with :
84+ username : cloudstruct
85+ password : ${{ secrets.DOCKER_PASSWORD }} # uses token
86+ - name : Login to GHCR
5987 uses : docker/login-action@v1
6088 with :
61- registry : ${{ env.REGISTRY }}
89+ registry : ghcr.io
6290 username : ${{ github.actor }}
6391 password : ${{ secrets.GITHUB_TOKEN }}
92+ - uses : actions/cache@v3
93+ with :
94+ path : /tmp/.buildx-cache
95+ key : ${{ runner.os }}-${{ runner.arch }}-buildx-${{ github.sha }}
96+ restore-keys : |
97+ ${{ runner.os }}-${{ runner.arch }}-buildx-
6498 - id : meta
6599 uses : docker/metadata-action@v3
66100 with :
67- images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
101+ images : |
102+ ${{ env.IMAGE_NAME }}
103+ ghcr.io/${{ env.IMAGE_NAME }}
68104 flavor : |
69105 latest=false
106+ suffix=-arm64v8
70107 tags : |
71- type=schedule,suffix=-arm64v8
72- type=ref,event=branch,suffix=-arm64v8
73- type=ref,event=tag,suffix=-arm64v8
74- type=ref,event=pr,suffix=-arm64v8
108+ # Only version, no revision
109+ type=match,pattern=v(.*)-(.*),group=1
110+ # branch
111+ type=ref,event=branch
112+ # semver
113+ type=semver,pattern={{version}}
75114 - name : push
76115 uses : docker/build-push-action@v2
77116 with :
78117 context : .
79118 push : true
80119 tags : ${{ steps.meta.outputs.tags }}
81120 labels : ${{ steps.meta.outputs.labels }}
82- cache-from : type=gha
83- cache-to : type=gha,mode=max
121+ cache-from : type=local,src=/tmp/.buildx-cache
122+ cache-to : type=local,dest=/tmp/.buildx-cache-new,mode=max
123+ # TEMP fix
124+ # https://github.com/docker/build-push-action/issues/252
125+ # https://github.com/moby/buildkit/issues/1896
126+ - name : cache
127+ run : |
128+ rm -rf /tmp/.buildx-cache
129+ mv /tmp/.buildx-cache-new /tmp/.buildx-cache
130+
84131 multi-arch-manifest :
85132 runs-on : ubuntu-latest
86133 needs : [build-amd64, build-arm64]
@@ -90,22 +137,129 @@ jobs:
90137 steps :
91138 - uses : actions/checkout@v2
92139 - uses : docker/setup-buildx-action@v1
93- - name : login
140+ - name : Login to Docker Hub
94141 uses : docker/login-action@v1
95142 with :
96- registry : ${{ env.REGISTRY }}
143+ username : cloudstruct
144+ password : ${{ secrets.DOCKER_PASSWORD }} # uses token
145+ - name : Login to GHCR
146+ uses : docker/login-action@v1
147+ with :
148+ registry : ghcr.io
97149 username : ${{ github.actor }}
98150 password : ${{ secrets.GITHUB_TOKEN }}
99- - id : meta
151+ - id : meta-dockerhub
152+ name : Metadata - Docker Hub
100153 uses : docker/metadata-action@v3
101154 with :
102- images : ${{ env.REGISTRY }}/${{ env. IMAGE_NAME }}
155+ images : ${{ env.IMAGE_NAME }}
103156 flavor : |
104157 latest=false
105158 tags : |
159+ # branch
106160 type=ref,event=branch
107- type=ref,event=tag
108- - name : manifest
109- run : docker manifest create ${{ steps.meta.outputs.tags }} --amend ${{ steps.meta.outputs.tags }}-amd64 --amend ${{ steps.meta.outputs.tags }}-arm64v8
110- - name : push
111- run : docker manifest push ${{ steps.meta.outputs.tags }}
161+ # semver
162+ type=semver,pattern={{version}}
163+ - id : meta-dockerhub-tag
164+ name : Metadata - Docker Hub (Tags)
165+ uses : docker/metadata-action@v3
166+ with :
167+ images : |
168+ ${{ env.IMAGE_NAME }}
169+ flavor : |
170+ latest=false
171+ tags : |
172+ # Only version, no revision
173+ type=match,pattern=v(.*)-(.*),group=1
174+ - id : meta-ghcr
175+ name : Metadata - GHCR
176+ uses : docker/metadata-action@v3
177+ with :
178+ images : ghcr.io/${{ env.IMAGE_NAME }}
179+ flavor : |
180+ latest=false
181+ tags : |
182+ # branch
183+ type=ref,event=branch
184+ # semver
185+ type=semver,pattern={{version}}
186+ - id : meta-ghcr-tag
187+ name : Metadata - GHCR (Tags)
188+ uses : docker/metadata-action@v3
189+ with :
190+ images : |
191+ ghcr.io/${{ env.IMAGE_NAME }}
192+ flavor : |
193+ latest=false
194+ tags : |
195+ # Only version, no revision
196+ type=match,pattern=v(.*)-(.*),group=1
197+ # Manifest for either branch or semver
198+ - name : manifest-dockerhub
199+ run : docker manifest create ${{ steps.meta-dockerhub.outputs.tags }} --amend ${{ steps.meta-dockerhub.outputs.tags }}-amd64 --amend ${{ steps.meta-dockerhub.outputs.tags }}-arm64v8
200+ - name : manifest-ghcr
201+ run : docker manifest create ${{ steps.meta-ghcr.outputs.tags }} --amend ${{ steps.meta-ghcr.outputs.tags }}-amd64 --amend ${{ steps.meta-ghcr.outputs.tags }}-arm64v8
202+ # Optional manifest for latest
203+ - name : manifest-dockerhub-latest
204+ run : docker manifest create ${{ env.IMAGE_NAME }}:latest --amend ${{ steps.meta-dockerhub.outputs.tags }}-amd64 --amend ${{ steps.meta-dockerhub.outputs.tags }}-arm64v8
205+ if : startsWith(github.ref, 'refs/tags/')
206+ - name : manifest-ghcr-latest
207+ run : docker manifest create ghcr.io/${{ env.IMAGE_NAME }}:latest --amend ${{ steps.meta-ghcr.outputs.tags }}-amd64 --amend ${{ steps.meta-ghcr.outputs.tags }}-arm64v8
208+ if : startsWith(github.ref, 'refs/tags/')
209+ # Optional manifest for tag versions (includes revisions)
210+ - name : manifest-dockerhub-tags
211+ run : docker manifest create ${{ steps.meta-dockerhub-tag.outputs.tags }} --amend ${{ steps.meta-dockerhub-tag.outputs.tags }}-amd64 --amend ${{ steps.meta-dockerhub-tag.outputs.tags }}-arm64v8
212+ if : startsWith(github.ref, 'refs/tags/')
213+ - name : manifest-ghcr-tags
214+ run : docker manifest create ${{ steps.meta-ghcr-tag.outputs.tags }} --amend ${{ steps.meta-ghcr-tag.outputs.tags }}-amd64 --amend ${{ steps.meta-ghcr-tag.outputs.tags }}-arm64v8
215+ if : startsWith(github.ref, 'refs/tags/')
216+ # Push various manifests
217+ - name : push-dockerhub
218+ run : docker manifest push ${{ steps.meta-dockerhub.outputs.tags }}
219+ - name : push-ghcr
220+ run : docker manifest push ${{ steps.meta-ghcr.outputs.tags }}
221+ - name : push-dockerhub-latest
222+ run : docker manifest push ${{ env.IMAGE_NAME }}:latest
223+ if : startsWith(github.ref, 'refs/tags/')
224+ - name : push-ghcr-latest
225+ run : docker manifest push ghcr.io/${{ env.IMAGE_NAME }}:latest
226+ if : startsWith(github.ref, 'refs/tags/')
227+ - name : push-dockerhub-tags
228+ run : docker manifest push ${{ steps.meta-dockerhub-tag.outputs.tags }}
229+ if : startsWith(github.ref, 'refs/tags/')
230+ - name : push-ghcr-tags
231+ run : docker manifest push ${{ steps.meta-ghcr-tag.outputs.tags }}
232+ if : startsWith(github.ref, 'refs/tags/')
233+ # Update Docker Hub from README
234+ - name : Docker Hub Description
235+ uses : peter-evans/dockerhub-description@v3
236+ with :
237+ username : cloudstruct
238+ password : ${{ secrets.DOCKER_PASSWORD }}
239+ repository : ${{ env.IMAGE_NAME }}
240+ readme-filepath : ./README.md
241+ short-description : " Cardano Node built from source on Debian"
242+
243+ github-release :
244+ runs-on : ubuntu-latest
245+ needs : [multi-arch-manifest]
246+ steps :
247+ - run : " echo \" RELEASE_TAG=${GITHUB_REF#refs/tags/}\" >> $GITHUB_ENV"
248+ - uses : actions/github-script@v5
249+ if : startsWith(github.ref, 'refs/tags/')
250+ with :
251+ github-token : ${{ secrets.GITHUB_TOKEN }}
252+ script : |
253+ try {
254+ await github.rest.repos.createRelease({
255+ draft: false,
256+ generate_release_notes: true,
257+ name: process.env.RELEASE_TAG,
258+ owner: context.repo.owner,
259+ prerelease: false,
260+ repo: context.repo.repo,
261+ tag_name: process.env.RELEASE_TAG,
262+ });
263+ } catch (error) {
264+ core.setFailed(error.message);
265+ }
0 commit comments