Skip to content
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

Docker build gives exit code: 137 with cargo #618

Open
MohamedAli-M opened this issue Mar 21, 2023 · 2 comments
Open

Docker build gives exit code: 137 with cargo #618

MohamedAli-M opened this issue Mar 21, 2023 · 2 comments

Comments

@MohamedAli-M
Copy link
Contributor

MohamedAli-M commented Mar 21, 2023

While building the Docker image (following the docker tutorial), an error occurred when running the command RUN cargo build, with an exit code of 137.

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.

image

@MohamedAli-M
Copy link
Contributor Author

At "Updating crates.io index"

On the machine (locally), it is incrementally updating the registry repo. On a docker image however, it is doing that from scratch. It is the act of pulling the registry that might be causing things to blow up.

The issue was solved by using the Cargo nightly sparse-registry feature. The feature will allow Cargo to access the crates.io index over HTTP, rather than git. It can provide a significant performance improvement.

Adding these commands in the Dockerfile was the solution :

RUN apt-get install curl -y RUN curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly -y ENV PATH=/root/.cargo/bin:$PATH

These commands installed curl and then used it to download and run the Rustup installer script, which installed Rust with the nightly toolchain. Finally, the PATH environment variable was updated to include the Rust executable path.

RUN rustup toolchain install nightly
RUN cargo +nightly install -Z sparse-registry --debug cargo-ament-build
RUN cargo build

This time, the build completed successfully without any errors.

Part of the solution was found here rust-lang/cargo#10781. In particular, the comments by epage and lexicalunit provided helpful guidance.

@greenscientist
Copy link
Collaborator

Using the nightly might too unstable for our need, but we could consider using the sparse protocol to download the crate by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants