Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions testcontainers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ reqwest = { version = "0.13.1", features = [
temp-dir = "0.2"
tempfile = "3.20"
tokio = { version = "1", features = ["macros"] }
rand = "0.10.0"
6 changes: 6 additions & 0 deletions testcontainers/src/core/containers/async_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub(crate) mod raw;
/// [drop_impl]: struct.ContainerAsync.html#impl-Drop
pub struct ContainerAsync<I: Image> {
pub(super) raw: raw::RawContainer,
pub no_drop: bool,
image: ContainerRequest<I>,
network: Option<Arc<Network>>,
dropped: bool,
Expand Down Expand Up @@ -92,6 +93,7 @@ where
host_port_exposure,
#[cfg(feature = "reusable-containers")]
reuse,
no_drop: false,
};

if !log_consumers.is_empty() {
Expand Down Expand Up @@ -246,6 +248,10 @@ where
I: Image,
{
fn drop(&mut self) {
if self.no_drop {
return;
}

#[cfg(feature = "reusable-containers")]
{
use crate::ReuseDirective::{Always, CurrentSession};
Expand Down
7 changes: 7 additions & 0 deletions testcontainers/src/core/containers/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ pub struct ContainerRequest<I: Image> {
#[cfg(feature = "device-requests")]
pub(crate) device_requests: Option<Vec<DeviceRequest>>,
pub(crate) open_stdin: Option<bool>,
pub(crate) reaper: bool,
pub(crate) reaper_ttl_seconds: u32,
}

/// Represents a port mapping between a host's external port and the internal port of a container.
Expand Down Expand Up @@ -260,6 +262,9 @@ impl<I: Image> ContainerRequest<I> {

impl<I: Image> From<I> for ContainerRequest<I> {
fn from(image: I) -> Self {
let reaper = image.reaper();
let reaper_ttl_seconds = image.reaper_ttl_seconds();

Self {
image,
overridden_cmd: Vec::new(),
Expand Down Expand Up @@ -298,6 +303,8 @@ impl<I: Image> From<I> for ContainerRequest<I> {
#[cfg(feature = "device-requests")]
device_requests: None,
open_stdin: None,
reaper: reaper,
reaper_ttl_seconds: reaper_ttl_seconds,
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions testcontainers/src/core/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ where
fn exec_before_ready(&self, cs: ContainerState) -> Result<Vec<ExecCommand>> {
Ok(Default::default())
}

fn reaper(&self) -> bool {
false
}

fn reaper_ttl_seconds(&self) -> u32 {
60
}
}

#[derive(Debug)]
Expand Down
1 change: 1 addition & 0 deletions testcontainers/src/images/docker_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ impl Image for DockerCli {
// keep container alive until dropped
["-c", "sleep infinity"]
}

}
22 changes: 22 additions & 0 deletions testcontainers/src/images/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub struct GenericImage {
wait_for: Vec<WaitFor>,
entrypoint: Option<String>,
exposed_ports: Vec<ContainerPort>,
reaper: bool,
reaper_ttl_seconds: u32,
}

impl GenericImage {
Expand All @@ -59,6 +61,8 @@ impl GenericImage {
wait_for: Vec::new(),
entrypoint: None,
exposed_ports: Vec::new(),
reaper: false,
reaper_ttl_seconds: 60, // default *_TIMEOUT for ryuk
}
}

Expand All @@ -67,6 +71,16 @@ impl GenericImage {
self
}

pub fn with_reaper_ttl_seconds(mut self, ttl_seconds: u32) -> Self {
self.reaper_ttl_seconds = ttl_seconds;
self
}

pub fn with_reaper(mut self, reaper: bool) -> Self {
self.reaper = reaper;
self
}

pub fn with_entrypoint(mut self, entrypoint: &str) -> Self {
self.entrypoint = Some(entrypoint.to_string());
self
Expand Down Expand Up @@ -98,6 +112,14 @@ impl Image for GenericImage {
fn expose_ports(&self) -> &[ContainerPort] {
&self.exposed_ports
}

fn reaper(&self) -> bool {
self.reaper
}

fn reaper_ttl_seconds(&self) -> u32 {
self.reaper_ttl_seconds
}
}

#[cfg(test)]
Expand Down
1 change: 1 addition & 0 deletions testcontainers/src/images/socat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ impl Image for Socat {
.join(" & "),
]
}

}
Loading