From f0dfabe5b7f1f8d23169c6e62a2f0c27bd6c5463 Mon Sep 17 00:00:00 2001 From: bndw Date: Sat, 14 Feb 2026 07:56:22 -0800 Subject: Add cgit web interface for browsing repos Adds cgit as a web frontend for browsing git repositories. Visiting the base domain now shows a cgit repo index with trees, commits, diffs, and blame views. Public repos (marked with git-daemon-export-ok) are browsable and cloneable over HTTPS. - Install cgit during host init - Configure cgit with dark theme and base domain integration - Add cgit CGI handler to base domain Caddyfile - Update README to emphasize git-centric workflow with cgit frontend --- internal/templates/templates.go | 91 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) (limited to 'internal') diff --git a/internal/templates/templates.go b/internal/templates/templates.go index 8f25f8f..b68a504 100644 --- a/internal/templates/templates.go +++ b/internal/templates/templates.go @@ -185,8 +185,24 @@ var codeCaddyTemplate = `{{.BaseDomain}} { } } + @cgitassets path /cgit/* + handle @cgitassets { + root * /usr/share/cgit + uri strip_prefix /cgit + file_server + } + handle { - respond "not found" 404 + reverse_proxy unix//run/fcgiwrap.socket { + transport fastcgi { + env SCRIPT_FILENAME /usr/lib/cgit/cgit.cgi + env QUERY_STRING {query} + env REQUEST_METHOD {method} + env PATH_INFO {path} + env HTTP_HOST {host} + env SERVER_NAME {host} + } + } } } ` @@ -239,6 +255,79 @@ func CodeCaddy(data map[string]string) (string, error) { return renderTemplate("code-caddy", codeCaddyTemplate, data) } +var cgitrcTemplate = `virtual-root=/ +css=/cgit/cgit.css +logo=/cgit/cgit.png +header=/opt/ship/cgit-header.html +scan-path=/srv/git/ +export-ok=git-daemon-export-ok +enable-http-clone=0 +clone-url=https://{{.BaseDomain}}/$CGIT_REPO_URL +root-title={{.BaseDomain}} +root-desc= +remove-suffix=.git +` + +var cgitHeaderTemplate = ` +` + +// CgitRC generates the /etc/cgitrc config file +func CgitRC(data map[string]string) (string, error) { + return renderTemplate("cgitrc", cgitrcTemplate, data) +} + +// CgitHeader generates the cgit header HTML file (dark theme) +func CgitHeader() string { + return cgitHeaderTemplate +} + // DockerService generates a systemd unit for a Docker-based app func DockerService(data map[string]string) (string, error) { return renderTemplate("docker-service", dockerServiceTemplate, data) -- cgit v1.2.3