mirror of
https://github.com/profullstack/agentbbs.git
synced 2026-12-01 09:24:46 +00:00
fix(pods): heal pods by image ID, not tag, so rebuilt images roll out
setup.sh rebuilds the pod image under the same tag (localhost/agentbbs-pod:latest). hasImage compared only the tag, so every existing pod looked current and kept the old image forever: the "Use c0mpute network" launcher (#183) and any Claude Code or Codex updates never reached existing members. Now an idle pod whose image ID differs from the tag's current ID is recreated (home volume kept). Unknown IDs still never trigger a heal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
82bc5ba4fc
commit
a7758bddb2
2 changed files with 47 additions and 5 deletions
|
|
@ -94,24 +94,48 @@ func (m *Manager) hasMount(name, dest string) bool {
|
|||
// Used to roll out a new pod image: a mismatch triggers an idle recreate so
|
||||
// members pick up added tooling without losing their home volume. A blank or
|
||||
// unresolvable image name is treated as a match (never heal on uncertainty).
|
||||
//
|
||||
// It compares image IDs, not just names: setup.sh rebuilds the pod image under
|
||||
// the same tag (localhost/agentbbs-pod:latest), so a name-only check never saw
|
||||
// a rebuild and existing pods kept the old image forever (new tooling such as
|
||||
// c0mpute never reached them).
|
||||
func (m *Manager) hasImage(name, image string) bool {
|
||||
if image == "" {
|
||||
return true
|
||||
}
|
||||
out, err := exec.Command(m.engine, "container", "inspect", "-f", "{{.ImageName}}", name).Output()
|
||||
out, err := exec.Command(m.engine, "container", "inspect", "-f", "{{.ImageName}}|{{.Image}}", name).Output()
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
got := strings.TrimSpace(string(out))
|
||||
// Normalize: inspect may report "localhost/agentbbs-pod:latest" while m.image
|
||||
// is the same; also tolerate the docker.io/library/ prefix podman adds.
|
||||
gotName, gotID, _ := strings.Cut(strings.TrimSpace(string(out)), "|")
|
||||
wantID := ""
|
||||
if out, err := exec.Command(m.engine, "image", "inspect", "-f", "{{.Id}}", image).Output(); err == nil {
|
||||
wantID = strings.TrimSpace(string(out))
|
||||
}
|
||||
return sameImage(gotName, gotID, image, wantID)
|
||||
}
|
||||
|
||||
// sameImage decides whether a container (gotName, gotID) runs the wanted image
|
||||
// (wantName, wantID). Names must match after normalization; when both IDs are
|
||||
// known they must match too. An unknown ID is not a mismatch.
|
||||
func sameImage(gotName, gotID, wantName, wantID string) bool {
|
||||
// Normalize: inspect may report "localhost/agentbbs-pod:latest" while the
|
||||
// wanted name is the same; also tolerate the docker.io/library/ prefix
|
||||
// podman adds.
|
||||
norm := func(s string) string {
|
||||
s = strings.TrimPrefix(s, "docker.io/library/")
|
||||
s = strings.TrimPrefix(s, "docker.io/")
|
||||
s = strings.TrimPrefix(s, "localhost/")
|
||||
return s
|
||||
}
|
||||
return norm(got) == norm(image)
|
||||
if norm(gotName) != norm(wantName) {
|
||||
return false
|
||||
}
|
||||
id := func(s string) string { return strings.TrimPrefix(strings.TrimSpace(s), "sha256:") }
|
||||
if id(gotID) == "" || id(wantID) == "" {
|
||||
return true
|
||||
}
|
||||
return id(gotID) == id(wantID)
|
||||
}
|
||||
|
||||
// agentDir is the host directory bind-mounted into a pod at /run/agentbbs-agent,
|
||||
|
|
|
|||
|
|
@ -35,3 +35,21 @@ func TestPublicHTMLMountCreatesAndMaps(t *testing.T) {
|
|||
t.Fatalf("expected %q to be a created directory, err=%v", wantHost, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSameImage(t *testing.T) {
|
||||
cases := []struct {
|
||||
gotName, gotID, wantName, wantID string
|
||||
want bool
|
||||
}{
|
||||
{"localhost/agentbbs-pod:latest", "62a86171b60a", "localhost/agentbbs-pod:latest", "dc18f4df01f5", false}, // rebuilt under the same tag
|
||||
{"localhost/agentbbs-pod:latest", "dc18f4df01f5", "agentbbs-pod:latest", "sha256:dc18f4df01f5", true},
|
||||
{"docker.io/library/ubuntu:24.04", "abc", "localhost/agentbbs-pod:latest", "abc", false}, // different image
|
||||
{"localhost/agentbbs-pod:latest", "", "localhost/agentbbs-pod:latest", "dc18", true}, // unknown id: no heal
|
||||
{"localhost/agentbbs-pod:latest", "dc18", "localhost/agentbbs-pod:latest", "", true},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if got := sameImage(c.gotName, c.gotID, c.wantName, c.wantID); got != c.want {
|
||||
t.Errorf("sameImage(%q,%q,%q,%q) = %v, want %v", c.gotName, c.gotID, c.wantName, c.wantID, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue