Fix rebuild_and_restart in Docker project containers
CARGO_MANIFEST_DIR is baked at image build time as /app/server, but project containers (Dockerfile.base) don't copy /app — the source is bind-mounted at /workspace instead. Fall back to project_root when the compile-time path doesn't exist. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+18
-4
@@ -107,11 +107,25 @@ pub async fn rebuild_and_restart(
|
||||
|
||||
// 2. Find the workspace root (parent of the server binary's source).
|
||||
// CARGO_MANIFEST_DIR at compile time points to the `server/` crate;
|
||||
// the workspace root is its parent.
|
||||
let manifest_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||
let workspace_root = manifest_dir
|
||||
// the workspace root is its parent. When running inside Docker the
|
||||
// compile-time path (/app) no longer exists — the source is bind-mounted
|
||||
// at the project_root instead, so fall back to that.
|
||||
let compile_time_root = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.parent()
|
||||
.ok_or_else(|| "Cannot determine workspace root from CARGO_MANIFEST_DIR".to_string())?;
|
||||
.filter(|p| p.join("Cargo.toml").exists());
|
||||
let workspace_root = match compile_time_root {
|
||||
Some(p) => p.to_path_buf(),
|
||||
None => {
|
||||
if project_root.join("Cargo.toml").exists() {
|
||||
project_root.to_path_buf()
|
||||
} else {
|
||||
return Err(
|
||||
"Cannot determine workspace root: neither CARGO_MANIFEST_DIR nor project_root contain Cargo.toml".to_string(),
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
let workspace_root = workspace_root.as_path();
|
||||
|
||||
slog!(
|
||||
"[rebuild] Building server from workspace root: {}",
|
||||
|
||||
Reference in New Issue
Block a user