-
Notifications
You must be signed in to change notification settings - Fork 1
191 lines (169 loc) · 5.93 KB
/
Copy pathdocker.yml
File metadata and controls
191 lines (169 loc) · 5.93 KB
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
name: docker
on:
workflow_run:
workflows: [build]
types: [completed]
permissions:
contents: read
jobs:
docker:
if: >-
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push' &&
(github.event.workflow_run.head_branch == 'master' ||
startsWith(github.event.workflow_run.head_branch, 'v'))
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
artifact: linux-amd64
- platform: linux/arm64
runner: ubuntu-24.04-arm
artifact: linux-arm64
runs-on: ${{ matrix.runner }}
permissions:
contents: read
packages: write
steps:
- name: checkout
uses: actions/checkout@v6
with:
ref: ${{ github.event.workflow_run.head_sha }}
persist-credentials: false
- name: set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: login to ghcr.io
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.PKG_TOKEN }}
- name: login to DockerHub
uses: docker/login-action@v4
with:
username: ${{ github.actor }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: build and push to ghcr.io by digest
id: build-ghcr
uses: docker/build-push-action@v7
with:
context: .
platforms: ${{ matrix.platform }}
build-args: |
CI=github
GITHUB_SHA=${{ github.event.workflow_run.head_sha }}
GIT_BRANCH=${{ github.event.workflow_run.head_branch }}
outputs: type=image,name=ghcr.io/ukeeper/ukeeper-readability,push-by-digest=true,name-canonical=true,push=true
- name: build and push to DockerHub by digest
id: build-dockerhub
uses: docker/build-push-action@v7
with:
context: .
platforms: ${{ matrix.platform }}
build-args: |
CI=github
GITHUB_SHA=${{ github.event.workflow_run.head_sha }}
GIT_BRANCH=${{ github.event.workflow_run.head_branch }}
outputs: type=image,name=umputun/ukeeper-readability,push-by-digest=true,name-canonical=true,push=true
- name: export digests
env:
DIGEST_GHCR: ${{ steps.build-ghcr.outputs.digest }}
DIGEST_DOCKERHUB: ${{ steps.build-dockerhub.outputs.digest }}
run: |
mkdir -p /tmp/digests/ghcr /tmp/digests/dockerhub
touch "/tmp/digests/ghcr/${DIGEST_GHCR#sha256:}"
touch "/tmp/digests/dockerhub/${DIGEST_DOCKERHUB#sha256:}"
- name: upload ghcr digest
uses: actions/upload-artifact@v7
with:
name: digests-ghcr-${{ matrix.artifact }}
path: /tmp/digests/ghcr/*
retention-days: 1
- name: upload dockerhub digest
uses: actions/upload-artifact@v7
with:
name: digests-dockerhub-${{ matrix.artifact }}
path: /tmp/digests/dockerhub/*
retention-days: 1
docker-merge:
needs: docker
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: download ghcr digests
uses: actions/download-artifact@v8
with:
path: /tmp/digests/ghcr
pattern: digests-ghcr-*
merge-multiple: true
- name: download dockerhub digests
uses: actions/download-artifact@v8
with:
path: /tmp/digests/dockerhub
pattern: digests-dockerhub-*
merge-multiple: true
- name: verify all digests present
run: |
for registry in ghcr dockerhub; do
expected=2
actual=$(find /tmp/digests/$registry -maxdepth 1 -type f | wc -l)
if [ "$actual" -ne "$expected" ]; then
echo "Expected $expected digests for $registry, found $actual"
ls -la /tmp/digests/$registry
exit 1
fi
done
echo "All digests present"
- name: set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: login to ghcr.io
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.PKG_TOKEN }}
- name: login to DockerHub
uses: docker/login-action@v4
with:
username: ${{ github.actor }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: determine tags
id: tags
env:
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
run: |
ref="${HEAD_BRANCH//\//_}"
echo "ref=${ref}" >> $GITHUB_OUTPUT
if [[ "$HEAD_BRANCH" == v* ]]; then
echo "is_tag=true" >> $GITHUB_OUTPUT
else
echo "is_tag=false" >> $GITHUB_OUTPUT
fi
- name: create ghcr.io manifest and push
working-directory: /tmp/digests/ghcr
env:
REF: ${{ steps.tags.outputs.ref }}
IS_TAG: ${{ steps.tags.outputs.is_tag }}
run: |
tags="-t ghcr.io/ukeeper/ukeeper-readability:${REF}"
if [[ "$IS_TAG" == "true" ]]; then
tags="${tags} -t ghcr.io/ukeeper/ukeeper-readability:latest"
fi
docker buildx imagetools create ${tags} \
$(printf 'ghcr.io/ukeeper/ukeeper-readability@sha256:%s ' *)
- name: create DockerHub manifest and push
working-directory: /tmp/digests/dockerhub
env:
REF: ${{ steps.tags.outputs.ref }}
IS_TAG: ${{ steps.tags.outputs.is_tag }}
run: |
tags="-t umputun/ukeeper-readability:${REF}"
if [[ "$IS_TAG" == "true" ]]; then
tags="${tags} -t umputun/ukeeper-readability:latest"
fi
docker buildx imagetools create ${tags} \
$(printf 'umputun/ukeeper-readability@sha256:%s ' *)