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

Enable remote debugging with ptvsd #3419

Merged
merged 13 commits into from
Feb 12, 2019
8 changes: 7 additions & 1 deletion bin/docker-entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ help() {
echo ""
echo "shell -- open shell"
echo "dev_server -- start Flask development server with debugger and auto reload"
echo "debug_server -- start Flask development server with remote debugger via ptvsd"
echo "create_db -- create database tables"
echo "manage -- CLI to manage redash"
echo "tests -- run tests"
Expand Down Expand Up @@ -70,7 +71,12 @@ case "$1" in
;;
dev_server)
export FLASK_DEBUG=1
exec /app/manage.py runserver --no-debugger --no-reload -h 0.0.0.0
exec /app/manage.py runserver --debugger --reload -h 0.0.0.0
;;
debug_server)
export FLASK_DEBUG=1
arikfr marked this conversation as resolved.
Show resolved Hide resolved
export REMOTE_DEBUG=1
exec /app/manage.py runserver -h 0.0.0.0
;;
shell)
exec /app/manage.py shell
Expand Down
9 changes: 9 additions & 0 deletions docker-compose.debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This configuration file is for **development** setup. For production, refer to
# docker-compose.production.yml.
version: '3'
services:
server:
command: debug_server
ports:
- "5678:5678"
- "5000:5000"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just add 5678 to the server exposed ports + find a way to signal to Docker to start with a different command?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about 85f9598? This way you would switch to debugging by running:

docker-compose stop server && docker-compose run --rm --service-ports server debug && docker-compose start server

and attaching via VSCode. Once you're done, a Ctrl+C will get you back to your usual reloading, non-debuggable dev server.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

I think it's time to introduce bin/dev to the OSS repo too, and then we can do bin/dev debug to avoid the copy pasting.

I'll take care of this.

1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ services:
- postgres
- redis
ports:
- "5678:5678"
- "5000:5000"
volumes:
- ".:/app"
Expand Down
2 changes: 1 addition & 1 deletion redash/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


import os
if os.environ.get("FLASK_DEBUG"):
if os.environ.get("REMOTE_DEBUG"):
import ptvsd
ptvsd.enable_attach(address=('0.0.0.0', 5678))

Expand Down