implement virt nerdctl, containerd & buildah sal #1

Open
opened 2025-04-02 06:53:54 +00:00 by despiegk · 2 comments
Owner

nicely wrap the features which are useful for us
only need to be tested on ubuntu 24.04

the user friendlyness and defensiveness is the most important

nicely wrap the features which are useful for us only need to be tested on ubuntu 24.04 the user friendlyness and defensiveness is the most important
maximevanhees was assigned by despiegk 2025-04-02 06:53:58 +00:00
Author
Owner

lets use the following paradigm to rewrap some of the more complicated ones, so its easy and consistent to use
especially container creation

maybe then also the additional things to be done can be layered on top of this as method on this BuildahFromBuilder

🔄 Updated: BuildahFromBuilder with .execute()

use std::process::{Command, Output, Stdio};
use std::io;

pub struct BuildahFromBuilder {
    image: String,
    name: Option<String>,
    pull: Option<String>,
    authfile: Option<String>,
    creds: Option<String>,
}

impl BuildahFromBuilder {
    pub fn new(image: &str) -> Self {
        Self {
            image: image.to_string(),
            name: None,
            pull: None,
            authfile: None,
            creds: None,
        }
    }

    pub fn name(mut self, name: &str) -> Self {
        self.name = Some(name.to_string());
        self
    }

    pub fn pull(mut self, policy: &str) -> Self {
        self.pull = Some(policy.to_string());
        self
    }

    pub fn authfile(mut self, path: &str) -> Self {
        self.authfile = Some(path.to_string());
        self
    }

    pub fn creds(mut self, creds: &str) -> Self {
        self.creds = Some(creds.to_string());
        self
    }

    pub fn execute(self) -> io::Result<Output> {
        let mut cmd = Command::new("buildah");
        cmd.arg("from");

        if let Some(ref name) = self.name {
            cmd.arg("--name").arg(name);
        }

        if let Some(ref pull) = self.pull {
            cmd.arg("--pull").arg(pull);
        }

        if let Some(ref authfile) = self.authfile {
            cmd.arg("--authfile").arg(authfile);
        }

        if let Some(ref creds) = self.creds {
            cmd.arg("--creds").arg(creds);
        }

        cmd.arg(&self.image);

        cmd.stdout(Stdio::inherit())
            .stderr(Stdio::inherit())
            .output()
    }
}

Usage

fn main() -> std::io::Result<()> {
    let result = BuildAh::new("alpine:latest")
        .name("my-container")
        .pull("always")
        .execute()?;

    println!("Command exited with: {}", result.status);
    Ok(())
}

💡 Benefits

  • Fluent API: new(...).option().option().execute()
  • Easy to extend with more flags
  • Hides the messy Command setup
  • You can still expose .build() or .to_command() if needed for debugging or scripting use

Want to add async support or error handling for failed execution as well?

lets use the following paradigm to rewrap some of the more complicated ones, so its easy and consistent to use especially container creation maybe then also the additional things to be done can be layered on top of this as method on this BuildahFromBuilder ### 🔄 Updated: `BuildahFromBuilder` with `.execute()` ```rust use std::process::{Command, Output, Stdio}; use std::io; pub struct BuildahFromBuilder { image: String, name: Option<String>, pull: Option<String>, authfile: Option<String>, creds: Option<String>, } impl BuildahFromBuilder { pub fn new(image: &str) -> Self { Self { image: image.to_string(), name: None, pull: None, authfile: None, creds: None, } } pub fn name(mut self, name: &str) -> Self { self.name = Some(name.to_string()); self } pub fn pull(mut self, policy: &str) -> Self { self.pull = Some(policy.to_string()); self } pub fn authfile(mut self, path: &str) -> Self { self.authfile = Some(path.to_string()); self } pub fn creds(mut self, creds: &str) -> Self { self.creds = Some(creds.to_string()); self } pub fn execute(self) -> io::Result<Output> { let mut cmd = Command::new("buildah"); cmd.arg("from"); if let Some(ref name) = self.name { cmd.arg("--name").arg(name); } if let Some(ref pull) = self.pull { cmd.arg("--pull").arg(pull); } if let Some(ref authfile) = self.authfile { cmd.arg("--authfile").arg(authfile); } if let Some(ref creds) = self.creds { cmd.arg("--creds").arg(creds); } cmd.arg(&self.image); cmd.stdout(Stdio::inherit()) .stderr(Stdio::inherit()) .output() } } ``` --- ### ✅ Usage ```rust fn main() -> std::io::Result<()> { let result = BuildAh::new("alpine:latest") .name("my-container") .pull("always") .execute()?; println!("Command exited with: {}", result.status); Ok(()) } ``` --- ### 💡 Benefits - **Fluent API**: `new(...).option().option().execute()` - Easy to **extend** with more flags - Hides the messy `Command` setup - You can still expose `.build()` or `.to_command()` if needed for debugging or scripting use Want to add async support or error handling for failed execution as well?
Author
Owner

best results I am getting right now with AI are roo code in vscode
use openrouter with sonnet3.7

in roo.code there are very nice options how to code faster and cheaper

best results I am getting right now with AI are roo code in vscode use openrouter with sonnet3.7 in roo.code there are very nice options how to code faster and cheaper
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: herocode/sal#1
No description provided.