Make installed banger self-contained
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).
This commit is contained in:
parent
375900cf65
commit
ce1be52047
13 changed files with 437 additions and 107 deletions
|
|
@ -4,7 +4,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -66,57 +65,64 @@ func Ensure(layout Layout) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func DetectRepoRoot() string {
|
||||
if env := os.Getenv("BANGER_REPO_ROOT"); env != "" {
|
||||
return env
|
||||
}
|
||||
candidates := []string{}
|
||||
if wd, err := os.Getwd(); err == nil {
|
||||
candidates = append(candidates, wd)
|
||||
}
|
||||
if exe, err := os.Executable(); err == nil {
|
||||
candidates = append(candidates, filepath.Dir(exe))
|
||||
}
|
||||
if look, err := exec.LookPath("firecracker"); err == nil {
|
||||
candidates = append(candidates, filepath.Dir(look))
|
||||
}
|
||||
for _, candidate := range candidates {
|
||||
if root := walkForRepoRoot(candidate); root != "" {
|
||||
return root
|
||||
var executablePath = os.Executable
|
||||
|
||||
func ResolveRuntimeDir(configuredRuntimeDir, deprecatedRepoRoot string) string {
|
||||
for _, candidate := range []string{
|
||||
os.Getenv("BANGER_RUNTIME_DIR"),
|
||||
os.Getenv("BANGER_REPO_ROOT"),
|
||||
configuredRuntimeDir,
|
||||
deprecatedRepoRoot,
|
||||
} {
|
||||
if candidate = strings.TrimSpace(candidate); candidate != "" {
|
||||
return filepath.Clean(candidate)
|
||||
}
|
||||
}
|
||||
exe, err := executablePath()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
exeDir := filepath.Dir(exe)
|
||||
if filepath.Base(exeDir) == "bin" {
|
||||
installRuntimeDir := filepath.Clean(filepath.Join(exeDir, "..", "lib", "banger"))
|
||||
if HasRuntimeBundle(installRuntimeDir) {
|
||||
return installRuntimeDir
|
||||
}
|
||||
}
|
||||
if HasRuntimeBundle(exeDir) {
|
||||
return exeDir
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func walkForRepoRoot(start string) string {
|
||||
current := start
|
||||
for {
|
||||
if hasRepoArtifacts(current) {
|
||||
return current
|
||||
}
|
||||
parent := filepath.Dir(current)
|
||||
if parent == current {
|
||||
return ""
|
||||
}
|
||||
current = parent
|
||||
func HasRuntimeBundle(dir string) bool {
|
||||
if strings.TrimSpace(dir) == "" {
|
||||
return false
|
||||
}
|
||||
required := []string{
|
||||
"firecracker",
|
||||
"customize.sh",
|
||||
"packages.apt",
|
||||
"wtf/root/boot/vmlinux-6.8.0-94-generic",
|
||||
}
|
||||
}
|
||||
|
||||
func hasRepoArtifacts(dir string) bool {
|
||||
required := []string{"firecracker", "README.md"}
|
||||
for _, name := range required {
|
||||
if _, err := os.Stat(filepath.Join(dir, name)); err != nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
for _, name := range []string{"rootfs-docker.ext4", "rootfs.ext4"} {
|
||||
if _, err := os.Stat(filepath.Join(dir, name)); err == nil {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func BangerdPath() (string, error) {
|
||||
if env := os.Getenv("BANGER_DAEMON_BIN"); env != "" {
|
||||
return env, nil
|
||||
}
|
||||
exe, err := os.Executable()
|
||||
exe, err := executablePath()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
@ -129,16 +135,6 @@ func BangerdPath() (string, error) {
|
|||
return candidate, nil
|
||||
}
|
||||
}
|
||||
if root := DetectRepoRoot(); root != "" {
|
||||
for _, candidate := range []string{
|
||||
filepath.Join(root, "bangerd"),
|
||||
filepath.Join(root, "bangerd.exe"),
|
||||
} {
|
||||
if _, err := os.Stat(candidate); err == nil {
|
||||
return candidate, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", errors.New("bangerd binary not found next to banger; build ./cmd/bangerd")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue