Fix the misleading make install path where banger and bangerd still depended on a repo checkout for Firecracker, guest artifacts, image builds, and the SSH key. Replace repo-root inference with an explicit runtime bundle model: resolve a runtime_dir from env/config/install layout, derive concrete artifact paths from it, and update the daemon, CLI, and image-build flow to use those paths. Keep repo_root only as an explicit compatibility alias instead of auto-detecting it. Teach customize.sh to run from a read-only bundled runtime tree while writing transient state under XDG/BANGER_STATE_DIR, and make make install copy the runtime assets into PREFIX/lib/banger so installed binaries stay usable outside the repo. Validate with go test ./..., make build, bash -n customize.sh, and make install DESTDIR=/tmp/banger-install PREFIX=/usr. An out-of-repo installed-binary smoke test was attempted, but this sandbox blocked bangerd from binding its Unix socket (setsockopt: operation not permitted).
72 lines
2.3 KiB
Go
72 lines
2.3 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"banger/internal/paths"
|
|
)
|
|
|
|
func TestLoadDerivesArtifactPathsFromRuntimeDir(t *testing.T) {
|
|
runtimeDir := t.TempDir()
|
|
for _, rel := range []string{
|
|
"firecracker",
|
|
"id_ed25519",
|
|
"namegen",
|
|
"customize.sh",
|
|
"packages.apt",
|
|
"rootfs-docker.ext4",
|
|
"wtf/root/boot/vmlinux-6.8.0-94-generic",
|
|
"wtf/root/boot/initrd.img-6.8.0-94-generic",
|
|
"wtf/root/lib/modules/6.8.0-94-generic/modules.dep",
|
|
} {
|
|
path := filepath.Join(runtimeDir, rel)
|
|
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
|
t.Fatalf("mkdir %s: %v", filepath.Dir(path), err)
|
|
}
|
|
if err := os.WriteFile(path, []byte("test"), 0o644); err != nil {
|
|
t.Fatalf("write %s: %v", path, err)
|
|
}
|
|
}
|
|
|
|
t.Setenv("BANGER_RUNTIME_DIR", runtimeDir)
|
|
cfg, err := Load(paths.Layout{ConfigDir: t.TempDir()})
|
|
if err != nil {
|
|
t.Fatalf("Load: %v", err)
|
|
}
|
|
|
|
if cfg.RuntimeDir != runtimeDir {
|
|
t.Fatalf("RuntimeDir = %q, want %q", cfg.RuntimeDir, runtimeDir)
|
|
}
|
|
if cfg.FirecrackerBin != filepath.Join(runtimeDir, "firecracker") {
|
|
t.Fatalf("FirecrackerBin = %q", cfg.FirecrackerBin)
|
|
}
|
|
if cfg.SSHKeyPath != filepath.Join(runtimeDir, "id_ed25519") {
|
|
t.Fatalf("SSHKeyPath = %q", cfg.SSHKeyPath)
|
|
}
|
|
if cfg.NamegenPath != filepath.Join(runtimeDir, "namegen") {
|
|
t.Fatalf("NamegenPath = %q", cfg.NamegenPath)
|
|
}
|
|
if cfg.CustomizeScript != filepath.Join(runtimeDir, "customize.sh") {
|
|
t.Fatalf("CustomizeScript = %q", cfg.CustomizeScript)
|
|
}
|
|
if cfg.DefaultRootfs != filepath.Join(runtimeDir, "rootfs-docker.ext4") {
|
|
t.Fatalf("DefaultRootfs = %q", cfg.DefaultRootfs)
|
|
}
|
|
if cfg.DefaultBaseRootfs != filepath.Join(runtimeDir, "rootfs-docker.ext4") {
|
|
t.Fatalf("DefaultBaseRootfs = %q", cfg.DefaultBaseRootfs)
|
|
}
|
|
if cfg.DefaultKernel != filepath.Join(runtimeDir, "wtf/root/boot/vmlinux-6.8.0-94-generic") {
|
|
t.Fatalf("DefaultKernel = %q", cfg.DefaultKernel)
|
|
}
|
|
if cfg.DefaultInitrd != filepath.Join(runtimeDir, "wtf/root/boot/initrd.img-6.8.0-94-generic") {
|
|
t.Fatalf("DefaultInitrd = %q", cfg.DefaultInitrd)
|
|
}
|
|
if cfg.DefaultModulesDir != filepath.Join(runtimeDir, "wtf/root/lib/modules/6.8.0-94-generic") {
|
|
t.Fatalf("DefaultModulesDir = %q", cfg.DefaultModulesDir)
|
|
}
|
|
if cfg.DefaultPackagesFile != filepath.Join(runtimeDir, "packages.apt") {
|
|
t.Fatalf("DefaultPackagesFile = %q", cfg.DefaultPackagesFile)
|
|
}
|
|
}
|