-
-
Notifications
You must be signed in to change notification settings - Fork 51
Feat improve local devex #1827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
osintalex
wants to merge
7
commits into
webrecorder:main
Choose a base branch
from
osintalex:feat-improve-local-devex
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feat improve local devex #1827
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
baf170c
feat: skaffold yaml working
osintalex 66f7a58
feat: backend hot reload with skaffold
osintalex 35b7463
chore: add trailing newlines
osintalex 39c4a1b
feat: add debugger and prioritise local values yaml
osintalex afa8306
feat: debug and hot reload for op container
osintalex 01b8f50
chore: add trailing newline
osintalex 01a0303
refactor: remove probes for easier local dev
osintalex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Deploy the Backend with Hot Reloading and Interactive Debugging | ||
|
||
This guide explains how to deploy Browsertrix with [skaffold](https://skaffold.dev/) | ||
so the backend hot reloads and allows interactive debugging. | ||
|
||
This may save time since you don't need to rebuild the backend container every time you change code | ||
and can use a debugger to step through code. | ||
|
||
## Requirements | ||
|
||
Follow the documentation to [install skaffold](https://skaffold.dev/docs/install/), i.e. if you are on | ||
Mac OS run: | ||
|
||
```sh | ||
brew install skaffold | ||
``` | ||
|
||
To install helm and set up a local Kubernetes cluster, see the section on [local dev set up](local-dev-setup.md). | ||
|
||
## Quickstart | ||
|
||
From the command line, run: | ||
|
||
```sh | ||
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 | ||
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 these debug configurations in VSCode: | ||
|
||
```JSON | ||
{ | ||
"name": "Attach to Browsertrix Backend API", | ||
"type": "debugpy", | ||
"request": "attach", | ||
"connect": { | ||
"host": "127.0.0.1", | ||
"port": 5678 | ||
}, | ||
"pathMappings": [ | ||
{ | ||
"localRoot": "${workspaceFolder}/backend/btrixcloud/", | ||
"remoteRoot": "/app/btrixcloud/" | ||
} | ||
], | ||
"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 | ||
} | ||
``` | ||
|
||
This will attach to the Kubernetes pod running Browsertrix and persist between | ||
hot reloads. Change your code, wait for the application to reload, | ||
and still hit breakpoints in the same debugging session. | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
apiVersion: skaffold/v4beta11 | ||
kind: Config | ||
metadata: | ||
name: browsertrix | ||
build: | ||
artifacts: | ||
# only put the backend in here since it's quite easy now | ||
# to run frontend locally and get hot reloading with yarn | ||
- image: docker.io/webrecorder/browsertrix-backend | ||
context: backend | ||
docker: | ||
dockerfile: Dockerfile | ||
sync: | ||
manual: | ||
- src: 'btrixcloud/**/*' | ||
dest: . | ||
portForward: | ||
# so you can hit the API on `localhost:8000` | ||
- resourceType: service | ||
resourceName: browsertrix-cloud-backend | ||
namespace: default | ||
port: 8000 | ||
localPort: 8000 | ||
# for the debugger | ||
- resourceType: deployment | ||
resourceName: browsertrix-cloud-backend | ||
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: | ||
- name: btrix | ||
chartPath: chart | ||
valuesFiles: | ||
- chart/values.yaml | ||
# local must come after values since it is expected to override | ||
- chart/local.yaml | ||
# 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 | ||
# we need to override some settings for skaffold dev | ||
skaffold_dev: true | ||
# 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 | ||
backend_api_command_override: | ||
- sh | ||
- -c | ||
- > | ||
pip install --no-input debugpy | ||
&& | ||
python -Xfrozen_modules=off -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 -Xfrozen_modules=off -m debugpy --listen 0.0.0.0:5679 | ||
-m uvicorn btrixcloud.main_op:app_root | ||
--reload --host 0.0.0.0 --port 8756 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.