Documentation
¶
Overview ¶
Package homelab provides homelab application scanning and registry.
Index ¶
- Constants
- Variables
- func AppVersion(app App) string
- func LoadRunRescan() func() error
- func ParseCompose(data []byte) ([]ComposeService, []string, []PortMapping, map[string]string, error)
- func ParseImageVersion(image string) string
- func RunRescan() error
- func SetRunRescan(fn func() error)
- type App
- type AppCapability
- type AppStatus
- type AuthInfo
- type AuthType
- type ComposeService
- type Config
- type DiscoveryConfig
- type DockerComposeRuntime
- func (r *DockerComposeRuntime) Logs(ctx context.Context, app App, tail int) ([]string, error)
- func (r *DockerComposeRuntime) Pull(ctx context.Context, app App) error
- func (r *DockerComposeRuntime) Restart(ctx context.Context, app App) error
- func (r *DockerComposeRuntime) Start(ctx context.Context, app App) error
- func (r *DockerComposeRuntime) Status(ctx context.Context, app App) (AppStatus, error)
- func (r *DockerComposeRuntime) Stop(ctx context.Context, app App) error
- func (r *DockerComposeRuntime) Update(ctx context.Context, app App) error
- type EndpointInfo
- type HealthStatus
- type NoopRuntime
- func (NoopRuntime) Logs(ctx context.Context, _ App, _ int) ([]string, error)
- func (NoopRuntime) Pull(ctx context.Context, _ App) error
- func (NoopRuntime) Restart(ctx context.Context, _ App) error
- func (NoopRuntime) Start(ctx context.Context, _ App) error
- func (NoopRuntime) Status(ctx context.Context, app App) (AppStatus, error)
- func (NoopRuntime) Stop(ctx context.Context, _ App) error
- func (NoopRuntime) Update(ctx context.Context, _ App) error
- type Permissions
- type PortMapping
- type Registry
- type Runtime
- type RuntimeConfig
- type RuntimeMode
- type SSHRuntime
- func (r *SSHRuntime) Logs(ctx context.Context, app App, tail int) ([]string, error)
- func (r *SSHRuntime) Pull(ctx context.Context, app App) error
- func (r *SSHRuntime) Restart(ctx context.Context, app App) error
- func (r *SSHRuntime) Start(ctx context.Context, app App) error
- func (r *SSHRuntime) Status(ctx context.Context, app App) (AppStatus, error)
- func (r *SSHRuntime) Stop(ctx context.Context, app App) error
- func (r *SSHRuntime) Update(ctx context.Context, app App) error
- type Scanner
Constants ¶
const ( CapBookmark = "bookmark" CapArchive = "archive" CapReader = "reader" CapKanban = "kanban" CapFinance = "finance" CapInfra = "infra" CapShellHistory = "shell_history" CapForge = "forge" )
Capability type string constants used for label-based and probe-based discovery. These must stay in sync with pkg/hub/capability.go.
const ( LabelCapability = "flowbot.capability" LabelBackend = "flowbot.backend" LabelEndpointBase = "flowbot.endpoint.base" LabelEndpointHealth = "flowbot.endpoint.health" LabelEndpointHealthTTL = "flowbot.endpoint.health_ttl" LabelAuthType = "flowbot.auth.type" LabelAuthHeader = "flowbot.auth.header" LabelAuthPrefix = "flowbot.auth.prefix" LabelAuthTokenKey = "flowbot.auth.token_key" LabelAuthTokenSource = "flowbot.auth.token_source" )
Label key constants for the flowbot docker-compose label convention.
Variables ¶
var DefaultRegistry = NewRegistry()
DefaultRegistry is the process-wide registry instance.
Functions ¶
func AppVersion ¶
AppVersion extracts the application version from the first service that has a tagged image. Returns an empty string if no tag is found.
func LoadRunRescan ¶ added in v0.93.0
func LoadRunRescan() func() error
LoadRunRescan returns the currently registered rescan function, or nil.
func ParseCompose ¶
func ParseCompose(data []byte) ([]ComposeService, []string, []PortMapping, map[string]string, error)
ParseCompose parses a Docker Compose YAML document and returns the extracted services, network names, aggregated port mappings, and merged labels.
func ParseImageVersion ¶
ParseImageVersion extracts the version tag from a Docker image reference. Returns the portion after the last colon if present and represents a tag (not a registry port); returns an empty string when there is no valid tag or the image uses a digest reference (@sha256:...).
func RunRescan ¶
func RunRescan() error
RunRescan triggers a full homelab scan + probe + registry update. Returns nil if no rescan function has been registered.
func SetRunRescan ¶ added in v0.93.0
func SetRunRescan(fn func() error)
SetRunRescan registers the function used to trigger a full homelab rescan. Safe for concurrent use.
Types ¶
type App ¶
type App struct {
Name string `json:"name"`
Path string `json:"path"`
ComposeFile string `json:"compose_file"`
Services []ComposeService `json:"services,omitzero"`
Networks []string `json:"networks,omitzero"`
Ports []PortMapping `json:"ports,omitzero"`
Labels map[string]string `json:"labels,omitzero"`
Status AppStatus `json:"status"`
Health HealthStatus `json:"health"`
// Capabilities discovered from labels and/or probing.
Capabilities []AppCapability `json:"capabilities,omitzero"`
}
App represents a discovered homelab application with its compose metadata, runtime status, and any capabilities derived from labels or probing.
type AppCapability ¶
type AppCapability struct {
Capability string `json:"capability"`
Backend string `json:"backend"`
Endpoint *EndpointInfo `json:"endpoint,omitzero"`
Auth *AuthInfo `json:"auth,omitzero"`
}
AppCapability links a homelab app to a capability and carries discovered endpoint and authentication metadata for automatic binding.
func ParseLabels ¶
func ParseLabels(labels map[string]string) []AppCapability
ParseLabels extracts AppCapability entries from the labels map using the flowbot label convention. Returns nil when no capability label is present or the capability value is not recognised.
type AppStatus ¶
type AppStatus string
AppStatus indicates the aggregate running state of an app's containers.
type AuthInfo ¶
type AuthInfo struct {
Type AuthType `json:"type"`
Header string `json:"header,omitzero"`
Prefix string `json:"prefix,omitzero"`
TokenKey string `json:"token_key,omitzero"`
TokenSource string `json:"token_source,omitzero"`
}
AuthInfo describes the authentication mechanism discovered for an endpoint.
type AuthType ¶
type AuthType string
AuthType identifies the authentication mechanism used by an API endpoint.
type ComposeService ¶
type ComposeService struct {
Name string `json:"name"`
Image string `json:"image,omitzero"`
Container string `json:"container,omitzero"`
Ports []PortMapping `json:"ports,omitzero"`
}
ComposeService describes a single service entry within a Docker Compose file.
type Config ¶
type Config struct {
Root string
AppsDir string
ComposeFile string
Allowlist []string
Runtime RuntimeConfig
Permissions Permissions
Discovery DiscoveryConfig
}
Config controls how the homelab scanner discovers applications and configures the runtime and permission model.
type DiscoveryConfig ¶
type DiscoveryConfig struct {
ProbeEnabled bool `json:"probe_enabled"`
ProbeTimeout time.Duration `json:"probe_timeout"`
ProbeConcurrency int `json:"probe_concurrency"`
ProbeNetworks []string `json:"probe_networks,omitzero"`
ProbePortStrategy string `json:"probe_port_strategy"`
FingerprintEnabled bool `json:"fingerprint_enabled"`
LabelPriority bool `json:"label_priority"`
}
DiscoveryConfig controls the behaviour of runtime endpoint discovery probing.
type DockerComposeRuntime ¶
type DockerComposeRuntime struct {
// contains filtered or unexported fields
}
DockerComposeRuntime executes docker compose commands locally using the Docker CLI against a configured Docker socket.
func NewDockerComposeRuntime ¶
func NewDockerComposeRuntime(config RuntimeConfig, appsDir string) *DockerComposeRuntime
NewDockerComposeRuntime creates a DockerComposeRuntime that shells out to docker compose using the configured socket path.
func (*DockerComposeRuntime) Pull ¶
func (r *DockerComposeRuntime) Pull(ctx context.Context, app App) error
func (*DockerComposeRuntime) Restart ¶
func (r *DockerComposeRuntime) Restart(ctx context.Context, app App) error
func (*DockerComposeRuntime) Start ¶
func (r *DockerComposeRuntime) Start(ctx context.Context, app App) error
type EndpointInfo ¶
type EndpointInfo struct {
BaseURL string `json:"base_url"`
Health string `json:"health,omitzero"`
HealthTTL time.Duration `json:"health_ttl,omitzero"`
Ports []int `json:"ports,omitzero"`
}
EndpointInfo describes a discovered API endpoint on an app service.
type HealthStatus ¶
type HealthStatus string
HealthStatus indicates the observed health of an app.
const ( HealthUnknown HealthStatus = "unknown" HealthHealthy HealthStatus = "healthy" HealthUnhealthy HealthStatus = "unhealthy" )
type NoopRuntime ¶
type NoopRuntime struct{}
NoopRuntime is a Runtime that returns not-implemented errors for all mutating operations and preserves the existing status on reads.
type Permissions ¶
type Permissions struct {
Status bool
Logs bool
Start bool
Stop bool
Restart bool
Pull bool
Update bool
Exec bool
}
Permissions defines which container lifecycle operations are allowed.
type PortMapping ¶
type PortMapping struct {
Host string `json:"host,omitzero"`
HostPort string `json:"host_port,omitzero"`
Container string `json:"container,omitzero"`
Protocol string `json:"protocol,omitzero"`
}
PortMapping represents a single host-to-container port binding.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds the current set of discovered homelab applications and their associated permissions, protected by a read-write mutex.
func NewRegistry ¶
func NewRegistry() *Registry
func (*Registry) Permissions ¶
func (r *Registry) Permissions() Permissions
func (*Registry) SetPermissions ¶
func (r *Registry) SetPermissions(p Permissions)
type Runtime ¶
type Runtime interface {
Status(ctx context.Context, app App) (AppStatus, error)
Logs(ctx context.Context, app App, tail int) ([]string, error)
Start(ctx context.Context, app App) error
Stop(ctx context.Context, app App) error
Restart(ctx context.Context, app App) error
Pull(ctx context.Context, app App) error
Update(ctx context.Context, app App) error
}
Runtime defines the container lifecycle operations that can be performed on a homelab application.
var DefaultRuntime Runtime = NoopRuntime{}
DefaultRuntime is the process-wide runtime used when no explicit runtime is provided. Defaults to NoopRuntime.
func NewRuntime ¶
func NewRuntime(config RuntimeConfig, appsDir string) Runtime
NewRuntime selects the appropriate Runtime implementation based on the configured mode.
type RuntimeConfig ¶
type RuntimeConfig struct {
Mode RuntimeMode
DockerSocket string
SSHHost string
SSHPort int
SSHUser string
SSHPassword string
SSHKey string
SSHHostKey string
}
RuntimeConfig selects the runtime mode and its connection parameters.
type RuntimeMode ¶
type RuntimeMode string
RuntimeMode selects which backend the homelab runtime uses.
const ( RuntimeModeNone RuntimeMode = "none" RuntimeModeDockerSocket RuntimeMode = "docker_socket" RuntimeModeSSH RuntimeMode = "ssh" )
type SSHRuntime ¶
type SSHRuntime struct {
// contains filtered or unexported fields
}
SSHRuntime executes docker compose commands on a remote host over SSH.
func NewSSHRuntime ¶
func NewSSHRuntime(config RuntimeConfig, appsDir string) *SSHRuntime
NewSSHRuntime creates an SSHRuntime that connects to the configured host.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner discovers homelab applications by scanning a directory for Docker Compose files and parsing their metadata.
func NewScanner ¶
NewScanner creates a Scanner with normalised configuration defaults.