Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify arbitrary container arguments #1315

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions .changes/1315.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"description": "allow appending arbitrary arguments to container runtime",
"type": "added"
}
8 changes: 8 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ impl Environment {
get_possible_image(self, "IMAGE", "IMAGE_TOOLCHAIN", get_target, get_target)
}

fn extra_args(&self, target: &Target) -> (Option<Vec<String>>, Option<Vec<String>>) {
self.get_values_for("EXTRA_ARGS", target, split_to_cloned_by_ws)
}

fn dockerfile(&self, target: &Target) -> (Option<String>, Option<String>) {
self.get_values_for("DOCKERFILE", target, ToOwned::to_owned)
}
Expand Down Expand Up @@ -409,6 +413,10 @@ impl Config {
)
}

pub fn extra_args(&self, target: &Target) -> Result<Option<Vec<String>>> {
self.get_from_ref(target, Environment::extra_args, CrossToml::extra_args)
}

pub fn env_volumes(&self, target: &Target) -> Result<Option<Vec<String>>> {
self.get_from_ref(target, Environment::volumes, CrossToml::env_volumes)
}
Expand Down
16 changes: 16 additions & 0 deletions src/cross_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use std::str::FromStr;
pub struct CrossEnvConfig {
volumes: Option<Vec<String>>,
passthrough: Option<Vec<String>>,
/// Additional arguments to the underlying container engine
extra_args: Option<Vec<String>>,
}

/// Build configuration
Expand Down Expand Up @@ -362,6 +364,14 @@ impl CrossToml {
)
}

pub fn extra_args(&self, target: &Target) -> (Option<&[String]>, Option<&[String]>) {
self.get_ref(
target,
|build| build.env.extra_args.as_deref(),
|t| t.env.extra_args.as_deref(),
)
}

/// Returns the default target to build,
pub fn default_target(&self, target_list: &TargetList) -> Option<Target> {
self.build
Expand Down Expand Up @@ -614,6 +624,7 @@ mod tests {
env: CrossEnvConfig {
volumes: Some(vec![p!("VOL1_ARG"), p!("VOL2_ARG")]),
passthrough: Some(vec![p!("VAR1"), p!("VAR2")]),
extra_args: None,
},
xargo: Some(true),
build_std: None,
Expand Down Expand Up @@ -652,6 +663,7 @@ mod tests {
env: CrossEnvConfig {
passthrough: Some(vec![p!("VAR1"), p!("VAR2")]),
volumes: Some(vec![p!("VOL1_ARG"), p!("VOL2_ARG")]),
extra_args: None,
},
xargo: Some(false),
build_std: Some(true),
Expand All @@ -670,6 +682,7 @@ mod tests {
env: CrossEnvConfig {
passthrough: None,
volumes: None,
extra_args: None,
},
xargo: None,
build_std: None,
Expand Down Expand Up @@ -740,6 +753,7 @@ mod tests {
env: CrossEnvConfig {
passthrough: None,
volumes: Some(vec![p!("VOL")]),
extra_args: None,
},
},
);
Expand All @@ -750,6 +764,7 @@ mod tests {
env: CrossEnvConfig {
volumes: None,
passthrough: Some(vec![]),
extra_args: None,
},
xargo: Some(true),
build_std: None,
Expand Down Expand Up @@ -824,6 +839,7 @@ mod tests {
env: CrossEnvConfig {
passthrough: None,
volumes: None,
extra_args: None,
},
build_std: None,
xargo: Some(true),
Expand Down
1 change: 1 addition & 0 deletions src/docker/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub(crate) fn run(

let mut docker = engine.subcommand("run");
docker.add_userns();
docker.add_extra_args(&options)?;

// Podman on macOS doesn't support selinux labels, see issue #756
#[cfg(target_os = "macos")]
Expand Down
3 changes: 3 additions & 0 deletions src/docker/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,9 @@ pub(crate) fn run(
msg_info,
)
.wrap_err("could not determine mount points")?;
docker
.add_extra_args(&options)
.wrap_err("could not determine additional container arguments")?;

docker
.add_seccomp(engine.kind, target, &paths.metadata)
Expand Down
9 changes: 9 additions & 0 deletions src/docker/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,7 @@ pub(crate) trait DockerCommandExt {
target: &Target,
metadata: &CargoMetadata,
) -> Result<()>;
fn add_extra_args(&mut self, options: &DockerOptions) -> Result<()>;
fn add_mounts(
&mut self,
options: &DockerOptions,
Expand Down Expand Up @@ -1164,6 +1165,14 @@ impl DockerCommandExt for Command {
Ok(())
}

fn add_extra_args(&mut self, options: &DockerOptions) -> Result<()> {
let extra_args = options.config.extra_args(&options.target)?;
if let Some(args) = extra_args {
self.args(args);
}
Ok(())
}

fn add_mounts(
&mut self,
options: &DockerOptions,
Expand Down