...
This commit is contained in:
@@ -6,12 +6,30 @@
|
||||
let buildah_exists = which("buildah");
|
||||
println(`Buildah exists: ${buildah_exists}`);
|
||||
|
||||
// Create a builder object
|
||||
println("\nCreating a builder object:");
|
||||
let container_name = "my-container-example";
|
||||
|
||||
// Create a new builder
|
||||
let builder = bah_new(container_name, "alpine:latest");
|
||||
|
||||
// Reset the builder to remove any existing container
|
||||
println("\nResetting the builder to start fresh:");
|
||||
let reset_result = builder.reset();
|
||||
println(`Reset result: ${reset_result}`);
|
||||
|
||||
// Create a new container after reset
|
||||
println("\nCreating a new container after reset:");
|
||||
builder = bah_new(container_name, "alpine:latest");
|
||||
println(`Container created with ID: ${builder.container_id}`);
|
||||
println(`Builder created with name: ${builder.name}, image: ${builder.image}`);
|
||||
|
||||
// List available images (only if buildah is installed)
|
||||
println("Listing available container images:");
|
||||
println("\nListing available container images:");
|
||||
// if ! buildah_exists != "" {
|
||||
// //EXIT
|
||||
// }
|
||||
let images = bah_images();
|
||||
let images = builder.images();
|
||||
println(`Found ${images.len()} images`);
|
||||
|
||||
// Print image details (limited to 3)
|
||||
@@ -24,73 +42,65 @@ for img in images {
|
||||
count += 1;
|
||||
}
|
||||
|
||||
//Create a container from an image
|
||||
println("\nCreating a container from alpine image:");
|
||||
let container = bah_from("alpine:latest");
|
||||
println(`Container result: success=${container.success}, code=${container.code}`);
|
||||
println(`Container stdout: "${container.stdout}"`);
|
||||
println(`Container stderr: "${container.stderr}"`);
|
||||
let container_id = container.stdout;
|
||||
println(`Container ID: ${container_id}`);
|
||||
|
||||
//Run a command in the container
|
||||
println("\nRunning a command in the container:");
|
||||
let run_result = bah_run(container_id, "echo 'Hello from container'");
|
||||
let run_result = builder.run("echo 'Hello from container'");
|
||||
println(`Command output: ${run_result.stdout}`);
|
||||
|
||||
//Add a file to the container
|
||||
println("\nAdding a file to the container:");
|
||||
let test_file = "test_file.txt";
|
||||
run(`echo "Test content" > ${test_file}`);
|
||||
let add_result = bah_add(container_id, test_file, "/");
|
||||
// Create the test file using Rhai's file_write function
|
||||
file_write(test_file, "Test content");
|
||||
println(`Created test file: ${test_file}`);
|
||||
println(`Created test file: ${test_file}`);
|
||||
let add_result = builder.add(test_file, "/");
|
||||
println(`Add result: ${add_result.success}`);
|
||||
|
||||
//Commit the container to create a new image
|
||||
println("\nCommitting the container to create a new image:");
|
||||
let commit_result = bah_commit(container_id, "my-custom-image:latest");
|
||||
let commit_result = builder.commit("my-custom-image:latest");
|
||||
println(`Commit result: ${commit_result.success}`);
|
||||
|
||||
//Remove the container
|
||||
println("\nRemoving the container:");
|
||||
let remove_result = bah_remove(container_id);
|
||||
let remove_result = builder.remove();
|
||||
println(`Remove result: ${remove_result.success}`);
|
||||
|
||||
//Clean up the test file
|
||||
delete(test_file);
|
||||
|
||||
// Demonstrate build options
|
||||
println("\nDemonstrating build options:");
|
||||
let build_options = bah_new_build_options();
|
||||
build_options.tag = "example-image:latest";
|
||||
build_options.context_dir = ".";
|
||||
build_options.file = "example_Dockerfile";
|
||||
// Demonstrate static methods
|
||||
println("\nDemonstrating static methods:");
|
||||
println("Building an image from a Dockerfile:");
|
||||
let build_result = builder.build("example-image:latest", ".", "example_Dockerfile", "chroot");
|
||||
println(`Build result: ${build_result.success}`);
|
||||
|
||||
println("Build options configured:");
|
||||
println(` - Tag: ${build_options.tag}`);
|
||||
println(` - Context: ${build_options.context_dir}`);
|
||||
println(` - Dockerfile: ${build_options.file}`);
|
||||
// Pull an image
|
||||
println("\nPulling an image:");
|
||||
let pull_result = builder.image_pull("alpine:latest", true);
|
||||
println(`Pull result: ${pull_result.success}`);
|
||||
|
||||
// Demonstrate commit options
|
||||
println("\nDemonstrating commit options:");
|
||||
let commit_options = bah_new_commit_options();
|
||||
commit_options.format = "docker";
|
||||
commit_options.squash = true;
|
||||
commit_options.rm = true;
|
||||
// Skip commit options demonstration since we removed the legacy functions
|
||||
println("\nSkipping commit options demonstration (legacy functions removed)");
|
||||
|
||||
println("Commit options configured:");
|
||||
println(` - Format: ${commit_options.format}`);
|
||||
println(` - Squash: ${commit_options.squash}`);
|
||||
println(` - Remove container: ${commit_options.rm}`);
|
||||
// Demonstrate config method
|
||||
println("\nDemonstrating config method:");
|
||||
// Create a new container for config demonstration
|
||||
println("Creating a new container for config demonstration:");
|
||||
builder = bah_new("config-demo-container", "alpine:latest");
|
||||
println(`Container created with ID: ${builder.container_id}`);
|
||||
|
||||
// Demonstrate config options
|
||||
println("\nDemonstrating config options:");
|
||||
let config_options = bah_new_config_options();
|
||||
config_options.author = "Rhai Example";
|
||||
config_options.cmd = "/bin/sh -c 'echo Hello from Buildah'";
|
||||
let config_options = #{
|
||||
"author": "Rhai Example",
|
||||
"cmd": "/bin/sh -c 'echo Hello from Buildah'"
|
||||
};
|
||||
let config_result = builder.config(config_options);
|
||||
println(`Config result: ${config_result.success}`);
|
||||
|
||||
println("Config options configured:");
|
||||
println(` - Author: ${config_options.author}`);
|
||||
println(` - Command: ${config_options.cmd}`);
|
||||
// Clean up the container
|
||||
println("Removing the config demo container:");
|
||||
builder.remove();
|
||||
|
||||
|
||||
"Buildah operations script completed successfully!"
|
Reference in New Issue
Block a user