Unable to debug CKAN inside Docker containers

CKAN is an opensource web application, which uses Flask and werkzeug.

Docker setup: OK

I added Docker under Run/Debug Configurations, as well as the Python interpreter included within the CKAN Docker image, and I am able to run CKAN.

I had to comment out "USER ckan" from the Dockerfile, because otherwise CKAN would fail to write files to the shared folder created by PyCharm automatically (to share the project code). It looks like PyCharm does not allow to set a different user to run its debugger (there is a "sudo" option, which does not seem to help in this case).

Flask configuration: unable to configure it properly

I then tried to create a Flask server configuration, using "wsgi" as Target and "application" as Application, but it doesn't seem correct:

Error: A valid Flask application was not obtained from 'wsgi:application'.

Custom Python application: setup seems OK, but PyCharm seems to fail

I tried to use the same command specified in the Dockerfile to run CKAN, by creating a Python configuration, using "/usr/lib/ckan/venv/bin/ckan" as Script Path, and "-c /etc/ckan/production.ini run --host 0.0.0.0" as Parameters.

It seems to work, but I get an error message:

ckan | 2021-10-05 10:51:39,661 INFO [ckan.cli.server] Running CKAN on http://0.0.0.0:5000
ckan | 2021-10-05 10:51:39,661 WARNI [werkzeug] * Running on all addresses.
ckan | WARNING: This is a development server. Do not use it in a production deployment.
ckan | /usr/lib/ckan/venv/bin/python: No module named ckan.__main__; 'ckan' is a package and cannot be directly executed
ckan exited with code 1

It is hard for me to figure out what is happening, as PyCharm plays some magic tricks behind the scenes, like adding an extra docker compose file to open the debug port, add some helpers, add the code in a different directory (under /opt/project), and overriding the main command.

I then tried to use "/opt/project/ckan/cli/cli.py" as Script path, and CKAN now exits with code 0, but no server is started. Which makes sense, as there is no real main there. I tried to add it, but then PyCharm disabled the run and debug buttons. I restarted it, reconnected to Docker, reconfigured everything, readded the Docker interpreter, but nothing worked, and PyCharm does not give any error to me.

Could it be that CKAN requires running `pip3 install -e .` before starting it? I do not know, since I am not able to start the debug function any more, after many hours and something like ~100 tries (I tried very hard, since it would be great if my colleagues could rely on PyCharm, but I would need to support them first).

I also tried adding ssh to the container and adding it as remote interpreter. It worked, but it is a bit confusing, since I cannot start CKAN.

 

Any suggestion? :)

0
1 comment

I found a solution!

My main problems were:

  • Try to add `pip install -e .` as a "Remote task", which made PyCharm run/debug button going disabled/gray (without giving any error)
  • Not having a way to run CKAN without installing it first and using an entrypoint installed on bin (I proposed a patch for CKAN)

Additional details here: https://github.com/ckan/ckan/discussions/6457#discussioncomment-1436466

0

Please sign in to leave a comment.