Skip to content

Commit

Permalink
Merge #750
Browse files Browse the repository at this point in the history
750: Allow key-value pairs in config volumes. r=otavio a=Alexhuszagh

Allow volumes to use the `["VOL=/path/to/volume"]' syntax as well, so additional mount points can be defined by value in the `env.volumes` section of the config file. Allows the following syntax:

```toml
[build.env]
volumes = ["VOL=/path/to/mount/"]
```

Not implementing it with the `env.passthrough` was a complete oversight on my part, related to #743 and #748.

Co-authored-by: Alex Huszagh <ahuszagh@gmail.com>
  • Loading branch information
bors[bot] and Alexhuszagh authored Jun 3, 2022
2 parents ee4df2b + 7359534 commit c72b1d7
Showing 1 changed file with 19 additions and 15 deletions.
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

0 comments on commit c72b1d7

Please sign in to comment.