#!/usr/bin/env herodo
// kata_basic.rhai
// Demonstrates running a container with Kata runtime and resource limits
// including CPU, memory, and disk space limits
//
// PREREQUISITES:
// 1. Kata Containers must be fully installed (including containerd-shim-kata-v2 binary)
// 2. The runtime must be registered in containerd's config.toml

print("Starting Kata container workflow...");

let container_name = "kata-demo";
let kata_runtime = "io.containerd.kata.v2";  // Use the runtime_type from your containerd config

// Create a container using Kata runtime with:
// - CPU limit: 1.5 CPUs
// - Memory limit: 512MB
// - Disk limit: 10GB (for the Kata VM block device - only works with Kata)
let container = nerdctl_container_from_image(container_name, "alpine:latest")
    .reset()
    .with_detach(true)
    .with_runtime(kata_runtime)
    .with_cpu_limit("1.5")
    .with_memory_limit("512m")
    .with_disk_limit("10G")  
    .with_env("APP_NAME", "kata-demo")
    .start();

print("\nKata container created and started successfully!");
print(`Container name: ${container.name}`);
print(`Container ID: ${container.container_id}`);

// Verify the container is running
print("\n=== Checking container status ===");
let status = container.status();
print(`Container state: ${status.state}`);
print(`Container status: ${status.status}`);

// Get container logs
print("\n=== Container logs ===");
let logs = container.logs();
print(logs.stdout);

"Kata container script completed successfully!"

