INCATools / ontology-development-kit

Bootstrap an OBO Library ontology
http://incatools.github.io/ontology-development-kit/
BSD 3-Clause "New" or "Revised" License
214 stars 54 forks source link

Cant run test suite as root on Ubuntu #899

Closed matentzn closed 1 year ago

matentzn commented 1 year ago

When running make build tests on Ubuntu as I have always done, I get the following error:

./seed-via-docker.sh  -c -t my-ontology1 myont
This script only works with ODK 1.3.2 and later. For ODK 1.3.1 or earlier, use https://raw.githubusercontent.com/INCATools/ontology-development-kit/v1.3.1/seed-via-docker.sh
Traceback (most recent call last):
  File "/tools/odk.py", line 993, in <module>
    cli()
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/tools/odk.py", line 877, in seed
    raise Exception('max one repo; current={}'.format(repo))
Exception: max one repo; current=('Matentzoglu', 'myont')
make[2]: *** [Makefile:22: test_no_yaml_dependencies_none] Error 1
make[2]: Leaving directory '/root/ws/ontology-development-kit'
make[1]: *** [Makefile:110: test-flavor] Error 2
make[1]: Leaving directory '/root/ws/ontology-development-kit'

This has always worked, and I don't have any indications of what could be wrong..

... Other than perhaps the fact that my server does not have any user management and only a root user..

gouttegd commented 1 year ago

Exception: max one repo; current=('Matentzoglu', 'myont')

The odk.py script is complaining it is receiving more than one argument.

That script is invoked through seed-via-docker.sh like this:

docker run -e ODK_USER_ID=$(id -u) -e ODK_GROUP_ID=$(id -g) -v $PWD:/work -w /work --rm obolibrary/$ODK_IMAGE:$ODK_TAG /tools/odk.py seed --gitname "$ODK_GITNAME" --gitemail "$ODK_GITEMAIL" "$@"

The seed-via-docker.sh script is itself invoked by make tests like this:

test_no_yaml_dependencies_none:
    $(CMD) $(EMAIL_ARGS) -c -t my-ontology1 myont

So in the end, the invocation should be:

docker run -e ODK_USER_ID=$(id -u) -e ODK_GROUP_ID=$(id -g) -v $PWD:/work -w /work --rm obolibrary/$ODK_IMAGE:$ODK_TAG /tools/odk.py seed --gitname "$ODK_GITNAME" --gitemail "$ODK_GITEMAIL" -c -t my-ontology1 myont

So myont should be the only non-optional argument. So where does the Matentzoglu argument come from?

The only beginning of an explanation I have is it must come from the ODK_GITNAME variable, which is initialised in the seed-via-docker.sh script as follows:

ODK_GITNAME=${ODK_GITNAME:-$(git config --get user.name)}

Most likely your Git username is set to “Nico Matentzoglu”? Then the invocation becomes:

docker run -e ODK_USER_ID=$(id -u) -e ODK_GROUP_ID=$(id -g) -v $PWD:/work -w /work --rm obolibrary/$ODK_IMAGE:$ODK_TAG /tools/odk.py seed --gitname "Nico Matentzoglu" --gitemail "$ODK_GITEMAIL" -c -t my-ontology1 myont

So it looks like as if somehow the quoting around the expansion of the ODK_GITNAME variable was stripped, so that only Nico is taken as the value of the --gitname option and Matentzoglu is interpreted as the first positional argument:

docker run -e ODK_USER_ID=$(id -u) -e ODK_GROUP_ID=$(id -g) -v $PWD:/work -w /work --rm obolibrary/$ODK_IMAGE:$ODK_TAG /tools/odk.py seed --gitname Nico Matentzoglu --gitemail "$ODK_GITEMAIL" -c -t my-ontology1 myont

But I have no idea how that could be happening. I can’t reproduce the issue here. My own Git username is, obviously enough, Damien Goutte-Gattat, but it is always passed to the script as one argument only, as it should.

gouttegd commented 1 year ago

... Other than perhaps the fact that my server does not have any user management and only a root user..

I won’t even bother to ask you why. But I can reproduce the issue by setting ODK_USER_ID to 0 in seed-via-docker.sh (which is the value it would get when the script itself is called by the root user).

That’s because, while the entrypoint.sh script does quote its argument when sudo-ing the command to execute inside the container in the normal case:

exec sudo -H -E -u odkuser "$@"

it does not do so when exec'ing the same command in the case it should run as root:

if [ x$ODK_USER_ID = x0 ]; then
    exec $@
fi
matentzn commented 1 year ago

@gouttegd THANKS a mil! Running tests now, but your explanations make total sense!