OCI layer blobs accumulate forever — every pull writes layers to
~/.cache/banger/oci/blobs/sha256/<hex> via go-containerregistry's
filesystem cache, and nothing ever evicts them. The cache is purely
a re-pull-avoidance (every flattened image is independent of the
blobs that sourced it), so it's a perfect candidate for an opt-in
operator-driven prune.
New surface:
* api: ImageCachePruneParams{DryRun}, ImageCachePruneResult
{BytesFreed, BlobsFreed, DryRun, CacheDir}.
* daemon: ImageService.PruneOCICache walks layout.OCICacheDir for
a (bytes, blobs) tally, then — outside dry-run — atomically
renames the cache aside, recreates it empty, and rm -rf's the
aside dir. The rename-then-rm avoids leaving the cache in a
half-removed state if a pull starts mid-prune (the in-flight
pull's open files survive the rename via standard Linux
semantics; it just sees a fresh empty cache afterwards). Missing
cache dir is treated as zero — fresh installs that have never
pulled an OCI image don't error.
* dispatch: image.cache.prune RPC (paramHandler-wrapped, mirroring
every other image RPC). Documented-methods test list updated.
* cli: `banger image cache` group with a `prune` subcommand
(--dry-run flag). Output is a single line: "freed 1.2 GiB
across 47 blob(s) in /var/cache/banger/oci" or "would free …".
formatBytes helper for the size pretty-print.
docs/oci-import.md: replaced the "Tech debt: cache eviction" bullet
with a "Cache lifecycle" section describing the new command and
the in-flight-pull caveat.
Tests: PruneOCICache covers the happy path (real prune empties the
cache, recreates an empty dir, doesn't leak the .pruning- aside),
the dry-run path (returns size, leaves blobs intact), and the
fresh-install path (cache dir absent → zero result, no error).
Smoke at JOBS=4 still green; live exercise against an empty cache
on a system install prints the expected zero summary.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
245 lines
6.6 KiB
Go
245 lines
6.6 KiB
Go
package api
|
|
|
|
import (
|
|
"time"
|
|
|
|
"banger/internal/model"
|
|
)
|
|
|
|
type Empty struct{}
|
|
|
|
type PingResult struct {
|
|
Status string `json:"status"`
|
|
PID int `json:"pid"`
|
|
Version string `json:"version,omitempty"`
|
|
Commit string `json:"commit,omitempty"`
|
|
BuiltAt string `json:"built_at,omitempty"`
|
|
}
|
|
|
|
type ShutdownResult struct {
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
type VMCreateParams struct {
|
|
Name string `json:"name,omitempty"`
|
|
ImageName string `json:"image_name,omitempty"`
|
|
VCPUCount *int `json:"vcpu_count,omitempty"`
|
|
MemoryMiB *int `json:"memory_mib,omitempty"`
|
|
SystemOverlaySize string `json:"system_overlay_size,omitempty"`
|
|
WorkDiskSize string `json:"work_disk_size,omitempty"`
|
|
NATEnabled bool `json:"nat_enabled,omitempty"`
|
|
NoStart bool `json:"no_start,omitempty"`
|
|
}
|
|
|
|
type VMCreateStatusParams struct {
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
type VMCreateOperation struct {
|
|
ID string `json:"id"`
|
|
VMID string `json:"vm_id,omitempty"`
|
|
VMName string `json:"vm_name,omitempty"`
|
|
Stage string `json:"stage,omitempty"`
|
|
Detail string `json:"detail,omitempty"`
|
|
StartedAt time.Time `json:"started_at,omitempty"`
|
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
|
Done bool `json:"done"`
|
|
Success bool `json:"success"`
|
|
Error string `json:"error,omitempty"`
|
|
VM *model.VMRecord `json:"vm,omitempty"`
|
|
}
|
|
|
|
type VMCreateBeginResult struct {
|
|
Operation VMCreateOperation `json:"operation"`
|
|
}
|
|
|
|
type VMCreateStatusResult struct {
|
|
Operation VMCreateOperation `json:"operation"`
|
|
}
|
|
|
|
type VMRefParams struct {
|
|
IDOrName string `json:"id_or_name"`
|
|
}
|
|
|
|
type VMKillParams struct {
|
|
IDOrName string `json:"id_or_name"`
|
|
Signal string `json:"signal,omitempty"`
|
|
}
|
|
|
|
type VMSetParams struct {
|
|
IDOrName string `json:"id_or_name"`
|
|
VCPUCount *int `json:"vcpu_count,omitempty"`
|
|
MemoryMiB *int `json:"memory_mib,omitempty"`
|
|
WorkDiskSize string `json:"work_disk_size,omitempty"`
|
|
NATEnabled *bool `json:"nat_enabled,omitempty"`
|
|
}
|
|
|
|
type VMListResult struct {
|
|
VMs []model.VMRecord `json:"vms"`
|
|
}
|
|
|
|
type VMShowResult struct {
|
|
VM model.VMRecord `json:"vm"`
|
|
}
|
|
|
|
type VMStatsResult struct {
|
|
VM model.VMRecord `json:"vm"`
|
|
Stats model.VMStats `json:"stats"`
|
|
}
|
|
|
|
type VMLogsResult struct {
|
|
LogPath string `json:"log_path"`
|
|
}
|
|
|
|
type VMSSHResult struct {
|
|
Name string `json:"name"`
|
|
GuestIP string `json:"guest_ip"`
|
|
}
|
|
|
|
type VMHealthResult struct {
|
|
Name string `json:"name"`
|
|
Healthy bool `json:"healthy"`
|
|
}
|
|
|
|
type VMPingResult struct {
|
|
Name string `json:"name"`
|
|
Alive bool `json:"alive"`
|
|
}
|
|
|
|
type VMPort struct {
|
|
Proto string `json:"proto"`
|
|
BindAddress string `json:"bind_address,omitempty"`
|
|
Port int `json:"port"`
|
|
PID int `json:"pid,omitempty"`
|
|
Process string `json:"process,omitempty"`
|
|
Command string `json:"command,omitempty"`
|
|
Endpoint string `json:"endpoint,omitempty"`
|
|
}
|
|
|
|
type VMPortsResult struct {
|
|
Name string `json:"name"`
|
|
DNSName string `json:"dns_name,omitempty"`
|
|
Ports []VMPort `json:"ports"`
|
|
}
|
|
|
|
type WorkspaceExportParams struct {
|
|
IDOrName string `json:"id_or_name"`
|
|
GuestPath string `json:"guest_path,omitempty"`
|
|
BaseCommit string `json:"base_commit,omitempty"`
|
|
}
|
|
|
|
type WorkspaceExportResult struct {
|
|
GuestPath string `json:"guest_path"`
|
|
BaseCommit string `json:"base_commit"`
|
|
Patch []byte `json:"patch"`
|
|
ChangedFiles []string `json:"changed_files"`
|
|
HasChanges bool `json:"has_changes"`
|
|
}
|
|
|
|
type VMWorkspacePrepareParams struct {
|
|
IDOrName string `json:"id_or_name"`
|
|
SourcePath string `json:"source_path"`
|
|
GuestPath string `json:"guest_path,omitempty"`
|
|
Branch string `json:"branch,omitempty"`
|
|
From string `json:"from,omitempty"`
|
|
Mode string `json:"mode,omitempty"`
|
|
IncludeUntracked bool `json:"include_untracked,omitempty"`
|
|
}
|
|
|
|
type VMWorkspacePrepareResult struct {
|
|
Workspace model.WorkspacePrepareResult `json:"workspace"`
|
|
}
|
|
|
|
type ImageRegisterParams struct {
|
|
Name string `json:"name,omitempty"`
|
|
RootfsPath string `json:"rootfs_path,omitempty"`
|
|
WorkSeedPath string `json:"work_seed_path,omitempty"`
|
|
KernelPath string `json:"kernel_path,omitempty"`
|
|
InitrdPath string `json:"initrd_path,omitempty"`
|
|
ModulesDir string `json:"modules_dir,omitempty"`
|
|
KernelRef string `json:"kernel_ref,omitempty"`
|
|
}
|
|
|
|
type ImagePullParams struct {
|
|
Ref string `json:"ref"`
|
|
Name string `json:"name,omitempty"`
|
|
KernelPath string `json:"kernel_path,omitempty"`
|
|
InitrdPath string `json:"initrd_path,omitempty"`
|
|
ModulesDir string `json:"modules_dir,omitempty"`
|
|
KernelRef string `json:"kernel_ref,omitempty"`
|
|
SizeBytes int64 `json:"size_bytes,omitempty"`
|
|
}
|
|
|
|
type ImageRefParams struct {
|
|
IDOrName string `json:"id_or_name"`
|
|
}
|
|
|
|
type ImageCachePruneParams struct {
|
|
DryRun bool `json:"dry_run,omitempty"`
|
|
}
|
|
|
|
type ImageCachePruneResult struct {
|
|
BytesFreed int64 `json:"bytes_freed"`
|
|
BlobsFreed int `json:"blobs_freed"`
|
|
DryRun bool `json:"dry_run"`
|
|
CacheDir string `json:"cache_dir"`
|
|
}
|
|
|
|
type ImageListResult struct {
|
|
Images []model.Image `json:"images"`
|
|
}
|
|
|
|
type ImageShowResult struct {
|
|
Image model.Image `json:"image"`
|
|
}
|
|
|
|
type KernelEntry struct {
|
|
Name string `json:"name"`
|
|
Distro string `json:"distro,omitempty"`
|
|
Arch string `json:"arch,omitempty"`
|
|
KernelVersion string `json:"kernel_version,omitempty"`
|
|
SHA256 string `json:"sha256,omitempty"`
|
|
Source string `json:"source,omitempty"`
|
|
ImportedAt string `json:"imported_at,omitempty"`
|
|
KernelPath string `json:"kernel_path,omitempty"`
|
|
InitrdPath string `json:"initrd_path,omitempty"`
|
|
ModulesDir string `json:"modules_dir,omitempty"`
|
|
}
|
|
|
|
type KernelListResult struct {
|
|
Entries []KernelEntry `json:"entries"`
|
|
}
|
|
|
|
type KernelRefParams struct {
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
type KernelShowResult struct {
|
|
Entry KernelEntry `json:"entry"`
|
|
}
|
|
|
|
type KernelImportParams struct {
|
|
Name string `json:"name"`
|
|
FromDir string `json:"from_dir"`
|
|
Distro string `json:"distro,omitempty"`
|
|
Arch string `json:"arch,omitempty"`
|
|
}
|
|
|
|
type KernelPullParams struct {
|
|
Name string `json:"name"`
|
|
Force bool `json:"force,omitempty"`
|
|
}
|
|
|
|
type KernelCatalogEntry struct {
|
|
Name string `json:"name"`
|
|
Distro string `json:"distro,omitempty"`
|
|
Arch string `json:"arch,omitempty"`
|
|
KernelVersion string `json:"kernel_version,omitempty"`
|
|
SizeBytes int64 `json:"size_bytes,omitempty"`
|
|
Description string `json:"description,omitempty"`
|
|
Pulled bool `json:"pulled"`
|
|
}
|
|
|
|
type KernelCatalogResult struct {
|
|
Entries []KernelCatalogEntry `json:"entries"`
|
|
}
|