BuildCommand

Struct BuildCommand 

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

Docker build command builder with fluent API

Fields§

§executor: CommandExecutor

Command executor for extensibility

Implementations§

Source§

impl BuildCommand

Source

pub fn new(context: impl Into<String>) -> Self

Create a new build command for the specified context

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".");
Source

pub fn add_host(self, host: impl Into<String>) -> Self

Add a custom host-to-IP mapping

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .add_host("myhost:192.168.1.100");
Source

pub fn build_arg(self, key: impl Into<String>, value: impl Into<String>) -> Self

Set a build-time variable

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .build_arg("VERSION", "1.0.0")
    .build_arg("DEBUG", "true");
Source

pub fn build_args_map(self, args: HashMap<String, String>) -> Self

Set multiple build-time variables

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

let mut args = HashMap::new();
args.insert("VERSION".to_string(), "1.0.0".to_string());
args.insert("DEBUG".to_string(), "true".to_string());

let build_cmd = BuildCommand::new(".").build_args_map(args);
Source

pub fn cache_from(self, image: impl Into<String>) -> Self

Add an image to consider as cache source

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .cache_from("myapp:cache");
Source

pub fn cgroup_parent(self, parent: impl Into<String>) -> Self

Set the parent cgroup for RUN instructions

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .cgroup_parent("/docker");
Source

pub fn compress(self) -> Self

Compress the build context using gzip

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".").compress();
Source

pub fn cpu_period(self, period: i64) -> Self

Set CPU period limit

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .cpu_period(100000);
Source

pub fn cpu_quota(self, quota: i64) -> Self

Set CPU quota limit

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .cpu_quota(50000);
Source

pub fn cpu_shares(self, shares: i64) -> Self

Set CPU shares (relative weight)

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .cpu_shares(512);
Source

pub fn cpuset_cpus(self, cpus: impl Into<String>) -> Self

Set CPUs in which to allow execution

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .cpuset_cpus("0-3");
Source

pub fn cpuset_mems(self, mems: impl Into<String>) -> Self

Set MEMs in which to allow execution

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .cpuset_mems("0-1");
Source

pub fn disable_content_trust(self) -> Self

Skip image verification

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .disable_content_trust();
Source

pub fn file(self, dockerfile: impl Into<PathBuf>) -> Self

Set the name/path of the Dockerfile

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .file("Dockerfile.prod");
Source

pub fn force_rm(self) -> Self

Always remove intermediate containers

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .force_rm();
Source

pub fn iidfile(self, file: impl Into<PathBuf>) -> Self

Write the image ID to a file

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .iidfile("/tmp/image_id.txt");
Source

pub fn isolation(self, isolation: impl Into<String>) -> Self

Set container isolation technology

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .isolation("hyperv");
Source

pub fn label(self, key: impl Into<String>, value: impl Into<String>) -> Self

Set metadata label for the image

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .label("version", "1.0.0")
    .label("maintainer", "team@example.com");
Source

pub fn labels(self, labels: HashMap<String, String>) -> Self

Set multiple metadata labels

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

let mut labels = HashMap::new();
labels.insert("version".to_string(), "1.0.0".to_string());
labels.insert("env".to_string(), "production".to_string());

let build_cmd = BuildCommand::new(".").labels(labels);
Source

pub fn memory(self, limit: impl Into<String>) -> Self

Set memory limit

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .memory("1g");
Source

pub fn memory_swap(self, limit: impl Into<String>) -> Self

Set memory + swap limit

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .memory_swap("2g");
Source

pub fn network(self, mode: impl Into<String>) -> Self

Set networking mode for RUN instructions

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .network("host");
Source

pub fn no_cache(self) -> Self

Do not use cache when building

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .no_cache();
Source

pub fn platform(self, platform: impl Into<String>) -> Self

Set platform for multi-platform builds

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .platform("linux/amd64");
Source

pub fn pull(self) -> Self

Always attempt to pull newer base images

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .pull();
Source

pub fn quiet(self) -> Self

Suppress build output and print image ID on success

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .quiet();
Source

pub fn no_rm(self) -> Self

Remove intermediate containers after successful build (default: true)

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .no_rm(); // Don't remove intermediate containers
Source

pub fn security_opt(self, opt: impl Into<String>) -> Self

Add a security option

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .security_opt("seccomp=unconfined");
Source

pub fn shm_size(self, size: impl Into<String>) -> Self

Set size of /dev/shm

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .shm_size("128m");
Source

pub fn tag(self, tag: impl Into<String>) -> Self

Add a name and tag for the image

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .tag("myapp:latest")
    .tag("myapp:1.0.0");
Source

pub fn tags(self, tags: Vec<String>) -> Self

Set multiple tags for the image

§Examples
use docker_wrapper::BuildCommand;

let tags = vec!["myapp:latest".to_string(), "myapp:1.0.0".to_string()];
let build_cmd = BuildCommand::new(".").tags(tags);
Source

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

Set the target build stage

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .target("production");
Source

pub fn ulimit(self, limit: impl Into<String>) -> Self

Add a ulimit option

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .ulimit("nofile=65536:65536");
Source

pub fn allow(self, entitlement: impl Into<String>) -> Self

Add an extra privileged entitlement

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .allow("network.host");
Source

pub fn annotation(self, annotation: impl Into<String>) -> Self

Add an annotation to the image

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .annotation("org.opencontainers.image.title=MyApp");
Source

pub fn attest(self, attestation: impl Into<String>) -> Self

Add attestation parameters

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .attest("type=provenance,mode=max");
Source

pub fn build_context(self, context: impl Into<String>) -> Self

Add additional build context

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .build_context("mycontext=../path");
Source

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

Override the configured builder

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .builder("mybuilder");
Source

pub fn cache_to(self, destination: impl Into<String>) -> Self

Add cache export destination

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .cache_to("type=registry,ref=myregistry/cache");
Source

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

Set method for evaluating build

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .call("check");
Source

pub fn check(self) -> Self

Enable check mode (shorthand for “–call=check”)

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .check();
Source

pub fn load(self) -> Self

Enable load mode (shorthand for “–output=type=docker”)

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .load();
Source

pub fn metadata_file(self, file: impl Into<PathBuf>) -> Self

Write build result metadata to file

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .metadata_file("/tmp/metadata.json");
Source

pub fn no_cache_filter(self, stage: impl Into<String>) -> Self

Do not cache specified stage

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .no_cache_filter("build-stage");
Source

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

Set type of progress output

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .progress("plain");
Source

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

Set provenance attestation (shorthand for “–attest=type=provenance”)

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .provenance("mode=max");
Source

pub fn push(self) -> Self

Enable push mode (shorthand for “–output=type=registry”)

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .push();
Source

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

Set SBOM attestation (shorthand for “–attest=type=sbom”)

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .sbom("generator=image");
Source

pub fn secret(self, secret: impl Into<String>) -> Self

Add secret to expose to the build

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .secret("id=mysecret,src=/local/secret");
Source

pub fn ssh(self, ssh: impl Into<String>) -> Self

Add SSH agent socket or keys to expose

§Examples
use docker_wrapper::BuildCommand;

let build_cmd = BuildCommand::new(".")
    .ssh("default");
Source

pub fn get_executor(&self) -> &CommandExecutor

Get a reference to the command executor

Source

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

Get a mutable reference to the command executor

Source§

impl BuildCommand

Source

pub async fn stream<F>(&self, handler: F) -> Result<StreamResult>
where F: FnMut(OutputLine) + Send + 'static,

Run the build command with streaming output

§Examples
use docker_wrapper::BuildCommand;
use docker_wrapper::StreamHandler;

let result = BuildCommand::new(".")
    .tag("myapp:latest")
    .stream(StreamHandler::print())
    .await?;
§Errors

Returns an error if the build fails or encounters an I/O error

Trait Implementations§

Source§

impl Clone for BuildCommand

Source§

fn clone(&self) -> BuildCommand

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 BuildCommand

Source§

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

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

impl Default for BuildCommand

Source§

fn default() -> Self

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

impl DockerCommand for BuildCommand

Source§

type Output = BuildOutput

The output type this command produces
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 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 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)
Source§

impl StreamableCommand for BuildCommand

Source§

fn stream<'life0, 'async_trait, F>( &'life0 self, handler: F, ) -> Pin<Box<dyn Future<Output = Result<StreamResult>> + Send + 'async_trait>>
where F: FnMut(OutputLine) + Send + 'static + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Run the command with streaming output Read more
Source§

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

Run the command with streaming output via a channel Read more

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,