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
|
|
@ -12,8 +12,14 @@ import (
|
|||
)
|
||||
|
||||
type fileConfig struct {
|
||||
RuntimeDir string `toml:"runtime_dir"`
|
||||
RepoRoot string `toml:"repo_root"`
|
||||
FirecrackerBin string `toml:"firecracker_bin"`
|
||||
SSHKeyPath string `toml:"ssh_key_path"`
|
||||
NamegenPath string `toml:"namegen_path"`
|
||||
CustomizeScript string `toml:"customize_script"`
|
||||
DefaultImageName string `toml:"default_image_name"`
|
||||
DefaultRootfs string `toml:"default_rootfs"`
|
||||
DefaultBaseRootfs string `toml:"default_base_rootfs"`
|
||||
DefaultKernel string `toml:"default_kernel"`
|
||||
DefaultInitrd string `toml:"default_initrd"`
|
||||
|
|
@ -30,7 +36,6 @@ type fileConfig struct {
|
|||
|
||||
func Load(layout paths.Layout) (model.DaemonConfig, error) {
|
||||
cfg := model.DaemonConfig{
|
||||
RepoRoot: paths.DetectRepoRoot(),
|
||||
AutoStopStaleAfter: 0,
|
||||
StatsPollInterval: model.DefaultStatsPollInterval,
|
||||
MetricsPollInterval: model.DefaultMetricsPollInterval,
|
||||
|
|
@ -40,39 +45,45 @@ func Load(layout paths.Layout) (model.DaemonConfig, error) {
|
|||
DefaultDNS: model.DefaultDNS,
|
||||
DefaultImageName: "default",
|
||||
}
|
||||
if cfg.RepoRoot != "" {
|
||||
cfg.DefaultBaseRootfs = filepath.Join(cfg.RepoRoot, "rootfs.ext4")
|
||||
cfg.DefaultKernel = filepath.Join(cfg.RepoRoot, "wtf/root/boot/vmlinux-6.8.0-94-generic")
|
||||
cfg.DefaultInitrd = filepath.Join(cfg.RepoRoot, "wtf/root/boot/initrd.img-6.8.0-94-generic")
|
||||
cfg.DefaultModulesDir = filepath.Join(cfg.RepoRoot, "wtf/root/lib/modules/6.8.0-94-generic")
|
||||
cfg.DefaultPackagesFile = filepath.Join(cfg.RepoRoot, "packages.apt")
|
||||
}
|
||||
|
||||
path := filepath.Join(layout.ConfigDir, "config.toml")
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return cfg, nil
|
||||
}
|
||||
return cfg, err
|
||||
}
|
||||
if info.IsDir() {
|
||||
return cfg, nil
|
||||
}
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
var file fileConfig
|
||||
if err := toml.Unmarshal(data, &file); err != nil {
|
||||
return cfg, err
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return cfg, err
|
||||
}
|
||||
} else if !info.IsDir() {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
if err := toml.Unmarshal(data, &file); err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
}
|
||||
if file.RepoRoot != "" {
|
||||
cfg.RepoRoot = file.RepoRoot
|
||||
|
||||
cfg.RuntimeDir = paths.ResolveRuntimeDir(file.RuntimeDir, file.RepoRoot)
|
||||
applyRuntimeDefaults(&cfg)
|
||||
|
||||
if file.FirecrackerBin != "" {
|
||||
cfg.FirecrackerBin = file.FirecrackerBin
|
||||
}
|
||||
if file.SSHKeyPath != "" {
|
||||
cfg.SSHKeyPath = file.SSHKeyPath
|
||||
}
|
||||
if file.NamegenPath != "" {
|
||||
cfg.NamegenPath = file.NamegenPath
|
||||
}
|
||||
if file.CustomizeScript != "" {
|
||||
cfg.CustomizeScript = file.CustomizeScript
|
||||
}
|
||||
if file.DefaultImageName != "" {
|
||||
cfg.DefaultImageName = file.DefaultImageName
|
||||
}
|
||||
if file.DefaultRootfs != "" {
|
||||
cfg.DefaultRootfs = file.DefaultRootfs
|
||||
}
|
||||
if file.DefaultBaseRootfs != "" {
|
||||
cfg.DefaultBaseRootfs = file.DefaultBaseRootfs
|
||||
}
|
||||
|
|
@ -123,3 +134,48 @@ func Load(layout paths.Layout) (model.DaemonConfig, error) {
|
|||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func applyRuntimeDefaults(cfg *model.DaemonConfig) {
|
||||
if cfg.RuntimeDir == "" {
|
||||
return
|
||||
}
|
||||
cfg.FirecrackerBin = defaultRuntimePath(cfg.FirecrackerBin, cfg.RuntimeDir, "firecracker")
|
||||
cfg.SSHKeyPath = defaultRuntimePath(cfg.SSHKeyPath, cfg.RuntimeDir, "id_ed25519")
|
||||
cfg.NamegenPath = defaultRuntimePath(cfg.NamegenPath, cfg.RuntimeDir, "namegen")
|
||||
cfg.CustomizeScript = defaultRuntimePath(cfg.CustomizeScript, cfg.RuntimeDir, "customize.sh")
|
||||
cfg.DefaultKernel = defaultRuntimePath(cfg.DefaultKernel, cfg.RuntimeDir, "wtf/root/boot/vmlinux-6.8.0-94-generic")
|
||||
cfg.DefaultInitrd = defaultRuntimePath(cfg.DefaultInitrd, cfg.RuntimeDir, "wtf/root/boot/initrd.img-6.8.0-94-generic")
|
||||
cfg.DefaultModulesDir = defaultRuntimePath(cfg.DefaultModulesDir, cfg.RuntimeDir, "wtf/root/lib/modules/6.8.0-94-generic")
|
||||
cfg.DefaultPackagesFile = defaultRuntimePath(cfg.DefaultPackagesFile, cfg.RuntimeDir, "packages.apt")
|
||||
if cfg.DefaultRootfs == "" {
|
||||
cfg.DefaultRootfs = firstExistingRuntimePath(
|
||||
filepath.Join(cfg.RuntimeDir, "rootfs-docker.ext4"),
|
||||
filepath.Join(cfg.RuntimeDir, "rootfs.ext4"),
|
||||
)
|
||||
}
|
||||
if cfg.DefaultBaseRootfs == "" {
|
||||
cfg.DefaultBaseRootfs = firstExistingRuntimePath(
|
||||
filepath.Join(cfg.RuntimeDir, "rootfs.ext4"),
|
||||
cfg.DefaultRootfs,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func defaultRuntimePath(current, runtimeDir, relative string) string {
|
||||
if current != "" {
|
||||
return current
|
||||
}
|
||||
return filepath.Join(runtimeDir, relative)
|
||||
}
|
||||
|
||||
func firstExistingRuntimePath(paths ...string) string {
|
||||
for _, candidate := range paths {
|
||||
if candidate == "" {
|
||||
continue
|
||||
}
|
||||
if _, err := os.Stat(candidate); err == nil {
|
||||
return candidate
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue