Documentation
¶
Index ¶
Constants ¶
const ( // ResultUpToDate: the check succeeded and nothing needed installing // (the installed version is the latest release, or the pinned one). ResultUpToDate = "up_to_date" // ResultUpdated: the check succeeded and a release was installed. ResultUpdated = "updated" // ResultFailed: the check failed; Status.LastError says why. ResultFailed = "failed" )
Values of Status.LastResult.
const ( // TriggerAuto marks a check run by the periodic loop (Start). TriggerAuto = "auto" // TriggerManual marks a one-shot check (RunOnce, e.g. `pilotctl update`). TriggerManual = "manual" )
Values of Status.LastCheckTrigger.
const StatusFileName = "update-state.json"
StatusFileName is the default name of the file the updater writes after every check. When Config.StatusPath is empty and Config.StatePath is set, the status file lives next to the control file (for the standard install: ~/.pilot/auto-update.json -> ~/.pilot/update-state.json).
Variables ¶
This section is empty.
Functions ¶
func VerifyChecksum ¶
VerifyChecksum checks the SHA256 of archivePath against the checksums file.
Types ¶
type Config ¶
type Config struct {
CheckInterval time.Duration
Repo string // "owner/repo"
InstallDir string
Version string // updater's own version (used for user-agent)
// PinnedVersion locks the updater to a specific release tag
// (e.g. "v1.10.5"). When set, the updater installs exactly that
// version — regardless of whether it is newer, older, or already
// current — and will not chase the latest release. An empty
// string (default) preserves the existing "always follow latest"
// behaviour. Set to an empty string to un-pin and resume
// auto-updating to the latest stable.
PinnedVersion string
// SkipAttestation disables SLSA attestation verification of
// checksums.txt. This is the ONLY way to bypass attestation: when
// false (the default), the updater fetches the GitHub SLSA provenance
// bundle and verifies it in-process with sigstore-go (no gh CLI, no
// external tooling required); if it cannot verify, the update is
// refused (fails closed). Intended for test environments where the
// test repos do not have real attestations. Leaving it false in
// production keeps provenance verification mandatory. The SHA256
// checksums.txt match is always enforced regardless of this flag.
SkipAttestation bool
// StatePath, when non-empty, points to a JSON control file
// {"enabled": bool} that gates the AUTOMATIC update loop and is
// re-read on every tick. When the file is absent or {"enabled":
// false} the loop performs NO updates — so any deployment that sets
// StatePath is OFF BY DEFAULT until explicitly enabled (e.g. via
// `pilotctl update enable`). A manual one-shot RunOnce always runs,
// ignoring this gate. An empty StatePath preserves the legacy
// always-on loop behaviour for backward compatibility.
StatePath string
// StatusPath is where the updater records the outcome of every check
// (see Status): last check time and result, last error, consecutive
// failures, installed and latest versions, and whether the loop is
// running. Empty means "update-state.json next to StatePath"; with
// neither set, nothing is written (LastStatus still reports it).
StatusPath string
}
Config holds the updater configuration.
type GitHubAsset ¶
type GitHubAsset struct {
Name string `json:"name"`
BrowserDownloadURL string `json:"browser_download_url"`
}
GitHubAsset represents a release asset.
type GitHubRelease ¶
type GitHubRelease struct {
TagName string `json:"tag_name"`
Assets []GitHubAsset `json:"assets"`
}
GitHubRelease represents a subset of the GitHub release API response.
type Semver ¶
type Semver struct {
Major int
Minor int
Patch int
// Pre holds the prerelease identifiers that follow the first hyphen,
// without the leading hyphen. It is empty for a plain release tag.
// "v1.2.3-rc1" yields "rc1"; "v1.2.3" yields "".
Pre string
}
Semver represents a parsed semantic version.
func ParseSemver ¶
ParseSemver parses a version string like "v1.2.3" or "1.2.3" or "v1.2.3-rc1". It strips the "v" prefix and any "+build" metadata, keeps the numeric major.minor.patch triple, and retains the prerelease suffix in Pre.
func (Semver) Compare ¶ added in v0.2.5
Compare returns -1, 0 or +1 as v sorts before, equal to, or after other. Ordering follows semantic-version precedence: the numeric triple is compared first, then the prerelease suffix. A version carrying a prerelease suffix sorts before the same version without one, so "1.2.3-rc1" < "1.2.3".
type Service ¶
type Service struct{}
Service is the L11 plugin lifecycle adapter for the updater. The daemon does not register this today — cmd/updater is a standalone binary that uses updater.New / *Updater.Start directly. The adapter exists so the plugin package conforms to the L10 Service contract and so the no_updater build tag has a meaningful counterpart (see service_disabled.go).
When this plugin is eventually wired into cmd/daemon's plugin runtime, this Service will own the *Updater lifecycle. Today its Start/Stop are no-ops; it is registered nowhere.
func NewService ¶
func NewService() *Service
NewService returns a Service ready for daemon.RegisterPlugin (when cmd/daemon eventually starts registering it). Distinct from updater.New, which constructs the standalone *Updater used by cmd/updater.
type Status ¶ added in v0.2.5
type Status struct {
// UpdaterVersion is the version of the updater that wrote the record.
UpdaterVersion string `json:"updater_version,omitempty"`
// Repo is the GitHub owner/repo releases are read from.
Repo string `json:"repo,omitempty"`
// PinnedVersion is the pin in force for the last check ("" = latest).
PinnedVersion string `json:"pinned_version,omitempty"`
// LastCheckAt is when the last check finished.
LastCheckAt time.Time `json:"last_check_at,omitzero"`
// LastCheckTrigger is TriggerAuto or TriggerManual.
LastCheckTrigger string `json:"last_check_trigger,omitempty"`
// LastResult is ResultUpToDate, ResultUpdated or ResultFailed.
LastResult string `json:"last_result,omitempty"`
// LastError is the error of the last check; empty when it succeeded.
LastError string `json:"last_error,omitempty"`
// ConsecutiveFailures counts failed checks since the last success.
ConsecutiveFailures int `json:"consecutive_failures"`
// LastSuccessAt is when a check last completed without error.
LastSuccessAt time.Time `json:"last_success_at,omitzero"`
// CurrentVersion is the installed release after the last check.
CurrentVersion string `json:"current_version,omitempty"`
// LatestVersion is the release the last check compared against: the
// latest published release, or the pinned tag when pinned.
LatestVersion string `json:"latest_version,omitempty"`
// LastUpdateAt / LastUpdateVersion record the last release installed.
LastUpdateAt time.Time `json:"last_update_at,omitzero"`
LastUpdateVersion string `json:"last_update_version,omitempty"`
// RestartError is set when new binaries were installed but the daemon
// is not running them: it was left on the old version, or it was
// stopped and did not come back. It says how to restart it. On Linux the
// updater stops the daemon only when systemd will start it again, so a
// daemon without such a service (e.g. `pilotctl daemon start` in a
// container) is left running and reported here. Cleared by the next
// successful restart and, on Linux, by the next check that finds the
// daemon running the installed binary.
RestartError string `json:"restart_error,omitempty"`
// LoopPID and LoopStartedAt identify the long-running updater process
// (the service started via Start). Absent when no loop ever ran.
LoopPID int `json:"loop_pid,omitempty"`
LoopStartedAt time.Time `json:"loop_started_at,omitzero"`
// NextCheckAt is when the loop will next wake up (plus up to 30s of
// jitter). A NextCheckAt well in the past means the loop is not running.
NextCheckAt time.Time `json:"next_check_at,omitzero"`
}
Status is the machine-readable record of what the updater last did. It is persisted as JSON at Config.StatusPath after every check so that other tools (`pilotctl update status`, `daemon status`, support scripts) can tell whether updates are actually working, instead of only whether they are switched on.
The file can be shared by the long-running updater service and one-shot RunOnce callers configured with the same StatusPath (or StatePath). Each writer takes an advisory lock (StatusFileName + ".lock") and merges its fields into what is already on disk, so a manual run keeps the loop's LoopPID/NextCheckAt and the loop keeps the failure streak a manual run started. A RunOnce caller with neither path set writes nothing.
func ReadStatus ¶ added in v0.2.5
ReadStatus loads the status file written by the updater. A missing file returns an error satisfying errors.Is(err, fs.ErrNotExist), which callers should read as "the updater has never recorded a check here".
type Updater ¶
type Updater struct {
// contains filtered or unexported fields
}
Updater periodically checks GitHub Releases for new versions and optionally applies them.
func (*Updater) LastStatus ¶ added in v0.2.5
LastStatus returns the status recorded by this Updater's most recent check (or loop event). It is available even when no status file is configured, so a caller of RunOnce can report the outcome without reading the file.
func (*Updater) RunOnce ¶ added in v0.2.2
RunOnce runs the update check once synchronously and returns. Unlike Start, it does not enter a periodic loop — it performs a single check (checking the pinned version or latest release), applies the update if available, and returns. Useful for one-shot invocations from `pilotctl update` and similar CLI commands. It ALWAYS runs — the StatePath enabled-gate applies only to the automatic loop, so a manual `pilotctl update` works even when auto-update is disabled.
It returns the check's error (nil when already up to date or when the update was installed), so callers can report failure and exit non-zero. LastStatus describes the outcome in detail, and the same record is written to the status file when one is configured.
RunOnce never exits the calling process. When the release replaces the pilot-updater binary, the daemon is still restarted onto the new binaries; a separately running updater service picks up its new binary the next time its service manager restarts it.