upgrade

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package upgrade fetches the latest release for stable, beta and edge channels from a GitHub repo, compares versions, and runs the read-only checks that gate a self-upgrade.

Index

Constants

View Source
const (
	ChannelStable = "stable"
	ChannelBeta   = "beta"
	ChannelEdge   = "edge"
)

Update channels a running build can compare itself against. ChannelStable is GitHub's own "latest release" concept (unchanged default behavior); ChannelBeta and ChannelEdge follow release.yml's own image-channel job scheme: a hyphenated SemVer tag (e.g. v1.2.3-beta.1) gets :beta, a main push gets :edge.

View Source
const (
	StatusOK      = "ok"
	StatusWarn    = "warn"
	StatusFail    = "fail"
	StatusUnknown = "unknown"
)

Check statuses.

View Source
const (
	ChecksumsAsset = "checksums.txt"
	SignatureAsset = "checksums.txt.sigstore.json"
)

Asset names the release workflow publishes next to the binaries.

View Source
const ChannelAll = "all"

ChannelAll is the history view that mixes stable and pre-releases.

View Source
const DefaultCacheTTL = time.Hour

DefaultCacheTTL is how long a Cache entry stays fresh before a caller should fetch again: shared by GET /api/v1/updates, updatecheck.Scheduler, and alerting's kind=version_skew evaluator, so none of them hits GitHub more often than this regardless of its own call cadence.

View Source
const ManifestAsset = "release-manifest.json"

ManifestAsset is the per-release file the release workflow publishes with the binary's own `version --json` output, so a release's schema version is known without downloading and running it.

View Source
const VerifierTool = "cosign"

VerifierTool is the program the installer uses to check the release signature.

Variables

This section is empty.

Functions

func Blocked

func Blocked(checks []Check) bool

Blocked reports whether any check is a hard failure.

func UpdateAvailable

func UpdateAvailable(currentVersion string, latest *Release) bool

UpdateAvailable reports whether latest represents a newer build than currentVersion. A "dev" build never reports an update available: there is no meaningful newer build to compare an unreleased build against. Two SemVer tags compare by precedence (beta.9 < beta.15); anything else (edge's main-<sha>) falls back to inequality.

func ValidChannel

func ValidChannel(c string) bool

ValidChannel reports whether c is one of the three recognized channels.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache holds the last successful channel lookup, so GET /api/v1/updates and internal/updatecheck.Scheduler don't hit GitHub on every call. Keyed by channel (not just a bare TTL) so switching channels never serves a stale result cached for a different one.

func NewCache

func NewCache() *Cache

NewCache returns an empty Cache, ready to use.

func (*Cache) Fresh

func (c *Cache) Fresh(ttl time.Duration, channel string) (*Release, bool)

Fresh returns the cached release for channel if one exists and is within ttl.

func (*Cache) Set

func (c *Cache) Set(channel string, release *Release)

Set records release as the latest lookup result for channel.

func (*Cache) Stale

func (c *Cache) Stale(channel string) (*Release, bool)

Stale returns whatever was last cached for channel, regardless of age, for use when a fresh fetch just failed.

type Check

type Check struct {
	Code    string `json:"code"`
	Name    string `json:"name"`
	Status  string `json:"status"`
	Message string `json:"message"`
}

Check is one preflight result.

func Run

func Run(ctx context.Context, in Inputs) []Check

Run evaluates every preflight check. It never changes anything.

type Fetchers

type Fetchers struct {
	Stable func(context.Context) (*Release, error)
	Beta   func(context.Context) (*Release, error)
	Edge   func(context.Context) (*Release, error)
}

Fetchers groups one fetch function per channel, the same overridable seam Router.fetchLatestRelease (internal/api/updates.go) already establishes for testing without a real outbound call.

func DefaultFetchers

func DefaultFetchers(repo string) Fetchers

DefaultFetchers wires the three real GitHub lookups above for repo ("owner/name").

func (Fetchers) LatestForChannel

func (f Fetchers) LatestForChannel(ctx context.Context, channel string) (*Release, error)

LatestForChannel dispatches to the fetcher for channel, defaulting to Stable for an unrecognized or empty channel.

type HistoryAsset

type HistoryAsset struct {
	Name string `json:"name"`
	Size int64  `json:"size"`
	URL  string `json:"url"`
}

HistoryAsset is one downloadable file on a release.

type HistoryRelease

type HistoryRelease struct {
	Tag         string         `json:"tag"`
	URL         string         `json:"url"`
	PublishedAt string         `json:"published_at"`
	Body        string         `json:"body"`
	Prerelease  bool           `json:"prerelease"`
	Assets      []HistoryAsset `json:"assets"`
}

HistoryRelease is one published GitHub release, with the asset details a rollback plan needs.

func FetchHistory

func FetchHistory(ctx context.Context, repo, channel string, limit int) ([]HistoryRelease, error)

FetchHistory lists the newest limit releases of repo for channel. An empty result with a nil error means GitHub has none for that channel.

func (HistoryRelease) Asset

func (r HistoryRelease) Asset(name string) (HistoryAsset, bool)

Asset returns the asset called name.

func (HistoryRelease) AssetNames

func (r HistoryRelease) AssetNames() []string

AssetNames lists every asset name, for Run's Inputs.

type Inputs

type Inputs struct {
	Lookup        func(string) (string, bool)
	DockerVersion func(ctx context.Context) (string, error)
	FreeBytes     func() (int64, error)
	NewestBackup  func() (time.Time, bool, error)
	Now           time.Time
	AssetNames    []string
	ReleaseKnown  bool
	// LookPath finds the signature verifier (cosign) on the host; nil reports unknown.
	LookPath func(string) (string, error)
}

Inputs is everything Run needs, injected so tests use fakes.

type KnownBad

type KnownBad struct {
	Prefix string `json:"prefix"`
	Reason string `json:"reason"`
}

KnownBad is one Docker Engine version prefix that must not run an upgrade.

func LoadKnownBad

func LoadKnownBad(lookup func(string) (string, bool)) ([]KnownBad, error)

LoadKnownBad reads the known-bad Docker list from APP_DOCKER_KNOWN_BAD_FILE when set, otherwise from the embedded data file.

type Manifest

type Manifest struct {
	Version       string `json:"version"`
	SchemaVersion int    `json:"schema_version"`
}

Manifest is the content of ManifestAsset.

func FetchManifest

func FetchManifest(ctx context.Context, rawURL string) (Manifest, error)

FetchManifest downloads and decodes a release manifest. Only https URLs on github.com are fetched, and the body is size-capped.

type Release

type Release struct {
	Tag         string
	URL         string
	PublishedAt string
	Body        string
	AssetNames  []string
}

Release is the subset of a GitHub release, or (for the edge channel) a main-branch commit treated as a pseudo-release, that a channel-aware update check needs.

func FetchLatestBeta

func FetchLatestBeta(ctx context.Context, repo string) (*Release, error)

FetchLatestBeta fetches the newest prerelease from GitHub's releases list, skipping drafts. nil, nil means no prerelease has ever been published.

func FetchLatestEdge

func FetchLatestEdge(ctx context.Context, repo string) (*Release, error)

FetchLatestEdge fetches the latest commit on main and reports it as a pseudo-release tagged "main-<short sha>", matching release.yml's own image-channel job scheme for what a main push's Docker image tag is (IMAGE_VERSION: main-<sha>). nil, nil means the lookup found nothing (an empty or inaccessible repo).

func FetchLatestStable

func FetchLatestStable(ctx context.Context, repo string) (*Release, error)

FetchLatestStable fetches GitHub's /releases/latest: the newest non-prerelease, non-draft release. With no stable release it falls back to the newest pre-release (install.sh's rule). nil, nil means nothing has been published at all.

type SchemaVerdict

type SchemaVerdict string

SchemaVerdict says whether a target binary can run on the current database.

const (
	// VerdictBinaryOnly: the target supports the database as it is (equal).
	VerdictBinaryOnly SchemaVerdict = "binary_only"
	// VerdictForward: the target is newer and will migrate the database.
	VerdictForward SchemaVerdict = "forward"
	// VerdictRestoreRequired: the target is older than the database and would
	// refuse to start; only a backup restore (losing newer data) works.
	VerdictRestoreRequired SchemaVerdict = "restore_required"
	// VerdictUnknown: the target's schema version could not be determined.
	VerdictUnknown SchemaVerdict = "unknown"
)

Verdicts for a rollback or re-roll against the database's schema version.

func VerdictFor

func VerdictFor(dbVersion, targetVersion int) SchemaVerdict

VerdictFor compares the database's schema version with the target binary's. A negative value means unknown on that side.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL