Argus icon indicating copy to clipboard operation
Argus copied to clipboard

Dependency error with docker dev environment

Open stveit opened this issue 2 years ago • 2 comments

The environment was setup by running the Frontend from the Argus-Frontend repo docker-compose file, and the backend stuff from the Argus repo docker-compose file. Error messages were made when the frontend sent certain requests to the backend:

api_1       | 2022-06-02 09:01:25,252 django.request ERROR    Internal Server Error: /api/
api_1       | Traceback (most recent call last):
api_1       |   File "/argus/src/argus/site/views.py", line 80, in get
api_1       |     from argus.version import __version__
api_1       | ModuleNotFoundError: No module named 'argus.version'
api_1       | 
api_1       | During handling of the above exception, another exception occurred:
api_1       | 
api_1       | Traceback (most recent call last):
api_1       |   File "/usr/local/lib/python3.8/site-packages/asgiref/sync.py", line 458, in thread_handler
api_1       |     raise exc_info[1]
api_1       |   File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 38, in inner
api_1       |     response = await get_response(request)
api_1       |   File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 233, in _get_response_async
api_1       |     response = await wrapped_callback(request, *callback_args, **callback_kwargs)
api_1       |   File "/usr/local/lib/python3.8/site-packages/asgiref/sync.py", line 423, in __call__
api_1       |     ret = await asyncio.wait_for(future, timeout=None)
api_1       |   File "/usr/local/lib/python3.8/asyncio/tasks.py", line 455, in wait_for
api_1       |     return await fut
api_1       |   File "/usr/local/lib/python3.8/site-packages/asgiref/current_thread_executor.py", line 22, in run
api_1       |     result = self.fn(*self.args, **self.kwargs)
api_1       |   File "/usr/local/lib/python3.8/site-packages/asgiref/sync.py", line 462, in thread_handler
api_1       |     return func(*args, **kwargs)
api_1       |   File "/usr/local/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
api_1       |     return view_func(*args, **kwargs)
api_1       |   File "/usr/local/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
api_1       |     return self.dispatch(request, *args, **kwargs)
api_1       |   File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 509, in dispatch
api_1       |     response = self.handle_exception(exc)
api_1       |   File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 469, in handle_exception
api_1       |     self.raise_uncaught_exception(exc)
api_1       |   File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
api_1       |     raise exc
api_1       |   File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 506, in dispatch
api_1       |     response = handler(request, *args, **kwargs)
api_1       |   File "/argus/src/argus/site/views.py", line 84, in get
api_1       |     __version__ = pkg_resources.get_distribution("argus-server").version
api_1       |   File "/usr/local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 466, in get_distribution
api_1       |     dist = get_provider(dist)
api_1       |   File "/usr/local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 342, in get_provider
api_1       |     return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
api_1       |   File "/usr/local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 886, in require
api_1       |     needed = self.resolve(parse_requirements(requirements))
api_1       |   File "/usr/local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 772, in resolve
api_1       |     raise DistributionNotFound(req, requirers)
api_1       | pkg_resources.DistributionNotFound: The 'argus-server' distribution was not found and is required by the application

Seems the docker setup requires the 'argus-server' package to exist when it cant find argus.server. I solved this by adding pip install argus-server to the Dockerfile.

Im uncertain how this is supposed to be working. Is argus.server is supposed to be found when running the api in a container, or is the argus-server package supposed to be used under these circumstances?

decided to jot down the problem in this issue before i forgot about it

stveit avatar Jun 02 '22 07:06 stveit

I'm not sure I understand from this how you actually set up the backend container (did you copy some Dockerfile or build one of your own, inspired by "what's out there"). But this error seems like the backend is run directly from the source code without being actually installed to the system, and the argus.version module uses pkg_resources to discover its own version - which requires the package to be installed.

In a dev setting, you would use something like pip install -e . from the source code to install the package as symlinks to the source (the -e stands for "editable install").

lunkwill42 avatar Jun 09 '22 07:06 lunkwill42

I used the Dockerfile within the repo, just ran docker-compose up. I assume this should do all necessary setup for the container. Do I still have to manually run extra installations in the container?

One change I have done is to use a docker-compose override file containing this to get the frontend working:

services:
  api:
    environment:
      - ARGUS_FRONTEND_URL=http://localhost:8080

stveit avatar Jun 09 '22 08:06 stveit