Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/retirement-command-output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ftw": patch
---

Keep complete errors and backup paths visible when retiring Python, and find the installed updater even when its Compose service has a custom name.
2 changes: 2 additions & 0 deletions .github/brand/compatibility-allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
^docs/ha-integration\.md:> \*\*Compatibility contract:\*\* the MQTT prefix `forty-two-watts`, discovery$
^docs/ha-integration\.md:> identifier `forty_two_watts`, client ID `forty-two-watts-ha`, and existing$
^go/cmd/ftw-updater/main\.go:.*legacyMainServiceName.*= "forty-two-watts"$
# Published compatibility updater image remains supported during migration.
^go/cmd/ftw-updater/self_replace\.go:.*legacyUpdaterImage.*= "ghcr.io/frahlg/forty-two-watts-updater"$
^go/cmd/ftw/main\.go:// caldavUsername resolves the CalDAV username \(default fortytwowatts\)\.$
^go/internal/ha/bridge\.go:.*topicPrefix string // stable wire ID, e\.g\. "forty-two-watts"$
^scripts/deploy-go\.sh:.*ln -sf ftw forty-two-watts$
Expand Down
3 changes: 3 additions & 0 deletions go/cmd/ftw-updater/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ func main() {
srv.mainServiceName = selectedService
srv.imageID = srv.currentServiceImageID
if *retirePython {
// This is an interactive command. Preserve the helper's complete output,
// including the final error or backup path after its startup messages.
srv.runner = dockerStreaming
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
retire := srv.retirePythonViaHelper
Expand Down
26 changes: 24 additions & 2 deletions go/cmd/ftw-updater/retire_python.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ func retiredPythonCompose(data []byte) ([]byte, bool, error) {
// The running updater mounts Compose read-only. Use its exact local image in
// a short-lived helper with a writable project mount, as self-replacement does.
func (s *server) retirePythonViaHelper(ctx context.Context) error {
image, err := s.imageID(ctx, "ftw-updater")
service, err := s.updaterServiceName()
Comment thread
frahlg marked this conversation as resolved.
if err != nil {
return err
}
image, err := s.imageID(ctx, service)
if err != nil {
return fmt.Errorf("current updater image: %w", err)
}
Expand All @@ -188,6 +192,16 @@ func (s *server) retirePythonViaHelper(ctx context.Context) error {
return s.runner(ctx, nil, args...)
}

func dockerStreaming(ctx context.Context, extraEnv []string, args ...string) error {
cmd := exec.CommandContext(ctx, "docker", args...)
if len(extraEnv) > 0 {
cmd.Env = append(os.Environ(), extraEnv...)
}
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}

func (s *server) retiredPythonContainers(ctx context.Context) ([]string, error) {
coreID, err := s.serviceContainerID(ctx, s.mainServiceName)
if err != nil {
Expand Down Expand Up @@ -259,6 +273,10 @@ func (s *server) retirePythonOptimizer(ctx context.Context) error {
if err != nil {
return err
}
if len(changes) == 0 && len(ids) == 0 {
fmt.Println("Compose has no retired Python wiring and no Python service remains.")
return nil
}
suffix := ".before-python-removal-" + time.Now().UTC().Format("20060102T150405.000000000")
for _, c := range changes {
if err := os.WriteFile(c.path+suffix, c.before, c.mode); err != nil {
Expand Down Expand Up @@ -286,7 +304,11 @@ func (s *server) retirePythonOptimizer(ctx context.Context) error {
return restore(fmt.Errorf("remove retired container: %w", err))
}
}
fmt.Println("Python optimizer removed. Compose backups:", suffix, "Recreate Core at its pinned version to release the old IPC mount.")
fmt.Println("Python optimizer removed.")
if len(changes) > 0 {
fmt.Println("Compose backups:", suffix)
}
fmt.Println("Recreate Core at its pinned version to release the old IPC mount.")
return nil
}

Expand Down
7 changes: 7 additions & 0 deletions go/cmd/ftw-updater/retire_python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ func TestUpdaterRejectsRetiredOptimizer(t *testing.T) {

func TestRetirePythonHelperUsesLocalImageAndWritableProject(t *testing.T) {
s, runner := newTestServer(t)
writeCompose(t, s.composeFile, "services:\n renamed-updater:\n image: mirror.example/team/ftw-updater:v2.16.0-beta.1\n")
s.imageID = func(_ context.Context, service string) (string, error) {
if service != "renamed-updater" {
t.Fatalf("looked up %q instead of the installed updater", service)
}
return "sha256:current", nil
}
t.Setenv("COMPOSE_PROJECT_NAME", "existing-site")
if err := s.retirePythonViaHelper(context.Background()); err != nil {
t.Fatal(err)
Expand Down
3 changes: 2 additions & 1 deletion go/cmd/ftw-updater/self_replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (

const (
canonicalUpdaterImage = "ghcr.io/srcfl/ftw-updater"
legacyUpdaterImage = "ghcr.io/frahlg/forty-two-watts-updater"
// updaterTagEnv pins the sidecar image the same way mainTagEnv pins Core.
// These must match the tagEnv values in componentSpec.
updaterTagEnv = "FTW_UPDATER_IMAGE_TAG"
Expand Down Expand Up @@ -215,7 +216,7 @@ func isUpdaterImage(image string) bool {
if idx := strings.Index(repo[slash+1:], ":"); idx >= 0 {
repo = repo[:slash+1+idx]
}
if repo == canonicalUpdaterImage {
if repo == canonicalUpdaterImage || repo == legacyUpdaterImage {
return true
}
return strings.HasSuffix(repo, "/ftw-updater")
Expand Down
3 changes: 3 additions & 0 deletions go/cmd/ftw-updater/self_replace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ func TestIsUpdaterImage(t *testing.T) {
}{
{"ghcr.io/srcfl/ftw-updater:latest", true},
{"ghcr.io/srcfl/ftw-updater", true},
{legacyUpdaterImage + ":v2.16.0-beta.1", true},
{legacyUpdaterImage + ":${FTW_UPDATER_IMAGE_TAG:-latest}", true},
{legacyUpdaterImage + "@sha256:abc", true},
// Compose images reach us unexpanded; the default's own colon must not
// be mistaken for the tag separator.
{"ghcr.io/srcfl/ftw-updater:${FTW_UPDATER_IMAGE_TAG:-latest}", true},
Expand Down