Files
magpie/internal/gui/update_remote.go
T
yetone 598bc45346 update: a container's hint names the found version's own image, not :latest (fishmagic80 on X)
In Docker, Settings › About on the Daily channel said "0.1.4479 is out
… docker pull ghcr.io/yetone/magpie:latest". :latest is the newest
release (docker.yml), daily and stable the Daily and Stable channels'
(docker-daily.yml, docker-stable.yml), so :latest held 0.1.4504, not the
0.1.4479 announced; on Stable it is weeks apart. docker.yml writes every
release's own tag (ghcr.io/yetone/magpie:0.1.4479; checked on ghcr: 4479,
4395, latest, daily, stable, 0.1 all resolve, daily = 4479's digest).

update.Image(version) is that tag, and every place that printed the
command names it now, with "recreate the container from it" (a compose
file on :latest would otherwise run the old tag again):
- the GUI's Version row and Update pill (/api/update's new `image`,
  stuck "container"; app.js updateStuck);
- `magpie update` in a container (internal/cli);
- a Remote magpie row's tip for a container: UpdateRemotes now keeps the
  version it asked for on an "unsupported" answer too, so the tip names
  that version's image;
- i18n zh, zh-TW, ja, de for both strings;
- docs/docker (en, zh, ja): Updates says Settings › About names the
  version's own image and that latest may be ahead of the channel;
  llms-full and search indexes rebuilt (site/docs-index.mjs).

Run at this tree (mica, through mica-run):
- red on origin/main 14b6b9555 with the new tests copied in:
  TestUpdateInContainerSaysPullTheImage (cli: ":latest" in the error),
  TestRemoteMagpieAskedToFollow (gateway: Version v0.1.100, not the asked
  v0.1.200), update-stuck.test.cjs container cases and
  remote-update.test.cjs, both engines;
- green here: go test ./internal/update ./internal/cli, internal/gateway
  and internal/provider -run TestRemote*, internal/gui except
  TestGatewayModeListsNoOwnSessions, which fails the same on
  14b6b9555 alone (#7064);
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./..., go build, gofmt -l (nothing);
- node --test site/docker-tags.test.mjs; GUI files in chromium and
  webkit: update-stuck, remote-update, update-channel,
  update-stable-newest, update-release-page, update-check, lan-docker,
  i18n-keys, gui-de, gui-zh-tw, i18n-en-no-cjk (216 pass, 0 fail);
  gui-ja's "ja has every zh string" is red on main for another string
  (#7144).

Not run before the push: the full `go test -tags nogui ./...` (mote and
mica each had another session's full suite running); it runs after.
Not tried: a real container pulling the new tag. Not checked at runtime:
whether the version's image is already on ghcr; docker.yml pushes it in
~6 minutes, before the release is published, and a missing one makes
docker pull fail with "manifest unknown", not pull another version.
2026-11-19 10:26:23 +08:00

94 lines
3.6 KiB
Go

package gui
import (
"time"
"github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/settings"
"github.com/yetone/magpie/internal/update"
)
// updateAsked answers provider.RemoteUpdatePath: another magpie using
// this one as its Remote magpie updated to want (nnlrl_75403 on Discord).
// This one updates as its own automatic update would, downloading the
// latest and restarting into it once nothing would be cut short
// (waitIdle), or says why it doesn't: nothing newer, automatic updates
// or downloads turned off here (the user's to keep), or a copy it can't
// replace (a container's image, a package manager's, a folder it can't
// write, a build from source).
func (u *updater) updateAsked(want string) provider.RemoteUpdate {
switch {
case !update.Released(Version):
return provider.RemoteUpdate{State: "unsupported", Why: "source"}
case !update.Newer(want, Version):
return provider.RemoteUpdate{State: "current"}
}
if s := settings.Load(); s.NoAutoUpdate || s.NoAutoDownload {
return provider.RemoteUpdate{State: "off"}
}
u.mu.Lock()
restart, bundle, exe, stuck, packaged := u.autoRestart, u.bundle, u.exe, u.stuck, u.packaged
u.mu.Unlock()
if bundle == "" && exe == "" || restart == nil {
out := provider.RemoteUpdate{State: "unsupported", Why: stuck}
if stuck == "package" && packaged != nil {
out.Manager, out.Command = packaged.Name(), packaged.Command()
}
if out.Why == "" || out.Why == "translocated" || out.Why == "read-only" {
out.Why = "not-writable"
}
return out
}
u.download()
u.waitIdle(restart, false)
return provider.RemoteUpdate{State: "updating"}
}
// remoteUpdateJSON is a Remote magpie's row's word on its last ask to
// update (provider.UpdateRemotes): Say on the row, Tip over it, each an
// English key the page translates with the rest as its values.
type remoteUpdateJSON struct {
Say string `json:"say"`
Tip string `json:"tip"`
V string `json:"v,omitempty"`
Manager string `json:"manager,omitempty"`
Cmd string `json:"cmd,omitempty"`
Image string `json:"image,omitempty"`
}
// remoteUpdateNote is what the Remote magpie id's row says of its last
// ask to update, nil when nothing: one that is current, or not asked.
func remoteUpdateNote(id string, now time.Time) *remoteUpdateJSON {
u, ok := provider.RemoteUpdateOf(id, now)
if !ok {
return nil
}
j := &remoteUpdateJSON{Say: "can't update itself", V: u.Version, Manager: u.Manager, Cmd: u.Command}
switch u.State {
case "updating":
j.Say, j.Tip = "updating to {v}", "This magpie updated, so that one was asked to update to {v} too. It restarts into it once nothing is in flight."
case "off":
j.Say, j.Tip = "automatic updates off", "Automatic updates are turned off on that computer, so it stays on its version."
case "old":
j.Say, j.Tip = "update it there", "That magpie is too old to be updated from here: update it on that computer once."
case "refused":
j.Say, j.Tip = "update it there", "Updating it from here takes a gateway key with full access there; this provider's key is read-only or held."
default:
switch u.Why {
case "container":
j.Tip = "It runs in a container: pull the image of {v} (docker pull {image}) and recreate the container from it."
j.Image = update.Image(u.Version)
case "package":
j.Tip = "{manager} installed it there: update it with {manager}."
if u.Command != "" {
j.Tip = "{manager} installed it there: update it with {cmd}"
}
case "source":
j.Tip = "It was built from source: update it the way it was built."
default:
j.Tip = "magpie can't replace itself where it runs on that computer: update it there."
}
}
return j
}