okfn / docker-ckan

Docker images and Docker Compose setup for CKAN [Not Maintained]
GNU Affero General Public License v3.0
81 stars 88 forks source link

IDE integrated remote debugging options (vscode) #76

Open ccancellieri opened 3 years ago

ccancellieri commented 3 years ago

I really don't like when projects impose the development environment so my following issue is not so much inline with my philosophy but... It taken 1 day of work to obtain something better than pdb that I'd love to share and have it integrated (as an option) into this project

This patch will add remote (to docker) debug facilities and an already configured project environment to be able to debug python (and Jinja2) interactively directly from the Visual Studio IDE.

All you need is the Docker plugin installed into the IDE (it's provided by the community and very easy to use).

The remote debug leverages over debugpy and the docker plugin looks also open source.

I created my branch 2.8-vscode to discuss changes before the pr. The patch is a bit more complex than necessary because the starting project does not have a 2.8 branch ready to use (can I we have it?).

https://github.com/okfn/docker-ckan/compare/master...ccancellieri:2.8-vscode?expand=1

If you like that we can discuss how to integrate into the master as well (yes it works also for 2.9.3 but my plugins still not)

I think a switch variable into .env can be used to enable/disable it, on my branch is enabled by default,

Actually it looks amazing I'm also able to debug jinja2 templates for free

amercader commented 3 years ago

@ccancellieri thanks for this. As you say, I'm not keen on include dev environment specific options in the repo and impose eg debugpy on all users. But I'd be happy to add a section on the README documenting the changes so users are aware of them

ccancellieri commented 3 years ago

:) thanks looks great.

Il giorno lun 21 giu 2021 alle ore 11:30 Adrià Mercader < @.***> ha scritto:

@ccancellieri https://github.com/ccancellieri thanks for this. As you say, I'm not keen on include dev environment specific options in the repo and impose eg debugpy on all users. But I'd be happy to add a section on the README documenting the changes so users are aware of them

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/okfn/docker-ckan/issues/76#issuecomment-864884226, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG5WWYQYOFJVB5KHDD4Q23TT4BD3ANCNFSM4677GMEQ .

-- Mr. Carlo Cancellieri skype: ccancellieri Twitter: @cancellieric LinkedIn: http://it.linkedin.com/in/ccancellieri/

GordianDziwis commented 2 years ago

Could you rename the issue to include "remote debugging"? I was searching for a solution and did not find it until someone nice on gitter pointed me to it.

frafra commented 2 years ago

Personal note: having ssh is even better because it allows to easily synchronize files with scp (so you can easily test your WIP bugfix), it works great with IDE like PyCharm, and it does not require installing any IDE specific library or tool.

Here is what I use in my debug Dockerfile and entrypoint:

Dockerfile:

# [...]

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
    apt-get install -qq openssh-server && \
    apt-get -q clean && \
    rm -rf /var/lib/apt/lists/*
RUN passwd -d $(whoami) && \
    mkdir -p -m0755 /var/run/sshd

EXPOSE 22
CMD ["/usr/sbin/sshd", "-D", "-o", "PermitRootLogin=yes", "-o", "PermitEmptyPAsswords=yes", "-o", "PermitUserEnvironment=yes"]

entrypoint.sh:

# [...]

mkdir -p $HOME/.ssh
env > $HOME/.ssh/environment

exec "$@"
wardi commented 6 months ago

Let's move this discussion to https://github.com/ckan/ckan-docker because this would be a great feature for many users. I think it's fair to expect many users will be on vscode

AyanIanniello commented 6 months ago

@ccancellieri Thanks a lot for sharing your knowledge in how this topic. I've been struggling to setup debugpy.

I'm working in a container built from the images in ckan-docker repo using vscode and right now I'm trying to replicate the changes you've made here to setup debugpy.

Do you know where could I find the "start_ckan_development.sh" that is running ckan 2.10.3 in ckan-docker ? so I can insert the lines below like you did for ckan 2.8:

pip install debugpy
sudo -u ckan -EH /usr/bin/python -m debugpy --log-to-stderr --wait-for-client --listen 0.0.0.0:5678 /usr/bin/paster serve --reload $CKAN_INI 

I'd appreciate any help from the community as well @wardi Thanks a lot!

kowh-ai commented 6 months ago

@AyanIanniello check out https://github.com/ckan/ckan-docker/tree/master?tab=readme-ov-file#5-ckan-images where it mentions overriding the start_ckan.sh file. You can do the same with the start_ckan_development.sh file. The actual file used is here: https://github.com/ckan/ckan-docker-base/blob/main/ckan-2.10/dev/setup/start_ckan_development.sh (ie: in the ckan-docker-base repo

ccancellieri commented 6 months ago

Hi happy to help, so about 2.9 and 2.10 i was preparing other ah hoc branches, now, I'll start a new fork from the new official repository to work on 2.10.3. Please feel free to explore the branches list of my repository.

FYI:

kowh-ai commented 6 months ago

As per @wardi suggestion I have opened a discussion in the ckan-docker repo: https://github.com/ckan/ckan-docker/discussions/122