From 2a1762b96897e7a2b951650ae5b7c69dbfb54612 Mon Sep 17 00:00:00 2001 From: Alex Manning Date: Fri, 1 Mar 2024 20:43:56 +0000 Subject: [PATCH] Add a mautrix-meta bridge. --- .woodpecker/mautrix-meta.yaml | 12 +++ charts/mautrix-meta/.helmignore | 23 +++++ charts/mautrix-meta/Chart.yaml | 7 ++ charts/mautrix-meta/templates/_helpers.tpl | 62 +++++++++++++ charts/mautrix-meta/templates/secret.yaml | 11 +++ charts/mautrix-meta/templates/service.yaml | 16 ++++ .../mautrix-meta/templates/statefulset.yaml | 87 +++++++++++++++++++ charts/mautrix-meta/values.yaml | 58 +++++++++++++ 8 files changed, 276 insertions(+) create mode 100644 .woodpecker/mautrix-meta.yaml create mode 100644 charts/mautrix-meta/.helmignore create mode 100644 charts/mautrix-meta/Chart.yaml create mode 100644 charts/mautrix-meta/templates/_helpers.tpl create mode 100644 charts/mautrix-meta/templates/secret.yaml create mode 100644 charts/mautrix-meta/templates/service.yaml create mode 100644 charts/mautrix-meta/templates/statefulset.yaml create mode 100644 charts/mautrix-meta/values.yaml diff --git a/.woodpecker/mautrix-meta.yaml b/.woodpecker/mautrix-meta.yaml new file mode 100644 index 0000000..ce631ab --- /dev/null +++ b/.woodpecker/mautrix-meta.yaml @@ -0,0 +1,12 @@ +--- +when: + path: "charts/mautrix-meta/**" + branch: main +steps: + package: + image: "docker.io/alpine/helm:latest" + secrets: [helm_user, helm_password, helm_repo] + commands: + - helm plugin install https://github.com/chartmuseum/helm-push + - helm repo add therepo $HELM_REPO --username $HELM_USER --password $HELM_PASSWORD + - helm cm-push charts/mautrix-meta therepo diff --git a/charts/mautrix-meta/.helmignore b/charts/mautrix-meta/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/mautrix-meta/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/mautrix-meta/Chart.yaml b/charts/mautrix-meta/Chart.yaml new file mode 100644 index 0000000..7c689db --- /dev/null +++ b/charts/mautrix-meta/Chart.yaml @@ -0,0 +1,7 @@ +apiVersion: v2 +name: mautrix-meta +description: meta <-> matrix bridge +type: application + +version: 0.0.1 +appVersion: "v0.1.0" diff --git a/charts/mautrix-meta/templates/_helpers.tpl b/charts/mautrix-meta/templates/_helpers.tpl new file mode 100644 index 0000000..fba69aa --- /dev/null +++ b/charts/mautrix-meta/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "mautrix-meta.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "mautrix-meta.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "mautrix-meta.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "mautrix-meta.labels" -}} +helm.sh/chart: {{ include "mautrix-meta.chart" . }} +{{ include "mautrix-meta.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "mautrix-meta.selectorLabels" -}} +app.kubernetes.io/name: {{ include "mautrix-meta.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "mautrix-meta.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "mautrix-meta.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/mautrix-meta/templates/secret.yaml b/charts/mautrix-meta/templates/secret.yaml new file mode 100644 index 0000000..316aefd --- /dev/null +++ b/charts/mautrix-meta/templates/secret.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "mautrix-meta.fullname" . }} + labels: + {{- include "mautrix-meta.labels" . | nindent 4 }} +type: Opaque +stringData: + config.yaml: | + {{- fromYaml .Values.config | toYaml | nindent 4 }} + registration.yaml: "" diff --git a/charts/mautrix-meta/templates/service.yaml b/charts/mautrix-meta/templates/service.yaml new file mode 100644 index 0000000..2cd0e06 --- /dev/null +++ b/charts/mautrix-meta/templates/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "mautrix-meta.fullname" . }}-appservice-nocollide + labels: + {{- include "mautrix-meta.labels" . | nindent 4 }} +spec: + publishNotReadyAddresses: true + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: appservice + protocol: TCP + name: appservice + selector: + {{- include "mautrix-meta.selectorLabels" . | nindent 4 }} diff --git a/charts/mautrix-meta/templates/statefulset.yaml b/charts/mautrix-meta/templates/statefulset.yaml new file mode 100644 index 0000000..8292f2c --- /dev/null +++ b/charts/mautrix-meta/templates/statefulset.yaml @@ -0,0 +1,87 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ include "mautrix-meta.fullname" . }} + labels: + {{- include "mautrix-meta.labels" . | nindent 4 }} +spec: + serviceName: {{ include "mautrix-meta.fullname" . }}-appservice-nocollide + revisionHistoryLimit: {{ .Values.revisionHistoryLimit }} + replicas: 1 + selector: + matchLabels: + {{- include "mautrix-meta.selectorLabels" . | nindent 6 }} + template: + metadata: + annotations: + checksum/config: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }} + {{- with .Values.podAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "mautrix-meta.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: appservice + containerPort: 29319 + protocol: TCP + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - name: mainconfig + readOnly: true + mountPath: "/data" + - name: tmp + mountPath: "/tmp" + workingDir: "/data" + command: + - "/usr/bin/mautrix-meta" + - --no-update + startupProbe: + httpGet: + port: appservice + path: "/_matrix/mau/live" + periodSeconds: 10 + failureThreshold: 60 + livenessProbe: + httpGet: + port: appservice + path: "/_matrix/mau/live" + periodSeconds: 10 + failureThreshold: 12 + readinessProbe: + httpGet: + port: appservice + path: "/_matrix/mau/ready" + periodSeconds: 10 + failureThreshold: 12 + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + volumes: + - name: mainconfig + secret: + secretName: {{ include "mautrix-meta.fullname" . }} + - name: tmp + emptyDir: {} diff --git a/charts/mautrix-meta/values.yaml b/charts/mautrix-meta/values.yaml new file mode 100644 index 0000000..a268bad --- /dev/null +++ b/charts/mautrix-meta/values.yaml @@ -0,0 +1,58 @@ +# Default values for mautrix-meta. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +image: + repository: dock.mau.dev/mautrix/meta + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +revisionHistoryLimit: 5 + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +podAnnotations: {} + +podSecurityContext: + runAsNonRoot: true + +securityContext: + capabilities: + drop: + - ALL + readOnlyRootFilesystem: true + runAsNonRoot: true + runAsUser: 1337 + runAsGroup: 1337 + allowPrivilegeEscalation: false + +service: + type: ClusterIP + port: 29319 + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +# Mautrix-meta configuration must be in the config key here: +# however it is reccomended to keep it in a different file and +# use --set-file config=config.yaml when invoking helm. +# This allows diffing with the example configuration to update it. +config: {}