Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions testcontainers/src/core/containers/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub struct ContainerRequest<I: Image> {
pub(crate) privileged: bool,
pub(crate) cap_add: Option<Vec<String>>,
pub(crate) cap_drop: Option<Vec<String>>,
pub(crate) readonly_rootfs: Option<bool>,
pub(crate) security_opt: Option<Vec<String>>,
pub(crate) shm_size: Option<u64>,
pub(crate) cgroupns_mode: Option<CgroupnsMode>,
pub(crate) userns_mode: Option<String>,
Expand Down Expand Up @@ -198,6 +200,14 @@ impl<I: Image> ContainerRequest<I> {
pub fn user(&self) -> Option<&str> {
self.user.as_deref()
}

pub fn security_opt(&self) -> Option<&Vec<String>> {
self.security_opt.as_ref()
}

pub fn readonly_rootfs(&self) -> Option<bool> {
self.readonly_rootfs
}
}

impl<I: Image> From<I> for ContainerRequest<I> {
Expand All @@ -219,6 +229,8 @@ impl<I: Image> From<I> for ContainerRequest<I> {
privileged: false,
cap_add: None,
cap_drop: None,
security_opt: None,
readonly_rootfs: None,
shm_size: None,
cgroupns_mode: None,
userns_mode: None,
Expand Down
22 changes: 22 additions & 0 deletions testcontainers/src/core/image/image_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ pub trait ImageExt<I: Image> {

/// Sets the user that commands are run as inside the container.
fn with_user(self, user: impl Into<String>) -> ContainerRequest<I>;

/// Sets the container's root filesystem to be mounted as read-only
fn with_readonly_rootfs(self, readonly_rootfs: Option<bool>) -> ContainerRequest<I>;

/// Sets security options for the container
fn with_security_opt(self, security_opt: Option<Vec<String>>) -> ContainerRequest<I>;
}

/// Implements the [`ImageExt`] trait for the every type that can be converted into a [`ContainerRequest`].
Expand Down Expand Up @@ -391,4 +397,20 @@ impl<RI: Into<ContainerRequest<I>>, I: Image> ImageExt<I> for RI {
..container_req
}
}

fn with_readonly_rootfs(self, readonly_rootfs: Option<bool>) -> ContainerRequest<I> {
let container_req = self.into();
ContainerRequest {
readonly_rootfs,
..container_req
}
}

fn with_security_opt(self, security_opt: Option<Vec<String>>) -> ContainerRequest<I> {
let container_req = self.into();
ContainerRequest {
security_opt,
..container_req
}
}
}
2 changes: 2 additions & 0 deletions testcontainers/src/runners/async_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ where
userns_mode: container_req.userns_mode().map(|v| v.to_string()),
cap_add: container_req.cap_add().cloned(),
cap_drop: container_req.cap_drop().cloned(),
readonly_rootfs: container_req.readonly_rootfs(),
security_opt: container_req.security_opt().cloned(),
..Default::default()
}),
working_dir: container_req.working_dir().map(|dir| dir.to_string()),
Expand Down