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

Configure project so that Docker container code can be debugged visually in VS Code #21

Closed
MBARIMike opened this issue Jul 19, 2021 · 6 comments

Comments

@MBARIMike
Copy link
Contributor Author

Struggling to get a debug.yml to build inside VS Code. Ran into a weird error message:

failed to compute cache key: "/compose/production/postgres/maintenance" not found: not found
[2021-07-20T19:37:45.724Z] ERROR: Service 'postgres' failed to build : Build failed

This comment seems to provide a hint as to how to fix. Sure enough, commenting out the **/compose* line from the smdb/.dockerignore file that VS Code created makes the error go away:

**/__pycache__
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
##**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
README.md

@MBARIMike
Copy link
Contributor Author

With these commits am able to build the devcontainer in VS Code, but haven't figured out how to stop on a breakpoint in views.py or load.py. Still a WIP.

@MBARIMike
Copy link
Contributor Author

Am able to set a breakpoint in VS Code for a manage.py shell_plus command when launched from this configuration.

@MBARIMike
Copy link
Contributor Author

Still struggling with setting a VS Code breakpoint in views.py with manage.py runserver running...

Am able to get into command line debugging with the debug.yml (with a breakpoint() added in smdb/smdb/views.py`) thusly:

export COMPOSE_FILE=$SMDB_HOME/smdb/debug.yml
docker-compose up -d
docker-compose stop django
(base) ➜  SeafloorMappingDB git:(main) ✗ docker-compose run --rm --service-ports django python manage.py runserver_plus 0.0.0.0:8000
Creating smdb_django_run ... done
PostgreSQL is available
 * Running on http://0.0.0.0:8000/ (Press CTRL+C to quit)
 * Restarting with stat
Performing system checks...

System check identified no issues (0 silenced).

Django version 3.1.10, using settings 'config.settings.local'
Development server is running at http://0.0.0.0:8000/
Using the Werkzeug debugger (http://werkzeug.pocoo.org/)
Quit the server with CONTROL-C.
 * Debugger is active!
 * Debugger PIN: 282-534-888
 # Make request from http://localhost:8000/
INFO 2021-07-23 15:44:04,955 views.py get_context_data():26 Serializing 1384 missions to geojson...
> /app/smdb/views.py(28)get_context_data()
-> context["missions"] = json.loads(
(Pdb)

This does not work unless I use the --service-ports option for docker-compose. I'm thinking that somehow I need to do what --service-ports does inside the container that VS Code is using.

I looked at adding the --service-ports run argument in devcontainer.json, but the "runArgs" directive appears to work only for the "docker" command, not "docker-compose".

I'm also exploring using debugpy in the manage.py runserver command executed in the container. So far no joy.

@MBARIMike
Copy link
Contributor Author

The online tutorials for getting Django debugging to work in VS Code are varied. I had to overlook the ones that did not focus on a Docker container deployed installation. Rather than trying to get debugging working via the command: /start in the container I made a launch.json configuration and had /start execute runserver_plus on port 8001. PR #22 now works pretty well. The new instructions in README.md can be followed to debug code in VS Code.

@MBARIMike
Copy link
Contributor Author

The developer experience is fairly good now with SeafloorMappingDB in VS Code. Am able to:

  • Operate runserver_plus, shell_plus, and scripts/load.py using the visual debugger
  • Perform Source Control operations (add, commit, push, pull) from the UI
  • Have code introspection, automated pep-8, linting, and black formatting in the editor
  • Get a functional development system up and running by simply opening the cloned SeafloorMappingDB directory in VS Code – note that Docker Dashboard on the Mac provides a button to do just this!
  • Execute all the tests only from the top level – individual tests and debugging of tests does not work

The last item is apparently a known Issue which I'll leave open in #25

MBARIMike added a commit that referenced this issue Oct 14, 2021
[requires.io] dependency update on main branch
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

1 participant