Skip to content

Commit 441facb

Browse files
DavidKellyonGitHubyGuy
authored andcommitted
add helm chart
1 parent 4cae8f9 commit 441facb

File tree

7 files changed

+222
-0
lines changed

7 files changed

+222
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,18 @@ docker compose down
165165
```
166166

167167

168+
## Deploy to Kubernetes with Helm
169+
The chatgpt-bot-chart deploys a containerized chatgpt-bot instance which will connect to a running mattermost container in the same kubernetes cluster. Chart uses 'mattermost-team-edition' and the 'mattermost' namespace by default. Uses environment variables MATTERMOST_TOKEN and OPENAI_API_KEY.
170+
```bash
171+
helm upgrade chatgpt-bot ./helm/chatgpt-bot-chart \
172+
--create-namespace \
173+
--install \
174+
-n mattermost \
175+
-f ./helm/chatgpt-bot-chart/values.yaml \
176+
--set chatbot.mattermostToken="$MATTERMOST_TOKEN" \
177+
--set chatbot.openaiApiKey="$OPENAI_API_KEY"
178+
```
179+
168180
## Example Conversation
169181

170182
Here's an example chat that I just had with our bot:

helm/chatgpt-bot-chart/Chart.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: chatgpt-bot-chart
3+
description: A Helm chart for Kubernetes
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.1.0
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: 0.0.0
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "chatgpt-bot-chart.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 "chatgpt-bot-chart.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 "chatgpt-bot-chart.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "chatgpt-bot-chart.labels" -}}
37+
helm.sh/chart: {{ include "chatgpt-bot-chart.chart" . }}
38+
{{ include "chatgpt-bot-chart.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "chatgpt-bot-chart.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "chatgpt-bot-chart.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "chatgpt-bot-chart.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "chatgpt-bot-chart.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: {{ include "chatgpt-bot-chart.fullname" . }}-secret
5+
data:
6+
MATTERMOST_TOKEN: {{ .Values.chatbot.mattermostToken | b64enc }}
7+
OPENAI_API_KEY: {{ .Values.chatbot.openaiApiKey | b64enc }}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "chatgpt-bot-chart.fullname" . }}
5+
labels:
6+
{{- include "chatgpt-bot-chart.labels" . | nindent 4 }}
7+
spec:
8+
{{- if not .Values.autoscaling.enabled }}
9+
replicas: {{ .Values.replicaCount }}
10+
{{- end }}
11+
selector:
12+
matchLabels:
13+
{{- include "chatgpt-bot-chart.selectorLabels" . | nindent 6 }}
14+
template:
15+
metadata:
16+
{{- with .Values.podAnnotations }}
17+
annotations:
18+
{{- toYaml . | nindent 8 }}
19+
{{- end }}
20+
labels:
21+
{{- include "chatgpt-bot-chart.selectorLabels" . | nindent 8 }}
22+
spec:
23+
{{- with .Values.imagePullSecrets }}
24+
imagePullSecrets:
25+
{{- toYaml . | nindent 8 }}
26+
{{- end }}
27+
serviceAccountName: {{ include "chatgpt-bot-chart.serviceAccountName" . }}
28+
securityContext:
29+
{{- toYaml .Values.podSecurityContext | nindent 8 }}
30+
containers:
31+
- name: {{ .Chart.Name }}
32+
securityContext:
33+
{{- toYaml .Values.securityContext | nindent 12 }}
34+
image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
35+
imagePullPolicy: {{ .Values.image.pullPolicy }}
36+
env:
37+
- name: MATTERMOST_URL
38+
value: {{ .Values.mattermost.clusterUrl }}:{{ .Values.mattermost.port }}
39+
envFrom:
40+
- secretRef:
41+
name: {{ include "chatgpt-bot-chart.fullname" . }}-secret
42+
ports:
43+
- name: http
44+
containerPort: {{ .Values.service.port }}
45+
protocol: TCP
46+
resources:
47+
{{- toYaml .Values.resources | nindent 12 }}
48+
{{- with .Values.nodeSelector }}
49+
nodeSelector:
50+
{{- toYaml . | nindent 8 }}
51+
{{- end }}
52+
{{- with .Values.affinity }}
53+
affinity:
54+
{{- toYaml . | nindent 8 }}
55+
{{- end }}
56+
{{- with .Values.tolerations }}
57+
tolerations:
58+
{{- toYaml . | nindent 8 }}
59+
{{- end }}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{{- if .Values.serviceAccount.create -}}
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
name: {{ include "chatgpt-bot-chart.serviceAccountName" . }}
6+
labels:
7+
{{- include "chatgpt-bot-chart.labels" . | nindent 4 }}
8+
{{- with .Values.serviceAccount.annotations }}
9+
annotations:
10+
{{- toYaml . | nindent 4 }}
11+
{{- end }}
12+
{{- end }}

helm/chatgpt-bot-chart/values.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
mattermost:
2+
# <your-mattermost-service-name>.<namespace-where-service-is-deployed>.svc.cluster.local
3+
clusterUrl: http://mattermost-team-edition.mattermost.svc.cluster.local
4+
port: 8065
5+
6+
replicaCount: 1
7+
8+
image:
9+
registry: ghcr.io/yguy
10+
repository: chatgpt-mattermost-bot
11+
pullPolicy: IfNotPresent
12+
# Overrides the image tag whose default is the chart appVersion.
13+
tag: "latest"
14+
15+
imagePullSecrets: []
16+
nameOverride: ""
17+
fullnameOverride: "chatgpt-bot"
18+
19+
serviceAccount:
20+
create: true
21+
annotations: {}
22+
name: ""
23+
24+
podAnnotations: {}
25+
26+
podSecurityContext: {}
27+
28+
securityContext: {}
29+
30+
service:
31+
type: ClusterIP
32+
port: 80
33+
34+
resources: {}
35+
36+
autoscaling:
37+
enabled: false
38+
minReplicas: 1
39+
maxReplicas: 100
40+
targetCPUUtilizationPercentage: 80
41+
42+
nodeSelector: {}
43+
44+
tolerations: []
45+
46+
affinity: {}

0 commit comments

Comments
 (0)