feat: prepare installation workspaces through existing readiness services

This commit is contained in:
Codex
2026-10-06 18:23:24 +02:00
parent af4c7b5df9
commit 785d96ea50
15 changed files with 378 additions and 42 deletions
+61 -10
View File
@@ -24,15 +24,22 @@ import (
)
type Request struct{ PlanPath, InstallationPath string }
type RuntimeCheck struct {
ID string `json:"id"`
Status string `json:"status"`
}
type Result struct {
SchemaVersion int `json:"schema_version"`
PlatformReady bool `json:"platform_ready"`
WorkspaceReady bool `json:"workspace_ready"`
BindingsReady bool `json:"bindings_ready"`
BindingImport *BindingReport `json:"binding_import,omitempty"`
Stage string `json:"stage"`
Action string `json:"action"`
Journal string `json:"journal,omitempty"`
SchemaVersion int `json:"schema_version"`
PlatformReady bool `json:"platform_ready"`
WorkspaceReady bool `json:"workspace_ready"`
BindingsReady bool `json:"bindings_ready"`
BindingImport *BindingReport `json:"binding_import,omitempty"`
WorkspacePreparation *BindingReport `json:"workspace_preparation,omitempty"`
RuntimeChecks []RuntimeCheck `json:"runtime_checks"`
FunctionalAcceptance bool `json:"functional_acceptance"`
Stage string `json:"stage"`
Action string `json:"action"`
Journal string `json:"journal,omitempty"`
}
type journal struct {
SchemaVersion int `json:"schema_version"`
@@ -49,6 +56,9 @@ type Check func(context.Context, preflight.Plan) error
func Run(ctx context.Context, request Request, runner compose.Runner, check Check) (result Result, err error) {
result = Result{SchemaVersion: 1, Stage: "plan", Action: "Produce a current plan from complete prepared documents."}
for _, id := range []string{"workspace-test", "workflow-doctor", "pi-test"} {
result.RuntimeChecks = append(result.RuntimeChecks, RuntimeCheck{ID: id, Status: "pending"})
}
fail := func(stage, action string) (Result, error) {
result.Stage = stage
result.Action = action
@@ -208,20 +218,61 @@ func Run(ctx context.Context, request Request, runner compose.Runner, check Chec
result.BindingsReady = err == nil
return err
}},
{"workspace-preparation", func() error {
report, err := runPreparedClient(ctx, plan, runner, payload, true)
result.WorkspacePreparation = &report
return err
}},
}
for index, check := range result.RuntimeChecks {
action := check.ID
stages = append(stages, struct {
name string
run func() error
}{action, func() error {
err := runtimeDiagnostic(ctx, plan, runner, action)
result.RuntimeChecks[index].Status = "passed"
if err != nil {
result.RuntimeChecks[index].Status = "failed"
}
return err
}})
}
// Reconcile each idempotent stage against Docker/migration authority on every retry.
// A journal entry alone is never proof that a container or migration still exists.
for _, stage := range stages {
if err := operation(stage.name, stage.run); err != nil {
if result.WorkspacePreparation != nil && result.WorkspacePreparation.Code == "schema_review_required" {
return fail(stage.name, "Review the pending schema synchronization in application Administration, then repeat apply. No destructive change was confirmed by the installer.")
}
return fail(stage.name, err.Error())
}
}
result.PlatformReady = true
result.Stage = "bindings-ready"
result.Action = "Platform and prepared database bindings are ready. Complete workspace readiness before a human-reviewed question."
result.WorkspaceReady = true
result.Stage = "workspace-ready"
result.Action = "Platform, workspace preparation and runtime checks passed. Open the application for the manual human-reviewed question."
return result, nil
}
func runtimeDiagnostic(ctx context.Context, plan preflight.Plan, runner compose.Runner, action string) error {
bound, cancel := context.WithTimeout(ctx, 5*time.Minute)
defer cancel()
name, err := compose.NewOneShotContainerName(plan.Installation.ProjectName() + "-readiness")
if err != nil {
return err
}
value, err := runner.Run(bound, plan.Installation.ComposeArgs("run", "--rm", "-T", "--no-deps", "--pull", "never", "--name", name,
"--entrypoint", "node", "core", "/app/backend/dist/operator-command.js", action), nil)
var report struct {
Ready bool `json:"ready"`
}
if err != nil || value.ExitCode != 0 || json.Unmarshal([]byte(value.Stdout), &report) != nil || !report.Ready {
return errors.New("Runtime diagnostic failed; inspect application diagnostics and correct the prepared configuration")
}
return nil
}
func installAssets(installation config.Installation, plan preflight.Plan) error {
names := make([]string, 0, len(plan.Release.Files))
for name := range plan.Release.Files {