From 07c0c7bd6a594c09acbcc3a20b1397b00f275c8d Mon Sep 17 00:00:00 2001 From: Omer Lachish Date: Sun, 10 Feb 2019 13:49:38 +0200 Subject: [PATCH 1/8] open port 3000 for remote debugging --- docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yml b/docker-compose.yml index e01be5bfd1..555b1bee28 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,7 @@ services: - postgres - redis ports: + - "3000:3000" - "5000:5000" volumes: - ".:/app" From 1834f8c708727f259c037fc0c941cc26838d7d2a Mon Sep 17 00:00:00 2001 From: Omer Lachish Date: Sun, 10 Feb 2019 13:49:47 +0200 Subject: [PATCH 2/8] add ptvsd --- requirements_dev.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements_dev.txt b/requirements_dev.txt index d0332fb2c1..5bb09cfe90 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -8,3 +8,4 @@ mock==2.0.0 pymongo[tls,srv]==3.6.1 botocore==1.12.85 PyAthena>=1.0.0 +ptvsd==4.2.3 From eb8bdf8d33f3da7eeeb7bf34dc2d905c578c2ef7 Mon Sep 17 00:00:00 2001 From: Omer Lachish Date: Sun, 10 Feb 2019 15:14:02 +0200 Subject: [PATCH 3/8] use port 5678 to avoid changes in VSCode's default config --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 555b1bee28..6adaee14d0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: - postgres - redis ports: - - "3000:3000" + - "5678:5678" - "5000:5000" volumes: - ".:/app" From 48c1c73299a08b66a4de369b6f6c4859c9e598fe Mon Sep 17 00:00:00 2001 From: Omer Lachish Date: Sun, 10 Feb 2019 15:14:15 +0200 Subject: [PATCH 4/8] attach to ptvsd --- bin/docker-entrypoint | 2 +- redash/__init__.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bin/docker-entrypoint b/bin/docker-entrypoint index 8cc09a4949..956ddbb41b 100755 --- a/bin/docker-entrypoint +++ b/bin/docker-entrypoint @@ -70,7 +70,7 @@ case "$1" in ;; dev_server) export FLASK_DEBUG=1 - exec /app/manage.py runserver --debugger --reload -h 0.0.0.0 + exec /app/manage.py runserver --no-debugger --no-reload -h 0.0.0.0 ;; shell) exec /app/manage.py shell diff --git a/redash/__init__.py b/redash/__init__.py index b82f257095..2ae502a231 100644 --- a/redash/__init__.py +++ b/redash/__init__.py @@ -3,7 +3,7 @@ import urlparse import urllib -import redis +import redis from flask import Flask, current_app from flask_sslify import SSLify from werkzeug.contrib.fixers import ProxyFix @@ -22,6 +22,17 @@ __version__ = '6.0.0' +import os +if os.environ.get("FLASK_DEBUG"): + import ptvsd + + # Allow other computers to attach to ptvsd at this IP address and port. + ptvsd.enable_attach(address=('0.0.0.0', 5678)) + + # Pause the program until a remote debugger is attached + # ptvsd.wait_for_attach() + + def setup_logging(): handler = logging.StreamHandler(sys.stdout if settings.LOG_STDOUT else sys.stderr) formatter = logging.Formatter(settings.LOG_FORMAT) From edf0d9fdc0609e48074002429f54ad8fc03cd4a4 Mon Sep 17 00:00:00 2001 From: Omer Lachish Date: Sun, 10 Feb 2019 15:18:00 +0200 Subject: [PATCH 5/8] no need to wait for attach --- redash/__init__.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/redash/__init__.py b/redash/__init__.py index 2ae502a231..0ee69a2405 100644 --- a/redash/__init__.py +++ b/redash/__init__.py @@ -25,13 +25,8 @@ import os if os.environ.get("FLASK_DEBUG"): import ptvsd - - # Allow other computers to attach to ptvsd at this IP address and port. ptvsd.enable_attach(address=('0.0.0.0', 5678)) - # Pause the program until a remote debugger is attached - # ptvsd.wait_for_attach() - def setup_logging(): handler = logging.StreamHandler(sys.stdout if settings.LOG_STDOUT else sys.stderr) From 0e16a593f0046384c9d287440d5f0e8997f852ca Mon Sep 17 00:00:00 2001 From: Omer Lachish Date: Sun, 10 Feb 2019 22:04:10 +0200 Subject: [PATCH 6/8] actually, --debugger seems to be working --- bin/docker-entrypoint | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/docker-entrypoint b/bin/docker-entrypoint index 956ddbb41b..ac9c2efe55 100755 --- a/bin/docker-entrypoint +++ b/bin/docker-entrypoint @@ -70,7 +70,7 @@ 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 --no-reload -h 0.0.0.0 ;; shell) exec /app/manage.py shell From 2dca6d4f52489f1915a8c33f5b893aa69002fe27 Mon Sep 17 00:00:00 2001 From: Omer Lachish Date: Sun, 10 Feb 2019 22:33:54 +0200 Subject: [PATCH 7/8] create a new docker entry point for remote debugging --- bin/docker-entrypoint | 8 +++++++- docker-compose.debug.yml | 9 +++++++++ docker-compose.yml | 1 - redash/__init__.py | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 docker-compose.debug.yml diff --git a/bin/docker-entrypoint b/bin/docker-entrypoint index ac9c2efe55..b108c95dc6 100755 --- a/bin/docker-entrypoint +++ b/bin/docker-entrypoint @@ -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" @@ -70,7 +71,12 @@ case "$1" in ;; dev_server) export FLASK_DEBUG=1 - exec /app/manage.py runserver --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 + export REMOTE_DEBUG=1 + exec /app/manage.py runserver -h 0.0.0.0 ;; shell) exec /app/manage.py shell diff --git a/docker-compose.debug.yml b/docker-compose.debug.yml new file mode 100644 index 0000000000..d6a798ec08 --- /dev/null +++ b/docker-compose.debug.yml @@ -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" \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 6adaee14d0..e01be5bfd1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,6 @@ services: - postgres - redis ports: - - "5678:5678" - "5000:5000" volumes: - ".:/app" diff --git a/redash/__init__.py b/redash/__init__.py index 0ee69a2405..8c681c0ce6 100644 --- a/redash/__init__.py +++ b/redash/__init__.py @@ -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)) From 85f9598b7e35efd172d469d7c8e66ad918438e77 Mon Sep 17 00:00:00 2001 From: Omer Lachish Date: Mon, 11 Feb 2019 12:32:07 +0200 Subject: [PATCH 8/8] alternative method to switch to debugging --- bin/docker-entrypoint | 6 +++--- docker-compose.debug.yml | 9 --------- docker-compose.yml | 1 + 3 files changed, 4 insertions(+), 12 deletions(-) delete mode 100644 docker-compose.debug.yml diff --git a/bin/docker-entrypoint b/bin/docker-entrypoint index b108c95dc6..c028ea2470 100755 --- a/bin/docker-entrypoint +++ b/bin/docker-entrypoint @@ -39,7 +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 "debug -- 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" @@ -73,10 +73,10 @@ case "$1" in export FLASK_DEBUG=1 exec /app/manage.py runserver --debugger --reload -h 0.0.0.0 ;; - debug_server) + debug) export FLASK_DEBUG=1 export REMOTE_DEBUG=1 - exec /app/manage.py runserver -h 0.0.0.0 + exec /app/manage.py runserver --debugger --no-reload -h 0.0.0.0 ;; shell) exec /app/manage.py shell diff --git a/docker-compose.debug.yml b/docker-compose.debug.yml deleted file mode 100644 index d6a798ec08..0000000000 --- a/docker-compose.debug.yml +++ /dev/null @@ -1,9 +0,0 @@ -# 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" \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index e01be5bfd1..b1049ac4fc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,7 @@ services: - redis ports: - "5000:5000" + - "5678:5678" volumes: - ".:/app" environment: