jupyterhub / repo2docker

Turn repositories into Jupyter-enabled Docker images
https://repo2docker.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.61k stars 360 forks source link

AttributeError: module 'os' has no attribute 'geteuid' #889

Open matthewolckers opened 4 years ago

matthewolckers commented 4 years ago

Bug description

Expected behaviour

Expect to produce docker image.

Actual behaviour

Traceback (most recent call last):
  File "c:\appdata\local\continuum\anaconda3\lib\site-packages\traitlets\traitlets.py", line 528, in get
    value = obj._trait_values[self.name]
KeyError: 'user_id'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\appdata\local\continuum\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\appdata\local\continuum\anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\AppData\Local\Continuum\anaconda3\Scripts\repo2docker.exe\__main__.py", line 9, in <module>
  File "c:\appdata\local\continuum\anaconda3\lib\site-packages\repo2docker\__main__.py", line 345, in main
    r2d = make_r2d()
  File "c:\appdata\local\continuum\anaconda3\lib\site-packages\repo2docker\__main__.py", line 300, in make_r2d
    if r2d.user_id == 0 and not r2d.dry_run:
  File "c:\appdata\local\continuum\anaconda3\lib\site-packages\traitlets\traitlets.py", line 556, in __get__
    return self.get(obj, cls)
  File "c:\appdata\local\continuum\anaconda3\lib\site-packages\traitlets\traitlets.py", line 535, in get
    value = self._validate(obj, dynamic_default())
  File "c:\appdata\local\continuum\anaconda3\lib\site-packages\repo2docker\app.py", line 206, in _user_id_default
    return os.geteuid()
AttributeError: module 'os' has no attribute 'geteuid'

How to reproduce

  1. On a Windows 10 PC, open the Anaconda Command Prompt
  2. Run repo2docker https://github.com/matthewolckers/fbr2020

    • OS: Windows 10
    • Docker version: 19.03.8,
    • repo2docker version 0.11.0
betatim commented 4 years ago

geteuid() is only available on unix like systems. This explains why it doesn't work on Windows. I am not sure if we could easily add an alternative that would work on Windows and leave the current behaviour the same on unix-like systems.

Windows support in repo2docker is "low", mostly because it is hard and because none of the devs have access to a windows machine. If you have some time and spare brain cycles to look into this that would be great.

manics commented 3 years ago

geteuid() is used to set the default UID inside the Docker container: https://github.com/jupyterhub/repo2docker/blob/09a4cfb7cf68fb59175df0c7c3b11dd1e2f4ecb5/repo2docker/app.py#L201-L206

A reasonable workaround for windows could be to detect the OS and return an error message requiring --user-id to be specified.

ivergara commented 3 years ago

As a workaround, WSL2 can be used without problems.

I might try to fix this issue for Windows in general. Are there more known possible solutions besides the one mentioned by @manics ?

manics commented 3 years ago

AFAIK the only reason to make the UID inside the Docker image match the user's UID is so that if you mount the user's home directory into the container it'll be writeable. Is that possible on Windows and if so, how are UIDs mapped, since that might lead to a good solution?

ivergara commented 3 years ago

Doing a cursory search I found something that might be relevant in pip

Reproducing here the beginning of the referenced function

def check_path_owner(path):
    # type: (str) -> bool
    # If we don't have a way to check the effective uid of this process, then
    # we'll just assume that we own the directory.
    if sys.platform == "win32" or not hasattr(os, "geteuid"):
        return True

Perhaps a similar approach would be sufficient?

ivergara commented 3 years ago

I got to move from the original issue by forcing to run with a given GUID in the _user_id_default method.

    @default("user_id")
    def _user_id_default(self):
        """
        Default user_id to current running user.
        """
        if sys.platform == "win32" or not hasattr(os, "geteuid"):
            return 1001
        return os.geteuid()

With this change, the execution then stops working in step 31 when trying to execute install-miniforge.bash.

Step 30/50 : USER root
 ---> Using cache
 ---> 394ba1fe367c
Step 31/50 : RUN TIMEFORMAT='time: %3R' bash -c 'time /tmp/install-miniforge.bash' && rm /tmp/install-miniforge.bash /tmp/environment.yml
 ---> Running in cf91e3dafa9a
bash: /tmp/install-miniforge.bash: Permission denied
time: 0.001

My docker knowledge at this moment doesn't go too deep as to know how to start digging deeper into this error/issue. Anyone here has a hint on how to progress here to diagnose the problem in an effective way?

rmcrae commented 4 months ago

In other words, repo2docker is useless on Windows. great