From 61cb7971a39995ec827a45024cfe018d72d6e12e Mon Sep 17 00:00:00 2001 From: Eric Dahl Date: Sun, 22 Nov 2026 23:43:56 -0500 Subject: [PATCH 1/4] Site server check: every file, the clean URLs and the 404, over HTTP from website/Dockerfile (#767) Red: there is no Dockerfile yet. --url runs the same check against the live site, which passes it today. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VCgWWsrZ4EvHNNNTAe7RC1 --- .github/workflows/ci.yml | 3 + scripts/check_site_image.py | 150 ++++++++++++++++++++++++++++++++++++ scripts/ci_changes.py | 2 + 3 files changed, 155 insertions(+) create mode 100644 scripts/check_site_image.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 45779248..a3b2b91a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,6 +64,9 @@ jobs: run: node --test scripts/test_analytics.mjs scripts/test_capture.mjs - name: Site check run: python3 -I scripts/check_site.py website + - name: Site server check + # website/Dockerfile and nginx.conf (#767): built and run here, checked over HTTP against the files. + run: python3 -I scripts/check_site_image.py deck-panel: name: Deck panel diff --git a/scripts/check_site_image.py b/scripts/check_site_image.py new file mode 100644 index 00000000..7cea917a --- /dev/null +++ b/scripts/check_site_image.py @@ -0,0 +1,150 @@ +#!/usr/bin/env python3 +"""The website's server check (#767): website/Dockerfile and nginx.conf serve the site as the live one does. + +With no argument it builds website/Dockerfile, runs it on a free local port and checks it over HTTP, then removes the +container. With --url it checks a running site instead, such as https://getdeckbridge.app, before and after a switch. + +Checked, as the live site answered on 2026-11-22: + - every file under website/ answers 200 with the repo's bytes and its content type (404.html excepted: it answers 404); + - the clean URLs answer 200 with their index.html, with and without the trailing slash, never a redirect; + - an unknown path answers 404 with the 404 page. + +Usage: python3 -I scripts/check_site_image.py [--url BASE] +Needs Docker without --url (CI's Linux runner has it). +""" +import argparse +import os +import pathlib +import subprocess +import sys +import time +import urllib.error +import urllib.request + +ROOT = pathlib.Path(__file__).resolve().parent.parent +SITE = ROOT / "website" +IMAGE = "deckbridge-site-check" + +# The content type each extension answered with on the live site (nginx's defaults; .md has none, so octet-stream). +TYPES = { + ".html": "text/html", ".css": "text/css", ".js": "application/javascript", ".json": "application/json", + ".txt": "text/plain", ".md": "application/octet-stream", ".xml": "text/xml", ".woff2": "font/woff2", + ".png": "image/png", ".webp": "image/webp", +} + +# Clean URLs the site links to, and the file each serves. +CLEAN = { + "/": "index.html", + "/for/lc6000/": "for/lc6000/index.html", + "/for/lc6000": "for/lc6000/index.html", + "/support/": "support/index.html", + "/privacy/": "privacy/index.html", + "/capture/": "capture/index.html", +} + +NOT_FOUND_TEXT = "Track not found." + + +class NoRedirect(urllib.request.HTTPRedirectHandler): + def redirect_request(self, *args, **kwargs): + return None + + +OPENER = urllib.request.build_opener(NoRedirect) + + +def fetch(base, path, headers=None): + """(status, headers, body) for base+path, without following redirects.""" + request = urllib.request.Request(base + path, headers=headers or {}) + try: + with OPENER.open(request, timeout=10) as response: + return response.status, response.headers, response.read() + except urllib.error.HTTPError as error: + return error.code, error.headers, error.read() + + +def site_files(): + return sorted(p.relative_to(SITE).as_posix() for p in SITE.rglob("*") + if p.is_file() and p.name not in {"Dockerfile", "nginx.conf", ".DS_Store"}) + + +def content_type(headers): + return (headers.get("Content-Type") or "").split(";")[0].strip() + + +def check_files(base): + failures = [] + for name in site_files(): + status, headers, body = fetch(base, "/" + name) + want_status = 404 if name == "404.html" else 200 + if status != want_status: + failures.append(f"/{name}: status {status}, want {want_status}") + continue + if body != (SITE / name).read_bytes(): + failures.append(f"/{name}: bytes differ from website/{name}") + want_type = TYPES.get(pathlib.PurePath(name).suffix) + if want_type and content_type(headers) != want_type: + failures.append(f"/{name}: content type {content_type(headers)!r}, want {want_type!r}") + for path, name in CLEAN.items(): + status, headers, body = fetch(base, path) + if status != 200: + failures.append(f"{path}: status {status}, want 200") + elif body != (SITE / name).read_bytes(): + failures.append(f"{path}: bytes differ from website/{name}") + return failures + + +def check_not_found(base): + status, headers, body = fetch(base, "/no-such-track/") + failures = [] + if status != 404: + failures.append(f"/no-such-track/: status {status}, want 404") + if NOT_FOUND_TEXT not in body.decode("utf-8", "replace"): + failures.append(f"/no-such-track/: no {NOT_FOUND_TEXT!r}") + return failures + + +CHECKS = [check_files, check_not_found] + + +def run_checks(base): + failures = [failure for check in CHECKS for failure in check(base)] + for failure in failures: + print("FAIL", failure) + print(f"{len(failures)} failures against {base}") + return 1 if failures else 0 + + +def wait_up(base): + for _ in range(50): + try: + fetch(base, "/") + return + except OSError: + time.sleep(0.2) + raise SystemExit(f"The site at {base} didn't answer.") + + +def with_image(): + subprocess.run(["docker", "build", "-q", "-t", IMAGE, str(SITE)], check=True) + container = subprocess.run(["docker", "run", "-d", "--rm", "-p", "127.0.0.1::80", IMAGE], + check=True, capture_output=True, text=True).stdout.strip() + try: + port = subprocess.run(["docker", "port", container, "80/tcp"], check=True, capture_output=True, + text=True).stdout.split("\n")[0].rsplit(":", 1)[1] + base = f"http://127.0.0.1:{port}" + wait_up(base) + return run_checks(base) + finally: + subprocess.run(["docker", "stop", container], capture_output=True) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__.split("\n")[0]) + parser.add_argument("--url", help="check this running site instead of building the image") + args = parser.parse_args() + return run_checks(args.url.rstrip("/")) if args.url else with_image() + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/scripts/ci_changes.py b/scripts/ci_changes.py index 7934c652..283914c3 100644 --- a/scripts/ci_changes.py +++ b/scripts/ci_changes.py @@ -9,6 +9,8 @@ # and the LC6000 firmware tool. # Anything else, including .github/ and the release scripts the Kit job tests, runs the Mac jobs too. SITE_ONLY = ["website/*", "scripts/check_site.py", "scripts/test_check_site.py", "scripts/site-preview.sh", + # the server check (#767): builds website/Dockerfile, which the Site check job runs + "scripts/check_site_image.py", "scripts/test_*.mjs", "*.md", # the domain docs' check (GLOSSARY.md, docs/adr), which the Site check job runs "scripts/check_domain_docs.py", "scripts/test_check_domain_docs.py", From e528ae1473b34035d92c6bb4160b1ef180733a9c Mon Sep 17 00:00:00 2001 From: Eric Dahl Date: Sun, 22 Nov 2026 23:46:29 -0500 Subject: [PATCH 2/4] website/Dockerfile and nginx.conf: the site on pinned nginx, as live serves it (#767) Every file with its bytes and type, clean URLs with and without the slash, and the 404 page for unknown paths (404.html itself answers 404). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VCgWWsrZ4EvHNNNTAe7RC1 --- website/Dockerfile | 9 +++++++++ website/nginx.conf | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 website/Dockerfile create mode 100644 website/nginx.conf diff --git a/website/Dockerfile b/website/Dockerfile new file mode 100644 index 00000000..0892f761 --- /dev/null +++ b/website/Dockerfile @@ -0,0 +1,9 @@ +# getdeckbridge.app (#767): the static site on nginx, with its config in git. Coolify builds this with /website as +# the base directory. Pinned: change the tag on purpose, then run scripts/check_site_image.py. +FROM nginx:1.30.5-alpine +COPY . /usr/share/nginx/html +# The config isn't part of the site: move it into place, and drop this file from what's served. +RUN cd /usr/share/nginx/html \ + && mv nginx.conf /etc/nginx/conf.d/default.conf \ + && rm -f Dockerfile \ + && find . -name .DS_Store -delete diff --git a/website/nginx.conf b/website/nginx.conf new file mode 100644 index 00000000..b31f9293 --- /dev/null +++ b/website/nginx.conf @@ -0,0 +1,19 @@ +# getdeckbridge.app (#767): serves website/ as the live site did on Coolify's static build pack, byte for byte. +# Checked by scripts/check_site_image.py. +server { + listen 80; + server_name _; + root /usr/share/nginx/html; + index index.html; + + # Clean URLs: /for/lc6000/ and /for/lc6000 both serve for/lc6000/index.html, with no redirect. + location / { + try_files $uri $uri/index.html =404; + } + + # Unknown paths get the 404 page with status 404; the page itself isn't a page of its own. + error_page 404 /404.html; + location = /404.html { + internal; + } +} From 207afc2311b7d7fa83dea5f3edc5ceb77fb0d6f2 Mon Sep 17 00:00:00 2001 From: Eric Dahl Date: Sun, 22 Nov 2026 23:49:20 -0500 Subject: [PATCH 3/4] Site cache headers: pages, CSS and JS no-cache; fonts a year; images a month (#767) Red first against the live site, which sends no Cache-Control (18 failures). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VCgWWsrZ4EvHNNNTAe7RC1 --- scripts/check_site_image.py | 36 +++++++++++++++++++++++++++++++++++- website/nginx.conf | 15 ++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/scripts/check_site_image.py b/scripts/check_site_image.py index 7cea917a..94b0ecc6 100644 --- a/scripts/check_site_image.py +++ b/scripts/check_site_image.py @@ -8,6 +8,9 @@ - every file under website/ answers 200 with the repo's bytes and its content type (404.html excepted: it answers 404); - the clean URLs answer 200 with their index.html, with and without the trailing slash, never a redirect; - an unknown path answers 404 with the 404 page. +And new with #767 (the live site sent no cache headers): + - HTML is never cached long: no-cache, or at most 5 minutes; + - fonts and images are cached at least 30 days. Usage: python3 -I scripts/check_site_image.py [--url BASE] Needs Docker without --url (CI's Linux runner has it). @@ -104,7 +107,38 @@ def check_not_found(base): return failures -CHECKS = [check_files, check_not_found] +def max_age(headers): + """The Cache-Control max-age in seconds, 0 for no-cache or no-store, None when there's no Cache-Control.""" + value = headers.get("Cache-Control") + if value is None: + return None + parts = [part.strip() for part in value.split(",")] + if "no-cache" in parts or "no-store" in parts: + return 0 + ages = [int(part.split("=", 1)[1]) for part in parts if part.startswith("max-age=")] + return ages[0] if ages else None + + +SHORT = 300 +LONG = 30 * 24 * 3600 + + +def check_cache(base): + failures = [] + for path in ["/", "/for/lc6000/", "/support/", "/index.html", "/no-such-track/"]: + age = max_age(fetch(base, path)[1]) + if age is None or age > SHORT: + failures.append(f"{path}: HTML cached for {age} s, want no-cache or at most {SHORT} s") + long_lived = ["/fonts/Geist.woff2", "/fonts/GeistMono.woff2"] + sorted( + "/" + p.relative_to(SITE).as_posix() for p in (SITE / "img").iterdir() if p.suffix in {".png", ".webp"}) + for path in long_lived: + age = max_age(fetch(base, path)[1]) + if age is None or age < LONG: + failures.append(f"{path}: cached for {age} s, want at least {LONG} s") + return failures + + +CHECKS = [check_files, check_not_found, check_cache] def run_checks(base): diff --git a/website/nginx.conf b/website/nginx.conf index b31f9293..56d0ff34 100644 --- a/website/nginx.conf +++ b/website/nginx.conf @@ -6,14 +6,27 @@ server { root /usr/share/nginx/html; index index.html; - # Clean URLs: /for/lc6000/ and /for/lc6000 both serve for/lc6000/index.html, with no redirect. + # Clean URLs: /for/lc6000/ and /for/lc6000 both serve for/lc6000/index.html, with no redirect. Pages, CSS, JS and + # text keep their names across releases, so the browser checks each time (an ETag makes that cheap). location / { try_files $uri $uri/index.html =404; + add_header Cache-Control "no-cache" always; + } + + # Fonts change only with a new name; images rarely, so a month. + location ~* \.woff2$ { + try_files $uri =404; + add_header Cache-Control "public, max-age=31536000, immutable"; + } + location ~* \.(?:png|webp|jpg|svg|ico)$ { + try_files $uri =404; + add_header Cache-Control "public, max-age=2592000"; } # Unknown paths get the 404 page with status 404; the page itself isn't a page of its own. error_page 404 /404.html; location = /404.html { internal; + add_header Cache-Control "no-cache" always; } } From 49349d2063e017435e9ee5f81a887b1038423238 Mon Sep 17 00:00:00 2001 From: Eric Dahl Date: Sun, 22 Nov 2026 23:50:18 -0500 Subject: [PATCH 4/4] Site server check: text is gzipped when asked (#767) Red: nginx's image has gzip off. The live site already gzips. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VCgWWsrZ4EvHNNNTAe7RC1 --- scripts/check_site_image.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/scripts/check_site_image.py b/scripts/check_site_image.py index 94b0ecc6..68eed6ee 100644 --- a/scripts/check_site_image.py +++ b/scripts/check_site_image.py @@ -11,11 +11,13 @@ And new with #767 (the live site sent no cache headers): - HTML is never cached long: no-cache, or at most 5 minutes; - fonts and images are cached at least 30 days. + - text (HTML, CSS, JS, JSON, plain text, XML) is gzipped when asked, and unzips to the same bytes. Usage: python3 -I scripts/check_site_image.py [--url BASE] Needs Docker without --url (CI's Linux runner has it). """ import argparse +import gzip import os import pathlib import subprocess @@ -138,7 +140,21 @@ def check_cache(base): return failures -CHECKS = [check_files, check_not_found, check_cache] +GZIPPED = ["/index.html", "/site.css", "/analytics.js", "/controllers.json", "/llms.txt", "/sitemap.xml"] + + +def check_gzip(base): + failures = [] + for path in GZIPPED: + status, headers, body = fetch(base, path, {"Accept-Encoding": "gzip"}) + if headers.get("Content-Encoding") != "gzip": + failures.append(f"{path}: not gzipped (Content-Encoding {headers.get('Content-Encoding')!r})") + elif gzip.decompress(body) != (SITE / path.lstrip("/")).read_bytes(): + failures.append(f"{path}: gzipped bytes differ from website{path}") + return failures + + +CHECKS = [check_files, check_not_found, check_cache, check_gzip] def run_checks(base):