orchard
mirrorEvery site I host, in one repo, along with the Cloudflare Tunnel and Caddy that front them. It's all Go, Vite, and SQLite, and it runs on a desktop at home with nothing listening on an inbound port.
blogbuncaddycloudflare-tunneldockergogolanghomelabhtml-templatemonorepoself-hostedseosqlitestatic-sitetypstuptime-monitoringviteweb-analytics
1.PHONY: run build frontend clean
2
3# Vite watches and rebuilds build/dist while Go serves it from disk. Templates
4# are embedded, so a template change needs a Go restart; CSS and JS changes only
5# need a browser reload.
6#
7# Go waits for the manifest rather than sleeping a guessed number of seconds:
8# the server treats a missing manifest as fatal, so the startup order matters.
9#
10# REPOS_MIRROR=0 by default here. A dev run that clones the whole GitHub account
11# before it will serve a page is not a dev run.
12run:
13 cd frontend && bun run dev & \
14 i=0; while [ ! -f build/dist/.vite/manifest.json ]; do \
15 i=$$((i+1)); \
16 if [ $$i -gt 120 ]; then echo "vite did not produce a manifest in 60s" >&2; exit 1; fi; \
17 sleep 0.5; \
18 done; \
19 REPOS_MIRROR=$${REPOS_MIRROR:-0} REPOS_PASSWORD=$${REPOS_PASSWORD:-dev} go run .
20
21frontend:
22 cd frontend && bun install --frozen-lockfile && bun run build
23
24# The release binary. -tags embed swaps assets_disk.go for assets_embed.go, so
25# the Vite bundle is compiled in and ../../bin/repos.bythewood.me is the whole
26# server. The repositories it serves stay outside it, on a volume.
27build: frontend
28 go build -tags embed -trimpath -ldflags="-s -w" -o ../../bin/repos.bythewood.me .
29
30# build/repos holds real git repositories in dev. Removing it is removing data,
31# so clean leaves it alone and says so.
32clean:
33 rm -rf build/dist frontend/node_modules
34 @echo "left build/repos and build/data alone; they hold real repositories"