repos
/ orchard main

orchard

mirror

Every 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

2.2 KB · 76 lines · Go Raw History
 1package main
 2
 3import (
 4	"os"
 5	"path/filepath"
 6	"strings"
 7	"time"
 8)
 9
10const (
11	baseURL     = "https://repos.bythewood.me"
12	siteName    = "repos"
13	siteTagline = "Isaac Bythewood's source code"
14	authorName  = "Isaac Bythewood"
15	githubUser  = "overshard"
16
17	// analyticsID is in the page source of every site; it is identity, not a credential.
18	analyticsID = "49f89ef6-b0b2-4b47-879e-7e252a067d0c"
19
20	// containerName is baked in, not read at runtime. Repository pages show it
21	// as the bridge URL to seed a first push through, bypassing Cloudflare.
22	containerName = "orchard-repos"
23)
24
25// cloudflareBodyLimit is Cloudflare's ceiling on a proxied request body, 100MB on
26// Free and Pro. A tunnel hostname must stay proxied, so nothing here can raise it.
27const cloudflareBodyLimit = 100 << 20
28
29// Staging keeps a test hostname out of search results.
30var Staging = !strings.HasSuffix(baseURL, "//repos.bythewood.me")
31
32// Config is everything the environment sets.
33type Config struct {
34	// RepoRoot holds the bare repositories.
35	RepoRoot string
36	// DataDir holds repos.db.
37	DataDir string
38	// MirrorEvery is how often the GitHub mirror lane runs.
39	MirrorEvery time.Duration
40	// GCEvery is how often repositories are repacked, which nothing else does
41	// now that receive.autogc is off.
42	GCEvery time.Duration
43	// MirrorEnabled turns the GitHub lane off for dev runs.
44	MirrorEnabled bool
45}
46
47func LoadConfig() Config {
48	c := Config{
49		RepoRoot:      env("REPOS_ROOT", "./build/repos"),
50		DataDir:       env("REPOS_DATA", "./build/data"),
51		MirrorEvery:   6 * time.Hour,
52		GCEvery:       24 * time.Hour,
53		MirrorEnabled: os.Getenv("REPOS_MIRROR") != "0",
54	}
55
56	// git-http-backend runs with its working directory set to GIT_PROJECT_ROOT
57	// and resolves repositories under it, so a relative root resolves against
58	// itself and every clone 404s.
59	if abs, err := filepath.Abs(c.RepoRoot); err == nil {
60		c.RepoRoot = abs
61	}
62	if abs, err := filepath.Abs(c.DataDir); err == nil {
63		c.DataDir = abs
64	}
65	return c
66}
67
68func env(key, fallback string) string {
69	if v := os.Getenv(key); v != "" {
70		return v
71	}
72	return fallback
73}
74
75const sourceURL = "https://github.com/" + githubUser + "/orchard/tree/main/sites/repos.bythewood.me"