Skip to content

Commit

Permalink
Use CMD exec form with an ENTRYPOINT (#487)
Browse files Browse the repository at this point in the history
* use CMD exec form with an entrypoint

* lint
  • Loading branch information
coffee-cup authored Sep 1, 2022
1 parent 93b3105 commit 6d29f84
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/nixpacks/builder/docker/dockerfile_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ impl DockerfileGenerator for BuildPlan {

let dockerfile = formatdoc! {"
FROM {base_image}
ENTRYPOINT [\"/bin/bash\", \"-l\", \"-c\"]
WORKDIR {APP_DIR}
{assets_copy_cmd}
{dockerfile_phases_str}
Expand Down Expand Up @@ -228,9 +231,7 @@ impl DockerfileGenerator for StartPhase {
_output: &OutputDir,
) -> Result<String> {
let start_cmd = match &self.cmd {
Some(cmd) => {
format!("CMD {}", cmd)
}
Some(cmd) => utils::get_exec_command(cmd),
None => "".to_string(),
};

Expand Down
24 changes: 24 additions & 0 deletions src/nixpacks/builder/docker/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ pub fn get_copy_from_command(from: &str, files: &[String], app_dir: &str) -> Str
}
}

pub fn get_exec_command(command: &str) -> String {
let params = command.replace('\"', "\\\"");

format!("CMD [\"{}\"]", params)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -99,4 +105,22 @@ mod tests {
get_copy_from_command(from, &files, app_dir)
);
}

#[test]
fn test_get_exec_cmd() {
assert_eq!(
"CMD [\"command1\"]".to_string(),
get_exec_command("command1")
);

assert_eq!(
"CMD [\"command1 command2\"]".to_string(),
get_exec_command("command1 command2")
);

assert_eq!(
"CMD [\"command1 command2 -l \\\"asdf\\\"\"]".to_string(),
get_exec_command("command1 command2 -l \"asdf\"")
);
}
}

0 comments on commit 6d29f84

Please sign in to comment.