added tests for container commands
This commit is contained in:
@@ -19,50 +19,51 @@ pub fn run_buildah_example() -> Result<(), BuildahError> {
|
||||
|
||||
// Step 2: Run a command in the container
|
||||
println!("\n=== Installing nginx in container ===");
|
||||
let install_result = buildah::run(container_id, "dnf install -y nginx")?;
|
||||
let install_result = buildah::run(container_id, "dnf install -y nginx").unwrap();
|
||||
println!("{:#?}", install_result);
|
||||
println!("Installation output: {}", install_result.stdout);
|
||||
|
||||
// Step 3: Copy a file into the container
|
||||
println!("\n=== Copying configuration file to container ===");
|
||||
// Note: This would require an actual file to exist
|
||||
// buildah::copy(container_id, "./nginx.conf", "/etc/nginx/nginx.conf")?;
|
||||
println!("For a real example, you would copy a configuration file here");
|
||||
// // Step 3: Copy a file into the container
|
||||
// println!("\n=== Copying configuration file to container ===");
|
||||
// // Note: This would require an actual file to exist
|
||||
// buildah::copy(container_id, "./example.conf", "/etc/example.conf")?;
|
||||
// println!("For a real example, you would copy a configuration file here");
|
||||
|
||||
// Step 4: Configure container metadata
|
||||
println!("\n=== Configuring container metadata ===");
|
||||
let mut config_options = HashMap::new();
|
||||
config_options.insert("port".to_string(), "80".to_string());
|
||||
config_options.insert("label".to_string(), "maintainer=example@example.com".to_string());
|
||||
config_options.insert("entrypoint".to_string(), "/usr/sbin/nginx".to_string());
|
||||
// // Step 4: Configure container metadata
|
||||
// println!("\n=== Configuring container metadata ===");
|
||||
// let mut config_options = HashMap::new();
|
||||
// config_options.insert("port".to_string(), "80".to_string());
|
||||
// config_options.insert("label".to_string(), "maintainer=example@example.com".to_string());
|
||||
// config_options.insert("entrypoint".to_string(), "/usr/sbin/nginx".to_string());
|
||||
|
||||
buildah::config(container_id, config_options)?;
|
||||
println!("Container configured");
|
||||
// buildah::config(container_id, config_options)?;
|
||||
// println!("Container configured");
|
||||
|
||||
// Step 5: Commit the container to create a new image
|
||||
println!("\n=== Committing container to create image ===");
|
||||
let image_name = "my-nginx:latest";
|
||||
buildah::image_commit(container_id, image_name, Some("docker"), true, true)?;
|
||||
println!("Created image: {}", image_name);
|
||||
// // Step 5: Commit the container to create a new image
|
||||
// println!("\n=== Committing container to create image ===");
|
||||
// let image_name = "my-nginx:latest";
|
||||
// buildah::image_commit(container_id, image_name, Some("docker"), true, true)?;
|
||||
// println!("Created image: {}", image_name);
|
||||
|
||||
// Step 6: List images to verify our new image exists
|
||||
println!("\n=== Listing images ===");
|
||||
let images = buildah::images()?;
|
||||
println!("Found {} images:", images.len());
|
||||
for image in images {
|
||||
println!(" ID: {}", image.id);
|
||||
println!(" Names: {}", image.names.join(", "));
|
||||
println!(" Size: {}", image.size);
|
||||
println!(" Created: {}", image.created);
|
||||
println!();
|
||||
}
|
||||
// // Step 6: List images to verify our new image exists
|
||||
// println!("\n=== Listing images ===");
|
||||
// let images = buildah::images()?;
|
||||
// println!("Found {} images:", images.len());
|
||||
// for image in images {
|
||||
// println!(" ID: {}", image.id);
|
||||
// println!(" Names: {}", image.names.join(", "));
|
||||
// println!(" Size: {}", image.size);
|
||||
// println!(" Created: {}", image.created);
|
||||
// println!();
|
||||
// }
|
||||
|
||||
// Step 7: Clean up (optional in a real workflow)
|
||||
println!("\n=== Cleaning up ===");
|
||||
println!("In a real workflow, you might want to keep the image");
|
||||
println!("To remove the image, you would run:");
|
||||
println!("buildah::image_remove(\"{}\")", image_name);
|
||||
// // Step 7: Clean up (optional in a real workflow)
|
||||
// println!("\n=== Cleaning up ===");
|
||||
// println!("In a real workflow, you might want to keep the image");
|
||||
// println!("To remove the image, you would run:");
|
||||
// println!("buildah::image_remove(\"{}\")", image_name);
|
||||
|
||||
println!("\nBuildah example workflow completed successfully!");
|
||||
// println!("\nBuildah example workflow completed successfully!");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user