From 16c01b2e0f77bf7d259f100c85cf2ead217a0a74 Mon Sep 17 00:00:00 2001 From: Mahmoud-Emad Date: Sun, 7 Sep 2025 16:05:24 +0300 Subject: [PATCH] feat: Add ExecutorCrun and enable container node creation - Add ExecutorCrun to Executor type union - Expose ExecutorCrun.init() as public - Implement Container.node() to build builder.Node - Initialize ExecutorCrun and assign to new node - Set default node properties (platform, cputype) --- lib/builder/executor.v | 2 +- lib/builder/executor_crun.v | 2 +- lib/virt/heropods/container.v | 30 +++++++++++++++++++++++------- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/builder/executor.v b/lib/builder/executor.v index 2029dd46..5c9326d2 100644 --- a/lib/builder/executor.v +++ b/lib/builder/executor.v @@ -2,7 +2,7 @@ module builder import freeflowuniverse.herolib.data.ipaddress -type Executor = ExecutorLocal | ExecutorSSH +type Executor = ExecutorLocal | ExecutorSSH | ExecutorCrun pub struct ExecutorNewArguments { pub mut: diff --git a/lib/builder/executor_crun.v b/lib/builder/executor_crun.v index 46c18a52..232c4598 100644 --- a/lib/builder/executor_crun.v +++ b/lib/builder/executor_crun.v @@ -15,7 +15,7 @@ pub mut: debug bool = true } -fn (mut executor ExecutorCrun) init() ! { +pub fn (mut executor ExecutorCrun) init() ! { // Verify container exists and is running result := osal.exec(cmd: 'crun state ${executor.container_id}', stdout: false) or { return error('Container ${executor.container_id} not found or not accessible') diff --git a/lib/virt/heropods/container.v b/lib/virt/heropods/container.v index 3a34b9b0..c9e0210e 100644 --- a/lib/virt/heropods/container.v +++ b/lib/virt/heropods/container.v @@ -161,17 +161,33 @@ pub fn (mut self Container) tmux_pane(args TmuxPaneArgs) !&tmux.Pane { } pub fn (mut self Container) node() !&builder.Node { - if node := self.node { - return node + // If node already initialized, return it + if self.node != none { + return self.node } - // // Create a new ExecutorCrun for this container - // mut executor := builder.ExecutorCrun{ - // container_id: self.name - // } - + // Create builder factory (so node has proper lifecycle) mut b := builder.new()! + + // Create a new executor for this container + mut exec := builder.ExecutorCrun{ + container_id: self.name + debug: false + } + + // Initialize executor (checks container is running) + exec.init() or { + return error('Failed to init ExecutorCrun for container ${self.name}: ${err}') + } + + // Create a node with this executor mut node := b.node_new(name: 'container_${self.name}')! + node.executor = exec + node.platform = .alpine // TODO: detect from ContainerImageType + node.cputype = .intel // TODO: detect dynamically if needed + node.done = map[string]string{} + node.environment = map[string]string{} + node.hostname = self.name self.node = node return node