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

Allow key-value pairs in config volumes. #750

Merged
merged 1 commit into from
Jun 3, 2022
Merged
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
34 changes: 19 additions & 15 deletions src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ pub fn register(target: &Target, verbose: bool) -> Result<()> {
.run(verbose)
}

fn validate_env_var(var: &str) -> Result<(&str, Option<&str>)> {
let (key, value) = match var.split_once('=') {
Some((key, value)) => (key, Some(value)),
_ => (var, None),
};

if key == "CROSS_RUNNER" {
bail!("CROSS_RUNNER environment variable name is reserved and cannot be pass through");
}

Ok((key, value))
}

#[allow(clippy::too_many_arguments)] // TODO: refactor
pub fn run(
target: &Target,
Expand Down Expand Up @@ -114,19 +127,6 @@ pub fn run(

let mut docker = docker_command("run")?;

let validate_env_var = |var: &str| -> Result<()> {
let var = match var.split_once('=') {
Some((key, _)) => key,
_ => var,
};

if var == "CROSS_RUNNER" {
bail!("CROSS_RUNNER environment variable name is reserved and cannot be pass through");
}

Ok(())
};

for ref var in config.env_passthrough(target)? {
validate_env_var(var)?;

Expand All @@ -136,9 +136,13 @@ pub fn run(
}
let mut env_volumes = false;
for ref var in config.env_volumes(target)? {
validate_env_var(var)?;
let (var, value) = validate_env_var(var)?;
let value = match value {
Some(v) => Ok(v.to_string()),
None => env::var(var),
};

if let Ok(val) = env::var(var) {
if let Ok(val) = value {
let host_path: PathBuf;
let mount_path: PathBuf;

Expand Down