pub struct ContainerImageBuilder { /* private fields */ }Expand description
Builder for constructing and building container images
This builder follows the standard Rust builder pattern, allowing method chaining to configure container image build parameters.
§Required Values
The following values must be provided before calling build():
- Image name: Must be set with
with_name() - Dockerfile path: Must be set with
with_dockerfile()
§Default Values
- Tag: “latest”
- Build context: “.” (current directory)
- Build timeout: 300 seconds
Implementations§
Source§impl ContainerImageBuilder
impl ContainerImageBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new container image builder with default configuration
§Examples
use torrust_tracker_deployer_lib::testing::e2e::containers::ContainerImageBuilder;
let builder = ContainerImageBuilder::new();Sourcepub fn with_dockerfile(self, path: PathBuf) -> Self
pub fn with_dockerfile(self, path: PathBuf) -> Self
Sourcepub fn with_context(self, path: PathBuf) -> Self
pub fn with_context(self, path: PathBuf) -> Self
Sourcepub fn with_build_timeout(self, timeout: Duration) -> Self
pub fn with_build_timeout(self, timeout: Duration) -> Self
Set the build timeout duration
§Arguments
timeout- Maximum time to wait for build completion
§Examples
use torrust_tracker_deployer_lib::testing::e2e::containers::ContainerImageBuilder;
use std::time::Duration;
let builder = ContainerImageBuilder::new()
.with_build_timeout(Duration::from_secs(600));Sourcepub fn build(&self) -> Result<()>
pub fn build(&self) -> Result<()>
Build the container image using the configured parameters
This method executes the docker build command with the configured
parameters. It provides detailed error information if the build fails.
§Errors
Returns an error if:
- Image name was not provided (use
with_name()) - Dockerfile path was not provided (use
with_dockerfile()) - Docker command cannot be executed (e.g., Docker not installed)
- Docker build process fails (non-zero exit code)
§Examples
use torrust_tracker_deployer_lib::testing::e2e::containers::ContainerImageBuilder;
use std::path::PathBuf;
let builder = ContainerImageBuilder::new()
.with_name("my-image")
.with_dockerfile(PathBuf::from("Dockerfile"));
builder.build()?;Sourcepub fn image_tag(&self) -> String
pub fn image_tag(&self) -> String
Get the full image tag (name:tag) that will be used for the build
§Panics
Panics if image name has not been set. Use with_name() first.
§Examples
use torrust_tracker_deployer_lib::testing::e2e::containers::ContainerImageBuilder;
let builder = ContainerImageBuilder::new()
.with_name("my-app")
.with_tag("v1.0");
assert_eq!(builder.image_tag(), "my-app:v1.0");Sourcepub fn image_name(&self) -> Option<&str>
pub fn image_name(&self) -> Option<&str>
Get the image name if it has been set
Sourcepub fn dockerfile_path(&self) -> Option<&PathBuf>
pub fn dockerfile_path(&self) -> Option<&PathBuf>
Get the dockerfile path if it has been set
Sourcepub fn context_path(&self) -> &PathBuf
pub fn context_path(&self) -> &PathBuf
Get the build context path
Sourcepub fn build_timeout(&self) -> Duration
pub fn build_timeout(&self) -> Duration
Get the build timeout
Trait Implementations§
Source§impl Clone for ContainerImageBuilder
impl Clone for ContainerImageBuilder
Source§impl Debug for ContainerImageBuilder
impl Debug for ContainerImageBuilder
Auto Trait Implementations§
impl Freeze for ContainerImageBuilder
impl RefUnwindSafe for ContainerImageBuilder
impl Send for ContainerImageBuilder
impl Sync for ContainerImageBuilder
impl Unpin for ContainerImageBuilder
impl UnsafeUnpin for ContainerImageBuilder
impl UnwindSafe for ContainerImageBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request