无法在 Docker 中使用具有 git 依赖项的货物补丁
Cannot use cargo patch with a git dependency in Docker
我正在尝试构建一个 docker 容器,其中包含一些在 git 中可用但在 crates.io 中不可用的前沿 crate。此外,那些 git 依赖项以一种有点困难的方式相互依赖,因此我必须使用 Cargo.toml
文件的 patch
部分。此外,该项目位于具有多个子箱的工作区中。
该项目在本地编译完美 cargo build --bin frontend
,但在内部编译失败 docker,出现以下错误:
STEP 13: RUN cargo vendor > .cargo/config
Updating git repository `https://github.com/GiGainfosystems/diesel`
error: failed to sync
Caused by:
failed to load pkg lockfile
Caused by:
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:
object not found - no match for id (0744b7e6e05582bf8fca21c0a5fbba08555abd94); class=Odb (9); code=NotFound (-3)
Error: error building at STEP "RUN cargo vendor > .cargo/config": error while running runtime: exit status 101
据我所知,它似乎无法在 GitHub 存储库中找到具有该提交散列的修订版,但我可以看到它 here,并且它在docker.
这是补丁配置:
[patch.crates-io.diesel]
git = "https://github.com/GiGainfosystems/diesel"
rev = "0744b7e6e05582bf8fca21c0a5fbba08555abd94"
[patch.crates-io.diesel_derives]
git = "https://github.com/GiGainfosystems/diesel"
rev = "0744b7e6e05582bf8fca21c0a5fbba08555abd94"
[patch.crates-io.diesel_migrations]
git = "https://github.com/GiGainfosystems/diesel"
rev = "0744b7e6e05582bf8fca21c0a5fbba08555abd94"
你知道我是否需要向 cargo 提供任何 git 配置才能访问此存储库吗?或者你认为它会发生什么?
作为参考,这是 docker 文件配置:
FROM rustlang/rust:nightly-alpine3.12 AS rust_builder
WORKDIR /root/rustbuild/
RUN apk -U upgrade
RUN apk add libpq
COPY Cargo.lock .
COPY Cargo.toml .
RUN mkdir .cargo
COPY backend ./backend
COPY frontend ./frontend
COPY common ./common
COPY scheduler ./scheduler
COPY cli_utils ./cli_utils
RUN cargo vendor > .cargo/config
RUN cargo build --bin frontend
请注意,我使用 rustlang/rust:nightly-alpine3.12
作为 Rust 容器,因为我需要一个夜间编译器,而 Alpine 出于多种原因,其中包括一个 NodeJS 部分,该部分也将使用相同的高山版。
问题是这个提交所在的分支已经被强制推送到它上面,因此,这个提交被“隐藏”了。如果 Cargo 不属于存储库中的任何分支,则不允许您使用提交。
解决方案是使用作为分支一部分的提交。
我正在尝试构建一个 docker 容器,其中包含一些在 git 中可用但在 crates.io 中不可用的前沿 crate。此外,那些 git 依赖项以一种有点困难的方式相互依赖,因此我必须使用 Cargo.toml
文件的 patch
部分。此外,该项目位于具有多个子箱的工作区中。
该项目在本地编译完美 cargo build --bin frontend
,但在内部编译失败 docker,出现以下错误:
STEP 13: RUN cargo vendor > .cargo/config
Updating git repository `https://github.com/GiGainfosystems/diesel`
error: failed to sync
Caused by:
failed to load pkg lockfile
Caused by:
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:
object not found - no match for id (0744b7e6e05582bf8fca21c0a5fbba08555abd94); class=Odb (9); code=NotFound (-3)
Error: error building at STEP "RUN cargo vendor > .cargo/config": error while running runtime: exit status 101
据我所知,它似乎无法在 GitHub 存储库中找到具有该提交散列的修订版,但我可以看到它 here,并且它在docker.
这是补丁配置:
[patch.crates-io.diesel]
git = "https://github.com/GiGainfosystems/diesel"
rev = "0744b7e6e05582bf8fca21c0a5fbba08555abd94"
[patch.crates-io.diesel_derives]
git = "https://github.com/GiGainfosystems/diesel"
rev = "0744b7e6e05582bf8fca21c0a5fbba08555abd94"
[patch.crates-io.diesel_migrations]
git = "https://github.com/GiGainfosystems/diesel"
rev = "0744b7e6e05582bf8fca21c0a5fbba08555abd94"
你知道我是否需要向 cargo 提供任何 git 配置才能访问此存储库吗?或者你认为它会发生什么?
作为参考,这是 docker 文件配置:
FROM rustlang/rust:nightly-alpine3.12 AS rust_builder
WORKDIR /root/rustbuild/
RUN apk -U upgrade
RUN apk add libpq
COPY Cargo.lock .
COPY Cargo.toml .
RUN mkdir .cargo
COPY backend ./backend
COPY frontend ./frontend
COPY common ./common
COPY scheduler ./scheduler
COPY cli_utils ./cli_utils
RUN cargo vendor > .cargo/config
RUN cargo build --bin frontend
请注意,我使用 rustlang/rust:nightly-alpine3.12
作为 Rust 容器,因为我需要一个夜间编译器,而 Alpine 出于多种原因,其中包括一个 NodeJS 部分,该部分也将使用相同的高山版。
问题是这个提交所在的分支已经被强制推送到它上面,因此,这个提交被“隐藏”了。如果 Cargo 不属于存储库中的任何分支,则不允许您使用提交。
解决方案是使用作为分支一部分的提交。