emk / rust-musl-builder

Docker images for compiling static Rust binaries using musl-libc and musl-gcc, with static versions of useful C libraries. Supports openssl and diesel crates.
Apache License 2.0
1.54k stars 193 forks source link

container not saving binary if using cache volumes #80

Closed sentient-abanchich closed 5 years ago

sentient-abanchich commented 5 years ago

I am guessing I'm just doing something wrong, but I found if I cache builds using this command (I'm using fish but I've also tried in bash and zsh:

alias rust-musl-builder='docker run --rm -it
-v (pwd):/home/rust/src
-v cargo-git:/home/rust/.cargo/git
-v cargo-registry:/home/rust/.cargo/registry
-v target:/home/rust/src/target
ekidd/rust-musl-builder:nightly-2019-07-08'

it doesn't save anything in target on my host after the first run. If I run rust-musl-builder without any command and ls ./target I can see the binary is created there.

Even when I rm the binary inside the container and rebuild using rust-musl-builder cargo build --release, it only appears in the container but not on my host computer (macOS).

If I set the alias to remove the caching volumes:

alias rust-musl-builder='docker run --rm -it
                                             -v (pwd):/home/rust/src
                                             ekidd/rust-musl-builder:nightly-2019-07-08'

it always works correctly and the binary does appear on my host.

One thing I've noticed is that the target directory WILL appear in my host's project directory after I try to build, but it will be empty; it's only the content of target which are not showing up.

Any thoughts on what the issue could be?

Thank you

emk commented 5 years ago

it doesn't save anything in target on my host after the first run. If I run rust-musl-builder without any command and ls ./target I can see the binary is created there.

This is actually deliberate. :-) But the reasons aren't obvious.

To cache builds, we need to keep the target directory on your Docker host. If you want to extract the binaries, see examples/build-release for example docker cp shell commands showing how to extract the binaries.

It would be good to explain this in the README.

sentient-abanchich commented 5 years ago

Awesome, thank you so much!