refactor: Migrate container management to heropods module

- Remove `herorun` module and related scripts
- Introduce `heropods` module for container management
- Enhance `tmux` module with pane clearing and creation
- Update `Container` methods to use `osal.Command` result
- Improve `ContainerFactory` for image & container handling
This commit is contained in:
Mahmoud-Emad
2025-09-07 15:56:59 +03:00
parent 9123c2bcb8
commit a74129ff90
18 changed files with 163 additions and 644 deletions

View File

@@ -17,22 +17,22 @@ pub enum ContainerImageType {
@[params]
pub struct ContainerNewArgs {
pub:
name string @[required]
image ContainerImageType = .alpine_3_20
name string @[required]
image ContainerImageType = .alpine_3_20
custom_image_name string // Used when image = .custom
docker_url string // Docker image URL for new images
reset bool
docker_url string // Docker image URL for new images
reset bool
}
pub fn (mut self ContainerFactory) new(args ContainerNewArgs) !&Container {
if args.name in self.containers && !args.reset {
return self.containers[args.name]
}
// Determine image to use
mut image_name := ''
mut rootfs_path := ''
match args.image {
.alpine_3_20 {
image_name = 'alpine'
@@ -52,35 +52,38 @@ pub fn (mut self ContainerFactory) new(args ContainerNewArgs) !&Container {
}
image_name = args.custom_image_name
rootfs_path = '/containers/images/${image_name}/rootfs'
// Check if image exists, if not and docker_url provided, create it
if !os.is_dir(rootfs_path) && args.docker_url != '' {
console.print_debug('Creating new image ${image_name} from ${args.docker_url}')
_ = self.image_new(
image_name: image_name
docker_url: args.docker_url
reset: args.reset
reset: args.reset
)!
}
}
}
// Verify rootfs exists
if !os.is_dir(rootfs_path) {
return error('Image rootfs not found: ${rootfs_path}. Please ensure the image is available.')
}
// Create container config
self.create_container_config(args.name, rootfs_path)!
// Create container using crun
osal.exec(cmd: 'crun create --bundle /containers/configs/${args.name} ${args.name}', stdout: true)!
osal.exec(
cmd: 'crun create --bundle /containers/configs/${args.name} ${args.name}'
stdout: true
)!
mut container := &Container{
name: args.name
name: args.name
factory: &self
}
self.containers[args.name] = container
return container
}
@@ -88,11 +91,11 @@ pub fn (mut self ContainerFactory) new(args ContainerNewArgs) !&Container {
fn (self ContainerFactory) create_container_config(container_name string, rootfs_path string) ! {
config_dir := '/containers/configs/${container_name}'
osal.exec(cmd: 'mkdir -p ${config_dir}', stdout: false)!
// Generate OCI config.json using template
config_content := $tmpl('config_template.json')
config_path := '${config_dir}/config.json'
mut p := pathlib.get_file(path: config_path, create: true)!
p.write(config_content)!
}
}