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
+20 -7
View File
@@ -24,11 +24,14 @@ import (
var bindingClientModule string
var bindingClient = bindingClientModule + "\nawait importPreparedBindings();\n"
var readinessClient = bindingClientModule + "\nawait importPreparedBindings(undefined, 'workspaces');\n"
type BindingReport struct {
OK bool `json:"ok"`
Code string `json:"code"`
Completed int `json:"completed"`
OK bool `json:"ok"`
Code string `json:"code"`
Completed int `json:"completed"`
WorkspaceID string `json:"workspaceId,omitempty"`
RunID string `json:"runId,omitempty"`
}
// Secrets travel only over the child pipe; they never enter argv, generated assets or journals.
@@ -122,19 +125,29 @@ func bindingPayload(plan preflight.Plan) ([]byte, error) {
}
func importBindings(ctx context.Context, plan preflight.Plan, runner compose.Runner, payload []byte) (BindingReport, error) {
bound, cancel := context.WithTimeout(ctx, 15*time.Minute)
return runPreparedClient(ctx, plan, runner, payload, false)
}
func runPreparedClient(ctx context.Context, plan preflight.Plan, runner compose.Runner, payload []byte, prepare bool) (BindingReport, error) {
client, success, timeout := bindingClient, "bindings_ready", 15*time.Minute
codes := []string{"bindings_ready", "authentication_required", "workspace_reconciliation_required", "binding_reconciliation_required", "container_connection_failed", "binding_import_failed"}
if prepare {
client, success, timeout = readinessClient, "workspaces_prepared", 60*time.Minute
codes = append(codes, "workspaces_prepared", "workspace_preparation_failed", "session_transport_unsupported", "schema_review_required", "schema_sync_failed", "schema_sync_pending", "preprocessing_failed", "preprocessing_blocked", "preprocessing_pending")
}
bound, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
name, err := compose.NewOneShotContainerName(plan.Installation.ProjectName() + "-bindings")
if err != nil {
return BindingReport{Code: "binding_import_failed"}, err
}
result, err := runner.Run(bound, plan.Installation.ComposeArgs("run", "--rm", "-T", "--no-deps", "--pull", "never", "--name", name,
"--entrypoint", "node", "core", "--input-type=module", "-e", bindingClient), bytes.NewReader(payload))
"--entrypoint", "node", "core", "--input-type=module", "-e", client), bytes.NewReader(payload))
var report BindingReport
if json.Unmarshal([]byte(result.Stdout), &report) != nil || !slices.Contains([]string{"bindings_ready", "authentication_required", "workspace_reconciliation_required", "binding_reconciliation_required", "container_connection_failed", "binding_import_failed"}, report.Code) {
if json.Unmarshal([]byte(result.Stdout), &report) != nil || !slices.Contains(codes, report.Code) {
return BindingReport{Code: "binding_import_failed"}, errors.New("Binding import did not return a valid report")
}
if err != nil || result.ExitCode != 0 || !report.OK || report.Code != "bindings_ready" || report.Completed < 1 {
if err != nil || result.ExitCode != 0 || !report.OK || report.Code != success || report.Completed < 1 {
return report, errors.New("Binding import stopped; reconcile the prepared documents with application administration and repeat planning")
}
return report, nil