-
Notifications
You must be signed in to change notification settings - Fork 49
269 lines (237 loc) · 10.1 KB
/
docker.yml
File metadata and controls
269 lines (237 loc) · 10.1 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
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
name: Dockerfiles
# Test and push dockerfiles when merged into main and on schedule.
on:
schedule:
# * is a special character in YAML so you have to quote this string
- cron: "0 0 1 * *"
push:
branches:
- main
workflow_dispatch:
# Cancel in-progress funs of the same workflow
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
targets:
runs-on: ubuntu-latest
outputs:
amd64: ${{ steps.amd64.outputs.distros }}
arm64: ${{ steps.arm64.outputs.distros }}
has_changes: ${{ steps.filter.outputs.docker == 'true' }}
dockerhub-rate-limit-before: ${{ steps.dockerhub_rate_before.outputs.rate_limit }}
dockerhub-rate-remaining-before: ${{ steps.dockerhub_rate_before.outputs.rate_remaining }}
dockerhub-rate-source-before: ${{ steps.dockerhub_rate_before.outputs.source }}
steps:
- uses: actions/checkout@v6
- name: Docker Hub rate limit (before)
id: dockerhub_rate_before
env:
DOCKERHUB_USERNAME: ${{ vars.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
shell: bash
continue-on-error: true
run: |
image_ref="library/alpine"
token_url="https://auth.docker.io/token?service=registry.docker.io&scope=repository:${image_ref}:pull"
source="anonymous"
token=""
if [[ -n "${DOCKERHUB_USERNAME}" && -n "${DOCKERHUB_PASSWORD}" ]]; then
source="authenticated"
token="$(curl -fsSL -u "${DOCKERHUB_USERNAME}:${DOCKERHUB_PASSWORD}" "${token_url}" | python3 -c 'import sys,json; print(json.load(sys.stdin).get("token",""))' || true)"
else
token="$(curl -fsSL "${token_url}" | python3 -c 'import sys,json; print(json.load(sys.stdin).get("token",""))' || true)"
fi
if [[ -z "${token}" ]]; then
echo "Unable to fetch Docker Hub token for rate-limit check."
exit 0
fi
headers="$(mktemp)"
curl -fsSI \
-H "Authorization: Bearer ${token}" \
-H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
"https://registry-1.docker.io/v2/${image_ref}/manifests/latest" > "${headers}" || true
rate_limit="$(grep -i '^ratelimit-limit:' "${headers}" | tail -n 1 | cut -d':' -f2- | xargs || true)"
rate_remaining="$(grep -i '^ratelimit-remaining:' "${headers}" | tail -n 1 | cut -d':' -f2- | xargs || true)"
echo "source=${source}" >> "$GITHUB_OUTPUT"
echo "rate_limit=${rate_limit}" >> "$GITHUB_OUTPUT"
echo "rate_remaining=${rate_remaining}" >> "$GITHUB_OUTPUT"
{
echo "### Docker Hub Rate Limit (Before)"
echo "- Source: \`${source}\`"
echo "- Limit: \`${rate_limit:-unknown}\`"
echo "- Remaining: \`${rate_remaining:-unknown}\`"
} >> "$GITHUB_STEP_SUMMARY"
- name: Find changed files
uses: dorny/paths-filter@v3
id: filter
with:
list-files: csv
filters: |
docker:
- '*.Dockerfile'
- name: Generate list of amd64 targets (filtered)
id: amd64
uses: ./.github/actions/docker-targets
with:
changed: ${{ steps.filter.outputs.docker_files }}
all: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
- name: Generate list of arm64 targets (filtered)
id: arm64
uses: ./.github/actions/docker-targets
with:
platform: "linux/arm64"
changed: ${{ steps.filter.outputs.docker_files }}
all: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
bake-build-amd64:
needs: targets
name: Build (${{ matrix.family }}:${{ matrix.distro }} @ amd64
if: ${{ needs.targets.outputs.has_changes == 'true' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(needs.targets.outputs.amd64) }}
steps:
- uses: actions/checkout@v6
- name: Build via composite action
uses: ./.github/actions/docker-bake
with:
family: ${{ matrix.family }} # e.g. ros2
distro: ${{ matrix.distro }} # e.g. rolling
ghcr-username: ${{ github.repository_owner }}
ghcr-password: ${{ secrets.GITHUB_TOKEN }}
push: ${{ github.ref == 'refs/heads/main' }}
bake-build-arm64:
needs: targets
name: Build (${{ matrix.family }}:${{ matrix.distro }} @ arm64)
if: ${{ needs.targets.outputs.has_changes == 'true' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-24.04-arm
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(needs.targets.outputs.arm64) }}
steps:
- uses: actions/checkout@v6
- name: Build via composite action
uses: ./.github/actions/docker-bake
with:
family: ${{ matrix.family }} # e.g. ros2
distro: ${{ matrix.distro }} # e.g. rolling
ghcr-username: ${{ github.repository_owner }}
ghcr-password: ${{ secrets.GITHUB_TOKEN }}
push: ${{ github.ref == 'refs/heads/main' }}
merge-manifests:
name: Merge manifests (${{ matrix.family }}:${{ matrix.distro }})
needs:
- bake-build-amd64
- bake-build-arm64
- targets
if: ${{ needs.targets.outputs.has_changes == 'true' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(needs.targets.outputs.amd64) }}
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v6
- name: Set current date
id: date
shell: bash
run: echo "today=$(date +%Y-%m-%d)" >> "$GITHUB_OUTPUT"
- name: Use current date
shell: bash
run: echo "Current date is ${{ steps.date.outputs.today }}"
- name: Download bake metadata artifacts
uses: actions/download-artifact@v8
with:
pattern: bake-metadata-${{ matrix.family }}-${{ matrix.distro }}-*
path: bake-metadata
merge-multiple: true
- name: Merge manifests
uses: ./.github/actions/docker-merge
with:
family: ${{ matrix.family }}
distro: ${{ matrix.distro }}
metadata: |
bake-metadata
extra-tag: ${{ steps.date.outputs.today }}
ghcr-username: ${{ github.repository_owner }}
ghcr-password: ${{ secrets.GITHUB_TOKEN }}
docker-username: ${{ vars.DOCKERHUB_USERNAME }}
docker-password: ${{ secrets.DOCKERHUB_PASSWORD }}
dry-run: ${{ github.ref != 'refs/heads/main' && github.event_name != 'workflow_dispatch' }}
docker:
needs:
- targets
- merge-manifests
runs-on: ubuntu-latest
steps:
- name: Docker Hub rate limit (after)
id: dockerhub_rate_after
env:
DOCKERHUB_USERNAME: ${{ vars.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
shell: bash
continue-on-error: true
run: |
image_ref="library/alpine"
token_url="https://auth.docker.io/token?service=registry.docker.io&scope=repository:${image_ref}:pull"
source="anonymous"
token=""
if [[ -n "${DOCKERHUB_USERNAME}" && -n "${DOCKERHUB_PASSWORD}" ]]; then
source="authenticated"
token="$(curl -fsSL -u "${DOCKERHUB_USERNAME}:${DOCKERHUB_PASSWORD}" "${token_url}" | python3 -c 'import sys,json; print(json.load(sys.stdin).get("token",""))' || true)"
else
token="$(curl -fsSL "${token_url}" | python3 -c 'import sys,json; print(json.load(sys.stdin).get("token",""))' || true)"
fi
if [[ -z "${token}" ]]; then
echo "Unable to fetch Docker Hub token for rate-limit check."
exit 0
fi
headers="$(mktemp)"
curl -fsSI \
-H "Authorization: Bearer ${token}" \
-H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
"https://registry-1.docker.io/v2/${image_ref}/manifests/latest" > "${headers}" || true
rate_limit="$(grep -i '^ratelimit-limit:' "${headers}" | tail -n 1 | cut -d':' -f2- | xargs || true)"
rate_remaining="$(grep -i '^ratelimit-remaining:' "${headers}" | tail -n 1 | cut -d':' -f2- | xargs || true)"
echo "source=${source}" >> "$GITHUB_OUTPUT"
echo "rate_limit=${rate_limit}" >> "$GITHUB_OUTPUT"
echo "rate_remaining=${rate_remaining}" >> "$GITHUB_OUTPUT"
{
echo "### Docker Hub Rate Limit (After)"
echo "- Source: \`${source}\`"
echo "- Limit: \`${rate_limit:-unknown}\`"
echo "- Remaining: \`${rate_remaining:-unknown}\`"
} >> "$GITHUB_STEP_SUMMARY"
- name: Docker Hub rate delta
if: always()
shell: bash
env:
BEFORE: ${{ needs.targets.outputs.dockerhub-rate-remaining-before }}
AFTER: ${{ steps.dockerhub_rate_after.outputs.rate_remaining }}
run: |
before_num="${BEFORE%%;*}"
after_num="${AFTER%%;*}"
if [[ "${before_num}" =~ ^[0-9]+$ && "${after_num}" =~ ^[0-9]+$ ]]; then
delta=$((before_num - after_num))
{
echo "### Docker Hub Rate Delta"
echo "- Remaining before: \`${BEFORE}\`"
echo "- Remaining after: \`${AFTER}\`"
echo "- Estimated consumed during workflow: \`${delta}\`"
} >> "$GITHUB_STEP_SUMMARY"
else
{
echo "### Docker Hub Rate Delta"
echo "- Could not compute numeric delta."
echo "- Remaining before: \`${BEFORE:-unknown}\`"
echo "- Remaining after: \`${AFTER:-unknown}\`"
} >> "$GITHUB_STEP_SUMMARY"
fi
- name: Check
run: echo "Completed successfully!"