pub struct ContainerConfigBuilder { /* private fields */ }Expand description
Flexible container configuration builder
This struct provides a builder pattern for configuring Docker containers with explicit configuration options instead of hardcoded values.
Currently supports the minimal set of features needed by the provisioned container:
- Image name and tag validation
- Container name customization
- Exposed ports (with validation)
- Wait conditions (with reasonable limits)
Implementations§
Source§impl ContainerConfigBuilder
impl ContainerConfigBuilder
Sourcepub fn new(image: impl Into<String>) -> Self
pub fn new(image: impl Into<String>) -> Self
Create a new container configuration builder with the specified image
§Arguments
image- Docker image name with optional tag (e.g., “redis:7”, “app:latest”)
§Example
use torrust_tracker_deployer_lib::testing::e2e::containers::config_builder::ContainerConfigBuilder;
let builder = ContainerConfigBuilder::new("torrust-provisioned-instance:latest");Sourcepub fn with_exposed_port(self, port: u16) -> Self
pub fn with_exposed_port(self, port: u16) -> Self
Add an exposed port to the container configuration
§Arguments
port- Port number to expose (as u16)
§Example
use torrust_tracker_deployer_lib::testing::e2e::containers::config_builder::ContainerConfigBuilder;
let builder = ContainerConfigBuilder::new("torrust-provisioned-instance:latest")
.with_exposed_port(22)
.with_exposed_port(80);Sourcepub fn with_container_name(self, name: impl Into<String>) -> Self
pub fn with_container_name(self, name: impl Into<String>) -> Self
Set a custom container name for the running container
§Arguments
name- Container name to use when starting the container
§Example
use torrust_tracker_deployer_lib::testing::e2e::containers::config_builder::ContainerConfigBuilder;
let builder = ContainerConfigBuilder::new("torrust-provisioned-instance:latest")
.with_container_name("my-custom-container-name");Sourcepub fn with_wait_condition(self, condition: WaitFor) -> Self
pub fn with_wait_condition(self, condition: WaitFor) -> Self
Add a wait condition to determine when the container is ready
§Arguments
condition- Wait condition (e.g., message on stdout, HTTP endpoint, etc.)
§Example
use torrust_tracker_deployer_lib::testing::e2e::containers::config_builder::ContainerConfigBuilder;
use testcontainers::core::WaitFor;
let builder = ContainerConfigBuilder::new("torrust-provisioned-instance:latest")
.with_wait_condition(WaitFor::message_on_stdout("sshd entered RUNNING state"));Sourcepub fn build(self) -> Result<GenericImage>
pub fn build(self) -> Result<GenericImage>
Build the final GenericImage with all configured options and validation
This method creates a GenericImage with all the configuration options
that were specified using the builder methods. It also validates the
configuration to catch common issues early.
§Returns
A configured GenericImage ready to be used with testcontainers
§Errors
Returns an error if:
- Image name is empty or invalid
- Any port number is invalid (e.g., 0)
- Too many wait conditions (performance concern)
§Example
use torrust_tracker_deployer_lib::testing::e2e::containers::config_builder::ContainerConfigBuilder;
use testcontainers::core::WaitFor;
let image = ContainerConfigBuilder::new("torrust-provisioned-instance:latest")
.with_exposed_port(22)
.with_wait_condition(WaitFor::message_on_stdout("sshd entered RUNNING state"))
.build()?;Sourcepub fn image_name(&self) -> &str
pub fn image_name(&self) -> &str
Sourcepub fn exposed_ports(&self) -> &[u16]
pub fn exposed_ports(&self) -> &[u16]
Sourcepub fn wait_conditions_count(&self) -> usize
pub fn wait_conditions_count(&self) -> usize
Trait Implementations§
Source§impl Clone for ContainerConfigBuilder
impl Clone for ContainerConfigBuilder
Auto Trait Implementations§
impl Freeze for ContainerConfigBuilder
impl RefUnwindSafe for ContainerConfigBuilder
impl Send for ContainerConfigBuilder
impl Sync for ContainerConfigBuilder
impl Unpin for ContainerConfigBuilder
impl UnsafeUnpin for ContainerConfigBuilder
impl UnwindSafe for ContainerConfigBuilder
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