diff --git a/tools/tht/internal/installapply/identity.go b/tools/tht/internal/installapply/identity.go index 345da4f1..6b57edff 100644 --- a/tools/tht/internal/installapply/identity.go +++ b/tools/tht/internal/installapply/identity.go @@ -39,6 +39,8 @@ func prepareIdentity(i config.Installation) error { } } core := services["core"].(map[string]any) + // Migrations do not launch Pi and must not mutate its image-owned home. + services["catalog-migrate"].(map[string]any)["entrypoint"] = []string{"/usr/bin/tini", "--"} core["volumes"] = append(core["volumes"].([]any), map[string]any{"type": "volume", "source": "harness-pi", "target": "/app/harness/.pi"}) services["catalog-db"].(map[string]any)["environment"] = map[string]string{"PGDATA": "/var/lib/postgresql/data/data"} volumes := map[string]any{} diff --git a/tools/tht/internal/installapply/identity_docker_test.go b/tools/tht/internal/installapply/identity_docker_test.go index 65d09f34..de262dae 100644 --- a/tools/tht/internal/installapply/identity_docker_test.go +++ b/tools/tht/internal/installapply/identity_docker_test.go @@ -2,6 +2,7 @@ package installapply import ( "context" + "encoding/json" "fmt" "io" "os" @@ -86,6 +87,31 @@ func TestPublishedImagesAcceptProtectedOperatorIdentity(t *testing.T) { t.Fatal("PostgreSQL did not become ready") } start() + // Execute the real Catalog and Memory migration scripts using the generated + // maintenance entrypoint, without inheriting Pi's image-owned home initialization. + run("exec", container, "psql", "-U", "postgres", "-v", "ON_ERROR_STOP=1", "-c", "CREATE ROLE thothii_catalog_runtime LOGIN;") + projection, err := os.ReadFile(i.LocalIdentityOverridePath()) + var overlay struct { + Services map[string]struct { + Entrypoint []string `json:"entrypoint"` + } `json:"services"` + } + if err != nil || json.Unmarshal(projection, &overlay) != nil { + t.Fatal("runtime override unavailable") + } + entry := overlay.Services["catalog-migrate"].Entrypoint + if len(entry) == 0 { + t.Fatal("migration entrypoint missing") + } + migrationArgs := []string{"run", "--rm", "--pull", "never", "--platform", plan.Platform, "--network", "container:" + container, "--user", user, + "--mount", "type=volume,src=" + i.ProjectName() + "_auth-state,dst=/proof,readonly", + "--mount", "type=bind,src=" + i.ControlDirectory() + "/core.passwd,dst=/etc/passwd,readonly", + "-e", "THT_CATALOG_DB_HOST=127.0.0.1", "-e", "THT_CATALOG_DB_NAME=postgres", + "-e", "THT_CATALOG_MIGRATOR_USER=postgres", "-e", "THT_CATALOG_MIGRATOR_PASSWORD_FILE=/proof/password", + "--entrypoint", entry[0], core} + migrationArgs = append(migrationArgs, entry[1:]...) + migrationArgs = append(migrationArgs, "bash", "/app/docker/catalog-migrate.sh") + run(migrationArgs...) run("exec", container, "psql", "-U", "postgres", "-v", "ON_ERROR_STOP=1", "-c", "CREATE TABLE installation_proof(value integer); INSERT INTO installation_proof VALUES (47);") run("stop", "--time", "10", container) run("rm", container)