-
Notifications
You must be signed in to change notification settings - Fork 3
298 lines (284 loc) · 10.7 KB
/
publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
name: publish
on:
push:
branches: ['main']
tags: ['v*.*.*']
concurrency: ${{ github.ref }}
env:
DOCKER_IMAGE_NAME: blinklabs/cardano-db-sync
GHCR_IMAGE_NAME: ghcr.io/blinklabs-io/cardano-db-sync
jobs:
build-amd64:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: blinklabs
password: ${{ secrets.DOCKER_PASSWORD }} # uses token
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-${{ runner.arch }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ runner.arch }}-buildx-
- id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKER_IMAGE_NAME }}
${{ env.GHCR_IMAGE_NAME }}
flavor: |
latest=false
suffix=-amd64
tags: |
# Only version, no revision
type=match,pattern=v(.*)-(.*),group=1
# Full version, with revision
type=match,pattern=v(.*),group=1
# branch
type=ref,event=branch
# semver
type=semver,pattern={{version}}
- name: push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
# TEMP fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
# TEMP fix
# Something strange is happening with the manifests when we push which
# breaks the downstream multi-arch-manifest, so pull and push to work
# around this by resubmitting manifests
- name: pull-and-push
run: |
for t in `echo '${{ steps.meta.outputs.tags }}'`; do
docker pull $t && docker push $t
done
build-arm64:
runs-on: ["self-hosted", "ARM64"]
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: blinklabs
password: ${{ secrets.DOCKER_PASSWORD }} # uses token
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-${{ runner.arch }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ runner.arch }}-buildx-
- id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKER_IMAGE_NAME }}
${{ env.GHCR_IMAGE_NAME }}
flavor: |
latest=false
suffix=-arm64v8
tags: |
# Only version, no revision
type=match,pattern=v(.*)-(.*),group=1
# branch
type=ref,event=branch
# semver
type=semver,pattern={{version}}
- name: push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
# TEMP fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
# TEMP fix
# Something strange is happening with the manifests when we push which
# breaks the downstream multi-arch-manifest, so pull and push to work
# around this by resubmitting manifests
- name: pull-and-push
run: |
for t in `echo '${{ steps.meta.outputs.tags }}'`; do
docker pull $t && docker push $t
done
multi-arch-manifest:
runs-on: ubuntu-latest
needs: [build-amd64, build-arm64]
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: blinklabs
password: ${{ secrets.DOCKER_PASSWORD }} # uses token
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: meta-dockerhub
name: Metadata - Docker Hub
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_IMAGE_NAME }}
flavor: |
latest=false
tags: |
# Only version, no revision
type=match,pattern=v(.*)-(.*),group=1
# branch
type=ref,event=branch
# semver
type=semver,pattern={{version}}
- id: meta-dockerhub-tag
name: Metadata - Docker Hub (Tags)
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKER_IMAGE_NAME }}
flavor: |
latest=false
tags: |
# Only version, no revision
type=match,pattern=v(.*)-(.*),group=1
- id: meta-ghcr
name: Metadata - GHCR
uses: docker/metadata-action@v5
with:
images: ${{ env.GHCR_IMAGE_NAME }}
flavor: |
latest=false
tags: |
# Only version, no revision
type=match,pattern=v(.*)-(.*),group=1
# branch
type=ref,event=branch
# semver
type=semver,pattern={{version}}
- id: meta-ghcr-tag
name: Metadata - GHCR (Tags)
uses: docker/metadata-action@v5
with:
images: |
${{ env.GHCR_IMAGE_NAME }}
flavor: |
latest=false
tags: |
# Only version, no revision
type=match,pattern=v(.*)-(.*),group=1
# First, create manifests and push to GHCR
# Manifest for either branch or semver
- name: manifest-ghcr
run: docker manifest create ${{ steps.meta-ghcr.outputs.tags }} --amend ${{ steps.meta-ghcr.outputs.tags }}-amd64 --amend ${{ steps.meta-ghcr.outputs.tags }}-arm64v8
# Optional manifest for latest
- name: manifest-ghcr-latest
run: docker manifest create ${{ env.GHCR_IMAGE_NAME }}:latest --amend ${{ steps.meta-ghcr.outputs.tags }}-amd64 --amend ${{ steps.meta-ghcr.outputs.tags }}-arm64v8
if: startsWith(github.ref, 'refs/tags/') && ! contains(github.ref, '-pre-')
# Optional manifest for tag versions (includes revisions)
- name: manifest-ghcr-tags
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
if: startsWith(github.ref, 'refs/tags/')
# Push various manifests
- name: push-ghcr
run: docker manifest push ${{ steps.meta-ghcr.outputs.tags }}
- name: push-ghcr-latest
run: docker manifest push ${{ env.GHCR_IMAGE_NAME }}:latest
if: startsWith(github.ref, 'refs/tags/') && ! contains(github.ref, '-pre-')
- name: push-ghcr-tags
run: docker manifest push ${{ steps.meta-ghcr-tag.outputs.tags }}
if: startsWith(github.ref, 'refs/tags/')
# Now, create manifests for Docker Hub
- name: manifest-dockerhub
run: docker manifest create ${{ steps.meta-dockerhub.outputs.tags }} --amend ${{ steps.meta-dockerhub.outputs.tags }}-amd64 --amend ${{ steps.meta-dockerhub.outputs.tags }}-arm64v8
- name: manifest-dockerhub-latest
run: docker manifest create ${{ env.DOCKER_IMAGE_NAME }}:latest --amend ${{ steps.meta-dockerhub.outputs.tags }}-amd64 --amend ${{ steps.meta-dockerhub.outputs.tags }}-arm64v8
if: startsWith(github.ref, 'refs/tags/') && ! contains(github.ref, '-pre-')
- name: manifest-dockerhub-tags
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
if: startsWith(github.ref, 'refs/tags/')
- name: push-dockerhub
run: docker manifest push ${{ steps.meta-dockerhub.outputs.tags }}
- name: push-dockerhub-latest
run: docker manifest push ${{ env.DOCKER_IMAGE_NAME }}:latest
if: startsWith(github.ref, 'refs/tags/') && ! contains(github.ref, '-pre-')
- name: push-dockerhub-tags
run: docker manifest push ${{ steps.meta-dockerhub-tag.outputs.tags }}
if: startsWith(github.ref, 'refs/tags/')
# Update Docker Hub from README
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v4
with:
username: blinklabs
password: ${{ secrets.DOCKER_PASSWORD }}
repository: ${{ env.DOCKER_IMAGE_NAME }}
readme-filepath: ./README.md
short-description: "Cardano DB-sync built from source on Debian"
github-release:
runs-on: ubuntu-latest
needs: [multi-arch-manifest]
steps:
- run: "echo \"RELEASE_TAG=${GITHUB_REF#refs/tags/}\" >> $GITHUB_ENV"
- uses: actions/github-script@v7
if: startsWith(github.ref, 'refs/tags/')
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
await github.rest.repos.createRelease({
draft: false,
generate_release_notes: true,
name: process.env.RELEASE_TAG,
owner: context.repo.owner,
prerelease: ${{ (startsWith(github.ref, 'refs/tags/') && contains(github.ref, '-pre-')) && true || false }},
repo: context.repo.repo,
tag_name: process.env.RELEASE_TAG,
});
} catch (error) {
core.setFailed(error.message);
}