AGhost-7/docker-dev

Cargo issues in rust-dev

aig787 opened this issue · 8 comments

Looks like cargo isn't added to the path and the registry has the wrong permissions in the rust container. Probably just need to move this line to the end of the build script and update path?
https://github.com/AGhost-7/docker-dev/blob/master/images/rust-dev/base/rust-install.sh#L7

❯ docker run --rm -v ~/Code/ring:/home/aghost-7/ring -v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock -e SSH_AUTH_SOCK="/run/host-services/ssh-auth.sock" -it aghost7/rust-dev:focal-stable /bin/bash
$ cd ring/
$ cargo build
bash: cargo: command not found
$ ~/.cargo/bin/c
cargo          cargo-clippy   cargo-fmt      cargo-miri     cargo-watch    clippy-driver
$ ~/.cargo/bin/cargo build
error: failed to get `untrusted` as a dependency of package `ring v0.16.15 (/home/aghost-7/ring)`

Caused by:
  failed to create directory `/home/aghost-7/.cargo/registry/index/github.com-1ecc6299db9ec823`

Caused by:
  Permission denied (os error 13)
$ ls -la ~/.cargo
total 36
drwxr-xr-x 1 aghost-7 aghost-7 4096 Oct 23 15:54 .
drwxr-xr-x 1 aghost-7 aghost-7 4096 Oct 24 21:29 ..
drwxr-xr-x 2 aghost-7 aghost-7 4096 Oct 23 16:05 bin
-rw-r--r-- 1 aghost-7 aghost-7  465 Oct 23 16:05 .crates2.json
-rw-r--r-- 1 aghost-7 aghost-7   99 Oct 23 16:05 .crates.toml
-rw-r--r-- 1 aghost-7 aghost-7   37 Oct 23 15:53 env
-rw-r--r-- 1 aghost-7 aghost-7    0 Oct 23 15:53 .package-cache
drwxr-xr-x 2 root     root     4096 Oct 23 15:51 registry

If you aren't using tmux, it would be better to pass in --login to bash. I wasn't able to reproduce your issue with volume permissions.

Strange that you aren't able to reproduce, this is what I get in tmux

docker run --rm -v ~/Code/ring:/home/aghost-7/ring -v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock -e SSH_AUTH_SOCK="/run/host-services/ssh-auth.sock" -it aghost7/rust-dev:focal-stable tmux new

$ cargo build
error: failed to get `untrusted` as a dependency of package `ring v0.16.15 (/home/aghost-7/ring)`

Caused by:
  failed to create directory `/home/aghost-7/.cargo/registry/index/github.com-1ecc6299db9ec823`

Caused by:
  Permission denied (os error 13)
$ ls -la ~/.cargo
total 36
drwxr-xr-x 1 aghost-7 aghost-7 4096 Oct 23 15:54 .
drwxr-xr-x 1 aghost-7 aghost-7 4096 Oct 26 16:47 ..
drwxr-xr-x 2 aghost-7 aghost-7 4096 Oct 23 16:05 bin
-rw-r--r-- 1 aghost-7 aghost-7  465 Oct 23 16:05 .crates2.json
-rw-r--r-- 1 aghost-7 aghost-7   99 Oct 23 16:05 .crates.toml
-rw-r--r-- 1 aghost-7 aghost-7   37 Oct 23 15:53 env
-rw-r--r-- 1 aghost-7 aghost-7    0 Oct 23 15:53 .package-cache
drwxr-xr-x 2 root     root     4096 Oct 23 15:51 registry

Maybe this will fix it?

docker volume create rust_registry
docker run --rm -v rust_registry:/rust_registry aghost7/rust-dev:focal-stable sudo chown -R 1000:1000 /rust_registry

docker run --rm -v ~/Code/ring:/home/aghost-7/ring -v rust_registry:/home/aghost-7/.cargo/registry -v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock -e SSH_AUTH_SOCK="/run/host-services/ssh-auth.sock" -it aghost7/rust-dev:focal-stable tmux new

Same results there. I wonder if this is a MacOS specific bug? The permissions are getting reset each time.

❯ docker run --rm -v ~/Code/ring:/home/aghost-7/ring -v rust_registry:/home/aghost-7/.cargo/registry -v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock -e SSH_AUTH_SOCK="/run/host-services/ssh-auth.sock" -it aghost7/rust-dev:focal-stable /bin/bash --login
 $ ls -la .cargo
total 28
drwxr-xr-x 1 aghost-7 aghost-7 4096 Oct 23 15:54 .
drwxr-xr-x 1 aghost-7 aghost-7 4096 Oct 26 17:57 ..
drwxr-xr-x 2 aghost-7 aghost-7 4096 Oct 23 16:05 bin
-rw-r--r-- 1 aghost-7 aghost-7  465 Oct 23 16:05 .crates2.json
-rw-r--r-- 1 aghost-7 aghost-7   99 Oct 23 16:05 .crates.toml
-rw-r--r-- 1 aghost-7 aghost-7   37 Oct 23 15:53 env
-rw-r--r-- 1 aghost-7 aghost-7    0 Oct 23 15:53 .package-cache
drwxr-xr-x 2 root     root     4096 Oct 23 15:51 registry
 $ sudo chown aghost-7: .cargo/registry/
 $ ls -la .cargo/
total 28
drwxr-xr-x 1 aghost-7 aghost-7 4096 Oct 23 15:54 .
drwxr-xr-x 1 aghost-7 aghost-7 4096 Oct 26 17:57 ..
drwxr-xr-x 2 aghost-7 aghost-7 4096 Oct 23 16:05 bin
-rw-r--r-- 1 aghost-7 aghost-7  465 Oct 23 16:05 .crates2.json
-rw-r--r-- 1 aghost-7 aghost-7   99 Oct 23 16:05 .crates.toml
-rw-r--r-- 1 aghost-7 aghost-7   37 Oct 23 15:53 env
-rw-r--r-- 1 aghost-7 aghost-7    0 Oct 23 15:53 .package-cache
drwxr-xr-x 2 aghost-7 aghost-7 4096 Oct 23 15:51 registry
 $ exit
logout
❯ docker run --rm -v ~/Code/ring:/home/aghost-7/ring -v rust_registry:/home/aghost-7/.cargo/registry -v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock -e SSH_AUTH_SOCK="/run/host-services/ssh-auth.sock" -it aghost7/rust-dev:focal-stable /bin/bash --login
 $ ls -la .cargo
total 28
drwxr-xr-x 1 aghost-7 aghost-7 4096 Oct 23 15:54 .
drwxr-xr-x 1 aghost-7 aghost-7 4096 Oct 26 17:58 ..
drwxr-xr-x 2 aghost-7 aghost-7 4096 Oct 23 16:05 bin
-rw-r--r-- 1 aghost-7 aghost-7  465 Oct 23 16:05 .crates2.json
-rw-r--r-- 1 aghost-7 aghost-7   99 Oct 23 16:05 .crates.toml
-rw-r--r-- 1 aghost-7 aghost-7   37 Oct 23 15:53 env
-rw-r--r-- 1 aghost-7 aghost-7    0 Oct 23 15:53 .package-cache
drwxr-xr-x 2 root     root     4096 Oct 23 15:51 registry

This seems to be the heart of the issue https://docs.docker.com/engine/reference/builder/.

Changing the volume from within the Dockerfile: If any build steps change the data within the volume after it has been declared, those changes will be discarded.

I modified the Dockerfile a little bit

 COPY rust-install.sh /usr/local/bin/rust-install.sh

 RUN mkdir -p $HOME/.cargo/registry
 RUN sudo chown -R $USER:$USER $HOME/.cargo/registry

 # For some reason rustup doesn't work well so I'll only place a volume for the
 # cargo registry.
 VOLUME $HOME/.cargo/registry

And the permissions are now correct in the container.

Is the chown necessary?

Nope, looks like the mkdir combined with the USER above takes care of it

Are you only using the rust image? If not, is this an issue with the other images?