Skip to content

Commit

Permalink
Merge branch 'main' into feature/cgroupns-mode-userns-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
DDtKey authored Apr 29, 2024
2 parents d2c79d6 + 4c0472e commit fbedebc
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 30 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file.

## [0.16.4] - 2024-04-29
### Details
#### Bug Fixes
- Properly expose mapped ports ([#610](https://github.com/testcontainers/testcontainers-rs/pull/610))

#### Features
- Introduce `properties-config` cargo feature ([#608](https://github.com/testcontainers/testcontainers-rs/pull/608))
- Support docker auth configuration for image pulling ([#609](https://github.com/testcontainers/testcontainers-rs/pull/609))
## [0.16.3] - 2024-04-27
### Details
#### Bug Fixes
Expand Down
4 changes: 2 additions & 2 deletions testcontainers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "testcontainers"
version = "0.16.3"
version = "0.16.4"
categories = ["development-tools::testing"]
readme = "README.md"
authors.workspace = true
Expand All @@ -26,7 +26,7 @@ futures = "0.3"
log = "0.4"
parse-display = "0.9.0"
serde = { version = "1", features = ["derive"] }
serde-java-properties = { version = "0.1.1", optional = true }
serde-java-properties = { version = "0.2.0", optional = true }
serde_json = "1"
serde_with = "3.7.0"
signal-hook = { version = "0.3", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion testcontainers/src/core/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl Client {
.into_iter()
.filter_map(|ipam_cfg| ipam_cfg.gateway)
.next()
.unwrap_or_else(|| "localhost".to_string()),
.unwrap_or_else(|| "127.0.0.1".to_string()),
_ => unreachable!("docker host is already validated in the config"),
}
}
Expand Down
11 changes: 5 additions & 6 deletions testcontainers/src/core/containers/async_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ pub struct ContainerAsync<I: Image> {
id: String,
image: RunnableImage<I>,
pub(super) docker_client: Arc<Client>,
#[cfg_attr(not(feature = "blocking"), allow(dead_code))]
pub(super) network: Option<Arc<Network>>,
network: Option<Arc<Network>>,
dropped: bool,
}

Expand Down Expand Up @@ -165,11 +164,11 @@ where

/// Returns the host ip address of docker container
pub async fn get_host_ip_address(&self) -> IpAddr {
self.docker_client
.docker_host_ip_address()
.await
let host_ip = self.docker_client.docker_host_ip_address().await;

host_ip
.parse()
.expect("invalid host IP")
.unwrap_or_else(|e| panic!("invalid host ip: '{host_ip}', error: {e}"))
}

pub async fn exec(&self, cmd: ExecCommand) {
Expand Down
1 change: 0 additions & 1 deletion testcontainers/src/core/containers/sync_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ impl<I: Image> Drop for Container<I> {
fn drop(&mut self) {
if let Some(mut active) = self.inner.take() {
active.runtime.block_on(async {
drop(active.async_impl.network.take());
match active.async_impl.docker_client.config.command() {
env::Command::Remove => active.async_impl.rm().await,
env::Command::Keep => {}
Expand Down
37 changes: 19 additions & 18 deletions testcontainers/src/runners/async_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,28 @@ where
.map(|network| network.starts_with("container:"))
.unwrap_or(false);

// exposed ports
// expose ports
if !is_container_networked {
config.exposed_ports = Some(
runnable_image
.expose_ports()
.into_iter()
.map(|p| (format!("{p}/tcp"), HashMap::new()))
.collect(),
);
let mapped_ports = runnable_image
.ports()
.as_ref()
.map(|ports| ports.iter().map(|p| p.internal).collect::<Vec<_>>())
.unwrap_or_default();

let ports_to_expose = runnable_image
.expose_ports()
.iter()
.copied()
.chain(mapped_ports)
.map(|p| (format!("{p}/tcp"), HashMap::new()))
.collect();

// exposed ports of the image + mapped ports
config.exposed_ports = Some(ports_to_expose);
}

// ports
if runnable_image.ports().is_some() || !runnable_image.expose_ports().is_empty() {
if runnable_image.ports().is_some() {
let empty: Vec<_> = Vec::new();
let bindings = runnable_image
.ports()
Expand All @@ -151,13 +160,7 @@ where
host_port: Some(p.local.to_string()),
}]),
)
})
.chain(
runnable_image
.expose_ports()
.into_iter()
.map(|p| (format!("{}/tcp", p), Some(vec![PortBinding::default()]))),
);
});

config.host_config = config.host_config.map(|mut host_config| {
host_config.port_bindings = Some(bindings.collect());
Expand All @@ -170,8 +173,6 @@ where
});
}

// extra hosts

let args = runnable_image
.args()
.clone()
Expand Down
4 changes: 2 additions & 2 deletions testcontainers/src/runners/sync_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ mod tests {
fn sync_run_command_should_expose_only_requested_ports() {
let image = GenericImage::new("hello-world", "latest");
let container = RunnableImage::from(image)
.with_mapped_port((123, 456))
.with_mapped_port((555, 888))
.with_mapped_port((124, 456))
.with_mapped_port((556, 888))
.start();

let container_details = inspect(container.id());
Expand Down

0 comments on commit fbedebc

Please sign in to comment.