wasm-pack icon indicating copy to clipboard operation
wasm-pack copied to clipboard

wasm-pack `.cache` directory creation fails in non-root containers

Open James-Mart opened this issue 1 year ago • 1 comments

🐛 Bug description

When running wasm-pack inside a non-root docker container, it fails with a permissions error (OS Error 13).

$ wasm-pack build rust/psibase/
Error: Permission denied (os error 13)
Caused by: Permission denied (os error 13)

Using strace I identified the reason was because wasm-pack was trying to create a .cache directory at the filesystem root, which a nonroot user is not permitted to do:

$ strace -e trace=file -o strace.txt wasm-pack build rust/psibase/
Error: Permission denied (os error 13)
Caused by: Permission denied (os error 13)

$ cat strace.txt
... // Redacted a bunch of the file for clarity
readlink("/home/james/code/psibase/rust/psibase/Cargo.toml", 0x7ffea2624f70, 1023) = -1 EINVAL (Invalid argument)
statx(AT_FDCWD, "/.cache/.wasm-pack", AT_STATX_SYNC_AS_STAT, STATX_ALL, 0x7ffea2625900) = -1 ENOENT (No such file or directory)
mkdir("/.cache/.wasm-pack", 0777)       = -1 ENOENT (No such file or directory)
mkdir("/.cache", 0777)                  = -1 EACCES (Permission denied)
statx(AT_FDCWD, "/.cache", AT_STATX_SYNC_AS_STAT, STATX_ALL, 0x7ffea2625420) = -1 ENOENT (No such file or directory)
+++ exited with 1 +++

Workaround: If I run my docker container with env variable config: -e WASM_PACK_CACHE=.wasm-pack-cache then the wasm-pack build command succeeds because it creates the cache directory at the working directory from which the wasm-pack command was run.

🤔 Expected Behavior

wasm-pack build should work the same whether my container is either root or non-root.

I suggest that the .cache directory should be created at the current working directory or at the project root, rather than at the filesystem root.

👟 Steps to reproduce

  1. Mount your rust project into a non-root docker container that contains wasm-pack and other build dependencies, something like: docker run --rm -it -v ${WORKSPACE}:${WORKSPACE} -w ${WORKSPACE} --user $(id -u):$(id -g) <DOCKER_IMAGE> /bin/bash
  2. Try wasm-pack build for from inside the container
  3. You should see a failure with a permissions error. If your image has strace installed, run build again using strace and you can see it's because of the .cache directory.
  4. You can even add the -e WASM_PACK_CACHE=.wasm-pack-cache environment variable into your container and try again and see the build succeed.

🌍 Your environment

Running wasm-pack inside a non-root ubuntu 22.04 docker container that containerizes my build environment. wasm-pack version: 0.12.1 rustc version: 1.72.1

James-Mart avatar Sep 25 '23 20:09 James-Mart

Damn, I just got bit by this real bad -- chased the issue around for a few hours before I found this. Infinite thanks for the workaround!

quilan1 avatar Dec 03 '23 01:12 quilan1