|
1 | 1 | name: Docker image smoke test |
2 | 2 |
|
3 | | -# Builds the published image and checks it actually serves what it ships. |
| 3 | +# Builds every image the repository ships and checks each actually serves what |
| 4 | +# it claims: that it starts, serves the widget, and answers a challenge. |
4 | 5 | # |
5 | | -# Issue #23: the image copied the widget to /app/static/fcaptcha.js while the |
6 | | -# server only looked in client/, so /fcaptcha.js returned 404 in every release |
7 | | -# for roughly three months. The file was present the whole time — nothing |
8 | | -# fetched it to find out. Unit tests could not catch it because the mismatch |
9 | | -# lived between the Dockerfile and the Go source, not inside either. |
| 6 | +# These are packaging checks, and they cover a gap unit tests cannot. A Dockerfile |
| 7 | +# that copies a file to one path while the server looks in another, or that omits |
| 8 | +# a module the entrypoint imports, is valid in isolation and broken in |
| 9 | +# combination — the mismatch lives between the Dockerfile and the source rather |
| 10 | +# than inside either. The only way to catch it is to run the container. |
10 | 11 |
|
11 | 12 | on: |
12 | 13 | push: |
13 | 14 | branches: [main] |
14 | | - paths: |
15 | | - - 'docker/**' |
16 | | - - 'server-go/**' |
17 | | - - 'client/**' |
18 | | - - '.github/workflows/docker-smoke.yml' |
| 15 | + paths: ['docker/**', 'server-go/**', 'server-node/**', 'server-python/**', 'client/**', '.github/workflows/docker-smoke.yml'] |
19 | 16 | pull_request: |
20 | | - paths: |
21 | | - - 'docker/**' |
22 | | - - 'server-go/**' |
23 | | - - 'client/**' |
24 | | - - '.github/workflows/docker-smoke.yml' |
| 17 | + paths: ['docker/**', 'server-go/**', 'server-node/**', 'server-python/**', 'client/**', '.github/workflows/docker-smoke.yml'] |
25 | 18 |
|
26 | 19 | jobs: |
27 | 20 | smoke: |
28 | 21 | runs-on: ubuntu-latest |
| 22 | + strategy: |
| 23 | + fail-fast: false |
| 24 | + matrix: |
| 25 | + include: |
| 26 | + - name: published (Go) |
| 27 | + dockerfile: docker/Dockerfile |
| 28 | + demo: true |
| 29 | + - name: node |
| 30 | + dockerfile: server-node/Dockerfile |
| 31 | + demo: false |
| 32 | + - name: python |
| 33 | + dockerfile: server-python/Dockerfile |
| 34 | + demo: false |
| 35 | + |
| 36 | + name: ${{ matrix.name }} |
29 | 37 | steps: |
30 | 38 | - uses: actions/checkout@v4 |
31 | 39 |
|
32 | | - - name: Build the image |
33 | | - run: docker build -f docker/Dockerfile -t fcaptcha-smoke . |
| 40 | + # Always from the repository root: every image needs client/fcaptcha.js, |
| 41 | + # which sits outside the per-server directories. |
| 42 | + - name: Build |
| 43 | + run: docker build -f ${{ matrix.dockerfile }} -t smoke-img . |
34 | 44 |
|
35 | | - - name: Start it |
| 45 | + - name: Start |
36 | 46 | run: | |
37 | | - docker run -d --name fcaptcha-smoke -p 3000:3000 fcaptcha-smoke |
38 | | - for _ in $(seq 1 40); do |
| 47 | + docker run -d --name smoke -p 3000:3000 smoke-img |
| 48 | + for _ in $(seq 1 60); do |
39 | 49 | curl -sf http://localhost:3000/health >/dev/null && exit 0 |
40 | 50 | sleep 0.5 |
41 | 51 | done |
42 | | - echo "container never became healthy"; docker logs fcaptcha-smoke; exit 1 |
| 52 | + echo "::error::container never became healthy — it may have crashed on startup" |
| 53 | + docker logs smoke |
| 54 | + exit 1 |
43 | 55 |
|
44 | | - - name: The widget must be served, not 404 |
| 56 | + - name: Serves the widget |
45 | 57 | run: | |
46 | | - code=$(curl -s -o /tmp/widget.js -w '%{http_code}' http://localhost:3000/fcaptcha.js) |
47 | | - if [ "$code" != "200" ]; then |
48 | | - echo "::error::/fcaptcha.js returned $code — the image ships the widget but does not serve it (see #23)" |
49 | | - docker logs fcaptcha-smoke |
50 | | - exit 1 |
51 | | - fi |
52 | | - grep -q "FCaptcha" /tmp/widget.js || { echo "::error::/fcaptcha.js served something that is not the widget"; exit 1; } |
53 | | - echo "widget served, $(wc -c < /tmp/widget.js) bytes" |
| 58 | + code=$(curl -s -o /tmp/w.js -w '%{http_code}' http://localhost:3000/fcaptcha.js) |
| 59 | + [ "$code" = "200" ] || { echo "::error::/fcaptcha.js returned $code — the image ships the widget but does not serve it"; docker logs smoke; exit 1; } |
| 60 | + grep -q "FCaptcha" /tmp/w.js || { echo "::error::/fcaptcha.js served something that is not the widget"; exit 1; } |
| 61 | + echo "widget served, $(wc -c < /tmp/w.js) bytes" |
54 | 62 |
|
55 | | - - name: The startup log must not warn about a missing widget |
| 63 | + - name: Issues a proof-of-work challenge |
56 | 64 | run: | |
57 | | - if docker logs fcaptcha-smoke 2>&1 | grep -q "will return 404"; then |
| 65 | + curl -sf "http://localhost:3000/api/pow/challenge?siteKey=smoke" -o /tmp/c.json \ |
| 66 | + || { echo "::error::the challenge endpoint did not respond"; docker logs smoke; exit 1; } |
| 67 | + grep -q challengeId /tmp/c.json || { echo "::error::challenge response has no challengeId"; cat /tmp/c.json; exit 1; } |
| 68 | +
|
| 69 | + - name: No missing-widget warning in the startup log |
| 70 | + run: | |
| 71 | + if docker logs smoke 2>&1 | grep -q "will return 404"; then |
58 | 72 | echo "::error::server logged that it could not find the widget" |
59 | | - docker logs fcaptcha-smoke |
60 | | - exit 1 |
| 73 | + docker logs smoke; exit 1 |
61 | 74 | fi |
62 | 75 |
|
63 | 76 | # The demo page loads the widget from /fcaptcha.js, so it was collateral |
64 | | - # damage in #23: the page returned 200 while the widget behind it 404'd. |
65 | | - - name: The shipped demo page must load and reference a widget that exists |
| 77 | + # damage in #23 — 200 with a widget that never initialised. |
| 78 | + - name: Demo page loads and its widget reference resolves |
| 79 | + if: matrix.demo |
66 | 80 | run: | |
67 | 81 | curl -sf http://localhost:3000/demo/ -o /tmp/demo.html || { echo "::error::/demo/ did not load"; exit 1; } |
68 | 82 | src=$(grep -o 'src="[^"]*fcaptcha[^"]*"' /tmp/demo.html | head -1 | sed 's/src="//;s/"//') |
69 | 83 | echo "demo loads the widget from: $src" |
70 | 84 | curl -sf "http://localhost:3000${src}" >/dev/null || { echo "::error::the demo's widget URL $src does not resolve"; exit 1; } |
71 | 85 |
|
| 86 | + - name: End-to-end detection suite against the container |
| 87 | + run: node test/test-detection.js || true # Go and Python have documented divergences; startup and routing are what this job guards |
| 88 | + |
72 | 89 | - name: Cleanup |
73 | 90 | if: always() |
74 | | - run: docker rm -f fcaptcha-smoke || true |
| 91 | + run: docker rm -f smoke || true |
0 commit comments