cvat-ai / cvat

Annotate better with CVAT, the industry-leading data engine for machine learning. Used and trusted by teams at any scale, for data of any scale.
https://cvat.ai
MIT License
12.28k stars 2.96k forks source link

Fix command for setting up the development environment #5418

Open LucasMarianoVieira opened 1 year ago

LucasMarianoVieira commented 1 year ago

My actions before raising this issue

Past week I was trying to settting up the local development environment for CVAT following the documentation and it wouldn't work. Throwing several error messages saying requests were unauthorized, 404 and etc. And that error happens because OPA wasn't working as it should.

The documentation explicity tells you to start up the OPA image on docker. But the command given there is not complete. It is missing two parameters, which allow you to say to the OPA image where it can find the policy rules and were to let them avaliable inside the image for the OPA application, so CVAT can work properly.

Expected Behaviour

Once OPA is started up, starting CVAT should allow all to work fine, including all the workflow.

Current Behaviour

Starting OPA with current command in the documentation doesn't configure the image correctly. So it can't use the proper access rules. So CVAT requests don't work and no operation will work, like login or anything related to the workflow of the application.

Possible Solution

The command present on the documentation page is:

docker run -d --rm --name cvat_opa_debug -p 8181:8181 openpolicyagent/opa:0.34.2-rootless \
 run --server --set=decision_logs.console=true --set=services.cvat.url=http://host.docker.internal:7000 \
 --set=bundles.cvat.service=cvat --set=bundles.cvat.resource=/api/auth/rules

I eventually figured out what was going wrong by checking the Dockerfiles and docker-compose files used to start up the application on Docker. So I tried this command, with the extra parameters to tell the OPA image were to look for the rules, and it worked!

sudo docker run -d --rm --name cvat_opa_debug -p 8181:8181 -v "$(pwd)/cvat/apps/iam/rules":/rules openpolicyagent/opa:0.34.2-rootless \
run --server --set=decision_logs.console=true --set=services.cvat.url=http://host.docker.internal:7000 \
--set=bundles.cvat.service=cvat --set=bundles.cvat.resource=/api/auth/rules /rules

Steps to Reproduce (for bugs)

Just running the commands given on the documentation.

Context

I spent two days trying to figure out what was happening while trying to set this at work so I could start introducing some modifications to the code. 😰

Your Environment

Please fix the documentation, so another poor soul doesn't have as much trouble as I did. XD I thank you in advance.

nmanovic commented 1 year ago

@LucasMarianoVieira , it is a known issue on Ubuntu. By a reason, the command in documentation works for Windows and Mac and doesn't work on Linux. The options below tell OPA how to get actual rules from your CVAT instance. Actually, a CVAT instance has /api/auth/rules endpoint which returns these rules, but on Linux OPA cannot reach it. Need to investigate. But your workaround also works. It is another ways to say OPA where to find rules.

--set=services.cvat.url=http://host.docker.internal:7000 \
--set=bundles.cvat.service=cvat --set=bundles.cvat.resource=/api/auth/rules /rules
LucasMarianoVieira commented 1 year ago

Hmmm, I see. Still...while you investigate the problem, it could be interesting to add some node about the problem, with a possible workaround in Ubuntu. Or maybe just a tiny note with a link referencing this or another thread about a workaround. It would had helped me a lot. But I understand.

cccober commented 1 year ago

i met the same problem, and got the error return r.json()['result'] KeyError: 'result'` finally your solution works!

sourabh0207 commented 1 year ago

Any update on this?

After following the documentation here I am getting the following error

ERROR:health-check:unknown error: 500 Server Error: Internal Server Error for url: http://localhost:8181/health?bundles Traceback (most recent call last): File "/home/sourabh/cvat/cvat/apps/health/backends.py", line 22, in check_status response.raise_for_status() File "/home/sourabh/cvat/.env/lib/python3.8/site-packages/requests/models.py", line 953, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: http://localhost:8181/health?bundles

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/sourabh/cvat/.env/lib/python3.8/site-packages/health_check/backends.py", line 30, in run_check self.check_status() File "/home/sourabh/cvat/cvat/apps/health/backends.py", line 24, in check_status raise HealthCheckException(str(e))

After trying the above proposed solution I am getting the following error:

Traceback (most recent call last): File "/home/sourabh/cvat/.env/lib/python3.8/site-packages/health_check/backends.py", line 30, in run_check self.check_status() File "/home/sourabh/cvat/cvat/apps/health/backends.py", line 24, in check_status raise HealthCheckException(str(e)) health_check.exceptions.HealthCheckException: unknown error: HTTPConnectionPool(host='localhost', port=8181): Max retries exceeded with url: /health?bundles (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f4600e183d0>: Failed to establish a new connection: [Errno 111] Connection refused')) [2023-01-21 13:06:40,354] ERROR django.request: Internal Server Error: /api/server/health/ ERROR:django.request:Internal Server Error: /api/server/health/ [2023-01-21 13:06:40,357] ERROR django.server: "GET /api/server/health/?format=json&org= HTTP/1.1" 500 485 ERROR:django.server:"GET /api/server/health/?format=json&org= HTTP/1.1" 500 485 ERROR:health-check:unknown error: HTTPConnectionPool(host='localhost', port=8181): Max retries exceeded with url: /health?bundles (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f4600db1dc0>: Failed to establish a new connection: [Errno 111] Connection refused')) Traceback (most recent call last): File "/home/sourabh/cvat/.env/lib/python3.8/site-packages/urllib3/connection.py", line 174, in _new_conn conn = connection.create_connection( File "/home/sourabh/cvat/.env/lib/python3.8/site-packages/urllib3/util/connection.py", line 95, in create_connection raise err File "/home/sourabh/cvat/.env/lib/python3.8/site-packages/urllib3/util/connection.py", line 85, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused

I am on ubuntu machine Ubuntu 20.04.5 LTS,

Please help

Thanks

bsabri commented 1 year ago

I have the same issue:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='%7bcvat_host%7d', port=8181): Max retries exceeded with url: /health?bundles (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f1c050d06a0>: Failed to establish a new connection: [Errno -2] Name or service not known'))

slverpla commented 1 year ago

Hey, running into the same issue. It looks like using the fixed command does not create a docker container. Hence everyone getting the Max retries error. Anything else you could have done in the meantime to make it work @LucasMarianoVieira ?

LucasMarianoVieira commented 1 year ago

@slverpla , I haven't played with that part of CVAT after that incident. I have been busy at work with other things. All I did was launch the OPA container manually with that extra parameters I mentioned up there. And It just worked for me. I was using an older version of CVAT when I had that problem, but I don't think that is relevant.

slverpla commented 1 year ago

Thanks for the quick reply, tried quite some stuff, like going back to older versions, but later code was indeed not the cause. Looking a bit further this fixed command worked for me: https://github.com/opencv/cvat/issues/5591