Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDE integrated remote debugging options (vscode) #76

Open
ccancellieri opened this issue Jun 20, 2021 · 9 comments
Open

IDE integrated remote debugging options (vscode) #76

ccancellieri opened this issue Jun 20, 2021 · 9 comments

Comments

@ccancellieri
Copy link

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

@ccancellieri ccancellieri changed the title Better debugging options IDE integrated debugging options (vscode) Jun 20, 2021
@amercader
Copy link
Member

@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
Copy link
Author

ccancellieri commented Jun 21, 2021 via email

@GordianDziwis
Copy link

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
Copy link

frafra commented Oct 14, 2021

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 "$@"

@ccancellieri ccancellieri changed the title IDE integrated debugging options (vscode) IDE integrated remote debugging options (vscode) Oct 17, 2021
@wardi
Copy link

wardi commented Feb 21, 2024

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
Copy link

@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
Copy link

kowh-ai commented Feb 21, 2024

@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
Copy link
Author

ccancellieri commented Feb 21, 2024

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:

  • In 2.9 I was able to have the debugpy working but with no hot reload.
  • Under windows remote attach is not linking the breakpoints (red dots will be grayed) as workaround u can put breakpoint() in the code, the visual studio code plugin will give u the control once the line is reached.

@kowh-ai
Copy link

kowh-ai commented Feb 22, 2024

As per @wardi suggestion I have opened a discussion in the ckan-docker repo: ckan/ckan-docker#122

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants