Skip to content

Commit

Permalink
Trim environment variable names when adding to Dockerfile (#1166)
Browse files Browse the repository at this point in the history
* trim the name of environment variables

* add test
  • Loading branch information
coffee-cup authored Aug 26, 2024
1 parent 2be073f commit 21325a6
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/nixpacks/builder/docker/dockerfile_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl DockerfileGenerator for BuildPlan {
// Make the variables available at runtime
variables
.iter()
.map(|var| format!("{}=${}", var.0, var.0))
.map(|var| format!("{}=${}", var.0.trim(), var.0.trim()))
.collect::<Vec<_>>()
.join(" ")
)
Expand Down Expand Up @@ -466,6 +466,8 @@ impl DockerfileGenerator for Phase {

#[cfg(test)]
mod tests {
use std::collections::BTreeMap;

use super::*;

#[test]
Expand All @@ -490,6 +492,11 @@ mod tests {
fn test_plan_generation() {
let mut plan = BuildPlan::default();

plan.add_variables(BTreeMap::from([(
"VAR1 ".to_string(),
"value1".to_string(),
)]));

let mut test1 = Phase::new("test1");
test1.add_cmd("echo test1");
test1.add_apt_pkgs(vec!["wget".to_owned()]);
Expand All @@ -512,5 +519,6 @@ mod tests {
assert!(dockerfile.contains("echo test2"));
assert!(dockerfile.contains("apt-get update"));
assert!(dockerfile.contains("wget"));
assert!(dockerfile.contains("ENV VAR1=$VAR1"));
}
}

0 comments on commit 21325a6

Please sign in to comment.