Skip to content

Commit

Permalink
Require dockerfile to be specified relative to cargo workspace root (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
Emilgardis authored Oct 15, 2024
2 parents d3e2f33 + 06c890f commit 4090bec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .changes/1574.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "fixed",
"description": "`dockerfile` path is now relative to cargo workspace root"
}
8 changes: 3 additions & 5 deletions src/docker/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ impl<'a> Dockerfile<'a> {
}

let path = match self {
Dockerfile::File { path, .. } => PathBuf::from(path),
Dockerfile::File { path, .. } => {
paths.metadata.workspace_root.join(PathBuf::from(path))
}
Dockerfile::Custom { content, .. } => {
let target_dir = paths
.metadata
Expand All @@ -147,10 +149,6 @@ impl<'a> Dockerfile<'a> {
}
}

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

if let Some(build_opts) = options.config.build_opts() {
Expand Down

0 comments on commit 4090bec

Please sign in to comment.