Skip to content

Commit c9da4e5

Browse files
committed
Enable remote debugging using VSCode - see HEA-760
This changes allows setting LAUNCHER in .env and then using VSCode to attach to the Python process running inside the Docker container(s)
1 parent 56c64eb commit c9da4e5

File tree

7 files changed

+83
-5
lines changed

7 files changed

+83
-5
lines changed

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,53 @@ baseline
2323

2424
This produces a .puml file that can be rendered using a PlantUML
2525
server, either within your IDE or using a service like http://www.plantuml.com/.
26+
27+
## Debugging inside Docker Containers
28+
29+
The `LAUNCHER` environment sets a wrapper program around the Python process
30+
(`gunicorn`, `dagster-daemon`, `dagster-webserver`). This can be used to
31+
enable a debugger inside Docker Containers:
32+
33+
1. Set `LAUNCHER="python3 -m debugpy --listen 0.0.0.0:5678"` in `.env`
34+
2. Create Launch Configurations in Visual Studio Code like:
35+
36+
```json
37+
{
38+
"name": "Python: Attach to app (Docker Container)",
39+
"type": "debugpy",
40+
"request": "attach",
41+
"connect": {
42+
"host": "localhost",
43+
"port": 5678
44+
},
45+
"pathMappings": [
46+
{
47+
"localRoot": "${workspaceFolder:hea}",
48+
"remoteRoot": "/usr/src/app"
49+
}
50+
],
51+
"django": true,
52+
"justMyCode": false
53+
},
54+
{
55+
"name": "Python: Attach to dagster-daemon (Docker Container)",
56+
"type": "debugpy",
57+
"request": "attach",
58+
"connect": {
59+
"host": "localhost",
60+
"port": 5680
61+
},
62+
"pathMappings": [
63+
{
64+
"localRoot": "${workspaceFolder:hea}",
65+
"remoteRoot": "/usr/src/app"
66+
}
67+
],
68+
"django": true,
69+
"justMyCode": false
70+
}
71+
```
72+
73+
3. Start the Docker containers as normal, and then use the Run and Debug
74+
pane in Visual Studio code to launch the configuration that attaches to
75+
the desired server.

docker-compose.override.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ services:
1515
build:
1616
target: dev
1717
ports:
18+
- "5678:5678"
1819
- "8000:8000"
1920
- "8888:8888"
2021
volumes:
@@ -30,6 +31,9 @@ services:
3031
- ./env.example:/usr/src/app/.env
3132
environment:
3233
DJANGO_SETTINGS_MODULE: hea.settings.local
34+
LAUNCHER: ${LAUNCHER} # e.g. "debugpy" or "ddtrace"
35+
# Disable frozen modules warning
36+
PYDEVD_DISABLE_FILE_VALIDATION: 1
3337
# Put .coverage in a writable directory
3438
COVERAGE_FILE: log/.coverage
3539
command:
@@ -41,6 +45,7 @@ services:
4145
restart: no
4246
ports:
4347
- "3000:3000"
48+
- "5679:5678"
4449
volumes:
4550
- ./:/usr/src/app
4651
# Separate volumes for writable directories inside the container
@@ -54,9 +59,14 @@ services:
5459
- ./env.example:/usr/src/app/.env
5560
environment:
5661
DJANGO_SETTINGS_MODULE: hea.settings.local
62+
LAUNCHER: ${LAUNCHER} # e.g. "debugpy" or "ddtrace"
63+
# Disable frozen modules warning
64+
PYDEVD_DISABLE_FILE_VALIDATION: 1
5765

5866
dagster_daemon:
5967
restart: no
68+
ports:
69+
- "5680:5678"
6070
volumes:
6171
- ./:/usr/src/app
6272
# Separate volumes for writable directories inside the container
@@ -70,4 +80,7 @@ services:
7080
- ./env.example:/usr/src/app/.env
7181
environment:
7282
DJANGO_SETTINGS_MODULE: hea.settings.local
83+
LAUNCHER: ${LAUNCHER} # e.g. "debugpy" or "ddtrace"
84+
# Disable frozen modules warning
85+
PYDEVD_DISABLE_FILE_VALIDATION: 1
7386

docker/app/run_dagster_daemon.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ echo Setting up logs
1313
touch log/django.log
1414
chown -R django:django log/*
1515

16-
echo Starting Dagster
17-
gosu django dagster-daemon run $*
16+
echo Starting Dagster Daemon
17+
if [ x"$LAUNCHER" != x"" ]; then
18+
echo using ${LAUNCHER}
19+
fi
20+
gosu django ${LAUNCHER} /usr/local/bin/dagster-daemon run $*

docker/app/run_dagster_webserver.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ echo Setting up logs
1313
touch log/django.log
1414
chown -R django:django log/*
1515

16-
echo Starting Dagster
17-
gosu django dagster-webserver -h 0.0.0.0 -p 3000 -m pipelines --path-prefix /${DAGSTER_WEBSERVER_PREFIX} $*
16+
echo Starting Dagster Webserver
17+
if [ x"$LAUNCHER" != x"" ]; then
18+
echo using ${LAUNCHER}
19+
fi
20+
gosu django ${LAUNCHER} /usr/local/bin/dagster-webserver -h 0.0.0.0 -p 3000 -m pipelines --path-prefix /${DAGSTER_WEBSERVER_PREFIX} $*

docker/app/run_django.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ touch log/django_sql.log
4040
chown -R django:django log/*
4141

4242
echo Starting Gunicorn with DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE}
43-
gosu django gunicorn ${APP}.wsgi:application \
43+
if [ x"$LAUNCHER" != x"" ]; then
44+
echo using ${LAUNCHER}
45+
fi
46+
gosu django ${LAUNCHER} /usr/local/bin/gunicorn ${APP}.wsgi:application \
4447
--name ${APP}${ENV} \
4548
--config $(dirname $(readlink -f "$0"))/gunicorn_config.py \
4649
$* 2>&1

env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,8 @@ BSS_METADATA_WORKBOOK='gdrive://Database Design/BSS Metadata' # 15XVXFjbom1sScV
4848
BSS_METADATA_STORAGE_OPTIONS='{"token": "service_account", "access": "read_only", "creds": ${GOOGLE_APPLICATION_CREDENTIALS}, "root_file_id": "0AOJ0gJ8sjnO7Uk9PVA"}'
4949
BSS_FILES_FOLDER='gdrive://Discovery Folder/Baseline Storage Sheets (BSS)'
5050
BSS_FILES_STORAGE_OPTIONS='{"token": "service_account", "access": "read_only", "creds": ${GOOGLE_APPLICATION_CREDENTIALS}, "root_file_id": "0AOJ0gJ8sjnO7Uk9PVA"}'
51+
52+
# LAUNCHER can be used to configure a wrapper program around the Python process
53+
# For example, to add ddtrace or debugpy
54+
# Use the VSCode debugger as a launcher
55+
# LAUNCHER = "python3 -m debugpy --listen 0.0.0.0:5679"

requirements/local.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
-r test.txt
22
-r lint.txt
3+
debugpy

0 commit comments

Comments
 (0)