Skip to content

Commit 3f68050

Browse files
committed
feat: debug and hot reload for op container
1 parent 9e96dc8 commit 3f68050

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

chart/templates/backend.yaml

+7-1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ spec:
147147
- name: op
148148
image: {{ .Values.backend_image }}
149149
imagePullPolicy: {{ .Values.backend_pull_policy }}
150+
{{- if .Values.backend_op_command_override }}
151+
command:
152+
{{- range .Values.backend_op_command_override }}
153+
- {{ . | quote }}
154+
{{- end }}
155+
{{- else }}
150156
command:
151157
- gunicorn
152158
- btrixcloud.main_op:app_root
@@ -158,7 +164,7 @@ spec:
158164
- "{{ .Values.backend_workers | default 1 }}"
159165
- --worker-class
160166
- uvicorn.workers.UvicornWorker
161-
167+
{{- end }}
162168
envFrom:
163169
- configMapRef:
164170
name: backend-env-config

docs/develop/backend-hot-reload-and-debugger.md

+26-4
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,25 @@ skaffold dev
2626
```
2727

2828
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.
29+
30+
Navigate to `localhost:8000/api/redoc` or `localhost:8000/api/docs` to see the documentation
31+
for the api container.
32+
33+
Navigate to `http://localhost:8756/redoc` or `http://localhost:8756/docs` to see the documentation
34+
for the op container.
35+
36+
Changing any code in `backend/btrixcloud` will trigger a reload in both the op and api containers.
3137

3238
### Debugger
3339

3440
Interactive debugging uses [debugpy](https://github.com/microsoft/debugpy), which
3541
works on VSCode but not PyCharm.
3642

37-
Use this debug configuration in VSCode:
43+
Use these debug configurations in VSCode:
3844

3945
```JSON
4046
{
41-
"name": "Attach to Browsertrix Backend",
47+
"name": "Attach to Browsertrix Backend API",
4248
"type": "debugpy",
4349
"request": "attach",
4450
"connect": {
@@ -52,6 +58,22 @@ Use this debug configuration in VSCode:
5258
}
5359
],
5460
"justMyCode": false
61+
},
62+
{
63+
"name": "Attach to Browsertrix Backend OP",
64+
"type": "debugpy",
65+
"request": "attach",
66+
"connect": {
67+
"host": "127.0.0.1",
68+
"port": 5679
69+
},
70+
"pathMappings": [
71+
{
72+
"localRoot": "${workspaceFolder}/backend/btrixcloud/",
73+
"remoteRoot": "/app/btrixcloud/"
74+
}
75+
],
76+
"justMyCode": false
5577
}
5678
```
5779

skaffold.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ portForward:
2727
namespace: default
2828
port: 5678
2929
localPort: 5678
30+
# so you can hit the op container on `localhost:8756`
31+
- resourceType: service
32+
resourceName: browsertrix-cloud-backend
33+
namespace: default
34+
# can't references {{ Values. }} hence hardcoding
35+
port: 8756
36+
localPort: 8756
37+
# for the debugger
38+
- resourceType: deployment
39+
resourceName: browsertrix-cloud-backend
40+
namespace: default
41+
port: 5679
42+
localPort: 5679
3043
deploy:
3144
helm:
3245
releases:
@@ -39,6 +52,9 @@ deploy:
3952
# See https://skaffold.dev/docs/deployers/helm/
4053
# must do this to make skaffold use local images with helm
4154
setValues:
55+
# we hardcoded this earlier so make sure it has same value
56+
# across the helm chart
57+
opPort: 8756
4258
# hot reloading doesn't work with default gunicorn command
4359
# so need to override to use uvicorn
4460
# plus need to start the process with debugpy to debug
@@ -51,3 +67,12 @@ deploy:
5167
python -m debugpy --listen 0.0.0.0:5678
5268
-m uvicorn btrixcloud.main:app_root
5369
--reload --host 0.0.0.0 --port 8000
70+
backend_op_command_override:
71+
- sh
72+
- -c
73+
- >
74+
pip install --no-input debugpy
75+
&&
76+
python -m debugpy --listen 0.0.0.0:5679
77+
-m uvicorn btrixcloud.main_op:app_root
78+
--reload --host 0.0.0.0 --port 8756

0 commit comments

Comments
 (0)