trzecieu / emscripten-docker

Docker image with Emscripten to compile ASM.js and WebAssembly
MIT License
97 stars 29 forks source link

In docs, suggest running docker with current user id rather than emscripten user #41

Closed maxbrunsfeld closed 5 years ago

maxbrunsfeld commented 5 years ago

Hi, this is a very useful image. Thanks for creating it!

It worked for me on my Mac, but when I tried to run it on Travis CI, I got a permission error as soon as emcc tried to write to the file system:

command: "docker" "run" "--rm" "--volume" "/home/travis/build/tree-sitter/tree-sitter/test/fixtures/grammars/javascript:/src" "--user" "emscripten" "trzeci/emscripten-slim" "emcc" "-o" "tree-sitter-javascript.wasm" "-Os" "-s" "WASM=1" "-s" "SIDE_MODULE=1" "-s" "EXPORTED_FUNCTIONS=[\"_tree_sitter_javascript\"]" "-I" "src"

emcc command failed - Unable to find image 'trzeci/emscripten-slim:latest' locally
latest: Pulling from trzeci/emscripten-slim
e79bb959ec00: Pulling fs layer
67c164866f5d: Pulling fs layer
f3b772b4e21c: Pulling fs layer
f3b772b4e21c: Verifying Checksum
f3b772b4e21c: Download complete
e79bb959ec00: Download complete
e79bb959ec00: Pull complete
67c164866f5d: Verifying Checksum
67c164866f5d: Download complete
67c164866f5d: Pull complete
f3b772b4e21c: Pull complete
Digest: sha256:9fcec955b3174a78b0422e6dde4c9e58e9a68e5646102b11b1ecb0f358987571
Status: Downloaded newer image for trzeci/emscripten-slim:latest
Traceback (most recent call last):
  File "/emsdk_portable/sdk/emcc.py", line 3308, in <module>
    sys.exit(run(sys.argv))
  File "/emsdk_portable/sdk/emcc.py", line 2066, in run
    src = re.sub(shared.JS.memory_initializer_pattern, repl, open(final).read(), count=1)
  File "/usr/lib/python2.7/re.py", line 155, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/emsdk_portable/sdk/emcc.py", line 2057, in repl
    open(memfile, 'wb').write(bytearray(membytes))
IOError: [Errno 13] Permission denied: 'tree-sitter-javascript.wasm.mem'

After reading about permissions issues with docker volumes, I replaced --user emscripten with --user $(id -u) (specifying my user id on the host, rather than a username). This fixed the problem for me.

I think this might be a better suggestion to make in the docs. What do you think?

trzecieu commented 5 years ago

Hi @maxbrunsfeld, indeed it's a good observation about problem with user rights. In fact I've done some article about that couple of weeks ago: https://trzeci.eu/fixing-permission-of-files-created-from-docker/ and most likely I will merge some patches for fixing permissions.

Please note that in your case, once you've done -u $(id -u):$(id -g) and for some reason current user id is not 1000, then inside container there is no HOME associated. To make your solution bullet proof, please add a hack : -e HOME=/tmp which will set HOME to /tmp folder which is always writeable.

trzecieu commented 5 years ago

Hi @maxbrunsfeld, I'm doing some more ground refactoring of images in https://github.com/trzecieu/emscripten-docker/issues/41 and your suggestion will be addressed there. Thank you!