Skip to content

Commit 60102f5

Browse files
committed
feat: backend hot reload with skaffold
1 parent bcd639b commit 60102f5

File tree

6 files changed

+68
-13
lines changed

6 files changed

+68
-13
lines changed

chart/templates/backend.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ spec:
5555
- name: api
5656
image: {{ .Values.backend_image }}
5757
imagePullPolicy: {{ .Values.backend_pull_policy }}
58+
{{- if .Values.backend_api_command_override }}
59+
command:
60+
{{- range .Values.backend_api_command_override }}
61+
- {{ . | quote }}
62+
{{- end }}
63+
{{- else }}
5864
command:
5965
- gunicorn
6066
- btrixcloud.main:app_root
@@ -66,6 +72,7 @@ spec:
6672
- "{{ .Values.backend_workers | default 1 }}"
6773
- --worker-class
6874
- uvicorn.workers.UvicornWorker
75+
{{- end }}
6976

7077
envFrom:
7178
- configMapRef:

docs/develop/backend-hot-reload.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Deploy the Backend with Hot Reloading
2+
3+
This guide explains how to deploy Browsertrix with [skaffold](https://skaffold.dev/) so the backend hot reloads. This
4+
may save you time since you don't need to rebuild the backend container every time you change code.
5+
6+
## Requirements
7+
8+
Follow the documentation to [install skaffold](https://skaffold.dev/docs/install/), i.e. if you are on
9+
Mac OS run:
10+
11+
```sh
12+
brew install skaffold
13+
```
14+
15+
To install helm and set up a local Kubernetes cluster, see the section on [local dev set up](local-dev-setup.md).
16+
17+
## Quickstart
18+
19+
From the command line, run:
20+
21+
```sh
22+
skaffold dev
23+
```
24+
25+
This will deploy Browsertrix into the cluster and port forward the API with hot reloading.
26+
Navigate to `localhost:8000/api/redoc` to see the documentation.
27+
Changing any code in `backend/btrixcloud` will trigger a reload.

docs/develop/frontend-dev.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ If connecting to a local deployment cluster, set `API_BASE_URL` to:
7272
API_BASE_URL=http://localhost:30870
7373
```
7474

75+
If the API is not running at `localhost:30870`, port forward it from your local cluster:
76+
77+
```sh
78+
kubectl port-forward svc/browsertrix-cloud-backend 30870:8000
79+
```
80+
7581
??? info "Port when using Minikube (on macOS)"
7682

7783
When using Minikube on macOS, the port will not be 30870. Instead, Minikube opens a tunnel to a random port,
@@ -85,7 +91,7 @@ Start the frontend development server:
8591
yarn start
8692
```
8793

88-
This will open `localhost:9870` in a new tab in your default browser.
94+
This will open `localhost:9870` in a new tab in your default browser. It will take a few minutes to finish.
8995

9096
Saving changes to files in `src` will automatically reload your browser window with the latest UI updates.
9197

docs/develop/local-dev-setup.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ helm upgrade --install -f ./chart/values.yaml \
116116
117117
??? info "MicroK8S"
118118
119-
If using microk8s, the commend will be:
119+
If using microk8s, the command will be:
120120
121121
```sh
122122
microk8s helm3 upgrade --install -f ./chart/values.yaml -f ./chart/local.yaml btrix ./chart/
@@ -133,3 +133,7 @@ Changes to settings in `./chart/local.yaml` can be deployed with `helm upgrade .
133133
## Deploying Frontend Only
134134

135135
If you are just making changes to the frontend, you can also [deploy the frontend separately](frontend-dev.md) using a dev server for quicker iteration.
136+
137+
## Deploying Backend with Hot Reloading
138+
139+
If you want to iterate faster on the backend, read [deploy the backend with hot reloading](backend-hot-reload.md).

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ nav:
6161
- develop/local-dev-setup.md
6262
- develop/frontend-dev.md
6363
- develop/docs.md
64+
- develop/backend-hot-reload.md
6465
- User Guide:
6566
- user-guide/index.md
6667
- user-guide/signup.md

skaffold.yaml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ metadata:
44
name: browsertrix
55
build:
66
artifacts:
7+
# only put the backend in here since it's quite easy now
8+
# to run frontend locally and get hot reloading with yarn
79
- image: docker.io/webrecorder/browsertrix-backend
810
context: backend
911
docker:
@@ -12,25 +14,33 @@ build:
1214
manual:
1315
- src: 'btrixcloud/**/*'
1416
dest: .
15-
- image: docker.io/webrecorder/browsertrix-frontend
16-
context: frontend
17-
docker:
18-
dockerfile: Dockerfile
19-
sync:
20-
manual:
21-
- src: 'src/**/*'
22-
dest: .
17+
portForward:
18+
- resourceType: service
19+
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
22+
namespace: default
23+
port: 8000
24+
localPort: 8000
2325
deploy:
2426
helm:
2527
releases:
2628
- name: btrix
2729
chartPath: chart
2830
valuesFiles:
2931
- chart/values.yaml
30-
# local must come after since it overrides stuff in values.yaml
31-
- chart/local.yaml
3232
# See https://skaffold.dev/docs/deployers/helm/
3333
# must do this to make skaffold use local images with helm
3434
setValues:
3535
backend_image: docker.io/webrecorder/browsertrix-backend
36-
frontend_image: docker.io/webrecorder/browsertrix-frontend
36+
backend_pull_policy: "Never"
37+
# hot reloading doesn't work with default gunicorn command
38+
# 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"

0 commit comments

Comments
 (0)