BakeCommand

Struct BakeCommand 

Source
pub struct BakeCommand {
    pub executor: CommandExecutor,
    /* private fields */
}
Expand description

Docker Bake Command Builder

Implements the docker bake command for building from configuration files like docker-compose.yml, docker-bake.hcl, or custom bake definitions.

§Docker Bake Overview

The bake command allows you to build multiple targets defined in configuration files, supporting advanced features like:

  • Multi-platform builds
  • Build matrix configurations
  • Shared build contexts
  • Variable substitution
  • Target dependencies

§Supported File Formats

  • docker-compose.yml - Docker Compose service definitions
  • docker-bake.hcl - HCL (HashiCorp Configuration Language) format
  • docker-bake.json - JSON format
  • Custom build definition files

§Examples

use docker_wrapper::BakeCommand;
use docker_wrapper::DockerCommand;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Build all targets from docker-compose.yml
    let output = BakeCommand::new()
        .file("docker-compose.yml")
        .execute()
        .await?;

    println!("Bake success: {}", output.success);
    Ok(())
}

Fields§

§executor: CommandExecutor

Command executor for handling raw arguments and execution

Implementations§

Source§

impl BakeCommand

Source

pub fn new() -> Self

Create a new BakeCommand instance

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new();
Source

pub fn target<S: Into<String>>(self, target: S) -> Self

Add a target to build

Multiple targets can be specified. If no targets are specified, all targets defined in the bake file will be built.

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .target("web")
    .target("api")
    .target("worker");
Source

pub fn targets<I, S>(self, targets: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Add multiple targets to build

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .targets(vec!["web", "api", "worker"]);
Source

pub fn file<S: Into<String>>(self, file: S) -> Self

Add a build definition file

Supports docker-compose.yml, docker-bake.hcl, docker-bake.json, and custom build definition files.

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .file("docker-compose.yml")
    .file("custom-bake.hcl");
Source

pub fn files<I, S>(self, files: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Add multiple build definition files

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .files(vec!["docker-compose.yml", "override.yml"]);
Source

pub fn allow<S: Into<String>>(self, resource: S) -> Self

Allow build to access specified resources

Grants permission to access host resources during build.

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .allow("network.host")
    .allow("security.insecure");
Source

pub fn builder<S: Into<String>>(self, builder: S) -> Self

Override the configured builder instance

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .builder("mybuilder");
Source

pub fn call<S: Into<String>>(self, method: S) -> Self

Set method for evaluating build

Valid values: “build”, “check”, “outline”, “targets”

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .call("check"); // Validate build configuration
Source

pub fn check(self) -> Self

Enable check mode (shorthand for –call=check)

Validates the build configuration without executing the build.

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .check();
Source

pub fn debug(self) -> Self

Enable debug logging

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .debug();
Source

pub fn list<S: Into<String>>(self, list_type: S) -> Self

List targets or variables

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .list("targets"); // List all available targets
Source

pub fn load(self) -> Self

Load images to Docker daemon (shorthand for –set=*.output=type=docker)

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .load();
Source

pub fn metadata_file<S: Into<String>>(self, file: S) -> Self

Write build result metadata to a file

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .metadata_file("build-metadata.json");
Source

pub fn no_cache(self) -> Self

Do not use cache when building images

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .no_cache();
Source

pub fn print(self) -> Self

Print the options without building

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .print();
Source

pub fn progress<S: Into<String>>(self, progress_type: S) -> Self

Set type of progress output

Valid values: “auto”, “quiet”, “plain”, “tty”, “rawjson”

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .progress("plain");
Source

pub fn provenance<S: Into<String>>(self, provenance: S) -> Self

Set provenance attestation (shorthand for –set=*.attest=type=provenance)

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .provenance("mode=max");
Source

pub fn pull(self) -> Self

Always attempt to pull all referenced images

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .pull();
Source

pub fn push(self) -> Self

Push images to registry (shorthand for –set=*.output=type=registry)

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .push();
Source

pub fn sbom<S: Into<String>>(self, sbom: S) -> Self

Set SBOM attestation (shorthand for –set=*.attest=type=sbom)

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .sbom("generator=docker/buildkit");
Source

pub fn set<K: Into<String>, V: Into<String>>(self, key: K, value: V) -> Self

Override target value (e.g., “targetpattern.key=value”)

This allows overriding any target configuration at build time.

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .set("web.platform", "linux/amd64,linux/arm64")
    .set("*.output", "type=registry");
Source

pub fn set_values<I, K, V>(self, values: I) -> Self
where I: IntoIterator<Item = (K, V)>, K: Into<String>, V: Into<String>,

Add multiple target value overrides

§Examples
use std::collections::HashMap;
use docker_wrapper::BakeCommand;

let mut overrides = HashMap::new();
overrides.insert("web.platform".to_string(), "linux/amd64".to_string());
overrides.insert("api.platform".to_string(), "linux/arm64".to_string());

let bake_cmd = BakeCommand::new()
    .set_values(overrides);
Source

pub fn target_count(&self) -> usize

Get the number of targets

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .target("web")
    .target("api");

assert_eq!(bake_cmd.target_count(), 2);
Source

pub fn get_targets(&self) -> &[String]

Get the list of targets

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .target("web")
    .target("api");

let targets = bake_cmd.get_targets();
assert_eq!(targets, &["web", "api"]);
Source

pub fn get_files(&self) -> &[String]

Get the list of build definition files

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new()
    .file("docker-compose.yml");

let files = bake_cmd.get_files();
assert_eq!(files, &["docker-compose.yml"]);
Source

pub fn is_push_enabled(&self) -> bool

Check if push mode is enabled

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new().push();
assert!(bake_cmd.is_push_enabled());
Source

pub fn is_load_enabled(&self) -> bool

Check if load mode is enabled

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new().load();
assert!(bake_cmd.is_load_enabled());
Source

pub fn is_dry_run(&self) -> bool

Check if dry-run mode is enabled (print without building)

§Examples
use docker_wrapper::BakeCommand;

let bake_cmd = BakeCommand::new().print();
assert!(bake_cmd.is_dry_run());

Trait Implementations§

Source§

impl Clone for BakeCommand

Source§

fn clone(&self) -> BakeCommand

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BakeCommand

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BakeCommand

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl DockerCommand for BakeCommand

Source§

type Output = CommandOutput

The output type this command produces
Source§

fn build_command_args(&self) -> Vec<String>

Build the complete command arguments including subcommands
Source§

fn execute<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Self::Output>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute the command and return the typed output
Source§

fn get_executor(&self) -> &CommandExecutor

Get the command executor for extensibility
Source§

fn get_executor_mut(&mut self) -> &mut CommandExecutor

Get mutable command executor for extensibility
Source§

fn execute_command<'life0, 'async_trait>( &'life0 self, command_args: Vec<String>, ) -> Pin<Box<dyn Future<Output = Result<CommandOutput>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

Helper method to execute the command with proper error handling
Source§

fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self

Add a raw argument to the command (escape hatch)
Source§

fn args<I, S>(&mut self, args: I) -> &mut Self
where I: IntoIterator<Item = S>, S: AsRef<OsStr>,

Add multiple raw arguments to the command (escape hatch)
Source§

fn flag(&mut self, flag: &str) -> &mut Self

Add a flag option (e.g., –detach, –rm)
Source§

fn option(&mut self, key: &str, value: &str) -> &mut Self

Add a key-value option (e.g., –name value, –env key=value)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,