Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(rexctl): compare voice machines by the instance's api build (#3855)

Hampus0435a8e26bc9
diff --git a/.github/workflows/release-image-set.yaml b/.github/workflows/release-image-set.yaml
index 971abe8dc..e0e7b92d7 100644
--- a/.github/workflows/release-image-set.yaml
+++ b/.github/workflows/release-image-set.yaml
@@ -185,17 +185,20 @@ jobs:
manifest = json.load(open(f"release-out/fluxer-release-{version}.json"))
compose = open(f"release-out/fluxer-release-{version}.yml").read()
images = {c["component"]: f'{c["image"]}@{c["digest"]}' for c in manifest["components"]}
+ versions = {c["component"]: c["build_version"] for c in manifest["components"]}
pattern = re.compile(r"^ ([a-z0-9-]+):\n image: \S*/([a-z0-9-]+)@\$\{[A-Z0-9_]+:-(sha256:[0-9a-f]{64})\}$", re.M)
services = {}
+ builds = {}
for service, component, digest in pattern.findall(compose):
ref = images.get(component)
if ref is None or not ref.endswith("@" + digest):
sys.exit(f"service {service} does not match component {component} in the manifest")
services[service] = ref
+ builds[service] = versions[component]
if not services or len(services) != compose.count("\n image: "):
sys.exit("could not map every service in the compose override to an image")
with open("fluxer_rexctl/internal/stack/imageset.json", "w") as f:
- json.dump({"release": version, "images": dict(sorted(services.items()))}, f, indent=2)
+ json.dump({"release": version, "images": dict(sorted(services.items())), "builds": dict(sorted(builds.items()))}, f, indent=2)
f.write("\n")
print(f"embedded {len(services)} service images for {version}")
EOF
diff --git a/fluxer_docs/src/content/docs/operator/voice-servers.mdx b/fluxer_docs/src/content/docs/operator/voice-servers.mdx
index 2c49db77e..7893536fa 100644
--- a/fluxer_docs/src/content/docs/operator/voice-servers.mdx
+++ b/fluxer_docs/src/content/docs/operator/voice-servers.mdx
@@ -321,7 +321,7 @@ rexctl doctor
`rexctl upgrade` on the Fluxer machine upgrades Fluxer first. Then it moves each voice server on the machine to the new LiveKit release, one at a time. It marks the server as draining. New calls then go elsewhere, and calls on it keep going. Docker then replaces the container, and LiveKit waits until those calls end, for up to 15 minutes. The server then takes new calls again, also when the upgrade fails or you stop it. A server you turned off or marked as draining in the admin panel stays that way.
-On a voice machine, `rexctl upgrade` updates rexctl to the release your instance runs, then upgrades the servers the same way. It never goes past your instance's release, and it refuses `--prefetch` and `--to`. It also updates the edge.
+On a voice machine, `rexctl upgrade` first checks the release your instance runs. When that release is newer than rexctl, rexctl updates itself to the latest release. It then upgrades the servers the same way, and updates the edge, once your instance runs the release of that rexctl or a newer one. Until then, the servers stay as they are. It refuses `--prefetch` and `--to`, and `rexctl upgrade --check` shows what it would do.
rexctl upgrades a server when the release has a new LiveKit image, and also when the release changes the server's files or settings. A server added with `--image` keeps that image.
diff --git a/fluxer_rexctl/cmd/upgrade.go b/fluxer_rexctl/cmd/upgrade.go
index 8b7cff898..b7f46c30b 100644
--- a/fluxer_rexctl/cmd/upgrade.go
+++ b/fluxer_rexctl/cmd/upgrade.go
@@ -414,6 +414,11 @@ func runUpgradeCheck(ctx context.Context, app *App, f *upgradeFlags) error {
return ierr
}
return err
+ case inst.State.IsVoice():
+ if f.To != "" {
+ return ui.Usage("A voice machine follows the release its instance runs. Run rexctl upgrade --check without --to.")
+ }
+ return runVoiceMachineCheck(ctx, app, inst)
default:
cur = inst.State.Release
}
diff --git a/fluxer_rexctl/cmd/voice_join.go b/fluxer_rexctl/cmd/voice_join.go
index 3770e34b5..8d8cecb00 100644
--- a/fluxer_rexctl/cmd/voice_join.go
+++ b/fluxer_rexctl/cmd/voice_join.go
@@ -508,10 +508,10 @@ func joinImage(app *App, preview *voice.Preview, f *voiceFlags) (string, string)
switch {
case preview.Release == "" || !release.Valid(preview.Release):
return own, "the pin of this rexctl, because the instance runs a development build"
- case preview.Release == app.Version:
- return own, "matches " + preview.Release
+ case preview.Release == ownAPIBuild():
+ return own, "matches the release the instance runs"
default:
- return own, fmt.Sprintf("the pin of rexctl %s. The instance runs %s, and rexctl upgrade brings this machine to it", app.Version, preview.Release)
+ return own, fmt.Sprintf("the pin of rexctl %s. The instance runs another release, and rexctl upgrade follows it", app.Version)
}
}
diff --git a/fluxer_rexctl/cmd/voice_lifecycle.go b/fluxer_rexctl/cmd/voice_lifecycle.go
index abb74dfb2..6c07d8fbc 100644
--- a/fluxer_rexctl/cmd/voice_lifecycle.go
+++ b/fluxer_rexctl/cmd/voice_lifecycle.go
@@ -21,6 +21,7 @@ import (
"github.com/fluxerapp/fluxer/fluxer_rexctl/internal/instance"
"github.com/fluxerapp/fluxer/fluxer_rexctl/internal/release"
"github.com/fluxerapp/fluxer/fluxer_rexctl/internal/settings"
+ "github.com/fluxerapp/fluxer/fluxer_rexctl/internal/stack"
"github.com/fluxerapp/fluxer/fluxer_rexctl/internal/ui"
"github.com/fluxerapp/fluxer/fluxer_rexctl/internal/voice"
)
@@ -215,7 +216,7 @@ func voiceMachinesUsing(inst *instance.Instance) []*instance.Instance {
return out
}
-func instanceRelease(ctx context.Context, domain string) (string, error) {
+func instanceBuild(ctx context.Context, domain string) (string, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://"+domain+"/.well-known/fluxer", nil)
if err != nil {
return "", err
@@ -231,26 +232,108 @@ func instanceRelease(ctx context.Context, domain string) (string, error) {
return resp.Header.Get("X-Fluxer-Version"), nil
}
-func runVoiceMachineUpgrade(ctx context.Context, app *App, inst *instance.Instance, dryRun bool) error {
+func ownAPIBuild() string {
+ images, err := stack.EmbeddedImages()
+ if err != nil {
+ return ""
+ }
+ return images.Builds["api"]
+}
+
+func compareInstanceBuild(build, own string) int {
+ if !release.Valid(build) || !release.Valid(own) {
+ return 0
+ }
+ return release.Compare(build, own)
+}
+
+type voiceMachinePlan struct {
+ domain string
+ image string
+ update *release.Release
+ older bool
+ pending []*instance.VoiceServer
+}
+
+func planVoiceMachineUpgrade(ctx context.Context, app *App, inst *instance.Instance, report bool) (*voiceMachinePlan, error) {
+ p := &voiceMachinePlan{domain: inst.State.Voice[0].Instance, image: ownLiveKitImage()}
+ build, err := instanceBuild(ctx, p.domain)
+ if err != nil {
+ return nil, ui.Wrap(err, fmt.Sprintf("rexctl can't connect to %s. Nothing changed.", p.domain), "Run rexctl upgrade again once the instance answers.")
+ }
+ switch compareInstanceBuild(build, ownAPIBuild()) {
+ case -1:
+ p.older = true
+ return p, nil
+ case 1:
+ rel, err := resolveRelease(ctx, "")
+ if err != nil {
+ return nil, err
+ }
+ if release.Compare(rel.Version, app.Version) > 0 {
+ p.update = rel
+ return p, nil
+ }
+ }
+ refreshJoinedServers(ctx, app, inst, report)
+ p.pending = staleVoiceServers(inst, p.image)
+ return p, nil
+}
+
+func printVoiceMachinePlan(app *App, p *voiceMachinePlan) {
+ switch {
+ case p.update != nil:
+ app.UI.Info("%s runs a newer release than this rexctl. rexctl would update itself to %s, then upgrade the voice servers once %s runs that release or a newer one.", p.domain, p.update.Version, p.domain)
+ case p.older:
+ app.UI.Info("%s runs an older release than this rexctl. Voice servers stay on their LiveKit release until the instance catches up.", p.domain)
+ case len(p.pending) == 0:
+ app.UI.OK("Every voice server on this machine is up to date.")
+ default:
+ for _, s := range p.pending {
+ app.UI.Info("rexctl would drain %s and start it again with %s.", s.ID, voiceTargetImage(s, p.image))
+ }
+ }
+}
+
+func runVoiceMachineCheck(ctx context.Context, app *App, inst *instance.Instance) error {
if len(inst.State.Voice) == 0 {
+ if app.Flags.JSON {
+ return app.UI.JSON(upgradeCheckJSON{Current: app.Version, Latest: app.Version})
+ }
app.UI.OK("This machine runs no voice servers.")
return nil
}
- domain := inst.State.Voice[0].Instance
- target, err := instanceRelease(ctx, domain)
+ p, err := planVoiceMachineUpgrade(ctx, app, inst, false)
if err != nil {
- return ui.Wrap(err, fmt.Sprintf("rexctl can't connect to %s. Nothing changed.", domain), "Run rexctl upgrade again once the instance answers.")
+ return err
}
- if release.Valid(target) && release.Valid(app.Version) && release.Compare(target, app.Version) > 0 {
- rel, err := resolveRelease(ctx, target)
- if err != nil {
- return err
- }
- if dryRun {
- app.UI.Info("rexctl would update itself to %s, the release %s runs, then upgrade the voice servers.", target, domain)
- return nil
+ if app.Flags.JSON {
+ out := upgradeCheckJSON{Current: app.Version, Latest: app.Version, Available: len(p.pending) > 0}
+ if p.update != nil {
+ out.Latest, out.Available = p.update.Version, true
}
- asset, err := rel.AssetFor(runtime.GOOS, runtime.GOARCH)
+ return app.UI.JSON(out)
+ }
+ printVoiceMachinePlan(app, p)
+ return nil
+}
+
+func runVoiceMachineUpgrade(ctx context.Context, app *App, inst *instance.Instance, dryRun bool) error {
+ if len(inst.State.Voice) == 0 {
+ app.UI.OK("This machine runs no voice servers.")
+ return nil
+ }
+ p, err := planVoiceMachineUpgrade(ctx, app, inst, !dryRun)
+ if err != nil {
+ return err
+ }
+ if dryRun || p.older {
+ printVoiceMachinePlan(app, p)
+ return nil
+ }
+ if p.update != nil {
+ target := p.update.Version
+ asset, err := p.update.AssetFor(runtime.GOOS, runtime.GOARCH)
if err != nil {
return ui.Failed(fmt.Sprintf("There's no rexctl %s for this machine.", target), "")
}
@@ -268,22 +351,6 @@ func runVoiceMachineUpgrade(ctx context.Context, app *App, inst *instance.Instan
}
return nil
}
- image := ownLiveKitImage()
- if release.Valid(target) && release.Valid(app.Version) && release.Compare(target, app.Version) < 0 {
- app.UI.Info("%s runs %s, older than this rexctl. Voice servers stay on their LiveKit release until the instance catches up.", domain, target)
- return nil
- }
- refreshJoinedServers(ctx, app, inst, !dryRun)
- pending := staleVoiceServers(inst, image)
- if dryRun {
- for _, s := range pending {
- app.UI.Info("rexctl would drain %s and start it again with %s.", s.ID, voiceTargetImage(s, image))
- }
- if len(pending) == 0 {
- app.UI.OK("Every voice server on this machine is up to date.")
- }
- return nil
- }
e, err := app.Engine(ctx, inst)
if err != nil {
return err
@@ -303,12 +370,12 @@ func runVoiceMachineUpgrade(ctx context.Context, app *App, inst *instance.Instan
return err
}
}
- for _, srv := range pending {
- if err := upgradeVoiceServer(ctx, app, e, nil, inst, srv, voiceTargetImage(srv, image), defaultDrainTimeout); err != nil {
+ for _, srv := range p.pending {
+ if err := upgradeVoiceServer(ctx, app, e, nil, inst, srv, voiceTargetImage(srv, p.image), defaultDrainTimeout); err != nil {
return err
}
}
- if len(pending) == 0 {
+ if len(p.pending) == 0 {
app.UI.OK("Every voice server on this machine is up to date.")
}
return nil
diff --git a/fluxer_rexctl/internal/stack/images.go b/fluxer_rexctl/internal/stack/images.go
index 91da83ea1..9eda3c46f 100644
--- a/fluxer_rexctl/internal/stack/images.go
+++ b/fluxer_rexctl/internal/stack/images.go
@@ -23,6 +23,7 @@ var imageSetJSON []byte
type ImageSet struct {
Release string `json:"release"`
Images map[string]string `json:"images"`
+ Builds map[string]string `json:"builds,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
Layers map[string]Layer `json:"layers,omitempty"`
Platforms map[string]map[string][]string `json:"platforms,omitempty"`