showcase
- v0.2.4
- 37 commits
- 1 branch
- 6 tags
- updated
- CI 2/2
spec.md
12.0 KB · 215 lines
1# daum.dev — read-only code site23A minimal, public, read-only view of Daniel's public Gitea repos, served at4the root of `daum.dev`. One Go binary in one Docker image: it rebuilds static5HTML from Gitea on a timer, serves it, and passes `git clone` and6`docker pull` through to Gitea. Nothing on the public side can write, log in,7or reach Gitea's UI or API.89## Goals1011- Home page that reads as danieldaum.net's /projects page: activity chart, featured repos, activity feed.12- Per-repo pages: README, file tree, file viewer with syntax highlighting,13 commit log, commit diffs, releases, pull requests (read-only), packages.14- Public clone: `git clone https://daum.dev/<repo>.git`15- Public image pull: `docker pull daum.dev/daniel/<image>:<tag>`16- No JavaScript. Matches danieldaum.net (saturn): dark only, saturn's Flexoki-based17 palettes (moss by default), Geist Pixel for all text, Geist Mono for code. See `docs/theme.md`.1819## Non-goals2021- Login, issues, comments, search, forks, stars, blame, editing anything.22- Private repos. They must never appear, even by mistake.23- Showing Tangled or GitHub data. Gitea is the only source.2425## Constraints for the implementer (Claude Code)2627- End state is a single Docker image running a single process. No Caddy, cron,28 or process supervisor inside it.29- Keep it small. Target under ~1,800 lines of Go total, excluding templates and CSS.30- Small commits, one feature each. No commit over ~400 changed lines.31- Go, standard library first. Allowed dependencies: `github.com/yuin/goldmark`32 (Markdown) and `github.com/alecthomas/chroma/v2` (highlighting). Ask before adding others.33- Shell out to the `git` CLI for repo data (`os/exec`), no go-git.34- Config is JSON (stdlib), not TOML/YAML.35- Templates and CSS embedded with `embed`.36- Don't copy knotless markup or CSS: its license is unknown. Use its layout as37 inspiration only (header → action row → clone box → latest commit → tree → README).3839## Environment4041- Gitea: Docker on the home server, user `daniel`. Moving to Tailscale-only (no public HTTPS).42 Must be Gitea ≥ 28.3.0 (heatmap API leaked private activity before that).43- The container runs on a home server/VM and listens on plain HTTP (`:8080`).44 Pangolin terminates TLS and proxies `daum.dev` to it. Cloudflare sits in front of Pangolin.45- atproto handle `@daum.dev` is verified by DNS TXT, so the site doesn't need46 `/.well-known/atproto-did`.47- This replaces the current `daum.dev` → `danieldaum.net` redirect. Link to danieldaum.net from the profile.48- Everything here goes down with the home server. Acceptable for now.4950## Architecture5152```53 Cloudflare → Pangolin (TLS) → daumdev container :8080 (one process)54 ├─ static files (/data/site/current)55 ├─ /<repo>.git/… → Gitea (fetch only)56 ├─ /v2/… → Gitea (GET/HEAD only)57 └─ builder goroutine, every 10 min58 └─ anonymous HTTP over Tailscale → Gitea API + git59```6061- `net/http` serves files and routes; `httputil.ReverseProxy` handles the62 pass-through (`FlushInterval: -1` so clones stream).63- The builder runs once at startup, then on a `time.Ticker`. It holds a mutex so64 builds never overlap. The server keeps serving the previous build while a new one runs.65- The allowlist is read from `config.json` in memory, so there's nothing to66 generate or reload. Config changes take effect on container restart.67- Server timeouts: `ReadHeaderTimeout` 10s, `IdleTimeout` 60s. No `WriteTimeout`68 on proxied routes (large clones and layers); 30s on page routes.69- `GET /healthz` returns 200 once the first build exists.7071### Security rules72731. **The generator uses no token.** Every API call and clone is anonymous, so it74 can only ever see public data. A private repo listed in config just fails to load and is skipped with a warning.752. **One allowlist:** repo and image names come from `config.json`. The builder76 only renders those, and the proxy only forwards those.773. **The router's default is 404.** Only these routes exist:78 - `GET` static files.79 - `GET /<repo>.git/info/refs` only when the query is exactly `service=git-upload-pack`.80 - `POST /<repo>.git/git-upload-pack`.81 - Anything with `git-receive-pack` → 403.82 - `GET|HEAD /v2/`, `GET /v2/token`, `GET|HEAD /v2/daniel/<image>/(manifests|blobs)/…` for allowlisted images.83 - Clone paths rewrite `/<repo>.git/…` → `/daniel/<repo>.git/…` upstream.844. **Registry token realm:** Gitea builds the `WWW-Authenticate` realm from its85 `ROOT_URL`, which will be a tailnet address. The proxy's `ModifyResponse`86 rewrites the realm to `https://daum.dev/v2/token`.87 Also strip any `Set-Cookie` and Gitea-specific headers from proxied responses,88 and never forward the client's `Authorization` or `Cookie` headers on git routes.895. **Rendering:** goldmark, with raw HTML never passed through. README HTML90 is rebuilt from a short allowlist of tags and attributes (see decisions,91 "README HTML: an allowlist"); everything else is dropped. Escape everything92 else through `html/template`. Files over 512 KB or binary: show size and a raw link, no render.93 README images: only relative paths inside the repo or https URLs.946. **Headers:** `Content-Security-Policy: default-src 'none'; style-src 'self'; img-src 'self' https:; font-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'`,95 plus `X-Content-Type-Options: nosniff`, `Referrer-Policy: no-referrer`. Raw files served as `text/plain` or with `Content-Disposition: attachment`.967. **Container:** runs as a non-root user with a read-only root filesystem,97 `cap_drop: [ALL]` and `no-new-privileges`. The only writable path is the98 `/data` volume (site builds + bare git mirrors). Config is mounted read-only at `/config.json`.998. Trust `X-Forwarded-*` only from Pangolin's address (used for logs only).1009. **Request limits:** cap request bodies on `git-upload-pack` (e.g. 10 MB) and101 reject any other method with a body.102103## Config (`config.json`)104105```json106{107 "gitea_url": "http://gitea.tailnet.example:3000",108 "user": "daniel",109 "site_url": "https://daum.dev",110 "repos": ["repo-a", "repo-b"],111 "images": ["repo-a"],112 "max_commits": 50113}114```115116## Data sources117118| Page piece | Source |119| -------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |120| Profile (avatar, name, bio) | `GET /api/v1/users/{user}` |121| Heatmap | `GET /api/v1/users/{user}/heatmap` (rendered as server-side SVG) |122| Repo meta (description, topics, default branch, website) | `GET /api/v1/repos/{user}/{repo}` |123| Language bar | `GET /api/v1/repos/{user}/{repo}/languages` |124| Releases | `GET /api/v1/repos/{user}/{repo}/releases` |125| Pull requests | `GET /api/v1/repos/{user}/{repo}/pulls?state=all` |126| Packages | `GET /api/v1/packages/{user}` (filter to repo-linked) |127| Tree, files, log, diffs, README | local bare mirror: `git clone --mirror` / `git fetch`, then `git ls-tree`, `git cat-file`, `git log`, `git show` |128129## Pages (URL → content)130131- `/` — saturn's /projects page header, activity chart and heatmap, featured repos, activity feed.132- `/<repo>/` — header (name, description, topics, latest release), action row133 (Code · Commits · Releases · Pulls · Packages), clone box (HTTPS + Tangled/GitHub links),134 latest commit line, root tree with last-commit message and age per entry, rendered README.135- `/<repo>/tree/<path>/` — directory listing.136- `/<repo>/blob/<path>` — highlighted file with line anchors (`#L12`).137- `/<repo>/raw/<path>` — raw bytes.138- `/<repo>/log/` — last `max_commits` commits on the default branch.139- `/<repo>/commit/<sha>/` — message, stats, unified diff (for those commits only).140- `/<repo>/releases/` — tag, title, date, notes (Markdown), asset links.141- `/<repo>/pulls/` — title, state, author, date, body. No diffs.142- `/<repo>/packages/` — name, version, type, pull/install command.143- Go repos: add `<meta name="go-import" content="daum.dev/<repo> git https://daum.dev/<repo>.git">` so `go get daum.dev/<repo>` works.144145Only the default branch is browsable. Tags show on the releases page.146147## Build loop1481491. For each repo: fetch mirror. If HEAD and API `updated_at` are unchanged since last run, reuse the old output.1502. Render into `/data/site/.tmp-<ts>/`, then swap a `current` symlink atomically. Keep one previous build.1513. On error: log it, keep serving the last good build, retry next tick. Never publish a partial build.1524. If there's no good build yet, the server returns 503 for pages (proxy routes still work).153154## Repo layout155156```157cmd/daumdev/main.go entrypoint: load config, start builder + server158internal/gitea/ API client (only the calls above)159internal/gitx/ git CLI wrappers160internal/build/ build loop, change detection, atomic swap161internal/render/ templates, markdown, highlight, heatmap SVG162internal/server/ router, static files, git + registry proxy, headers163web/templates/*.html embedded164web/static/style.css embedded, saturn tokens + components165Dockerfile multi-stage: golang → alpine + git, non-root166compose.yaml one service, example for deployment167testdata/ sample Gitea JSON + a tiny test repo168```169170### Image171172- Stage 1: `golang:<pinned>` builds a static binary (`CGO_ENABLED=0`, `-trimpath`).173- Stage 2: `alpine:<pinned>` with `git` and `ca-certificates` only (git is needed174 for mirrors; that's why it isn't distroless).175- `USER 10001`, `EXPOSE 8080`, `VOLUME /data`, `HEALTHCHECK` hitting `/healthz`.176- Pin base images by digest. Mirrors are owned by the runtime user, so don't177 add `safe.directory '*'`.178- One `compose.yaml` service:179180```yaml181services:182 daumdev:183 image: daumdev:latest184 read_only: true185 cap_drop: [ALL]186 security_opt: ["no-new-privileges:true"]187 volumes:188 - daumdev-data:/data189 - ./config.json:/config.json:ro190 ports: ["127.0.0.1:8080:8080"]191 restart: unless-stopped192volumes:193 daumdev-data:194```195196## Build order (one commit each)1971981. Skeleton, config loading, Gitea client, profile page with heatmap. Golden test from `testdata`.1992. Git mirror wrapper; repo page with README, latest commit, root tree.2003. Tree, blob (chroma), raw pages; size/binary limits.2014. Log and commit diff pages.2025. Releases, pulls, packages pages.2036. Builder loop: ticker, mutex, atomic swap, change detection.2047. Server: static files, security headers, `/healthz`, 404 default.2058. Git and registry proxy with route allowlist and realm rewrite.2069. Dockerfile + compose.yaml.20710. Security pass: Go tests for the router proving push, API, UI and unlisted paths return 403/404.208209## Done when210211- `git clone https://daum.dev/<repo>.git` works; `git push` to the same URL fails.212- `docker pull daum.dev/daniel/<image>` works anonymously; `docker push` fails.213- `/api/v1/…`, `/user/login`, `/daniel/<repo>` and any unlisted repo return 404.214- A private repo added to config never appears anywhere.215- Pages pass the CSP with zero console errors and render without JavaScript.