Skip to content

Commit 4090bec

Browse files
authored
Require dockerfile to be specified relative to cargo workspace root (#1574)
The docs say that [the dockerfile should be specified relative to Cargo.toml](https://github.com/cross-rs/cross/blob/main/docs/config_file.md#targettargetdockerfile), but actually it is specified [relative to current working directory](https://github.com/cross-rs/cross/blob/main/src/docker/custom.rs#L150-L153). This is confusing. This PR makes it so that dockerfiles are always relative to workspace root.
2 parents d3e2f33 + 06c890f commit 4090bec

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

.changes/1574.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "fixed",
3+
"description": "`dockerfile` path is now relative to cargo workspace root"
4+
}

src/docker/custom.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ impl<'a> Dockerfile<'a> {
120120
}
121121

122122
let path = match self {
123-
Dockerfile::File { path, .. } => PathBuf::from(path),
123+
Dockerfile::File { path, .. } => {
124+
paths.metadata.workspace_root.join(PathBuf::from(path))
125+
}
124126
Dockerfile::Custom { content, .. } => {
125127
let target_dir = paths
126128
.metadata
@@ -147,10 +149,6 @@ impl<'a> Dockerfile<'a> {
147149
}
148150
}
149151

150-
// note that this is always relative to the PWD: if we have
151-
// `$workspace_root/Dockerfile`, then running a build
152-
// `PWD=$workspace_root/src/ cross build` would require
153-
// the Dockerfile path to be specified as `../Dockerfile`.
154152
docker_build.args(["--file".into(), path]);
155153

156154
if let Some(build_opts) = options.config.build_opts() {

0 commit comments

Comments
 (0)