11 work units built in parallel and merged: Agent handlers (Phase 2): - P2.2 Deploy: pull images, stop/remove/run containers, update registry - P2.3 Lifecycle: stop/start/restart with desired_state tracking - P2.4 Status: list (registry), live check (runtime), get status (drift+events) - P2.5 Sync: receive desired state, reconcile unmanaged containers - P2.6 File transfer: push/pull scoped to /srv/<service>/, path validation - P2.7 Adopt: match <service>-* containers, derive component names - P2.8 Monitor: continuous watch loop, drift/flap alerting, event pruning - P2.9 Snapshot: VACUUM INTO database backup command CLI commands (Phase 3): - P3.2 Login, P3.3 Deploy, P3.4 Stop/Start/Restart - P3.5 List/Ps/Status, P3.6 Sync, P3.7 Adopt - P3.8 Service show/edit/export, P3.9 Push/Pull, P3.10 Node list/add/remove Deployment artifacts (Phase 4): - Systemd units (agent service + backup timer) - Example configs (CLI + agent) - Install script (idempotent) All packages: build, vet, lint (0 issues), test (all pass). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
79 lines
1.8 KiB
Go
79 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
mcpv1 "git.wntrmute.dev/kyle/mcp/gen/mcp/v1"
|
|
"git.wntrmute.dev/kyle/mcp/internal/config"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func adoptCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "adopt <service>",
|
|
Short: "Adopt all <service>-* containers into a service",
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
cfg, err := config.LoadCLIConfig(cfgPath)
|
|
if err != nil {
|
|
return fmt.Errorf("load config: %w", err)
|
|
}
|
|
|
|
nodeName, _ := cmd.Flags().GetString("node")
|
|
|
|
var addr string
|
|
if nodeName != "" {
|
|
for _, n := range cfg.Nodes {
|
|
if n.Name == nodeName {
|
|
addr = n.Address
|
|
break
|
|
}
|
|
}
|
|
if addr == "" {
|
|
return fmt.Errorf("node %q not found in config", nodeName)
|
|
}
|
|
} else {
|
|
if len(cfg.Nodes) == 0 {
|
|
return fmt.Errorf("no nodes configured")
|
|
}
|
|
nodeName = cfg.Nodes[0].Name
|
|
addr = cfg.Nodes[0].Address
|
|
}
|
|
|
|
client, conn, err := dialAgent(addr, cfg)
|
|
if err != nil {
|
|
return fmt.Errorf("dial %s: %w", nodeName, err)
|
|
}
|
|
defer func() { _ = conn.Close() }()
|
|
|
|
resp, err := client.AdoptContainers(context.Background(), &mcpv1.AdoptContainersRequest{
|
|
Service: args[0],
|
|
})
|
|
if err != nil {
|
|
return fmt.Errorf("adopt on %s: %w", nodeName, err)
|
|
}
|
|
|
|
results := resp.GetResults()
|
|
if len(results) == 0 {
|
|
fmt.Printf("no containers matching %q found on %s\n", args[0]+"-*", nodeName)
|
|
return nil
|
|
}
|
|
|
|
for _, r := range results {
|
|
if r.GetSuccess() {
|
|
fmt.Printf(" adopted %s -> %s\n", r.GetContainer(), r.GetComponent())
|
|
} else {
|
|
fmt.Printf(" failed %s -> %s: %s\n", r.GetContainer(), r.GetComponent(), r.GetError())
|
|
}
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|
|
|
|
cmd.Flags().String("node", "", "target node (default: first node in config)")
|
|
|
|
return cmd
|
|
}
|