Repository navigation
325 lines (294 loc) · 11.3 KB
/
Copy pathdocker.yml
File metadata and controls
325 lines (294 loc) · 11.3 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
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
name: Docker
on:
push:
branches:
- main
paths:
- "docker/**"
- "!docker/**/*.md"
- ".github/workflows/docker.yml"
pull_request:
paths:
- "docker/**"
- "!docker/**/*.md"
- ".github/workflows/docker.yml"
schedule:
- cron: "0 6 * * *"
workflow_dispatch:
inputs:
backfill_browser:
description: "Browser to backfill"
required: false
type: choice
options: [chrome, chromium]
default: chrome
backfill_version:
description: "Version to backfill, e.g. 156.0.8078.47 (publishes only that tag)"
required: false
type: string
concurrency:
group: docker-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
test:
name: Go tests
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
working-directory: docker
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: docker/go.mod
cache: false
- name: Check formatting
run: test -z "$(gofmt -l .)" || { gofmt -l .; exit 1; }
- name: Vet
run: go vet ./...
- name: Test
run: go test -race ./...
versions:
name: Browser versions
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
packages: read
outputs:
versions: ${{ steps.versions.outputs.versions }}
browsers: ${{ steps.versions.outputs.browsers }}
pin: ${{ steps.versions.outputs.pin }}
steps:
- name: Login to registry
if: github.event_name == 'schedule'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Find the newest versions
id: versions
env:
OWNER: ${{ github.repository_owner }}
EVENT: ${{ github.event_name }}
BACKFILL_BROWSER: ${{ inputs.backfill_browser }}
BACKFILL_VERSION: ${{ inputs.backfill_version }}
run: |
if [ -n "$BACKFILL_VERSION" ]; then
echo "versions={\"$BACKFILL_BROWSER\":\"$BACKFILL_VERSION\"}" >> "$GITHUB_OUTPUT"
echo "browsers=[\"$BACKFILL_BROWSER\"]" >> "$GITHUB_OUTPUT"
echo "pin=$BACKFILL_VERSION" >> "$GITHUB_OUTPUT"
exit 0
fi
chrome=$(curl -fsS https://dl.google.com/linux/chrome/deb/dists/stable/main/binary-amd64/Packages \
| awk '/^Package: google-chrome-stable$/ { found = 1 } found && /^Version:/ { print $2; exit }' | sed 's/-.*//')
chromium=$(docker run --rm debian:trixie-slim sh -c 'apt-get update -qq && apt-cache policy chromium' \
| awk '/Candidate:/ { print $2 }' | sed 's/-.*//')
echo "chrome $chrome, chromium $chromium"
browsers=()
for browser in chrome chromium; do
version=${!browser}
if [ "$EVENT" = "schedule" ] && docker manifest inspect "ghcr.io/$OWNER/$browser:$version" > /dev/null 2>&1; then
echo "$browser $version is already published"
else
browsers+=("\"$browser\"")
fi
done
echo "versions={\"chrome\":\"$chrome\",\"chromium\":\"$chromium\"}" >> "$GITHUB_OUTPUT"
echo "browsers=[$(IFS=,; echo "${browsers[*]}")]" >> "$GITHUB_OUTPUT"
build:
name: Build ${{ matrix.browser }} (${{ matrix.arch }})
needs: [versions]
if: needs.versions.outputs.browsers != '[]'
strategy:
fail-fast: false
matrix:
browser: ${{ fromJSON(needs.versions.outputs.browsers) }}
arch: [amd64, arm64]
include:
- arch: amd64
runner: ubuntu-latest
- arch: arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
timeout-minutes: 30
permissions:
contents: read
packages: write
env:
IMAGE: ghcr.io/${{ github.repository_owner }}/${{ matrix.browser }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Buildx
uses: docker/setup-buildx-action@v3
- name: Login to registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build image
uses: docker/build-push-action@v6
with:
context: docker
platforms: linux/${{ matrix.arch }}
build-args: |
BROWSER=${{ matrix.browser }}
BROWSER_VERSION=${{ fromJSON(needs.versions.outputs.versions)[matrix.browser] }}
BROWSER_PIN=${{ needs.versions.outputs.pin }}
VERSION=${{ github.sha }}
load: true
tags: ${{ matrix.browser }}:test
cache-from: type=gha,scope=${{ matrix.browser }}-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=${{ matrix.browser }}-${{ matrix.arch }}
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.4"
bundler-cache: true
- name: Run the Ferrum suite against the image
id: suite
continue-on-error: ${{ github.event_name != 'pull_request' }}
timeout-minutes: 20
env:
FERRUM_DEFAULT_TIMEOUT: 15
FERRUM_PROCESS_TIMEOUT: 25
run: |
docker run -d --name suite --network host --user "$(id -u):$(id -g)" -e CONCURRENT=4 \
-v "$GITHUB_WORKSPACE:$GITHUB_WORKSPACE" -v /tmp:/tmp ${{ matrix.browser }}:test
for i in $(seq 1 30); do curl -sf http://127.0.0.1:3000/health && break; sleep 1; done
FERRUM_URL=http://127.0.0.1:3000 bundle exec rspec --exclude-pattern "spec/unit/**/*_spec.rb"
- name: Report suite failure
if: steps.suite.outcome == 'failure' && github.event_name != 'pull_request'
run: |
echo "::warning::The Ferrum suite failed against ${{ matrix.browser }} ${{ matrix.arch }}, the image is published anyway"
mkdir -p /tmp/meta
touch "/tmp/meta/suite-failed-${{ matrix.browser }}-${{ matrix.arch }}"
- name: Driver logs
if: always()
run: docker logs suite 2>&1 | grep -v "browser stderr" | tail -200 || true
- name: Detect browser version
run: |
mkdir -p /tmp/meta
docker run --rm --entrypoint sh ${{ matrix.browser }}:test -c '"$BROWSER_PATH" --version' \
| grep -oE '[0-9]+(\.[0-9]+){3}' | head -1 > "/tmp/meta/version-${{ matrix.arch }}"
cat "/tmp/meta/version-${{ matrix.arch }}"
- name: Push by digest
id: push
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v6
with:
context: docker
platforms: linux/${{ matrix.arch }}
build-args: |
BROWSER=${{ matrix.browser }}
BROWSER_VERSION=${{ fromJSON(needs.versions.outputs.versions)[matrix.browser] }}
BROWSER_PIN=${{ needs.versions.outputs.pin }}
VERSION=${{ github.sha }}
cache-from: type=gha,scope=${{ matrix.browser }}-${{ matrix.arch }}
outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true
- name: Export digest
if: github.event_name != 'pull_request'
run: |
mkdir -p /tmp/meta/digests
touch "/tmp/meta/digests/${DIGEST#sha256:}"
env:
DIGEST: ${{ steps.push.outputs.digest }}
- name: Upload metadata
if: github.event_name != 'pull_request'
uses: actions/upload-artifact@v4
with:
name: meta-${{ matrix.browser }}-${{ matrix.arch }}
path: /tmp/meta
retention-days: 1
publish:
name: Publish ${{ matrix.browser }}
if: github.event_name != 'pull_request'
needs: [versions, build]
strategy:
matrix:
browser: ${{ fromJSON(needs.versions.outputs.browsers) }}
runs-on: ubuntu-latest
permissions:
packages: write
env:
IMAGE: ghcr.io/${{ github.repository_owner }}/${{ matrix.browser }}
PIN: ${{ needs.versions.outputs.pin }}
steps:
- name: Download metadata
uses: actions/download-artifact@v4
with:
pattern: meta-${{ matrix.browser }}-*
path: /tmp/meta
merge-multiple: true
- name: Setup Buildx
uses: docker/setup-buildx-action@v3
- name: Login to registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create multi-arch manifest
working-directory: /tmp/meta
run: |
tags=(-t "$IMAGE:latest")
amd64=$(cat version-amd64)
arm64=$(cat version-arm64)
if [ -n "$PIN" ]; then
tags=(-t "$IMAGE:$amd64")
elif [ -n "$amd64" ] && [ "$amd64" = "$arm64" ]; then
tags+=(-t "$IMAGE:$amd64" -t "$IMAGE:${amd64%%.*}")
else
echo "::warning::Browser versions differ (amd64: $amd64, arm64: $arm64), publishing only latest"
fi
docker buildx imagetools create "${tags[@]}" $(printf "$IMAGE@sha256:%s " $(ls digests))
docker buildx imagetools inspect "${tags[1]}"
notify:
name: Report problems
if: always() && github.event_name != 'pull_request'
needs: [versions, build, publish]
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
actions: read
issues: write
steps:
- name: Download metadata
continue-on-error: true
uses: actions/download-artifact@v4
with:
pattern: meta-*
path: /tmp/meta
merge-multiple: true
- name: Open or update the issue
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
VERSIONS_RESULT: ${{ needs.versions.result }}
BUILD_RESULT: ${{ needs.build.result }}
PUBLISH_RESULT: ${{ needs.publish.result }}
run: |
problems=()
[ "$VERSIONS_RESULT" = "failure" ] && problems+=("Looking up the newest browser versions failed")
[ "$BUILD_RESULT" = "failure" ] && problems+=("Building an image failed, nothing was published")
[ "$PUBLISH_RESULT" = "failure" ] && problems+=("Publishing an image failed")
for marker in $(ls /tmp/meta 2>/dev/null | grep '^suite-failed-'); do
problems+=("The Ferrum suite failed against ${marker#suite-failed-}, the image was published anyway")
done
[ ${#problems[@]} -eq 0 ] && exit 0
body="Scheduled or manual Docker run: $RUN_URL"$'\n\n'
for problem in "${problems[@]}"; do body+="- $problem"$'\n'; done
gh label create docker-release --color B60205 --description "Browser image release problems" 2>/dev/null || true
existing=$(gh issue list --label docker-release --state open --json number --jq '.[0].number // empty')
if [ -n "$existing" ]; then
gh issue comment "$existing" --body "$body"
else
gh issue create --label docker-release --title "Docker browser image release has problems" --body "$body"
fi