-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cargo build during a docker build takes forever and blows up memory on "Updating crates.io index" #10781
Comments
Note that I also see a bajillion log lines in the build log saying:
|
I have seen this same behavior on arm64 docker image builds using docker buildx and qemu. Not sure what a valid workaround is. |
Yep, definitely seems like a very similar, if not the same issue! In my case I'm wondering if a workaround could be pre-building/vendoring the cargo library and just copying it into the docker image 🤷🏻♀️ |
On your machine, it is incrementally updating the registry repo. On a docker image, it is doing that from scratch. If it is the act of pulling the registry that is causing things to blow up, you might be interested in https://blog.rust-lang.org/2022/06/22/sparse-registry-testing.html which causes us to only download exactly what is needed. |
@epage You are an absolute gem! Tested and working flawlessly. Diff: -RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
+RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly
RUN git clone https://github.com/twilight-rs/http-proxy.git
RUN cd http-proxy \
&& . $HOME/.cargo/env \
- && cargo +nightly build --release
+ && cargo +nightly build --release -Z sparse-registry I also noticed an improvement in the build process by doing: DOCKER_BUILDKIT=0 docker buildx build --ulimit nofile=1024000:1024000 --platform linux/amd64 . |
I do still get the jemalloc warnings and the actual build process is pretty slow (maybe because of these warnings?)... but at least that's totally resolved the memory explosion issue. |
Thanks for the great new feature! I'll try out that sparse nightly update and see if it resolves my issue as well! |
Sorry I'm a bit new to the nightly builds of cargo, but when I try the docker commands below, I get a /bin/sh: 1: cargo: not found error
What thing am I obviously missing and thank you for helping a newbie. |
Nvm I was able to figure it out via the following:
Note this feature is awesome and has fixed a long-standing problem with cargo on arm64 for me! I'll leave some feedback in the forum thread, but I hope to see this get mainline @epage ! Sorry for hi-jacking the issue here @lexicalunit ! |
I'm a bit confused about the setup, can you clarify a few things? You mention running on macOS? I'm guessing this is an aarch64 (apple silicon) machine? |
I'm deploying to a |
If you are just using docker to build something that is then deployed elsewhere, then I might suggest using an aarch64 linux image, and cross-compiling to x86_64. If I understand how Docker on macOS M1 works, that will not run under emulation. I believe it shouldn't be too difficult to install all the requisite cross-toolchain stuff in Debian, though I'm not sure. |
@ehuss I don't understand what you mean. I'm already selecting the platform with I also tested this suggestion and it seems to have no effect. |
I'm not familiar with Docker on M1, but I would guess that using |
So on macOS the Docker VM is already running $ nc -U ~/Library/Containers/com.docker.docker/Data/debug-shell.sock .
/ # uname -a
Linux docker-desktop 5.10.76-linuxkit #1 SMP PREEMPT Mon Nov 8 11:22:26 UTC 2021 aarch64 Linux The only want I know of to specify the platform in the It's just that I'm running the I wouldn't want to do |
My suggestion is to use the I believe this is a duplicate of #10583, so closing in favor of that. |
I believe the
Unless you mean that I should pass it thru to the
|
@lexicalunit you solved this? The build takes extremely long. |
@Jasperav I think the big issue I was encountering was that cross-compilation from ARM to x64 was just slower than building for x64 on an x64 system. I now just do my docker builds and deployments from a x64 mac and it's much faster. |
@lexicalunit thanks for the headsup, I get all kind of different errors while cross compiling :( well guess I need to get my windows system for deployments |
In case someone stumbles on this issue and is not satisfied with the suggestion of using nightly, this answer solved it for me: https://users.rust-lang.org/t/cargo-uses-too-much-memory-being-run-in-qemu/76531/2 ➡️ Add |
@simgt Just make sure if you are using a base image without git, the command will fail: => ERROR [builder 9/11] RUN cargo build --config net.git-fetch-with-cli=true --target x86_64-unknown-linux-musl --release 2.3s
------
> [builder 9/11] RUN cargo build --config net.git-fetch-with-cli=true --target x86_64-unknown-linux-musl --release:
#0 1.806 Updating crates.io index
#0 2.291 error: Unable to update registry `crates-io`
#0 2.291
#0 2.291 Caused by:
#0 2.291 failed to fetch `https://github.com/rust-lang/crates.io-index`
#0 2.291
#0 2.291 Caused by:
#0 2.291 could not execute process `git fetch --force --update-head-ok 'https://github.com/rust-lang/crates.io-index' '+HEAD:refs/remotes/origin/HEAD'` (never executed)
#0 2.291
#0 2.291 Caused by:
#0 2.292 No such file or directory (os error 2)
------
WARNING: No output specified for docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load
Dockerfile:22
--------------------
20 | # This is a dummy build to get the dependencies cached.
21 | #
22 | >>> RUN cargo build --config net.git-fetch-with-cli=true --target x86_64-unknown-linux-musl --release
23 |
24 | # Now copy in the rest of the sources
--------------------
error: failed to solve: process "/bin/sh -c cargo build --config net.git-fetch-with-cli=true --target x86_64-unknown-linux-musl --release" did not complete successfully: exit code: 101
$ docker run -ti rustlang/rust:nightly-buster-slim git --version
Unable to find image 'rustlang/rust:nightly-buster-slim' locally
nightly-buster-slim: Pulling from rustlang/rust
ebcd4e3db076: Pull complete
c63476507cda: Pull complete
Digest: sha256:609c65daad3c69f9a37717e45d794e2eab99ad488dc5d492b8fc85c97c1df531
Status: Downloaded newer image for rustlang/rust:nightly-buster-slim
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "git": executable file not found in $PATH: unknown.
ERRO[0044] error waiting for container: context canceled Fix in this case
RUN apt-get update && apt-get install -y git
RUN cargo build --config net.git-fetch-with-cli=true --target x86_64-unknown-linux-musl --release |
As of Rust 1.68, stable toolchain supports sparse protocol, so you don't need to use nightly. https://blog.rust-lang.org/inside-rust/2023/01/30/cargo-sparse-protocol.html |
Problem
In my
Dockerfile
I have this:And just this causes building the image to blow up on the
cargo build --release
command. It looks like the process gets stuck on the "Updating crates.io index" step forever until the docker container runs out of memory and kills it with exit code 137.I had to up my docker's vm to 20 GB just to get the command to execute properly. Building this library outside of docker works just fine, takes up almost no memory, and executes in mere seconds.
Steps
docker buildx build --platform linux/amd64 .
Possible Solution(s)
There must be some kind of networking configuration or bypass that can be done here? Why on earth does this work fine on my local machine, but blow up inside of docker build?
Notes
No response
Version
The text was updated successfully, but these errors were encountered: