Skip to content

Commit

Permalink
feat: debug and hot reload for op container
Browse files Browse the repository at this point in the history
  • Loading branch information
osintalex committed Jul 13, 2024
1 parent 9e96dc8 commit 3f68050
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
8 changes: 7 additions & 1 deletion chart/templates/backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ spec:
- name: op
image: {{ .Values.backend_image }}
imagePullPolicy: {{ .Values.backend_pull_policy }}
{{- if .Values.backend_op_command_override }}
command:
{{- range .Values.backend_op_command_override }}
- {{ . | quote }}
{{- end }}
{{- else }}
command:
- gunicorn
- btrixcloud.main_op:app_root
Expand All @@ -158,7 +164,7 @@ spec:
- "{{ .Values.backend_workers | default 1 }}"
- --worker-class
- uvicorn.workers.UvicornWorker

{{- end }}
envFrom:
- configMapRef:
name: backend-env-config
Expand Down
30 changes: 26 additions & 4 deletions docs/develop/backend-hot-reload-and-debugger.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,25 @@ skaffold dev
```

This will deploy Browsertrix into the cluster and port forward the API with hot reloading.
Navigate to `localhost:8000/api/redoc` or `localhost:8000/api/docs` to see the documentation.
Changing any code in `backend/btrixcloud` will trigger a reload.

Navigate to `localhost:8000/api/redoc` or `localhost:8000/api/docs` to see the documentation
for the api container.

Navigate to `http://localhost:8756/redoc` or `http://localhost:8756/docs` to see the documentation
for the op container.

Changing any code in `backend/btrixcloud` will trigger a reload in both the op and api containers.

### Debugger

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

Use this debug configuration in VSCode:
Use these debug configurations in VSCode:

```JSON
{
"name": "Attach to Browsertrix Backend",
"name": "Attach to Browsertrix Backend API",
"type": "debugpy",
"request": "attach",
"connect": {
Expand All @@ -52,6 +58,22 @@ Use this debug configuration in VSCode:
}
],
"justMyCode": false
},
{
"name": "Attach to Browsertrix Backend OP",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "127.0.0.1",
"port": 5679
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}/backend/btrixcloud/",
"remoteRoot": "/app/btrixcloud/"
}
],
"justMyCode": false
}
```

Expand Down
25 changes: 25 additions & 0 deletions skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ portForward:
namespace: default
port: 5678
localPort: 5678
# so you can hit the op container on `localhost:8756`
- resourceType: service
resourceName: browsertrix-cloud-backend
namespace: default
# can't references {{ Values. }} hence hardcoding
port: 8756
localPort: 8756
# for the debugger
- resourceType: deployment
resourceName: browsertrix-cloud-backend
namespace: default
port: 5679
localPort: 5679
deploy:
helm:
releases:
Expand All @@ -39,6 +52,9 @@ deploy:
# See https://skaffold.dev/docs/deployers/helm/
# must do this to make skaffold use local images with helm
setValues:
# we hardcoded this earlier so make sure it has same value
# across the helm chart
opPort: 8756
# hot reloading doesn't work with default gunicorn command
# so need to override to use uvicorn
# plus need to start the process with debugpy to debug
Expand All @@ -51,3 +67,12 @@ deploy:
python -m debugpy --listen 0.0.0.0:5678
-m uvicorn btrixcloud.main:app_root
--reload --host 0.0.0.0 --port 8000
backend_op_command_override:
- sh
- -c
- >
pip install --no-input debugpy
&&
python -m debugpy --listen 0.0.0.0:5679
-m uvicorn btrixcloud.main_op:app_root
--reload --host 0.0.0.0 --port 8756

0 comments on commit 3f68050

Please sign in to comment.