diff --git a/crates/dev_container/src/devcontainer_manifest.rs b/crates/dev_container/src/devcontainer_manifest.rs index 0c38538657d..2927bd58484 100644 --- a/crates/dev_container/src/devcontainer_manifest.rs +++ b/crates/dev_container/src/devcontainer_manifest.rs @@ -1922,6 +1922,7 @@ RUN sed -i -E 's/((^|\s)PATH=)([^\$]*)$/\1\${PATH:-\3}/g' /etc/profile || true let docker_cli = self.docker_client.docker_cli(); let mut command = Command::new(&docker_cli); + command.current_dir(&self.local_project_directory); command.arg("run"); @@ -3198,6 +3199,12 @@ mod test { let docker_run_command = docker_run_command.expect("ok"); assert_eq!(docker_run_command.get_program(), "docker"); + assert_eq!( + docker_run_command.get_current_dir(), + Some(Path::new(TEST_PROJECT_PATH)), + "docker run must execute with cwd set to the project directory so \ + relative paths in `runArgs` (e.g. `--env-file .devcontainer/.env`) resolve correctly" + ); let expected_config_file_label = PathBuf::from(TEST_PROJECT_PATH) .join(".devcontainer") .join("devcontainer.json"); diff --git a/crates/util/src/command.rs b/crates/util/src/command.rs index a131d3c15b9..265e1c47747 100644 --- a/crates/util/src/command.rs +++ b/crates/util/src/command.rs @@ -72,6 +72,10 @@ impl Command { self.0.get_args() } + pub fn get_current_dir(&self) -> Option<&Path> { + self.0.get_current_dir() + } + pub fn env(&mut self, key: impl AsRef, val: impl AsRef) -> &mut Self { self.0.env(key, val); self diff --git a/crates/util/src/command/darwin.rs b/crates/util/src/command/darwin.rs index c9d5bc40aed..2a99a0a51f3 100644 --- a/crates/util/src/command/darwin.rs +++ b/crates/util/src/command/darwin.rs @@ -225,6 +225,10 @@ impl Command { pub fn get_program(&self) -> &OsStr { self.program.as_os_str() } + + pub fn get_current_dir(&self) -> Option<&Path> { + self.current_dir.as_deref() + } } #[derive(Debug)]