Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ocrd resmgr download fails due to PermissionError with docker #252

Closed
sven-nm opened this issue Apr 30, 2021 · 3 comments · Fixed by #377
Closed

ocrd resmgr download fails due to PermissionError with docker #252

sven-nm opened this issue Apr 30, 2021 · 3 comments · Fixed by #377
Assignees
Labels
bug Something isn't working

Comments

@sven-nm
Copy link

sven-nm commented Apr 30, 2021

Hi all,
I faced the following issue which can lead to buggy behaviours. When downloading a model with ocrd resmgr, eg :

docker run -u $(id -u) -v $PWD/models:/usr/local/share/ocrd-resources ocrd/all:maximum ocrd resmgr download ocrd-tesserocr-recognize '*'

the following error constantly appears :

Traceback (most recent call last):
  File "/usr/bin/ocrd", line 33, in <module>
    sys.exit(load_entry_point('ocrd', 'console_scripts', 'ocrd')())
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 1256, in invoke
    Command.invoke(self, ctx)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/build/core/ocrd/ocrd/cli/resmgr.py", line 32, in resmgr_cli
    initLogging()
  File "/build/core/ocrd_utils/ocrd_utils/logging.py", line 129, in initLogging
    logging.config.fileConfig(config_file)
  File "/usr/lib/python3.6/logging/config.py", line 84, in fileConfig
    handlers = _install_handlers(cp, formatters)
  File "/usr/lib/python3.6/logging/config.py", line 148, in _install_handlers
    h = klass(*args)
  File "/usr/lib/python3.6/logging/__init__.py", line 1032, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/lib/python3.6/logging/__init__.py", line 1061, in _open
    return open(self.baseFilename, self.mode, encoding=self.encoding)
PermissionError: [Errno 13] Permission denied: '/data/ocrd.log'

Removing the -u $(id -u) specification in the docker commands solves the problems, but has the downside of creating model files with restricted permissions, which, in my case lead to errors when calling them.

Am I doing something wrong in the first place ?

@kba kba self-assigned this May 19, 2021
@kba kba added the bug Something isn't working label May 19, 2021
@bertsky
Copy link
Collaborator

bertsky commented Jun 8, 2021

Same happens with /.config (where ocrd resmgr wants to create ocrd).

I believe the reason for this is that when run as non-root, HOME is set to /, but that is owned by root.

As a workaround, it helps to run with -e HOME=/data (in addition to -u ...).

@bertsky
Copy link
Collaborator

bertsky commented Jun 20, 2023

Same happens with /.config (where ocrd resmgr wants to create ocrd).

I believe the reason for this is that when run as non-root, HOME is set to /, but that is owned by root.

As a workaround, it helps to run with -e HOME=/data (in addition to -u ...).

That only helps if /data is mounted (and owned by the same user), though.

In the OP's problem (i.e. ~/ocrd.log cannot be created), the cause was precisely that no /data was in fact mounted. So these are related, but not the same.

Regarding .config, we have the idea of using a subdirectory of ocrd-resources for that (so no additional volume would be necessary).

And regarding /data becoming writable for arbitrary users (for the case when no volume is mounted), why not just chmod 777 /data?

@kba
Copy link
Member

kba commented Jun 21, 2023

With the next release of ocrd_all, thanks to #377

  • resources.yml will be written to /usr/local/share/ocrd-resources (which needs to be mounted for the models anyway)
  • /data is now writable by everyone, so logs can be written there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants