Documentation
¶
Overview ¶
Package update finds newer VirtoMir releases on GitHub and installs them (ADR-0036): it downloads the release file that matches how this host installed VirtoMir and checks it against the published SHA-256, whose signature by the release key (.sha256.asc) it checks first. A .deb goes to apt and an .rpm to dnf in a transient systemd unit, so the upgrade survives the restart of virtomird itself; any other install (tarball, install.sh, a binary run from anywhere) gets the binary from the release tarball swapped in place and the daemon restarted.
Index ¶
- Constants
- func DebVersion(tag string) string
- func Newer(a, b string) bool
- type AutoConfig
- type Checker
- func (c *Checker) Check(ctx context.Context, force bool) Status
- func (c *Checker) GetAutoConfig() AutoConfig
- func (c *Checker) InitConfig(stateDir string)
- func (c *Checker) Install(ctx context.Context, dir string, report func(string)) (string, error)
- func (c *Checker) SetAutoConfig(cfg AutoConfig) error
- func (c *Checker) StartAutoUpdater(ctx context.Context, stateDir string, onActivity func(action, details string), ...)
- type Release
- type Status
Constants ¶
const ( MethodDeb = "deb" // /usr/bin/virtomird from the .deb (apt) MethodRPM = "rpm" // /usr/bin/virtomird from the .rpm (dnf) MethodBinary = "binary" // tarball, install.sh or a binary run from anywhere: replaced in place )
How this virtomird was installed decides what the updater downloads and how it installs it.
const ( ChannelMain = "main" // every change merged to main (the rolling "edge" release CI publishes) ChannelReleases = "releases" // tagged releases only // EdgeTag is the release CI replaces with a build of every push to main. EdgeTag = "edge" )
Update channels.
Variables ¶
This section is empty.
Functions ¶
func DebVersion ¶
DebVersion turns a tag (v0.2.0-rc1) into the package version (0.2.0~rc1): "~" sorts a candidate before its release. A build from main (v1.1.1-19-gabc1234) comes after its tag, so its commits are added with "+" (1.1.1+19.gabc1234).
Types ¶
type AutoConfig ¶ added in v0.7.2
type AutoConfig struct {
Enabled bool `json:"enabled"` // periodic background check enabled
Channel string `json:"channel"` // ChannelMain (default) or ChannelReleases
AutoInstall bool `json:"autoInstall"` // automatically install newer release
IntervalHours int `json:"intervalHours"` // interval between checks in hours (default 6)
LastCheckedAt time.Time `json:"lastCheckedAt,omitempty"`
LastUpdatedAt time.Time `json:"lastUpdatedAt,omitempty"`
LastResult string `json:"lastResult,omitempty"`
LastError string `json:"lastError,omitempty"`
}
AutoConfig defines automatic background update behavior (ADR-0036).
type Checker ¶
type Checker struct {
Repo string // owner/name; "" disables updates
Current string // running version
Token string // optional, for private repositories
API string // https://api.github.com (tests replace it)
HTTP *http.Client
// Download fetches the release package: no total timeout (a large package on a slow
// link takes longer than an API call), only connect/header limits and a stall check.
// nil: HTTP.
Download *http.Client
// Busy reports whether work is running that a restart would kill (background jobs).
// The auto-updater waits for it to clear before installing; nil: never busy.
Busy func() bool
// Installed reports whether this host can update itself; tests replace it.
Installed func() (bool, string)
// Method reports how VirtoMir was installed (MethodDeb, MethodRPM, MethodBinary); tests replace it.
Method func() string
RunInstaller func(ctx context.Context, debPath string) (string, error)
RunRPMInstaller func(ctx context.Context, rpmPath string) (string, error)
// Restart restarts the daemon after a binary update; tests replace it.
Restart func(exe string) (string, error)
// Keys sign the releases' checksums (nil: the VirtoMir release key); tests replace it.
Keys *signature.Keyring
// contains filtered or unexported fields
}
Checker talks to the GitHub API.
func (*Checker) Check ¶
Check asks GitHub for the latest release (at most once an hour unless force).
func (*Checker) GetAutoConfig ¶ added in v0.7.2
func (c *Checker) GetAutoConfig() AutoConfig
GetAutoConfig returns the current auto-update configuration.
func (*Checker) InitConfig ¶ added in v0.7.2
InitConfig loads the persisted AutoConfig from stateDir or initializes defaults.
func (*Checker) Install ¶
Install downloads the latest release's package into dir, checks its signed SHA-256 and starts apt in a transient unit. It returns once apt has been started: virtomird is restarted by the package's postinst a few seconds later.
func (*Checker) SetAutoConfig ¶ added in v0.7.2
func (c *Checker) SetAutoConfig(cfg AutoConfig) error
SetAutoConfig updates the auto-update settings and persists them to stateDir.
func (*Checker) StartAutoUpdater ¶ added in v0.7.2
func (c *Checker) StartAutoUpdater(ctx context.Context, stateDir string, onActivity func(action, details string), log *slog.Logger)
StartAutoUpdater runs the periodic GitHub update poller in the background. If AutoInstall is enabled and a new version is detected, it automatically downloads and triggers the upgrade. Call InitConfig first, so settings saved before the first check are not overwritten.
type Release ¶
type Release struct {
Tag string `json:"tag"`
Version string `json:"version"`
Name string `json:"name"`
Notes string `json:"notes"`
URL string `json:"url"` // release page
Published time.Time `json:"published"`
// Package is the file this host installs (.deb, .rpm or tarball; "" when the release has none).
Package string `json:"package,omitempty"`
// contains filtered or unexported fields
}
Release is a published VirtoMir release.
type Status ¶
type Status struct {
Current string `json:"current"`
Repo string `json:"repo"`
Latest *Release `json:"latest,omitempty"`
Available bool `json:"available"` // Latest is newer than Current
// Method is how this host installed VirtoMir: deb, rpm or binary.
Method string `json:"method"`
// Installable: this host can update itself with its install method.
Installable bool `json:"installable"`
Reason string `json:"reason,omitempty"` // why not installable
CheckedAt time.Time `json:"checkedAt"`
Error string `json:"error,omitempty"`
Auto AutoConfig `json:"auto"`
}
Status is what the Updates card shows.