Skip to content

Commit 1e3751d

Browse files
authored
Merge pull request #10 from stackhpc/refactor/dev-workflow-improvments
Add Tilt-based development workflow
2 parents ec6f4d1 + 9e20617 commit 1e3751d

File tree

12 files changed

+115
-19
lines changed

12 files changed

+115
-19
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
.vscode/
44
__pycache__/
55
**/*.secret
6+
.DS_Store
67

78
# Ignore local dev helpers
89
test-values.y[a]ml
910
chart/web-app/settings.yml
1011
gradio-client-test.py
11-
venv*/
12+
**venv*/
13+
1214

1315
# Helm chart stuff
1416
chart/Chart.lock

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,17 @@ The Helm chart consists of the following components:
5757
- A frontend web-app built using [Gradio](https://www.gradio.app) and [LangChain](https://www.langchain.com). The web app source code can be found in `chart/web-app` and gets written to a ConfigMap during the chart build and is then mounted into the UI pod and executed as the entry point for the UI docker image (built from `images/ui-base/Dockerfile`).
5858

5959
- A [stakater/Reloader](https://github.com/stakater/Reloader) instance which monitors the web-app ConfigMap for changes and restarts the frontend when the app code changes (i.e. whenever the Helm values are updated).
60+
61+
## Development
62+
63+
The GitHub repository includes a [tilt](https://tilt.dev) file for easier development. After installing tilt locally, simply run `tilt up` from the repo root to get started with development. This will trigger the following:
64+
65+
- Install the backend API components of the Helm chart on the remote k8s cluster specified by your current k8s context.
66+
67+
- Create a port-forward from the remote cluster to `localhost:8080`
68+
69+
- Create a local `tilt-dev-venv` in the repo root containing the required Python dependencies to run the frontend web app locally.
70+
71+
- Launch the frontend web app locally on `127.0.0.1:7860`, configured to use `localhost:8080` as the backend API
72+
73+
- Watch all components and only reload the minimal set of components needed when a file in the repo changes (e.g. modifying `chart/web-app/app.py` will restart the local web app instance only)

Tiltfile

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# The HuggingFace model to use for testing
2+
# hf_model = "ise-uiuc/Magicoder-S-DS-6.7B"
3+
hf_model = "TheBloke/WizardCoder-Python-34B-V1.0-AWQ"
4+
5+
# Toggles whether UI should be run locally using gradio hot-reloading
6+
# or should be included in the remote Helm install
7+
run_ui_locally = True
8+
9+
# Tilt warns is if we try to use tilt against a cluster named 'production'
10+
# Use this line to allow it for now
11+
allow_k8s_contexts('production-llm-service-admin@production-llm-service')
12+
13+
# TODO: Include image builds in tilt up
14+
# docker_build("images/ui-base/")
15+
16+
chart_yaml = helm(
17+
"chart/",
18+
values="hu-dev-values.yml",
19+
# Enable/disable remote UI install depending on if we're running it locally
20+
set=[
21+
"huggingface.model={}".format(hf_model),
22+
"ui.enabled={}".format(not str(run_ui_locally).lower())
23+
],
24+
)
25+
k8s_yaml(chart_yaml)
26+
27+
if not run_ui_locally:
28+
# Port-forward web app to localhost:8080
29+
k8s_resource("chart-ui", port_forwards="8080:7680")
30+
31+
# Port forward backend UI to localhost:8081 for local web app development
32+
k8s_resource("chart-api", port_forwards="8081:8000")
33+
34+
if run_ui_locally:
35+
venv_name = "tilt-dev-venv"
36+
requirements = "images/ui-base/requirements.txt"
37+
38+
# Ensure venv exists and matches requirements.txt
39+
local_resource(
40+
name="gradio-app-venv",
41+
deps=[requirements],
42+
cmd=" && ".join([
43+
"([[ -d {} ]] || python3 -m venv {})".format(venv_name, venv_name),
44+
"source {}/bin/activate".format(venv_name),
45+
"pip install -r {}".format(requirements),
46+
])
47+
)
48+
49+
# Run web app locally
50+
local_resource(
51+
name="gradio-app",
52+
deps=["chart/web-app/"],
53+
resource_deps=["gradio-app-venv"],
54+
serve_cmd=" && ".join([
55+
"cd chart/web-app",
56+
"python app.py {}".format(hf_model),
57+
])
58+
)

chart/Chart.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ annotations:
3131
dependencies:
3232
- name: reloader
3333
version: 1.0.63
34-
repository: https://stakater.github.io/stakater-charts
34+
repository: https://stakater.github.io/stakater-charts
35+
condition: ui.enabled

chart/templates/ui/app-config-map.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if .Values.ui.enabled -}}
12
apiVersion: v1
23
kind: ConfigMap
34
metadata:
@@ -8,3 +9,4 @@ data:
89
{{ (.Files.Glob "web-app/*").AsConfig | nindent 2 }}
910
settings.yml: |
1011
{{- .Values.ui.appSettings | toYaml | nindent 4 }}
12+
{{- end -}}

chart/templates/ui/deployment.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if .Values.ui.enabled -}}
12
apiVersion: apps/v1
23
kind: Deployment
34
metadata:
@@ -10,7 +11,7 @@ metadata:
1011
spec:
1112
replicas: 1
1213
selector:
13-
matchLabels:
14+
matchLabels:
1415
{{- include "azimuth-llm.ui-selectorLabels" . | nindent 6 }}
1516
strategy:
1617
{{- .Values.ui.updateStrategy | toYaml | nindent 4 }}
@@ -29,7 +30,7 @@ spec:
2930
volumeMounts:
3031
- name: app
3132
mountPath: /etc/web-app
32-
command:
33+
command:
3334
- python
3435
args:
3536
- {{ .Values.ui.entrypoint }}
@@ -44,4 +45,5 @@ spec:
4445
volumes:
4546
- name: app
4647
configMap:
47-
name: {{ .Release.Name }}-web-app
48+
name: {{ .Release.Name }}-web-app
49+
{{- end -}}

chart/templates/ui/service.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if .Values.ui.enabled -}}
12
apiVersion: v1
23
kind: Service
34
metadata:
@@ -12,4 +13,5 @@ spec:
1213
targetPort: ui
1314
type: {{ .Values.ui.service.type }}
1415
selector:
15-
{{- include "azimuth-llm.ui-selectorLabels" . | nindent 4 }}
16+
{{- include "azimuth-llm.ui-selectorLabels" . | nindent 4 }}
17+
{{- end -}}

chart/templates/ui/ui-zenith-client.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if .Values.ui.enabled -}}
12
{{- if .Values.ui.service.zenith.enabled -}}
23
apiVersion: zenith.stackhpc.com/v1alpha1
34
kind: Client
@@ -11,4 +12,5 @@ spec:
1112
serviceName: {{ .Values.ui.service.name }}
1213
auth:
1314
skip: {{ .Values.ui.service.zenith.skipAuth }}
14-
{{- end -}}
15+
{{- end -}}
16+
{{- end -}}

chart/templates/ui/ui-zenith-reservation.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if .Values.ui.enabled -}}
12
{{- if .Values.ui.service.zenith.enabled -}}
23
apiVersion: zenith.stackhpc.com/v1alpha1
34
kind: Reservation
@@ -13,4 +14,5 @@ metadata:
1314
{{- end }}
1415
spec:
1516
credentialSecretName: {{ .Release.Name }}-ui-zenith-credential
17+
{{- end -}}
1618
{{- end -}}

chart/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ api:
6464

6565
# Configuration for the frontend web interface
6666
ui:
67+
# Toggles installation of the gradio web UI
68+
enabled: true
6769
# The file from the UI config map to execute as the entrypoint to the frontend app
6870
entrypoint: app.py
6971
# The values to be written to settings.yml for parsing as frontend app setting

0 commit comments

Comments
 (0)