fix(pods): bind-mount host public_html into the pod so ~/public_html is served

A member's pod home (/home/dev) is a named container volume, but Caddy serves
<name>.<host> from the host path <data>/users/<name>/public_html. The two were
disconnected, so editing ~/public_html/index.html in the pod never changed the
served page — contradicting the on-screen "edit ~/public_html to make it yours"
instruction.

Bind-mount <data>/users/<user>/public_html at /home/dev/public_html when pods
start. The host tree is created if absent so the mount source exists, and under
the docker fallback (uid 1000) the one-shot init container now also chowns the
bind path; rootless podman maps container root to the host service user that
already owns the tree, so no chown is needed there.

Detect now takes the host users dir; pass "" to disable the bind.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Anthony Ettinger 2026-06-15 13:42:08 +00:00
parent 243ef58e59
commit 06bc5631d8
3 changed files with 129 additions and 22 deletions

View file

@ -0,0 +1,37 @@
package pods
import (
"os"
"path/filepath"
"testing"
)
// When no users dir is configured the bind is disabled: both return values are
// empty and no directory is created.
func TestPublicHTMLMountDisabled(t *testing.T) {
m := &Manager{} // usersDir == ""
host, spec := m.publicHTMLMount("chovy")
if host != "" || spec != "" {
t.Fatalf("expected empty host/spec when usersDir unset, got host=%q spec=%q", host, spec)
}
}
// With a users dir set, the member's public_html is created on the host and the
// volume spec maps it to /home/dev/public_html in the pod.
func TestPublicHTMLMountCreatesAndMaps(t *testing.T) {
users := t.TempDir()
m := &Manager{usersDir: users}
host, spec := m.publicHTMLMount("chovy")
wantHost := filepath.Join(users, "chovy", "public_html")
if host != wantHost {
t.Fatalf("host = %q, want %q", host, wantHost)
}
if want := wantHost + ":/home/dev/public_html"; spec != want {
t.Fatalf("spec = %q, want %q", spec, want)
}
if fi, err := os.Stat(wantHost); err != nil || !fi.IsDir() {
t.Fatalf("expected %q to be a created directory, err=%v", wantHost, err)
}
}