Add unikernel runtime: run services as Nanos VMs under QEMU/KVM
Implements the hypervisor design's Phase 1: a second runtime.Runtime backend (QEMU) that runs each service component as a Nanos unikernel VM instead of a podman container, selected per-component via a new runtime = "unikernel" service-def field. - internal/runtime/qemu.go: QEMURuntime. Pull extracts the ELF from the OCI image; Run does `ops build` + boots qemu-system-x86_64 with KVM, user-mode net port-forwards, QMP control socket and serial console log; Stop/Remove/Inspect/List/Logs map onto VM lifecycle + state dir. - proto/registry/servicedef: add runtime, memory_mb, vcpus fields (registry migration 5). - agent: holds both runtimes; runtimeFor() selects per component; listAllContainers() merges containers + VMs so drift/status see both. Unikernel runtime auto-enables on nodes with /dev/kvm + ops. Validated end-to-end on straylight: a test service deploys via `mcp deploy --direct`, boots as a Nanos unikernel, serves HTTP through the agent port-forward, and reports running via `mcp status`/`mcp logs`. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -51,7 +51,7 @@ func (a *Agent) StopService(ctx context.Context, req *mcpv1.StopServiceRequest)
|
||||
}
|
||||
}
|
||||
|
||||
if err := a.Runtime.Stop(ctx, containerName); err != nil {
|
||||
if err := a.runtimeFor(c.Runtime).Stop(ctx, containerName); err != nil {
|
||||
a.Logger.Info("stop container (ignored)", "container", containerName, "error", err)
|
||||
}
|
||||
|
||||
@@ -132,12 +132,14 @@ func startComponent(ctx context.Context, a *Agent, service string, c *registry.C
|
||||
containerName := ContainerNameFor(service, c.Name)
|
||||
r := &mcpv1.ComponentResult{Name: c.Name, Success: true}
|
||||
|
||||
rt := a.runtimeFor(c.Runtime)
|
||||
|
||||
// Remove any pre-existing container; ignore errors for non-existent ones.
|
||||
_ = a.Runtime.Stop(ctx, containerName)
|
||||
_ = a.Runtime.Remove(ctx, containerName)
|
||||
_ = rt.Stop(ctx, containerName)
|
||||
_ = rt.Remove(ctx, containerName)
|
||||
|
||||
spec := componentToSpec(service, c)
|
||||
if err := a.Runtime.Run(ctx, spec); err != nil {
|
||||
if err := rt.Run(ctx, spec); err != nil {
|
||||
r.Success = false
|
||||
r.Error = fmt.Sprintf("run container: %v", err)
|
||||
return r
|
||||
@@ -156,11 +158,12 @@ func restartComponent(ctx context.Context, a *Agent, service string, c *registry
|
||||
containerName := ContainerNameFor(service, c.Name)
|
||||
r := &mcpv1.ComponentResult{Name: c.Name, Success: true}
|
||||
|
||||
_ = a.Runtime.Stop(ctx, containerName)
|
||||
_ = a.Runtime.Remove(ctx, containerName)
|
||||
rt := a.runtimeFor(c.Runtime)
|
||||
_ = rt.Stop(ctx, containerName)
|
||||
_ = rt.Remove(ctx, containerName)
|
||||
|
||||
spec := componentToSpec(service, c)
|
||||
if err := a.Runtime.Run(ctx, spec); err != nil {
|
||||
if err := rt.Run(ctx, spec); err != nil {
|
||||
r.Success = false
|
||||
r.Error = fmt.Sprintf("run container: %v", err)
|
||||
_ = registry.UpdateComponentState(a.DB, service, c.Name, "", "stopped")
|
||||
@@ -177,14 +180,16 @@ func restartComponent(ctx context.Context, a *Agent, service string, c *registry
|
||||
// componentToSpec builds a runtime.ContainerSpec from a registry Component.
|
||||
func componentToSpec(service string, c *registry.Component) runtime.ContainerSpec {
|
||||
return runtime.ContainerSpec{
|
||||
Name: ContainerNameFor(service, c.Name),
|
||||
Image: c.Image,
|
||||
Network: c.Network,
|
||||
User: c.UserSpec,
|
||||
Restart: c.Restart,
|
||||
Ports: c.Ports,
|
||||
Volumes: c.Volumes,
|
||||
Cmd: c.Cmd,
|
||||
Name: ContainerNameFor(service, c.Name),
|
||||
Image: c.Image,
|
||||
Network: c.Network,
|
||||
User: c.UserSpec,
|
||||
Restart: c.Restart,
|
||||
Ports: c.Ports,
|
||||
Volumes: c.Volumes,
|
||||
Cmd: c.Cmd,
|
||||
MemoryMB: c.MemoryMB,
|
||||
VCPUs: c.VCPUs,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user