Skip to content

Commit

Permalink
Refactor web-app structure and add chart and CI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sd109 committed Oct 29, 2024
1 parent ad11e2c commit 27887b9
Show file tree
Hide file tree
Showing 24 changed files with 379 additions and 266 deletions.
64 changes: 31 additions & 33 deletions .github/workflows/build-push-artifacts.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Adapted from https://github.com/stackhpc/azimuth/blob/master/.github/workflows/build-push-artifacts.yaml
name: Publish artifacts
# Run the tasks on every push
# TODO: Add path filtering to only run on relevant changes
on: push
jobs:
# Job to run change detection
Expand All @@ -24,9 +23,10 @@ jobs:
id: filter
with:
base: ${{ github.ref_name }}
# TODO: Make image filters more granular
filters: |
images:
- 'images/**'
- 'web-apps/**'
chart:
- 'chart/**'
Expand All @@ -35,12 +35,11 @@ jobs:
name: Build and push images
runs-on: ubuntu-latest
needs: changes
if: ${{ needs.changes.outputs.images == 'true' || github.ref_type == 'tag' }}
# if: ${{ needs.changes.outputs.images == 'true' || github.ref_type == 'tag' }}
strategy:
matrix:
include:
# - component: api
- component: ui
- component: chat-interface
steps:
- name: Check out the repository
uses: actions/checkout@v4
Expand All @@ -56,46 +55,45 @@ jobs:
id: image-meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/stackhpc/azimuth-llm-${{ matrix.component }}-base
images: ghcr.io/stackhpc/azimuth-llm-${{ matrix.component }}
# Produce the branch name or tag and the SHA as tags
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha,prefix=
- name: Build and push image
uses: stackhpc/github-actions/docker-multiarch-build-push@allow-continue-after-scan
uses: azimuth-cloud/github-actions/docker-multiarch-build-push@update-trivy-action
with:
cache-key: ${{ matrix.component }}-base
context: ./images/${{ matrix.component }}-base
cache-key: ${{ matrix.component }}
context: ./web-apps/${{ matrix.component }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.image-meta.outputs.tags }}
labels: ${{ steps.image-meta.outputs.labels }}
fail_on_high_severity_cve: false

# Job to build and publish Helm chart
build_push_chart:
name: Build and push Helm chart
runs-on: ubuntu-latest
# Only build and push the chart if chart files have changed
needs: [changes]
if: ${{ needs.changes.outputs.chart == 'true' || github.ref_type == 'tag' }}
steps:
- name: Check out the repository
uses: actions/checkout@v4
with:
# This is important for the semver action to work correctly
# when determining the number of commits since the last tag
fetch-depth: 0
# # Job to build and publish Helm chart
# build_push_chart:
# name: Build and push Helm chart
# runs-on: ubuntu-latest
# # Only build and push the chart if chart files have changed
# needs: [changes]
# if: ${{ needs.changes.outputs.chart == 'true' || github.ref_type == 'tag' }}
# steps:
# - name: Check out the repository
# uses: actions/checkout@v4
# with:
# # This is important for the semver action to work correctly
# # when determining the number of commits since the last tag
# fetch-depth: 0

- name: Get SemVer version for current commit
id: semver
uses: stackhpc/github-actions/semver@master
# - name: Get SemVer version for current commit
# id: semver
# uses: azimuth-cloud/github-actions/semver@master

- name: Publish Helm charts
uses: stackhpc/github-actions/helm-publish@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ steps.semver.outputs.version }}
app-version: ${{ steps.semver.outputs.short-sha }}
# - name: Publish Helm charts
# uses: azimuth-cloud/github-actions/helm-publish@master
# with:
# token: ${{ secrets.GITHUB_TOKEN }}
# version: ${{ steps.semver.outputs.version }}
# app-version: ${{ steps.semver.outputs.short-sha }}
50 changes: 50 additions & 0 deletions .github/workflows/test-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Test pull request
on:
pull_request:
jobs:
chart_validation:
runs-on: ubuntu-latest
env:
CLUSTER_NAME: chart-testing
RELEASE_NAME: ci-test
steps:
- name: Checkout the repo
uses: actions/checkout@v4

- name: Install Helm
uses: azure/setup-helm@v4

- name: Set up chart testing
uses: helm/chart-testing-action@v2

- name: Run chart linting
run: ct lint --config ct.yaml

- name: Run helm template with default values
run: helm template ci-test .
working-directory: chart

- name: Build all web app images
run: ./build.sh
working-directory: web-apps

- name: Create Kind Cluster
uses: helm/kind-action@v1
with:
cluster-name: ${{ env.CLUSTER_NAME }}

- name: Load local docker images into kind cluster
run: |
IMAGE_NAMES=$(docker image ls | grep ghcr.io/stackhpc/azimuth-llm- | awk '{print $1}')
kind load docker-image $IMAGE_NAMES -n ${{ env.CLUSTER_NAME }}
- name: Add Helm repos for dependencies
run: |
helm repo add stakater https://stakater.github.io/stakater-charts
# https://github.com/helm/charts/blob/master/test/README.md#providing-custom-test-values
# Each chart/ci/*-values.yaml file will be treated as a separate test case with it's
# own helm install/test process.
- name: Run chart install and test
run: ct install --config ct.yaml

5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ __pycache__/

# Ignore local dev helpers
test-values.y[a]ml
chart/web-app/settings.yml
gradio-client-test.py
**venv*/


# Helm chart stuff
chart/Chart.lock
chart/charts
chart/charts
4 changes: 2 additions & 2 deletions chart/.helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ venv/
__pycache__/
images/
.hf-token.secret
hu-poc/
test-values.yaml
web-app/settings.yml
web-app/example-settings.yml
web-app/example-settings.yml
ci/
6 changes: 5 additions & 1 deletion chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
apiVersion: v2
name: azimuth-llm
description: HuggingFace LLM model serving along with a simple web interface.
maintainers:
- name: "Scott Davidson"
email: [email protected]
url: https://github.com/sd109

# A chart can be either an 'application' or a 'library' chart.
#
Expand Down Expand Up @@ -32,4 +36,4 @@ dependencies:
- name: reloader
version: 1.0.63
repository: https://stakater.github.io/stakater-charts
condition: ui.enabled
condition: ui.enabled
13 changes: 13 additions & 0 deletions chart/ci/web-apps-only-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
api:
enabled: false
ui:
image:
repository: ghcr.io/stackhpc/azimuth-llm-chat-interface
tag: latest
imagePullPolicy: Never
service:
zenith:
enabled: false
appSettings:
hf_model_name: AMead10/c4ai-command-r-08-2024-awq
backend_url: https://llm3-compute.cms.hu-berlin.de
23 changes: 23 additions & 0 deletions chart/templates/test/end-to-end.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{- if .Values.api.enabled -}}
apiVersion: batch/v1
kind: Job
metadata:
name: gradio-client-response
annotations:
"helm.sh/hook": test
spec:
template:
spec:
containers:
- name: gradio-client-test
image: ghcr.io/stackhpc/azimuth-llm-chat-interface
imagePullPolicy: IfNotPresent
command:
- python
- gradio-client-test.py
- http://{{ .Values.ui.service.name }}.{{ .Release.Namespace }}.svc
restartPolicy: Never
# Allow plenty of retries since downloading
# model weights can take a long time.
backoffLimit: 10
{{- end -}}
22 changes: 22 additions & 0 deletions chart/templates/test/web-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{- if not .Values.api.enabled -}}
apiVersion: batch/v1
kind: Job
metadata:
name: web-app-liveness
annotations:
"helm.sh/hook": test
spec:
template:
spec:
containers:
- name: web-app-test
image: nicolaka/netshoot:v0.12
imagePullPolicy: IfNotPresent
command:
- nc
- -vz
- {{ .Values.ui.service.name }}.{{ .Release.Namespace }}.svc
- "80"
restartPolicy: Never
backoffLimit: 3
{{- end -}}
5 changes: 2 additions & 3 deletions chart/templates/ui/app-config-map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ metadata:
labels:
{{- include "azimuth-llm.labels" . | nindent 4 }}
data:
{{ (.Files.Glob "web-app/*").AsConfig | nindent 2 }}
settings.yml: |
overrides.yml: |
{{- .Values.ui.appSettings | toYaml | nindent 4 }}
{{- end -}}
{{- end -}}
11 changes: 3 additions & 8 deletions chart/templates/ui/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,20 @@ spec:
containers:
- name: {{ .Release.Name }}-ui
image: {{ printf "%s:%s" .Values.ui.image.repository .Values.ui.image.version }}
imagePullPolicy: {{ .Values.ui.image.imagePullPolicy }}
ports:
- name: ui
containerPort: 7680
workingDir: /etc/web-app
containerPort: 7860
volumeMounts:
- name: app
mountPath: /etc/web-app
command:
- python
args:
- {{ .Values.ui.entrypoint }}
- {{ .Values.huggingface.model }}
env:
- name: PYTHONUNBUFFERED
value: "1"
tty: true # Make stdout from python visible in k8s logs
readinessProbe:
tcpSocket:
port: 7680
port: 7860
periodSeconds: 5
volumes:
- name: app
Expand Down
7 changes: 5 additions & 2 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ ui:
- Arial
# Container image config
image:
repository: ghcr.io/stackhpc/azimuth-llm-ui-base
version: "0.3.0"
# repository: ghcr.io/stackhpc/azimuth-llm-ui-base
# version: "0.3.0"
repository: azimuth-llm-chat-interface
version: latest
imagePullPolicy: IfNotPresent
# Service config
service:
name: web-app
Expand Down
73 changes: 0 additions & 73 deletions chart/web-app/config.py

This file was deleted.

Loading

0 comments on commit 27887b9

Please sign in to comment.