Open LHBL2003 opened 5 months ago
So I think I'm on the right track, but apparently there's something I need to do to get Netbox to load during debug. The debug in vscode stays in RUN, but I get the error message that the module Netbox is missing. Which leads me to the conclusion that you have to specify somehow in the debug that Netbox is also loaded.
I hope you use vscode :) and maybe you have the right .vscode files for me. So the files launch.json and tasks.json which are necessary for debugging.
Because that would make my life easier to help with the development of the plugin. I haven't done anything with Python yet, but if you can debug something it's a lot easier.
Exception has occurred: ModuleNotFoundError
No module named 'netbox'
File "/source/netbox_qrcode/__init__.py", line 1, in <module>
from netbox.plugins import PluginConfig
ModuleNotFoundError: No module named 'netbox'
I have created the following folder in the root folder:
.vscode
File: launch.json
{
"configurations": [
{
"name": "Docker: Python - Django",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug",
"python": {
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "netbox_qrcode"
}
],
"projectType": "django"
}
}
]
}
File tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "docker-build",
"label": "docker-build",
"platform": "python",
"dockerBuild": {
"tag": "debugdockercompose:latest",
"dockerfile": "${workspaceFolder}/develop/Dockerfile",
"context": "${workspaceFolder}",
"pull": true
}
},
{
"type": "docker-run",
"label": "docker-run: debug",
"dependsOn": [
"docker-build"
],
"python": {
"args": [
"runserver",
"0.0.0.0:8000",
"--nothreading",
"--noreload"
],
"file": "/source/netbox_qrcode/__init__.py"
}
}
]
}
@k01ek
I know you have little time, but I wanted to ask you if you use your development system with vscode and you also use the debug in vscode?
If so, I would be happy if you could send me your project, e.g. via ZIP, so that I can see what I am doing wrong?
Mail: Mister . Hempel at Gmail . com
No one has any ideas? That is apparently also wrong. This starts the containers for me now, but I can't get any further. I have no idea how to do this correctly.
File: launch.json
{
"configurations": [
{
"name": "Docker: Python - Django",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug",
"python": {
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/source"
}
],
"projectType": "django"
}
}
]
}
File tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "docker-run: debug",
"type": "docker-compose",
"dockerCompose": {
"up": {
"detached": true,
"build": true
},
"files": [
"${workspaceFolder}/develop/docker-compose.yml",
]
}
}
]
}
Maybe someone can save me from my torment. ;(
That is apparently also wrong. I can get to Settings.py but it cannot find Configuration.py because it is missing in the container. I also only have one container, as the Docker file is apparently not being processed. That was my attempt before the last post.
File: launch.json
{
"configurations": [
{
"name": "Docker: Python - Django",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug",
"python": {
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/source"
}
],
"projectType": "django"
}
}
]
}
File tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "docker-build",
"label": "docker-build",
"platform": "python",
"dockerBuild": {
"tag": "debugdockercompose:latest",
"dockerfile": "${workspaceFolder}/develop/Dockerfile",
"context": "${workspaceFolder}",
"pull": true
}
},
{
"type": "docker-run",
"label": "docker-run: debug",
"dependsOn": [
"docker-build"
],
"python": {
"args": [
"runserver",
"0.0.0.0:8000",
"--nothreading",
"--noreload"
],
"file": "/opt/netbox/netbox/manage.py"
}
}
]
}
I think I've now taken a step in the right direction, but it still doesn't work :D :(
I found this post. Debug Django in a docker-compose container with VS Code: https://miaoz2001.medium.com/debug-django-in-a-docker-compose-container-with-vs-code-88598dfc8be3
launch.json
{
"configurations": [
{
"name": "Docker: Python - Django",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/source"
}
],
"django": true,
}
]
}
Tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "docker-run: debug",
"type": "docker-compose",
"dockerCompose": {
"up": {
"detached": true,
"build": true
},
"files": [
"${workspaceFolder}/develop/docker-compose.yml",
]
}
}
]
}
docker-compose-debug.yml
---
version: '3'
services:
netbox:
build:
context: ../
dockerfile: develop/Dockerfile
command: >
["sh", "-c", "pip install debugpy -t /tmp &&
python manage.py migrate &&
python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678
python manage.py runserver 0.0.0.0:8000"
ports:
- '8000:8000'
- '5678:5678'
depends_on:
... The rest as in the docker-compose.yml
vsCode Terminal:
docker-compose -f develop/docker-compose.yml -f develop/docker-compose-debug.yml up --build
Now everything starts and the start also looks different in the vscode terminal view (more colorful). I can log on to http://localhost:8000/. But there is no waiting at breakpoints.
If I now click on Run and Debug (play symbol) I get this:
I can't believe I got it :D I'll create another empty VM and set everything up step by step so that others can also benefit from it.
Memo to myself. Links where I had asked something about it: https://github.com/netbox-community/netbox/discussions/16637 https://github.com/netbox-community/netbox/discussions/9397
https://github.com/microsoft/debugpy/discussions/1618 (Current location with a working solution. Until I integrate it into the plugin.)
I know this is more of a general knowledge, but I'm a C# / Visual Studio .Net kid.
I would like to develop one or the other to the plugin, but I don't know how to debug this.
I can get Docker Compose to work and with the help of your Github code I can always get it to start as the current Netbox version.
I also discovered a video on how to get Docker debugged with Python. https://www.youtube.com/watch?v=jtBVppyfDbE
However, I don't understand how to get the debugging to work in the downloaded Gitub project.
Can you perhaps make a short video or explain this?
THX