Skip to content

Commit 1e89968

Browse files
committed
feat: add debugger and prioritise local values yaml
1 parent 9e655c7 commit 1e89968

File tree

5 files changed

+83
-41
lines changed

5 files changed

+83
-41
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Deploy the Backend with Hot Reloading and Interactive Debugging
2+
3+
This guide explains how to deploy Browsertrix with [skaffold](https://skaffold.dev/)
4+
so the backend hot reloads and allows interactive debugging.
5+
6+
This may save time since you don't need to rebuild the backend container every time you change code
7+
and can use a debugger to step through code.
8+
9+
## Requirements
10+
11+
Follow the documentation to [install skaffold](https://skaffold.dev/docs/install/), i.e. if you are on
12+
Mac OS run:
13+
14+
```sh
15+
brew install skaffold
16+
```
17+
18+
To install helm and set up a local Kubernetes cluster, see the section on [local dev set up](local-dev-setup.md).
19+
20+
## Quickstart
21+
22+
From the command line, run:
23+
24+
```sh
25+
skaffold dev
26+
```
27+
28+
This will deploy Browsertrix into the cluster and port forward the API with hot reloading.
29+
Navigate to `localhost:8000/api/redoc` or `localhost:8000/api/docs` to see the documentation.
30+
Changing any code in `backend/btrixcloud` will trigger a reload.
31+
32+
### Debugger
33+
34+
Interactive debugging uses [debugpy](https://github.com/microsoft/debugpy), which
35+
works on VSCode but not PyCharm.
36+
37+
Use this debug configuration in VSCode:
38+
39+
```JSON
40+
{
41+
"name": "Attach to Browsertrix Backend",
42+
"type": "debugpy",
43+
"request": "attach",
44+
"connect": {
45+
"host": "127.0.0.1",
46+
"port": 5678
47+
},
48+
"pathMappings": [
49+
{
50+
"localRoot": "${workspaceFolder}/backend/btrixcloud/",
51+
"remoteRoot": "/app/btrixcloud/"
52+
}
53+
],
54+
"justMyCode": false
55+
}
56+
```
57+
58+
This will attach to the Kubernetes pod running Browsertrix and persist between
59+
hot reloads. Change your code, wait for the application to reload,
60+
and still hit breakpoints in the same debugging session.
61+
62+

docs/develop/backend-hot-reload.md

Lines changed: 0 additions & 27 deletions
This file was deleted.

docs/develop/local-dev-setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,4 @@ If you are just making changes to the frontend, you can also [deploy the fronten
136136

137137
## Deploying Backend with Hot Reloading
138138

139-
If you want to iterate faster on the backend, read [deploy the backend with hot reloading](backend-hot-reload.md).
139+
If you want to iterate faster on the backend, read [deploy the backend with hot reloading and interactive debugging](backend-hot-reload-and-debugger.md).

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ nav:
6161
- develop/local-dev-setup.md
6262
- develop/frontend-dev.md
6363
- develop/docs.md
64-
- develop/backend-hot-reload.md
64+
- develop/backend-hot-reload-and-debugger.md
6565
- User Guide:
6666
- user-guide/index.md
6767
- user-guide/signup.md

skaffold.yaml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,39 @@ build:
1515
- src: 'btrixcloud/**/*'
1616
dest: .
1717
portForward:
18+
# so you can hit the API on `localhost:8000`
1819
- resourceType: service
1920
resourceName: browsertrix-cloud-backend
20-
# assumes you are doing local dev in `default` namespace
21-
# if you aren't you need to change this manually
2221
namespace: default
2322
port: 8000
2423
localPort: 8000
24+
# for the debugger
25+
- resourceType: deployment
26+
resourceName: browsertrix-cloud-backend
27+
namespace: default
28+
port: 5678
29+
localPort: 5678
2530
deploy:
2631
helm:
2732
releases:
2833
- name: btrix
2934
chartPath: chart
3035
valuesFiles:
3136
- chart/values.yaml
37+
# local must come after values since it is expected to override
38+
- chart/local.yaml
3239
# See https://skaffold.dev/docs/deployers/helm/
3340
# must do this to make skaffold use local images with helm
3441
setValues:
35-
backend_image: docker.io/webrecorder/browsertrix-backend
36-
backend_pull_policy: "Never"
3742
# hot reloading doesn't work with default gunicorn command
3843
# so need to override to use uvicorn
39-
backend_api_command_override:
40-
- uvicorn
41-
- btrixcloud.main:app_root
42-
- --reload
43-
- --host
44-
- "0.0.0.0"
45-
- --port
46-
- "8000"
44+
# plus need to start the process with debugpy to debug
45+
backend_api_command_override:
46+
- sh
47+
- -c
48+
- >
49+
pip install --no-input debugpy
50+
&&
51+
python -m debugpy --listen 0.0.0.0:5678
52+
-m uvicorn btrixcloud.main:app_root
53+
--reload --host 0.0.0.0 --port 8000

0 commit comments

Comments
 (0)