Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
200 changes: 200 additions & 0 deletions scripts/check_site_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
#!/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.
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
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


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


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):
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())
2 changes: 2 additions & 0 deletions scripts/ci_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions website/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions website/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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. 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;
}
}
Loading