Cargo: Patches with git dependencies don't work in containers

Created on 8 Jul 2020  路  2Comments  路  Source: rust-lang/cargo

Problem
When building a cargo project in a workspace that has a [patch] section in the Cargo.toml file, with a Git dependency retrieved by revision, build fails saying that it didn't find the commit.

The commit exists and it's public, as it can be seen here. Moreover, if you run cargo build --bin backend outside of the container, everything works as expected.

Steps

  1. Clone this example repository.
  2. Run docker build . or podman build .
  3. Note that the output shows the following error:
STEP 8: RUN cargo build --bin backend
    Updating git repository `https://github.com/GiGainfosystems/diesel`
error: failed to resolve patches for `https://github.com/rust-lang/crates.io-index`

Caused by:
  failed to load source for dependency `diesel`

Caused by:
  Unable to update https://github.com/GiGainfosystems/diesel?rev=0744b7e6e05582bf8fca21c0a5fbba08555abd94#0744b7e6

Caused by:
  revspec '0744b7e6e05582bf8fca21c0a5fbba08555abd94' not found; class=Reference (4); code=NotFound (-3)

Possible Solution(s)

Notes
I am not 100% sure if this is a bug in cargo, a bug in the official containers, or a lack of understanding from my side.

If you run cargo build --bin backend outside of the container, it will work perfectly, but you will need libpq installed.

This has been proven to happen in any offical container, also in alpine containers and in nightly images here.

Output of cargo version:

cargo 1.44.1 (88ba85757 2020-06-11)


C-bug

All 2 comments

If you look at that commit in Github, it claims that it does not exist in any branch in the repository: https://github.com/GiGainfosystems/diesel/commit/0744b7e6e05582bf8fca21c0a5fbba08555abd94.

It could be that it works outside of the container since you already have the commit cached, but the containerized build doesn't and can't pull it from the repo.

Agreed looks like this is a git configuration error rather than an issue with Cargo, so closing.

Was this page helpful?
0 / 5 - 0 ratings