### BuildCommand Usage Example Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/commands.md Example demonstrating how to instantiate and run the BuildCommand. ```rust use blue_build::commands::{BlueBuildCommand, CommandArgs}; use blue_build::commands::build::BuildCommand; use std::path::PathBuf; let mut cmd = BuildCommand::builder() .recipe(vec![PathBuf::from("recipe.yml")]) .push(false) .build(); cmd.try_run()?; ``` -------------------------------- ### GenerateCommand Usage Example Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/commands.md Example demonstrating how to instantiate and run the GenerateCommand. ```rust use blue_build::commands::generate::GenerateCommand; use std::path::PathBuf; let mut cmd = GenerateCommand::builder() .recipe(Some(PathBuf::from("recipe.yml"))) .output(Some(PathBuf::from("Containerfile"))) .build(); cmd.try_run()?; ``` -------------------------------- ### GenerateCommand Configuration Example Source: https://github.com/blue-build/cli/blob/main/_autodocs/configuration.md Example of configuring the GenerateCommand with recipe, output path, registry, namespace, and validation settings. ```rust use blue_build::commands::generate::GenerateCommand; use std::path::PathBuf; let cmd = GenerateCommand::builder() .recipe(Some(PathBuf::from("recipe.yml"))) .output(Some(PathBuf::from("Containerfile"))) .registry(Some("ghcr.io".to_string())) .registry_namespace(Some("my-org".to_string())) .skip_validation(false) .build(); ``` -------------------------------- ### Install BlueBuild CLI with GitHub Script Source: https://github.com/blue-build/cli/blob/main/README.md Install the BlueBuild CLI using a bash script fetched from GitHub. This is a convenient method for quick installation. ```bash bash <(curl -s https://raw.githubusercontent.com/blue-build/cli/main/install.sh) ``` -------------------------------- ### BuildCommand Configuration Example Source: https://github.com/blue-build/cli/blob/main/_autodocs/configuration.md Example of configuring the BuildCommand with various options like recipe path, push, platform, compression, and retry settings. ```rust use blue_build::commands::build::BuildCommand; use blue_build_utils::platform::Platform; use blue_build_process_management::drivers::opts::CompressionType; use std::path::PathBuf; let cmd = BuildCommand::builder() .recipe(vec![PathBuf::from("recipe.yml")]) .push(true) .platform(vec![Platform::LinuxAmd64]) .compression_format(CompressionType::Gzip) .retry_push(true) .retry_count(3) .build(); ``` -------------------------------- ### Example Module Initialization Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/recipe.md Demonstrates how to initialize a `Module` struct with specific required fields, including module type, source, and environment variables. This is a practical example for setting up a build module. ```rust use blue_build_recipe::Module; let module = Module { required_fields: Some(ModuleRequiredFields { module_type: "script:latest".parse()?, source: Some("local".to_string()), env: Some(indexmap::indexmap! { "DEBUG" => "1" }), ..Default::default() }), from_file: None, }; ``` -------------------------------- ### Install BlueBuild CLI with Podman Source: https://github.com/blue-build/cli/blob/main/README.md Install the BlueBuild CLI binary to your system using a Podman container. The binary will be placed in /usr/local/bin. ```bash podman run --pull always --rm ghcr.io/blue-build/cli:latest-installer | bash ``` -------------------------------- ### Custom Containerfile Example Source: https://github.com/blue-build/cli/blob/main/_autodocs/recipes-guide.md An example of a custom Containerfile stored in the 'containerfiles/custom/' directory, demonstrating RUN and ENV instructions. ```dockerfile # Custom installation instructions RUN dnf install -y \ custom-package-1 \ custom-package-2 ENV MY_VAR=my_value ``` -------------------------------- ### Driver Initialization Examples Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/drivers.md Demonstrates how to initialize the Driver with default arguments for auto-detection or by explicitly specifying desired drivers using a builder pattern. ```rust use blue_build_process_management::drivers::{Driver, DriverArgs, types::BuildDriverType}; // Auto-detect drivers Driver::init(DriverArgs::default()); // Specify drivers Driver::init(DriverArgs::builder() .build_driver(Some(BuildDriverType::Podman)) .run_driver(Some(RunDriverType::Podman)) .build()); ``` -------------------------------- ### Complete Build Workflow Example Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/drivers.md Demonstrates a complete workflow: initializing drivers, building an image, inspecting its metadata, and signing it. Requires 'miette' for error handling. ```rust use blue_build_process_management::drivers::( Driver, DriverArgs, BuildDriver, InspectDriver, SigningDriver, types::BuildDriverType, opts::{BuildOpts, GetMetadataOpts, SignOpts}, ); use blue_build_utils::container::ImageRef; use std::path::PathBuf; fn build_and_sign_image() -> miette::Result<()> { // Initialize drivers Driver::init(DriverArgs::builder() .build_driver(Some(BuildDriverType::Podman)) .build()); // Build image Driver::build( BuildOpts::builder() .image(ImageRef::new("myimage:v1.0")) .containerfile(PathBuf::from("Containerfile")) .build() )?; // Inspect metadata let metadata = Driver::inspect( GetMetadataOpts::builder() .image("myimage:v1.0") .build() )?; println!("Built image for: {}", metadata.architecture); // Sign image Driver::sign( SignOpts::builder() .image("myimage:v1.0") .build() )?; Ok(()) } ``` -------------------------------- ### Install BlueBuild CLI with Docker Source: https://github.com/blue-build/cli/blob/main/README.md Install the BlueBuild CLI binary to your system using a Docker container. The binary will be placed in /usr/local/bin. ```bash docker run --pull always --rm ghcr.io/blue-build/cli:latest-installer | bash ``` -------------------------------- ### Initialize New Project Command Example Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/commands.md Use this to create a new BlueBuild project. You can specify the directory, CI provider, registry, and image name. If not specified, defaults will be used. ```rust use blue_build::commands::init::InitCommand; use blue_build::CiProvider; use std::path::PathBuf; let mut cmd = InitCommand::builder() .directory(Some(PathBuf::from("./my-project"))) .ci(CiProvider::Github) .registry(Some("docker.io".to_string())) .image_name(Some("my-app".to_string())) .build(); cmd.try_run()?; ``` -------------------------------- ### Install Bash Completions Source: https://github.com/blue-build/cli/blob/main/README.md Installs system-wide bash completions for the bluebuild CLI. Subsequent invocations will support tab autocompletions. ```bash bluebuild completions bash | sudo tee /usr/share/bash-completion/completions/bluebuild ``` -------------------------------- ### Template Rendering Example Source: https://github.com/blue-build/cli/blob/main/_autodocs/README.md Example of using Askama templates for rendering configuration files like Containerfiles. The `#[derive(Template)]` macro is used to define template structures. ```rust #[derive(Template)] #[template(path = "Containerfile.j2")] pub struct ContainerFileTemplate<'a> { ... } ``` -------------------------------- ### Complete Recipe Structure Source: https://github.com/blue-build/cli/blob/main/_autodocs/recipes-guide.md An example of a comprehensive recipe.yml file including optional fields and multi-stage build definitions. ```yaml name: My Image description: A custom image base-image: quay.io/fedora/fedora-silverblue image-version: 40 # Optional fields blue-build-tag: v0.9.35 nushell-version: 0.95.1 cosign-version: 2.2.0 alt-tags: - stable - latest platforms: - linux/amd64 - linux/arm64 labels: org.example.maintainer: john@example.com org.example.version: "1.0" # Multi-stage builds stages: - name: builder from: rust:latest modules: - type: script snippets: - cargo build --release # Main image modules modules: - type: script snippets: - dnf install -y curl ``` -------------------------------- ### Build and Switch Command Example Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/commands.md Use this snippet to build a recipe and then switch to it. Ensure the 'recipe.yml' exists and is correctly formatted. The `reboot` parameter controls whether the system reboots after the update. ```rust use blue_build::commands::switch::SwitchCommand; use std::path::PathBuf; let mut cmd = SwitchCommand::builder() .recipe(PathBuf::from("recipe.yml")) .reboot(true) .build(); cmd.try_run()?; ``` -------------------------------- ### Login Command Example Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/commands.md Logs into an image registry. Provide the server address and optionally username and password. If `password_stdin` is true, the password will be read from standard input. ```rust use blue_build::commands::login::LoginCommand; let mut cmd = LoginCommand::builder() .server("docker.io".to_string()) .username(Some("myuser".to_string())) .password(Some("mypassword".to_string())) .build(); cmd.try_run()?; ``` -------------------------------- ### Install BlueBuild CLI with Cargo Source: https://github.com/blue-build/cli/blob/main/README.md Install the BlueBuild CLI directly from source using Cargo. This method allows for building for your specific environment. ```bash cargo install --locked blue-build ``` -------------------------------- ### Validate Command Example Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/commands.md This example demonstrates how to validate a recipe file. Set `all_errors` to `true` to see all validation issues, or `false` to stop at the first error. The `recipe.yml` file must be accessible. ```rust use blue_build::commands::validate::ValidateCommand; use std::path::PathBuf; let mut cmd = ValidateCommand::builder() .recipe(PathBuf::from("recipe.yml")) .all_errors(false) .build(); cmd.try_run()?; ``` -------------------------------- ### Full Recipe Usage Example Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/recipe.md Demonstrates a typical workflow for parsing a recipe and accessing its basic information like name and base image. Includes conditional printing for platforms. ```rust use blue_build_recipe::Recipe; use std::path::PathBuf; let recipe = Recipe::parse("recipe.yml")?; println!("Building: {}", recipe.name); println!("Base: {}:{}", recipe.base_image, recipe.image_version); if let Some(platforms) = &recipe.platforms { println!("Platforms: {:?}", platforms); } ``` -------------------------------- ### Script Module Snippet Source: https://github.com/blue-build/cli/blob/main/_autodocs/recipes-guide.md An example of a script snippet within a module, used for executing commands like package installation or build steps. ```yaml modules: - type: script snippets: - dnf install -y curl ``` -------------------------------- ### Complete Example Bluebuild Recipe Source: https://github.com/blue-build/cli/blob/main/_autodocs/recipes-guide.md A comprehensive recipe demonstrating various configurations including image metadata, multi-platform support, stages, and module types like script, akmods, containerfile, and copy. ```yaml # Minimal required fields name: ${PROJECT_NAME}-image description: Custom Fedora Silverblue with development tools base-image: quay.io/fedora/fedora-silverblue image-version: 40 # Optional version configuration blue-build-tag: v0.9.35 nushell-version: 0.95.1 cosign-version: 2.2.0 # Multi-platform support platforms: - linux/amd64 - linux/arm64 # Alternative tags alt-tags: - stable - v1.0.0 # Custom labels labels: org.example.maintainer: "dev@example.com" org.example.repo: "https://github.com/example/project" # Multi-stage build stages: - name: builder from: rust:latest modules: - type: script snippets: - rustc --version - cargo build --release # Main image modules modules: # System packages - type: script snippets: - dnf install -y \ git \ podman \ podman-docker \ tmux \ neovim # NVIDIA support (optional) - type: akmods nvidia: proprietary # Custom containerfile - type: containerfile containerfiles: - custom # Copy from stage - type: copy from: builder src: /usr/local/cargo/bin/app dest: /usr/local/bin/app # Copy from files directory - type: copy src: files/etc/app.conf dest: /etc/app.conf # Environment setup - type: script env: EDITOR: nvim snippets: - echo "Development environment ready" ``` -------------------------------- ### Install Packages with Script Module Source: https://github.com/blue-build/cli/blob/main/_autodocs/configuration.md Use the script module to install packages like git and curl. Ensure the necessary environment variables and secrets are configured if required. ```yaml modules: - type: script snippets: - | ``` ```shell dnf install -y \ git \ curl ``` -------------------------------- ### Recipe::should_install_bluebuild Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/recipe.md Determines whether the BlueBuild component should be installed into the image. Returns true unless explicitly disabled. ```APIDOC ## Recipe::should_install_bluebuild ### Description Determines if BlueBuild should be installed in the image (not explicitly disabled). ### Method `should_install_bluebuild() -> bool` ### Response #### Success Response - **bool** - `true` if BlueBuild should be installed, `false` otherwise. ### Request Example ```rust if recipe.should_install_bluebuild() { // Install bluebuild } ``` ``` -------------------------------- ### Install BlueBuild CLI via Nix Profile Source: https://github.com/blue-build/cli/blob/main/README.md Install the BlueBuild CLI globally on non-NixOS systems using the Nix profile command. Replace '*' with a specific tag for version control. ```shell # you can replace "*" with a specific tag nix profile install https://flakehub.com/f/blue-build/cli/*.tar.gz#bluebuild ``` -------------------------------- ### Bug Report Command Example Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/commands.md Generates a GitHub issue with system configuration. Optionally include the path to a recipe file using `recipe_path`. ```rust use blue_build::commands::bug_report::BugReportCommand; let mut cmd = BugReportCommand::builder() .recipe_path(Some("recipe.yml".to_string())) .build(); cmd.try_run()?; ``` -------------------------------- ### External Module Definition Example Source: https://github.com/blue-build/cli/blob/main/_autodocs/recipes-guide.md An example of an external module file that includes script and containerfile modules. ```yaml - type: script snippets: - dnf install -y curl - type: containerfile snippets: - ENV APP_VERSION=1.0 ``` -------------------------------- ### Check if BlueBuild Should Be Installed Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/recipe.md Determines whether BlueBuild should be installed in the image. Returns `true` if not explicitly disabled. ```rust if recipe.should_install_bluebuild() { // Install bluebuild } ``` -------------------------------- ### Recipe File Structure Example Source: https://github.com/blue-build/cli/blob/main/_autodocs/configuration.md Defines the basic structure of a BlueBuild recipe file in YAML format, including name, description, base image, and image version. ```yaml name: My Custom Image description: A custom ostree image base-image: quay.io/fedora/fedora-silverblue image-version: 40 ``` -------------------------------- ### Generate Shell Completions Example Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/commands.md Generates shell completion scripts for various shells. Specify the target shell using the `shell` parameter. ```rust use blue_build::commands::completions::CompletionsCommand; use blue_build::Shell; let mut cmd = CompletionsCommand::builder() .shell(Shell::Bash) .build(); cmd.try_run()?; ``` -------------------------------- ### BlueBuild Tag Configuration Source: https://github.com/blue-build/cli/blob/main/_autodocs/recipes-guide.md Sets the specific BlueBuild version to install within the image. Can also be set to 'main' or 'null'. ```yaml blue-build-tag: v0.9.35 ``` -------------------------------- ### External Stage Definition Example Source: https://github.com/blue-build/cli/blob/main/_autodocs/recipes-guide.md An example of an external stage file that defines a 'compiler' stage using a specific base image and a script module. ```yaml name: compiler from: gcc:latest modules: - type: script snippets: - gcc --version ``` -------------------------------- ### Rebase to Unsigned Blue-Build Image Source: https://github.com/blue-build/cli/blob/main/integration-tests/empty-files-repo/README.md Use this command to rebase an existing atomic Fedora installation to the unsigned blue-build image. This step is necessary to install the proper signing keys and policies. ```bash rpm-ostree rebase ostree-unverified-registry:cli/blue-build/test-empty-files:latest ``` -------------------------------- ### Example Stage Definition in YAML Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/recipe.md Illustrates how to define a build stage using YAML, specifying the stage name, base image, and modules to be executed. This is commonly used in build configuration files. ```yaml stages: - name: builder from: rust:latest modules: - type: script snippets: - cargo build --release ``` -------------------------------- ### Example of Malformed YAML Source: https://github.com/blue-build/cli/blob/main/_autodocs/errors.md Illustrates a malformed YAML structure for a recipe file, highlighting a missing required field. ```yaml # Invalid YAML name: My Image description: Description base-image: quay.io/fedora image-version: # Missing version - error! ``` -------------------------------- ### Prune Command Example Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/commands.md Cleans up build driver caches and images. Use the `all` flag to remove all unused images, `force` to skip confirmation, and `volumes` to prune anonymous volumes. ```rust use blue_build::commands::prune::PruneCommand; let mut cmd = PruneCommand::builder() .all(true) .force(true) .volumes(true) .build(); cmd.try_run()?; ``` -------------------------------- ### Get System Status with BootDriver Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/drivers.md Retrieves the system's current status, checking for the booted image and any ongoing transactions. ```rust use blue_build_process_management::drivers::{Driver, BootDriver}; let status = Driver::status()?; if let Some(booted_image) = status.booted_image() { println!("Booted image: {}", booted_image); } if status.transaction_in_progress() { eprintln!("Transaction in progress"); } ``` -------------------------------- ### Check Command Availability Source: https://github.com/blue-build/cli/blob/main/_autodocs/errors.md Verify that required external commands like 'podman' or 'docker' are installed and accessible in the system's PATH. BlueBuild performs these checks automatically before building. ```bash # Verify required tools are installed which podman which docker # BlueBuild will check automatically bluebuild build recipe.yml ``` -------------------------------- ### Builder Pattern Example Source: https://github.com/blue-build/cli/blob/main/_autodocs/README.md Demonstrates the use of the `bon::Builder` derive macro for ergonomic struct construction. Use this pattern for creating complex structs with multiple optional fields. ```rust BuildCommand::builder() .recipe(vec![...]) .push(true) .build() ``` -------------------------------- ### Local Image Build with Switch Source: https://github.com/blue-build/cli/blob/main/README.md Builds and boots an image locally using an OCI archive tarball. Requires sudo only for moving the archive to /etc/bluebuild. ```bash bluebuild switch recipes/recipe.yml ``` -------------------------------- ### Local Image Build with Switch and Reboot Source: https://github.com/blue-build/cli/blob/main/README.md Builds and boots an image locally and initiates an immediate restart. Requires sudo only for moving the archive to /etc/bluebuild. ```bash bluebuild switch --reboot recipes/recipe.yml ``` -------------------------------- ### Driver Initialization Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/drivers.md Demonstrates how to initialize the `Driver` with default arguments for auto-detection or by specifying individual driver types. ```APIDOC ## Driver Initialization ```rust use blue_build_process_management::drivers::{Driver, DriverArgs, types::BuildDriverType}; // Auto-detect drivers Driver::init(DriverArgs::default()); // Specify drivers Driver::init(DriverArgs::builder() .build_driver(Some(BuildDriverType::Podman)) .run_driver(Some(RunDriverType::Podman)) .build()); ``` ``` -------------------------------- ### InitCommand / NewCommand Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/commands.md Creates a new BlueBuild project with template files. Allows specifying the directory, CI provider, container registry, and image name. ```APIDOC ## InitCommand / NewCommand ### Description Creates a new BlueBuild project with template files. Allows specifying the directory, CI provider, container registry, and image name. ### Constructor Parameters #### Path Parameters - `directory` (Option) - Optional - Project directory to initialize - `ci` (CiProvider) - Optional - CI provider (Github, Gitlab, None) - `registry` (Option) - Optional - Container registry domain - `image_name` (Option) - Optional - Default image name ``` -------------------------------- ### SwitchCommand Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/commands.md Builds and switches the current OS to a new image (requires rpm-ostree). ```APIDOC ## SwitchCommand ### Description Builds and switches the current OS to a new image (requires rpm-ostree). ### Constructor Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters | Parameter | Type | Required | Default | Description | |---|---|---|---|---| | `recipe` | `PathBuf` | Yes | None | Recipe file path. | | `reboot` | `bool` | No | false | Reboot after switching. | | `tempdir` | `Option` | No | None | Temporary directory for build artifacts. | | `skip_validation` | `bool` | No | false | Skip recipe validation. | | `drivers` | `DriverArgs` | No | None | Driver arguments. | ``` -------------------------------- ### BuildCommand Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/commands.md Builds a container image from a recipe file and optionally pushes it to a registry. ```APIDOC ## BuildCommand ### Description Builds a container image from a recipe file and optionally pushes it to a registry. ### Constructor Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters | Parameter | Type | Required | Default | Description | |---|---|---|---|---| | `recipe` | `Option>` | No | None | Recipe files to build. If not provided, defaults to `recipe.yml` in current directory | | `push` | `bool` | No | false | Push the image with all tags. Requires registry, username, password. Set via `BB_BUILD_PUSH` env var | | `platform` | `Vec` | No | empty | Build for specific platforms. Overrides recipe platform settings. Set via `BB_BUILD_PLATFORM` env var | | `compression_format` | `CompressionType` | No | `Gzip` | Compression format for pushed images. Options: Gzip, Zstd | | `retry_push` | `bool` | No | false | Enable retrying to push the image. Set via `BB_BUILD_RETRY_PUSH` env var | | `retry_count` | `u8` | No | 1 | Number of times to retry pushing. Set via `BB_BUILD_RETRY_COUNT` env var | | `archive` | `Option` | No | None | Archive built image to tarfile in specified directory. Set via `BB_BUILD_ARCHIVE` env var | | `registry_namespace` | `Option` | No | None | Registry namespace for image. Set via `BB_REGISTRY_NAMESPACE` env var | ### Example ```rust use blue_build::commands::{BlueBuildCommand, CommandArgs}; use blue_build::commands::build::BuildCommand; use std::path::PathBuf; let mut cmd = BuildCommand::builder() .recipe(vec![PathBuf::from("recipe.yml")]) .push(false) .build(); cmd.try_run()?; ``` ``` -------------------------------- ### Script Module Snippet in Stage Source: https://github.com/blue-build/cli/blob/main/_autodocs/recipes-guide.md An example of a script snippet within a module in a multi-stage build, used for compilation. ```yaml modules: - type: script snippets: - cargo build --release ``` -------------------------------- ### SwitchCommand Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/commands.md Builds a recipe file and optionally reboots the system. It allows specifying a temporary directory and skipping validation. ```APIDOC ## SwitchCommand ### Description Builds a recipe file and optionally reboots the system. It allows specifying a temporary directory and skipping validation. ### Constructor Parameters #### Path Parameters - `recipe` (PathBuf) - Required - Recipe file to build #### Query Parameters - `reboot` (bool) - Optional - Reboot system after update completes - `tempdir` (Option) - Optional - Directory for temporary files during build - `skip_validation` (bool) - Optional - Skip recipe validation ### Request Example ```rust use blue_build::commands::switch::SwitchCommand; use std::path::PathBuf; let mut cmd = SwitchCommand::builder() .recipe(PathBuf::from("recipe.yml")) .reboot(true) .build(); cmd.try_run()?; ``` ``` -------------------------------- ### Copy Module Snippet in Stage Source: https://github.com/blue-build/cli/blob/main/_autodocs/recipes-guide.md An example of a copy module snippet within a stage, used to transfer artifacts from a previous stage. ```yaml modules: - type: copy from: builder src: /app/target/release/app dest: /usr/bin/app ``` -------------------------------- ### Create Distrobox Environment for BlueBuild Source: https://github.com/blue-build/cli/blob/main/README.md Assemble a Distrobox environment for BlueBuild, which includes all necessary tools. This method creates a rootless image. ```bash distrobox assemble create ``` -------------------------------- ### check_command_exists Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/utils.md Verifies if a given command is available in the system's PATH. This is useful for ensuring that necessary external tools are installed before attempting to use them. ```APIDOC ## check_command_exists ### Description Verifies a command is available in PATH. ### Function Signature `pub fn check_command_exists(command: &str) -> Result<()>` ### Parameters - `command` (str) - The name of the command to check. ### Returns - `Result<()>` - Ok(()) if the command exists, otherwise an error. ### Errors - Command not found in PATH. ### Example ```rust use blue_build_utils::check_command_exists; check_command_exists("podman")?; ``` ``` -------------------------------- ### Initialize and Verify Credentials Programmatically Source: https://github.com/blue-build/cli/blob/main/_autodocs/errors.md Initialize credential loading for a specific registry using `Credentials::init` and `CredentialsArgs`. This process attempts to load necessary credentials. ```rust use blue_build_utils::credentials::{Credentials, CredentialsArgs}; Credentials::init( CredentialsArgs::builder() .registry("ghcr.io") .build() ); // Will attempt to load credentials ``` -------------------------------- ### Login with Password from Stdin Source: https://github.com/blue-build/cli/blob/main/_autodocs/configuration.md Provide the password for registry authentication via standard input. ```bash echo "mypass" | bluebuild login --username myuser --password-stdin ghcr.io ``` -------------------------------- ### Get Module Environment Variables Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/recipe.md Retrieves all environment variables defined within a module's configuration. This is useful for setting up the build environment. ```rust module.required_fields.as_ref().and_then(|rf| rf.get_env()) ``` -------------------------------- ### Get Environment Variable Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/utils.md Retrieves the value of an environment variable. Handles errors using miette if the variable is not set or contains invalid UTF-8. ```rust let path = get_env_var("HOME")?; ``` -------------------------------- ### Login with Username and Password Source: https://github.com/blue-build/cli/blob/main/_autodocs/configuration.md Authenticate with a registry using explicit username and password arguments. ```bash bluebuild login --username myuser --password mypass ghcr.io ``` -------------------------------- ### Get Current Timestamp Tag Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/utils.md Retrieves the current date formatted as a timestamp tag in YYYYMMDD format. Useful for versioning or unique identification. ```rust let tag = get_tag_timestamp(); // Returns: "20240429" ``` -------------------------------- ### MaybeVersion Serialization Example Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/recipe.md Illustrates how `MaybeVersion` enum variants are serialized. `null` maps to `MaybeVersion::None`, and a string value maps to `MaybeVersion::VersionOrBranch`. ```text - `null` → `MaybeVersion::None` - String value → `MaybeVersion::VersionOrBranch(String)` ``` -------------------------------- ### Build Bluebuild Container Images Source: https://github.com/blue-build/cli/blob/main/_autodocs/recipes-guide.md Commands for building and pushing container images from recipes. Supports building multiple recipes, specifying platforms, and generating Containerfiles. ```bash # Generate Containerfile bluebuild generate recipe.yml # Build image bluebuild build recipe.yml # Build and push bluebuild build --push recipe.yml # Build multiple recipes bluebuild build recipe1.yml recipe2.yml # Build for specific platforms bluebuild build --platform linux/amd64 --platform linux/arm64 recipe.yml ``` -------------------------------- ### Get Module Type List Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/recipe.md Retrieves a typed list of items from module configuration, such as containerfile snippets. Useful for dynamically accessing configuration details. ```rust if let Some(snippets) = module.required_fields.as_ref() .and_then(|rf| rf.get_module_type_list("containerfile", "snippets")) { // Process snippets } ``` -------------------------------- ### BuildOpts Structure Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/drivers.md Contains options for the build operation, including the target image reference, Containerfile path, secret mounts, and build features. ```rust pub struct BuildOpts { pub image: ImageRef, pub containerfile: PathBuf, pub secrets: SecretMounts, pub build_features: Vec, } ``` -------------------------------- ### Get Base Image Reference Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/recipe.md Retrieves an OCI `Reference` object for the base image specified in the recipe. Errors if the base image format is invalid. ```rust let image_ref = recipe.base_image_ref()?; ``` -------------------------------- ### Build Image Using Specific Driver (Podman) Source: https://github.com/blue-build/cli/blob/main/_autodocs/README.md Initializes and uses a specific build driver (e.g., Podman) to build a container image from a Containerfile. Requires the `blue_build_process_management` crate. ```rust use blue_build_process_management::drivers::{ Driver, DriverArgs, BuildDriver, types::BuildDriverType, opts::BuildOpts, }; // Initialize drivers Driver::init(DriverArgs::builder() .build_driver(Some(BuildDriverType::Podman)) .build()); // Build image Driver::build(BuildOpts::builder() .image("myimage:v1") .containerfile("Containerfile".into()) .build())?; ``` -------------------------------- ### Get Platform Architecture String Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/utils.md Retrieves the architecture string for a given Platform enum variant. Used to map enum variants to their corresponding string representations. ```rust let arch = Platform::LinuxAmd64.arch(); assert_eq!(arch, "amd64"); ``` -------------------------------- ### Get Containerfile List Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/recipe.md Retrieves a list of Containerfile import paths for modules specifically defined as containerfile types. This is used to manage external dependencies for container builds. ```rust module.required_fields.as_ref().and_then(|rf| rf.get_containerfile_list()) ``` -------------------------------- ### Build an Image with BlueBuild CLI Source: https://github.com/blue-build/cli/blob/main/_autodocs/README.md Use this snippet to build a container image using a specified recipe file and push the result to a registry. Requires the `blue_build` crate. ```rust use blue_build::commands::{BlueBuildCommand, BuildCommand}; use std::path::PathBuf; let mut cmd = BuildCommand::builder() .recipe(vec![PathBuf::from("recipe.yml")]) .push(true) .build(); cmd.try_run()?; ``` -------------------------------- ### Build Image with BlueBuild CLI Source: https://github.com/blue-build/cli/blob/main/README.md Execute the 'bluebuild build' command with the path to your recipe.yml to automatically template and build the image using Docker, Podman, or Buildah. ```bash bluebuild build ./recipes/recipe.yml ``` -------------------------------- ### Verify Blue-Build Image Signature Source: https://github.com/blue-build/cli/blob/main/integration-tests/empty-files-repo/README.md Verify the signature of the blue-build image using cosign. Ensure you have the 'cosign.pub' file from the repository. ```bash cosign verify --key cosign.pub cli/blue-build/test-empty-files ``` -------------------------------- ### LoginCommand Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/commands.md Logs into image registry services. Requires the server address and optionally accepts username and password. ```APIDOC ## LoginCommand ### Description Logs into image registry services. Requires the server address and optionally accepts username and password. ### Constructor Parameters #### Path Parameters - `server` (String) - Required - Registry server to login to - `password` (Option) - Optional - Password (cannot use with `password_stdin`) - `password_stdin` (bool) - Optional - Read password from stdin - `username` (Option) - Optional - Username for login ``` -------------------------------- ### InitReadmeTemplate Constructor Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/template.md Demonstrates how to construct and render an InitReadmeTemplate. This is used to generate the initial README.md for a new project. ```rust use blue_build_template::{InitReadmeTemplate, Template}; let template = InitReadmeTemplate::builder() .repo_name("my-image") .registry("ghcr.io") .image_name("my-org/my-image") .build(); let readme = template.render()?; ``` -------------------------------- ### Minimal Recipe Structure Source: https://github.com/blue-build/cli/blob/main/_autodocs/recipes-guide.md Defines the most basic configuration for a container image build using YAML format. ```yaml name: My Image description: A custom container image base-image: quay.io/fedora/fedora-silverblue image-version: 40 modules: [] ``` -------------------------------- ### Template Trait Usage Example Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/template.md Illustrates the general usage of the Template trait, which is implemented for all template structs via the #[derive(Template)] macro. This shows how to build and render a generic template. ```rust use blue_build_template::Template; let template = MyTemplate::builder() .field1("value") .build(); let output = template.render()?; ``` -------------------------------- ### Import Entire Stages File Source: https://github.com/blue-build/cli/blob/main/_autodocs/recipes-guide.md Demonstrates how an external file can contain multiple stage definitions that are all imported. ```yaml # stages/compiler.yml can contain: stages: - name: stage1 from: ... - name: stage2 from: ... ``` -------------------------------- ### Programmatic Build Execution and Error Handling Source: https://github.com/blue-build/cli/blob/main/_autodocs/errors.md Shows how to use the BlueBuild Rust API to build an image and handle potential errors using `miette::Result` and a match statement for reporting. ```rust use blue_build::commands::{BlueBuildCommand, BuildCommand}; use std::path::PathBuf; fn build_image() -> miette::Result<()> { let mut cmd = BuildCommand::builder() .recipe(vec![PathBuf::from("recipe.yml")]) .build(); cmd.try_run()?; } fn main() { match build_image() { Ok(()) => { println!("Build succeeded!"); } Err(e) => { eprintln!("Build failed:"); eprintln!("{e:?}"); // Full diagnostic output std::process::exit(1); } } } ``` -------------------------------- ### InitReadmeTemplate Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/template.md Template for generating a README.md file for new BlueBuild projects. It requires repository name, container registry domain, and image name. ```APIDOC ## InitReadmeTemplate Template for generating a README.md for new BlueBuild projects. ### Fields | Field | Type | Description | |-------|------|-------------| | `repo_name` | `Cow<'a, str>` | GitHub repository name | | `registry` | `Cow<'a, str>` | Container registry domain | | `image_name` | `Cow<'a, str>` | Image name/path | ### Constructor ```rust use blue_build_template::{InitReadmeTemplate, Template}; let template = InitReadmeTemplate::builder() .repo_name("my-image") .registry("ghcr.io") .image_name("my-org/my-image") .build(); let readme = template.render()?; ``` ``` -------------------------------- ### Generate Containerfile with BlueBuild CLI Source: https://github.com/blue-build/cli/blob/main/_autodocs/README.md Generates a Containerfile from a recipe file. Specify the input recipe and the desired output file path. Requires the `blue_build` crate. ```rust use blue_build::commands::{BlueBuildCommand, GenerateCommand}; let mut cmd = GenerateCommand::builder() .recipe(Some(PathBuf::from("recipe.yml"))) .output(Some(PathBuf::from("Containerfile"))) .build(); cmd.try_run()?; ``` -------------------------------- ### Select Build Driver via CLI Source: https://github.com/blue-build/cli/blob/main/_autodocs/configuration.md Specify the build driver to use for the build process using the --build-driver flag. ```bash bluebuild build --build-driver podman recipe.yml ``` -------------------------------- ### Include Containerfile Instructions Source: https://github.com/blue-build/cli/blob/main/_autodocs/recipes-guide.md Uses the 'containerfile' module type to include raw Containerfile instructions, referencing predefined containerfiles or providing inline snippets. ```yaml - type: containerfile containerfiles: - custom - nginx snippets: - | RUN echo "Inline instruction" ``` -------------------------------- ### Default BlueBuild Directory Structure Source: https://github.com/blue-build/cli/blob/main/_autodocs/configuration.md Illustrates the standard directory layout used by BlueBuild for recipes, containerfiles, files, modules, and stages. ```text project-root/ ├── recipes/ # Recipe files (default) │ └── recipe.yml ├── containerfiles/ # Containerfile definitions │ └── custom/ │ └── Containerfile ├── files/ # Files to COPY into image │ └── etc/ │ └── myconfig ├── modules/ # External module files │ └── common.yml └── stages/ # External stage files └── builder.yml ``` -------------------------------- ### Generate Containerfile with BlueBuild CLI Source: https://github.com/blue-build/cli/blob/main/README.md Use the 'bluebuild generate' command to create a Containerfile from your recipe.yml. The output file and recipe file paths must be specified. ```bash bluebuild generate -o ``` -------------------------------- ### Initialize Credentials Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/utils.md Initializes container registry credentials for the current session. Attempts to load credentials from explicit arguments, Docker/Podman helpers, or CI environment variables. Panics if the credentials mutex cannot be locked. ```rust use blue_build_utils::credentials::{Credentials, CredentialsArgs}; Credentials::init( CredentialsArgs::builder() .registry("ghcr.io") .username("myuser") .password("mypass") .build() ); ``` -------------------------------- ### Rebase to Signed Blue-Build Image Source: https://github.com/blue-build/cli/blob/main/integration-tests/empty-files-repo/README.md After rebasing to the unsigned image and rebooting, use this command to rebase to the signed blue-build image. This ensures the image is properly signed and verified. ```bash rpm-ostree rebase ostree-image-signed:docker://cli/blue-build/test-empty-files:latest ``` -------------------------------- ### Build an Image with BuildDriver Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/drivers.md Builds a container image using the specified BuildOpts, including image reference and Containerfile path. ```rust use blue_build_process_management::drivers::{Driver, BuildDriver}; use blue_build_process_management::drivers::opts::BuildOpts; use blue_build_utils::container::ImageRef; use std::path::PathBuf; Driver::build( BuildOpts::builder() .image(ImageRef::new("myimage:latest")) .containerfile(PathBuf::from("Containerfile")) .build() )?; ``` -------------------------------- ### Initialize DriverArgs in Rust Source: https://github.com/blue-build/cli/blob/main/_autodocs/configuration.md Programmatically configure build and run drivers using the DriverArgs builder in Rust. ```rust use blue_build_process_management::drivers::{DriverArgs, types::BuildDriverType}; let args = DriverArgs::builder() .build_driver(Some(BuildDriverType::Podman)) .run_driver(Some(RunDriverType::Podman)) .build(); Driver::init(args); ``` -------------------------------- ### GitlabCiTemplate Constructor Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/template.md Shows how to create and render a GitlabCiTemplate. This is used to generate the .gitlab-ci.yml file for a project. ```rust use blue_build_template::{GitlabCiTemplate, Template}; let template = GitlabCiTemplate::builder() .version("v0.9") .build(); let ci_config = template.render()?; ``` -------------------------------- ### Reference External Configuration Files Source: https://github.com/blue-build/cli/blob/main/_autodocs/configuration.md Modules and stages can be defined in separate YAML files and referenced using the 'from-file' directive. ```yaml modules: - from-file: modules/common.yml stages: - from-file: stages/builder.yml ``` -------------------------------- ### Credentials::init Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/utils.md Initializes container registry credentials for the current session. It attempts to load credentials from explicit arguments, credential helpers, or CI environment variables. ```APIDOC ## Credentials::init ### Description Initializes credentials for the current session. Attempts to load from: 1. Explicit arguments 2. Docker/Podman credential helpers 3. CI environment variables (GitLab CI, GitHub Actions) ### Method `init(args: CredentialsArgs)` ### Parameters * `args` (CredentialsArgs) - Arguments specifying how to initialize credentials. ### Panics If unable to lock the credentials mutex. ### Example ```rust use blue_build_utils::credentials::{Credentials, CredentialsArgs}; Credentials::init( CredentialsArgs::builder() .registry("ghcr.io") .username("myuser") .password("mypass") .build() ); ``` ``` -------------------------------- ### Copy from build context Source: https://github.com/blue-build/cli/blob/main/template/templates/modules/copy/README.md Use this snippet to copy a file from the build context into your image. Omit the 'from' property to enable this behavior. ```yaml modules: - type: copy src: file/to/copy.conf dest: /usr/etc/app/ ``` -------------------------------- ### BugReportCommand Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/commands.md Generates a pre-populated GitHub issue with system configuration. Optionally includes the path to a recipe file. ```APIDOC ## BugReportCommand ### Description Generates a pre-populated GitHub issue with system configuration. Optionally includes the path to a recipe file. ### Constructor Parameters #### Path Parameters - `recipe_path` (Option) - Optional - Path to recipe file to include in report ``` -------------------------------- ### Dockerfile equivalent for copying from context Source: https://github.com/blue-build/cli/blob/main/template/templates/modules/copy/README.md This shows the equivalent Dockerfile instruction generated by the above YAML configuration when copying from the build context. ```dockerfile COPY --linked file/to/copy.conf /usr/etc/app/ ``` -------------------------------- ### Output Logs to a Directory Source: https://github.com/blue-build/cli/blob/main/_autodocs/configuration.md Specify a directory to store build logs using the --log-out flag. ```bash bluebuild build --log-out /tmp/logs recipe.yml ``` -------------------------------- ### Dockerfile equivalent for copying from image Source: https://github.com/blue-build/cli/blob/main/template/templates/modules/copy/README.md This shows the equivalent Dockerfile instruction generated by the above YAML configuration. ```dockerfile COPY --linked --from=docker.io/mikefarah/yq /usr/bin/yq /usr/bin/ ``` -------------------------------- ### Verify Image Signature Source: https://github.com/blue-build/cli/blob/main/_autodocs/configuration.md Use the `bluebuild verify` command to check the signature of a built image. Cosign public keys are loaded from `cosign.pub` in the project root. ```bash # Verify image signature bluebuild verify image:tag ``` -------------------------------- ### PodmanDriver::copy_image_to_root_store Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/drivers.md Copies an image to the root storage using the Podman driver. ```APIDOC ## Copy Image to Root Store (PodmanDriver) ### Description Copies an image to the root storage using the Podman driver. ### Method `PodmanDriver::copy_image_to_root_store` ### Parameters #### Path Parameters - **image** (`&str`) - Required - The reference of the image to copy. ### Response #### Success Response - `()` - Indicates the image was successfully copied. #### Response Example (No specific response body example provided, success is indicated by the absence of an error.) ``` -------------------------------- ### GenerateCommand Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/commands.md Generates a Containerfile from a recipe file without building the image. ```APIDOC ## GenerateCommand ### Description Generates a Containerfile from a recipe file without building the image. ### Constructor Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters | Parameter | Type | Required | Default | Description | |---|---|---|---|---| | `recipe` | `Option` | No | None | Recipe file path. Defaults to `recipe.yml` | | `output` | `Option` | No | None | Output file path. If not set, writes to stdout | | `registry` | `Option` | No | None | Registry domain for image publishing | | `registry_namespace` | `Option` | No | None | Registry namespace for image publishing | | `display_full_recipe` | `bool` | No | false | Display expanded recipe instead of Containerfile | | `syntax_theme` | `Option` | No | None | Syntax highlighting theme. Default: `mocha-dark` | | `platform` | `Option` | No | None | Inspect image on specific platform for version retrieval | | `skip_validation` | `bool` | No | false | Skip recipe validation. Set via `BB_SKIP_VALIDATION` env var | ### Example ```rust use blue_build::commands::generate::GenerateCommand; use std::path::PathBuf; let mut cmd = GenerateCommand::builder() .recipe(Some(PathBuf::from("recipe.yml"))) .output(Some(PathBuf::from("Containerfile"))) .build(); cmd.try_run()?; ``` ``` -------------------------------- ### Define a Build Stage Source: https://github.com/blue-build/cli/blob/main/_autodocs/recipes-guide.md Defines a single build stage with its name, base image, optional platform, custom shell, and required modules. ```yaml - name: stage_name from: base:image:tag platform: linux/amd64 shell: - /bin/bash - -c modules: - type: script ... ``` -------------------------------- ### Add Custom Containerfile Instruction with Snippets Source: https://github.com/blue-build/cli/blob/main/template/templates/modules/containerfile/README.md Use the 'snippets' property to insert individual custom instructions directly into the Containerfile. Each snippet entry creates a new layer in the final image. ```yaml modules: - type: containerfile snippets: - RUN --mount=type=tmpfs,target=/tmp /some/script.sh ``` -------------------------------- ### InitReadmeTemplate Structure Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/template.md Defines the structure for generating a README.md file for new BlueBuild projects. It includes fields for repository name, container registry, and image name. ```rust #[derive(Debug, Clone, Template, Builder)] #[template(path = "init/README.j2", escape = "md")] pub struct InitReadmeTemplate<'a> { pub repo_name: Cow<'a, str>, pub registry: Cow<'a, str>, pub image_name: Cow<'a, str>, } ``` -------------------------------- ### Parse and Validate Recipe Programmatically Source: https://github.com/blue-build/cli/blob/main/_autodocs/errors.md Load and parse a recipe file using the `Recipe::parse` method from `blue_build_recipe`. This allows for programmatic validation of recipe content. ```rust use blue_build_recipe::Recipe; let recipe = Recipe::parse("recipe.yml")?; let image_ref = recipe.base_image_ref()?; ``` -------------------------------- ### InitReadmeTemplate Struct Source: https://github.com/blue-build/cli/blob/main/_autodocs/types.md A template for generating README files for new projects, including repository and image details. ```rust pub struct InitReadmeTemplate<'a> { pub repo_name: Cow<'a, str>, pub registry: Cow<'a, str>, pub image_name: Cow<'a, str>, } ``` -------------------------------- ### Import SigstoreDriver Source: https://github.com/blue-build/cli/blob/main/_autodocs/api-reference/drivers.md Imports the SigstoreDriver for image signing operations using Sigstore. ```rust use blue_build_process_management::drivers::SigstoreDriver; ``` -------------------------------- ### Set Build Driver via Environment Variable Source: https://github.com/blue-build/cli/blob/main/_autodocs/configuration.md Configure the build driver using the BB_BUILD_DRIVER environment variable. ```bash export BB_BUILD_DRIVER=docker bluebuild build recipe.yml ``` -------------------------------- ### Select Signing Driver via CLI Source: https://github.com/blue-build/cli/blob/main/_autodocs/configuration.md Specify the signing driver to use for signing artifacts using the --signing-driver flag. ```bash bluebuild build --signing-driver cosign recipe.yml ``` -------------------------------- ### Copy Files into Image Source: https://github.com/blue-build/cli/blob/main/_autodocs/recipes-guide.md Use the 'copy' module to transfer files from the local 'files/' directory into the container image. Ensure the source path is correct relative to the project root. ```yaml modules: - type: copy src: files/etc/myapp/config.yaml dest: /etc/myapp/config.yaml - type: copy src: files/usr/local/bin/myscript.sh dest: /usr/local/bin/myscript.sh ```