From 41c8f7cf6dc586e70a806c87580136c17015bc13 Mon Sep 17 00:00:00 2001 From: Mahmoud-Emad Date: Mon, 8 Sep 2025 14:29:26 +0300 Subject: [PATCH] feat: Add basic `heropods` container example - Initialize `heropods` factory using Podman - Create, start, and stop a custom `alpine` container - Execute a command within the container - Add debug log for container command execution --- examples/virt/heropods/runcommands.vsh | 19 +++++++++++++++++++ lib/virt/heropods/container.v | 1 + 2 files changed, 20 insertions(+) create mode 100644 examples/virt/heropods/runcommands.vsh diff --git a/examples/virt/heropods/runcommands.vsh b/examples/virt/heropods/runcommands.vsh new file mode 100644 index 00000000..f54fc43b --- /dev/null +++ b/examples/virt/heropods/runcommands.vsh @@ -0,0 +1,19 @@ +#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run + +import freeflowuniverse.herolib.virt.heropods + +mut factory := heropods.new( + reset: false + use_podman: true +) or { panic('Failed to init ContainerFactory: ${err}') } + +mut container := factory.new( + name: 'myalpine' + image: .custom + custom_image_name: 'alpine_3_20' + docker_url: 'docker.io/library/alpine:3.20' +)! + +container.start()! +container.exec(cmd: 'ls')! +container.stop()! diff --git a/lib/virt/heropods/container.v b/lib/virt/heropods/container.v index 1dd00842..bb2e1289 100644 --- a/lib/virt/heropods/container.v +++ b/lib/virt/heropods/container.v @@ -105,6 +105,7 @@ pub fn (mut self Container) exec(cmd_ osal.Command) !string { // Use the builder node to execute inside container mut node := self.node()! + console.print_debug('Executing command in container ${self.name}: ${cmd_.cmd}') return node.exec(cmd: cmd_.cmd, stdout: cmd_.stdout) }