Documentation
¶
Overview ¶
Package update implements Aviary version checks and binary upgrades.
Index ¶
- Constants
- Variables
- func CheckMessage(check CheckResult) string
- func CleanupStaging(target string)
- func ClearCache()
- func ConfigureEmulation(raw string) error
- func CurrentVersion() string
- func EmulationActive() bool
- func GitCheckout() string
- func GitPullMessage(res GitPullResult, plan DevReloadPlan) string
- func HotReloadDir() string
- func HotReloadGeneration(dir string) int
- func IsDevBuild() bool
- func NormalizeVersion(version string) string
- func Reexec(exe string, args []string, env []string) error
- func ReleaseURL(repo, version string) string
- func RequestRebuild() bool
- func SameVersion(a, b string) bool
- func Supervised() bool
- type CheckResult
- type DevReloadPlan
- type GitPullResult
- type GitState
- type HotReloadResult
- type HotReloadWait
- type InstallOptions
- type InstallResult
Constants ¶
const ( // DefaultRepo is the canonical GitHub repository for Aviary releases. DefaultRepo = "lsegal/aviary" // DefaultAPIBase is the GitHub API base used for release lookups. DefaultAPIBase = "https://api.github.com" // CheckInterval is how often the server's self-updater looks for a new release. CheckInterval = 5 * time.Minute )
const CheckoutEnv = "AVIARY_CHECKOUT"
CheckoutEnv is set by scripts/dev-go.mjs to the root of the source checkout the backend was built from. It is authoritative for git mode: the process's working directory is only a fallback, since a daemonized or restarted backend need not run inside the checkout.
const HotReloadEnv = "FORGO_HOT_DIR"
HotReloadEnv is set by `forgo run --watch` (which scripts/dev-go.mjs runs) to the control directory its in-process agent and the watcher share. Each reload is a generation N: the watcher links link-N, which lists the reasons it refuses a reload on "refuse " lines, and the agent answers resp-N with "ok" or "err <reason>" once it has applied the image or failed to.
const RestartFileEnv = "AVIARY_RESTART_FILE"
RestartFileEnv is set by scripts/dev-go.mjs to a file the backend creates before exiting to ask for a restart. The script then runs the backend again, rebuilding it from the checkout's current sources. A dev update restarts only when forgo cannot hot-reload the pulled code (see PlanDevReload).
Variables ¶
var DefaultHotReloadWait = HotReloadWait{ Poll: 250 * time.Millisecond, Timeout: 5 * time.Minute, Answer: 45 * time.Second, Settle: 5 * time.Second, }
DefaultHotReloadWait is how long a dev update waits for forgo.
Functions ¶
func CheckMessage ¶
func CheckMessage(check CheckResult) string
CheckMessage returns a short human-readable summary for a version check result.
func CleanupStaging ¶ added in v0.7.0
func CleanupStaging(target string)
CleanupStaging removes what earlier upgrades left behind: the backup of the replaced binary next to target, which Windows cannot delete while the old process is still running, and stale staging directories in the temp dir.
func ClearCache ¶ added in v0.7.0
func ClearCache()
ClearCache forgets the cached version check so the next Check asks GitHub.
func ConfigureEmulation ¶
ConfigureEmulation enables dev-only version emulation using <local>:<remote>.
func CurrentVersion ¶
func CurrentVersion() string
CurrentVersion returns the effective local version, honoring emulation when enabled. A dev build reports the full commit SHA of the code it runs: the git-mode checkout's HEAD, read on every call so a pulled checkout reports its new commit, else the VCS revision Go embedded in the binary, else "dev".
func EmulationActive ¶
func EmulationActive() bool
EmulationActive reports whether dev-only version emulation is enabled.
func GitCheckout ¶ added in v0.7.0
func GitCheckout() string
GitCheckout returns the source checkout the updater works on in git mode: a dev build running from an Aviary git checkout outside Docker, with version emulation off. It returns "" when the release updater is in force.
func GitPullMessage ¶ added in v0.7.0
func GitPullMessage(res GitPullResult, plan DevReloadPlan) string
GitPullMessage summarizes a git-mode update for the user, given how the pulled code goes live.
func HotReloadDir ¶ added in v0.7.1
func HotReloadDir() string
HotReloadDir returns forgo's hot reload control directory when the backend runs under `forgo run --watch` and its agent started, or "" otherwise.
func HotReloadGeneration ¶ added in v0.7.1
HotReloadGeneration returns the newest reload generation the watcher has linked in dir, or 0 before the first reload.
func IsDevBuild ¶
func IsDevBuild() bool
IsDevBuild reports whether the current binary version is not a clean semver release.
func NormalizeVersion ¶ added in v0.7.0
NormalizeVersion returns version as a release tag with a leading "v", so "1.2.3" and "v1.2.3" name the same release. Empty input stays empty.
func Reexec ¶ added in v0.7.0
Reexec replaces the current process with exe, keeping its PID so service managers see the same process.
func ReleaseURL ¶ added in v0.7.0
ReleaseURL returns the GitHub release page for version in repo.
func RequestRebuild ¶ added in v0.7.0
func RequestRebuild() bool
RequestRebuild asks scripts/dev-go.mjs to run the backend again from the checkout's sources once this process exits. It reports false when the backend is not supervised or the request could not be written, in which case the caller re-executes its own binary instead.
func SameVersion ¶ added in v0.7.0
SameVersion reports whether a and b name the same release, ignoring a leading "v". Non-semver versions compare as plain strings.
func Supervised ¶ added in v0.7.0
func Supervised() bool
Supervised reports whether a restart rebuilds the backend from its checkout.
Types ¶
type CheckResult ¶
type CheckResult struct {
CurrentVersion string `json:"currentVersion"`
LatestVersion string `json:"latestVersion,omitempty"`
UpgradeAvailable bool `json:"upgradeAvailable"`
UpgradeSupported bool `json:"upgradeSupported"`
Emulated bool `json:"emulated"`
CheckedAt time.Time `json:"checkedAt,omitempty"`
Message string `json:"message,omitempty"`
// ReleaseURL links the latest version to its release page.
ReleaseURL string `json:"releaseUrl,omitempty"`
// Git is set in git mode, when a dev build runs from a source checkout:
// updates are pulled from the checkout's upstream instead of a release.
Git *GitState `json:"git,omitempty"`
// NoCheckout is set for a dev build that would update in git mode but
// cannot locate its source checkout, so it has no way to check for updates.
NoCheckout bool `json:"noCheckout,omitempty"`
}
CheckResult describes the local version and the latest known release.
type DevReloadPlan ¶ added in v0.7.1
type DevReloadPlan struct {
// GoChanged is true when the pull changed Go sources forgo watches.
GoChanged bool
// RestartReason, when set, is why only a full restart runs the pulled
// code; hot reload cannot.
RestartReason string
}
DevReloadPlan decides how pulled commits go live in a dev checkout.
func PlanDevReload ¶ added in v0.7.1
func PlanDevReload(ctx context.Context, dir, from, to string, hotReload bool) (DevReloadPlan, error)
PlanDevReload inspects the files changed between from and to in the dev checkout dir. A change to go.mod or go.sum, or to a file a Go package embeds, needs a restart, since forgo watches only Go sources. Otherwise Go changes hot-reload when hotReload (forgo is active) is set, and need a restart when it is not.
type GitPullResult ¶ added in v0.7.0
type GitPullResult struct {
From string `json:"from"`
To string `json:"to"`
Commits int `json:"commits"`
Supervised bool `json:"supervised"`
HotReload bool `json:"hotReload"`
}
GitPullResult describes a git-mode update.
type GitState ¶ added in v0.7.0
type GitState struct {
Dir string `json:"dir"`
Branch string `json:"branch"`
Upstream string `json:"upstream,omitempty"`
Behind int `json:"behind"`
Ahead int `json:"ahead"`
Dirty bool `json:"dirty"`
// Supervised is true when a restart rebuilds the backend from the
// checkout (see RestartFileEnv), so pulled sources go live by restarting.
Supervised bool `json:"supervised"`
// HotReload is true when the backend runs under forgo's hot reload, so
// pulled Go changes go live without a restart where forgo can apply them.
HotReload bool `json:"hotReload"`
}
GitState describes a dev checkout's position relative to its upstream.
type HotReloadResult ¶ added in v0.7.1
type HotReloadResult struct {
// Applied is true when the newest reload went live in this process.
Applied bool
// Generation is the reload generation the verdict is about.
Generation int
// Reason says why the pulled code is not running when Applied is false.
Reason string
}
HotReloadResult is forgo's verdict on the reloads after a pull.
func WaitHotReload ¶ added in v0.7.1
func WaitHotReload(ctx context.Context, dir string, since int, opts HotReloadWait) HotReloadResult
WaitHotReload waits for forgo to reload the code a pull brought in, and reports whether the newest reload after generation since applied. A reload forgo refuses or fails, or no reload at all before the timeout (a pulled tree that does not compile never links), is reported with its reason.
type HotReloadWait ¶ added in v0.7.1
type HotReloadWait struct {
// Poll is how often the control directory is read.
Poll time.Duration
// Timeout bounds the whole wait.
Timeout time.Duration
// Answer bounds how long a linked generation may go unanswered; the
// watcher itself gives the agent 30 seconds.
Answer time.Duration
// Settle is added to the time the verdict took to arrive to decide how
// long to keep watching for a later generation: one that started on a
// partly written tree is followed by another once the first finishes,
// and that one takes about as long again.
Settle time.Duration
}
HotReloadWait tunes WaitHotReload.
type InstallOptions ¶
type InstallOptions struct {
Version string
TargetPath string
Repo string
APIBase string
Client *http.Client
}
InstallOptions controls how a release is downloaded and installed.
type InstallResult ¶
type InstallResult struct {
Version string `json:"version"`
Emulated bool `json:"emulated"`
Noop bool `json:"noop"`
}
InstallResult describes the outcome of an attempted upgrade install.
func Install ¶
func Install(ctx context.Context, opts InstallOptions) (InstallResult, error)
Install downloads and installs the requested Aviary release into TargetPath.