added example

This commit is contained in:
Maxime Van Hees 2025-04-02 14:41:50 +02:00
parent 288f17453b
commit 3f461334ec
7 changed files with 19 additions and 33 deletions

View File

@ -4,7 +4,7 @@
//! common container operations like creating containers, running commands, //! common container operations like creating containers, running commands,
//! and managing images. //! and managing images.
use crate::virt::buildah::{self, BuildahError}; use sal::virt::buildah::{self, BuildahError};
use std::collections::HashMap; use std::collections::HashMap;
/// Run a complete buildah workflow example /// Run a complete buildah workflow example
@ -114,8 +114,8 @@ pub fn run_all_examples() -> Result<(), BuildahError> {
// Uncomment these to run the examples // Uncomment these to run the examples
run_buildah_example()?; run_buildah_example()?;
build_image_example()?; // build_image_example()?;
registry_operations_example()?; // registry_operations_example()?;
println!("\nTo run these examples, uncomment the function calls in run_all_examples()"); println!("\nTo run these examples, uncomment the function calls in run_all_examples()");
println!("Note that these examples require buildah to be installed on your system"); println!("Note that these examples require buildah to be installed on your system");
@ -123,3 +123,7 @@ pub fn run_all_examples() -> Result<(), BuildahError> {
Ok(()) Ok(())
} }
fn main() {
run_all_examples();
}

View File

@ -80,7 +80,7 @@ impl Error for GitError {
*/ */
pub fn git_clone(url: &str) -> Result<String, GitError> { pub fn git_clone(url: &str) -> Result<String, GitError> {
// Check if git is installed // Check if git is installed
let git_check = Command::new("git") let _git_check = Command::new("git")
.arg("--version") .arg("--version")
.output() .output()
.map_err(GitError::GitNotInstalled)?; .map_err(GitError::GitNotInstalled)?;

View File

@ -293,17 +293,6 @@ impl GitExecutor {
// Execute git command with username/password // Execute git command with username/password
fn execute_with_credentials(&self, args: &[&str], username: &str, password: &str) -> Result<Output, GitExecutorError> { fn execute_with_credentials(&self, args: &[&str], username: &str, password: &str) -> Result<Output, GitExecutorError> {
// Helper method to execute a command and handle the result
fn execute_command(command: &mut Command) -> Result<Output, GitExecutorError> {
let output = command.output()?;
if output.status.success() {
Ok(output)
} else {
let error = String::from_utf8_lossy(&output.stderr);
Err(GitExecutorError::GitCommandFailed(error.to_string()))
}
}
// For HTTPS authentication, we need to modify the URL to include credentials // For HTTPS authentication, we need to modify the URL to include credentials
// Create a new vector to hold our modified arguments // Create a new vector to hold our modified arguments
let modified_args: Vec<String> = args.iter().map(|&arg| { let modified_args: Vec<String> = args.iter().map(|&arg| {

View File

@ -76,7 +76,7 @@ pub struct CommandResult {
impl CommandResult { impl CommandResult {
/// Create a default failed result with an error message /// Create a default failed result with an error message
fn error(message: &str) -> Self { fn _error(message: &str) -> Self {
Self { Self {
stdout: String::new(), stdout: String::new(),
stderr: message.to_string(), stderr: message.to_string(),
@ -132,10 +132,6 @@ fn handle_child_output(mut child: Child, silent: bool) -> Result<CommandResult,
let stdout = child.stdout.take(); let stdout = child.stdout.take();
let stderr = child.stderr.take(); let stderr = child.stderr.take();
// Buffers for captured output
let mut captured_stdout = String::new();
let mut captured_stderr = String::new();
// Process stdout // Process stdout
let stdout_handle = if let Some(out) = stdout { let stdout_handle = if let Some(out) = stdout {
let reader = BufReader::new(out); let reader = BufReader::new(out);
@ -191,18 +187,18 @@ fn handle_child_output(mut child: Child, silent: bool) -> Result<CommandResult,
.map_err(|e| RunError::ChildProcessError(format!("Failed to wait on child process: {}", e)))?; .map_err(|e| RunError::ChildProcessError(format!("Failed to wait on child process: {}", e)))?;
// Join our stdout thread if it exists // Join our stdout thread if it exists
if let Some(handle) = stdout_handle { let captured_stdout = if let Some(handle) = stdout_handle {
captured_stdout = handle.join().unwrap_or_default(); handle.join().unwrap_or_default()
} else { } else {
captured_stdout = "Failed to capture stdout".to_string(); "Failed to capture stdout".to_string()
} };
// Join our stderr thread if it exists // Join our stderr thread if it exists
if let Some(handle) = stderr_handle { let captured_stderr = if let Some(handle) = stderr_handle {
captured_stderr = handle.join().unwrap_or_default(); handle.join().unwrap_or_default()
} else { } else {
captured_stderr = "Failed to capture stderr".to_string(); "Failed to capture stderr".to_string()
} };
// Return the command result // Return the command result
Ok(CommandResult { Ok(CommandResult {

View File

@ -1,4 +1,4 @@
use redis::{Client, Connection, Commands, RedisError, RedisResult, Cmd}; use redis::{Client, Connection, RedisError, RedisResult, Cmd};
use std::env; use std::env;
use std::path::Path; use std::path::Path;
use std::sync::{Arc, Mutex, Once}; use std::sync::{Arc, Mutex, Once};

View File

@ -1,4 +1,3 @@
use std::process::Command;
use std::collections::HashMap; use std::collections::HashMap;
use crate::virt::buildah::execute_buildah_command; use crate::virt::buildah::execute_buildah_command;
use crate::process::CommandResult; use crate::process::CommandResult;

View File

@ -1,7 +1,6 @@
mod containers; mod containers;
mod images; mod images;
mod cmd; mod cmd;
mod example;
use std::fmt; use std::fmt;
use std::error::Error; use std::error::Error;
@ -45,4 +44,3 @@ impl Error for BuildahError {
pub use containers::*; pub use containers::*;
pub use images::*; pub use images::*;
pub use cmd::*; pub use cmd::*;
pub use example::*;