Skip to content

Commit 999fcfd

Browse files
ops: Create Helm Chart for Medcat Service (#14)
1 parent b4f9ce3 commit 999fcfd

File tree

20 files changed

+780
-7
lines changed

20 files changed

+780
-7
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Kubernetes - Lint, Test, and Publish Helm Charts
2+
3+
on: pull_request
4+
defaults:
5+
run:
6+
working-directory: ./deployment/kubernetes
7+
8+
9+
jobs:
10+
helm-lint-test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Set up Helm
20+
uses: azure/[email protected]
21+
with:
22+
version: v3.17.0
23+
24+
- uses: actions/[email protected]
25+
with:
26+
python-version: '3.x'
27+
check-latest: true
28+
29+
- name: Set up chart-testing
30+
uses: helm/[email protected]
31+
32+
- name: Run chart-testing (list-changed)
33+
id: list-changed
34+
run: |
35+
changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch}})
36+
if [[ -n "$changed" ]]; then
37+
echo "changed=true" >> "$GITHUB_OUTPUT"
38+
fi
39+
40+
- name: Run chart-testing (lint)
41+
if: steps.list-changed.outputs.changed == 'true'
42+
run: ct lint --target-branch ${{ github.event.repository.default_branch }}
43+
44+
- name: Create kind cluster
45+
if: steps.list-changed.outputs.changed == 'true'
46+
uses: helm/[email protected]
47+
48+
- name: Run chart-testing (install)
49+
if: steps.list-changed.outputs.changed == 'true'
50+
run: ct install --target-branch ${{ github.event.repository.default_branch }}
51+
52+
helm-publish:
53+
runs-on: ubuntu-latest
54+
needs: helm-lint-test
55+
env:
56+
CHART_VERSION: 0.0.1
57+
steps:
58+
- name: Log in to Docker Hub
59+
uses: docker/login-action@v1
60+
with:
61+
username: ${{ secrets.DOCKERHUB_USERNAME }}
62+
password: ${{ secrets.DOCKERHUB_TOKEN }}
63+
64+
- name: Set up Helm
65+
uses: azure/[email protected]
66+
with:
67+
version: v3.17.0
68+
69+
- name: Checkout
70+
uses: actions/checkout@v5
71+
72+
- name: Package Helm Charts
73+
run: helm package ./charts/medcat-service-helm --version $CHART_VERSION
74+
75+
- name: Helm OCI login to Docker Hub
76+
run: helm registry login registry-1.docker.io -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }}
77+
78+
- name: Push Helm Chart to Docker Hub OCI
79+
run: |
80+
helm push ./medcat-service-helm-${CHART_VERSION}.tgz oci://registry-1.docker.io/cogstacksystems

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ See the latest documentation on [Readthedocs](https://docs.cogstack.org/en/lates
77
## Project contents
88
- Source for the official cogstack documentation. This git repo stores the top level documetation that hosts on https://docs.cogstack.org
99
- CogStack deployment instructions and examples
10+
- Helm Charts for deployments
1011
- CogStack platform tools eg Observability.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
# Ignore packaged helm charts
3+
*.tgz
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apiVersion: v2
2+
name: medcat-service-helm
3+
description: A Helm chart to deploy CogStack medcat-service
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.0.1
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "latest"
25+
26+
maintainers:
27+
- name: alhendrickson
28+
29+
30+
icon: "https://avatars.githubusercontent.com/u/28688163"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# MedCAT Service Helm Chart
2+
3+
This Helm chart deploys the MedCAT service to a Kubernetes cluster.
4+
5+
## Installation
6+
7+
```sh
8+
helm install my-medcat-service oci://registry-1.docker.io/cogstacksystems/medcat-service-helm
9+
```
10+
11+
## Configuration
12+
13+
You should specify a model pack to be used by the service. By default it will use a small bundled model, which can be used for testing
14+
15+
---
16+
### Option 1: Use the demo model pack
17+
18+
There is a model pack already bundled into medcat service, and is the default in this chart.
19+
20+
This pack is only really used for testing, and has just a few concepts built in.
21+
22+
### Option 2: Download Model on Startup
23+
24+
Enable MedCAT to download the model from a remote URL on container startup.
25+
26+
Create a values file like `values-model-download.yaml` and update the env vars with:
27+
```yaml
28+
env:
29+
ENABLE_MODEL_DOWNLOAD: "true"
30+
MODEL_NAME: "medmen"
31+
MODEL_VOCAB_URL: "https://cogstack-medcat-example-models.s3.eu-west-2.amazonaws.com/medcat-example-models/vocab.dat"
32+
MODEL_CDB_URL: "https://cogstack-medcat-example-models.s3.eu-west-2.amazonaws.com/medcat-example-models/cdb-medmen-v1.dat"
33+
MODEL_META_URL: "https://cogstack-medcat-example-models.s3.eu-west-2.amazonaws.com/medcat-example-models/mc_status.zip"
34+
APP_MODEL_CDB_PATH: "/cat/models/medmen/cdb.dat"
35+
```
36+
37+
Use this if you prefer dynamic loading of models at runtime.
38+
39+
### Option 3: Get a model into a k8s volume, and mount it
40+
41+
The service can use a model pack if you want to setup your own download flow. For example, setup an initContainer pattern that downloads to a volume, then mount the volume yourself.
42+
43+
Use this env variable to point to the file:
44+
45+
Create a values file like `values-model-pack.yaml` and update the env vars with:
46+
```yaml
47+
env:
48+
# This defines the Model Pack used by the medcat service
49+
APP_MEDCAT_MODEL_PACK: "/cat/models/examples/example-medcat-v1-model-pack.zip"
50+
```
51+
52+
## Example
53+
54+
```sh
55+
helm install my-medcat ./medcat-chart -f values-model-pack.yaml
56+
```
57+
58+
or
59+
60+
```sh
61+
helm install my-medcat ./medcat-chart -f values-model-download.yaml
62+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
1. Get the application URL by running these commands:
2+
{{- if .Values.ingress.enabled }}
3+
{{- range $host := .Values.ingress.hosts }}
4+
{{- range .paths }}
5+
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
6+
{{- end }}
7+
{{- end }}
8+
{{- else if contains "NodePort" .Values.service.type }}
9+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "medcat-service.fullname" . }})
10+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
11+
echo http://$NODE_IP:$NODE_PORT
12+
{{- else if contains "LoadBalancer" .Values.service.type }}
13+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
14+
You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "medcat-service.fullname" . }}'
15+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "medcat-service.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
16+
echo http://$SERVICE_IP:{{ .Values.service.port }}
17+
{{- else if contains "ClusterIP" .Values.service.type }}
18+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "medcat-service.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
19+
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
20+
echo "Visit http://127.0.0.1:8080 to use your application"
21+
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT --pod-running-timeout=5m0s
22+
{{- end }}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "medcat-service.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "medcat-service.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "medcat-service.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "medcat-service.labels" -}}
37+
helm.sh/chart: {{ include "medcat-service.chart" . }}
38+
{{ include "medcat-service.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
app.kubernetes.io/part-of: cogstack
44+
{{- end }}
45+
46+
{{/*
47+
Selector labels
48+
*/}}
49+
{{- define "medcat-service.selectorLabels" -}}
50+
app.kubernetes.io/name: {{ include "medcat-service.name" . }}
51+
app.kubernetes.io/instance: {{ .Release.Name }}
52+
{{- end }}
53+
54+
{{/*
55+
Create the name of the service account to use
56+
*/}}
57+
{{- define "medcat-service.serviceAccountName" -}}
58+
{{- if .Values.serviceAccount.create }}
59+
{{- default (include "medcat-service.fullname" .) .Values.serviceAccount.name }}
60+
{{- else }}
61+
{{- default "default" .Values.serviceAccount.name }}
62+
{{- end }}
63+
{{- end }}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "medcat-service.fullname" . }}
5+
labels:
6+
{{- include "medcat-service.labels" . | nindent 4 }}
7+
spec:
8+
{{- if not .Values.autoscaling.enabled }}
9+
replicas: {{ .Values.replicaCount }}
10+
{{- end }}
11+
selector:
12+
matchLabels:
13+
{{- include "medcat-service.selectorLabels" . | nindent 6 }}
14+
template:
15+
metadata:
16+
{{- with .Values.podAnnotations }}
17+
annotations:
18+
{{- toYaml . | nindent 8 }}
19+
{{- end }}
20+
labels:
21+
{{- include "medcat-service.labels" . | nindent 8 }}
22+
{{- with .Values.podLabels }}
23+
{{- toYaml . | nindent 8 }}
24+
{{- end }}
25+
spec:
26+
{{- with .Values.imagePullSecrets }}
27+
imagePullSecrets:
28+
{{- toYaml . | nindent 8 }}
29+
{{- end }}
30+
serviceAccountName: {{ include "medcat-service.serviceAccountName" . }}
31+
{{- with .Values.podSecurityContext }}
32+
securityContext:
33+
{{- toYaml . | nindent 8 }}
34+
{{- end }}
35+
containers:
36+
- name: {{ .Chart.Name }}
37+
{{- with .Values.securityContext }}
38+
securityContext:
39+
{{- toYaml . | nindent 12 }}
40+
{{- end }}
41+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
42+
imagePullPolicy: {{ .Values.image.pullPolicy }}
43+
ports:
44+
- name: http
45+
containerPort: {{ .Values.service.port }}
46+
protocol: TCP
47+
env:
48+
{{- range $key, $value := .Values.envValueFrom }}
49+
- name: {{ $key | quote }}
50+
valueFrom:
51+
{{- tpl (toYaml $value) $ | nindent 10 }}
52+
{{- end }}
53+
{{- range $key, $value := .Values.env }}
54+
- name: "{{ tpl $key $ }}"
55+
value: "{{ tpl (print $value) $ }}"
56+
{{- end }}
57+
{{- with .Values.livenessProbe }}
58+
livenessProbe:
59+
{{- toYaml . | nindent 12 }}
60+
{{- end }}
61+
{{- with .Values.readinessProbe }}
62+
readinessProbe:
63+
{{- toYaml . | nindent 12 }}
64+
{{- end }}
65+
{{- with .Values.startupProbe }}
66+
startupProbe:
67+
{{- toYaml . | nindent 12 }}
68+
{{- end }}
69+
{{- with .Values.resources }}
70+
resources:
71+
{{- toYaml . | nindent 12 }}
72+
{{- end }}
73+
{{- with .Values.volumeMounts }}
74+
volumeMounts:
75+
{{- toYaml . | nindent 12 }}
76+
{{- end }}
77+
{{- with .Values.volumes }}
78+
volumes:
79+
{{- toYaml . | nindent 8 }}
80+
{{- end }}
81+
{{- with .Values.nodeSelector }}
82+
nodeSelector:
83+
{{- toYaml . | nindent 8 }}
84+
{{- end }}
85+
{{- with .Values.affinity }}
86+
affinity:
87+
{{- toYaml . | nindent 8 }}
88+
{{- end }}
89+
{{- with .Values.tolerations }}
90+
tolerations:
91+
{{- toYaml . | nindent 8 }}
92+
{{- end }}

0 commit comments

Comments
 (0)