diff --git a/helm/mautrix-whatsapp/.editorconfig b/helm/mautrix-whatsapp/.editorconfig new file mode 100644 index 0000000..d2097f2 --- /dev/null +++ b/helm/mautrix-whatsapp/.editorconfig @@ -0,0 +1,2 @@ +[*.{yaml,yml}] +indent_size = 2 diff --git a/helm/mautrix-whatsapp/.gitignore b/helm/mautrix-whatsapp/.gitignore new file mode 100644 index 0000000..3685de0 --- /dev/null +++ b/helm/mautrix-whatsapp/.gitignore @@ -0,0 +1,2 @@ +charts/* +!*.yaml diff --git a/helm/mautrix-whatsapp/.helmignore b/helm/mautrix-whatsapp/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/helm/mautrix-whatsapp/.helmignore @@ -0,0 +1,22 @@ +# 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 +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/helm/mautrix-whatsapp/Chart.yaml b/helm/mautrix-whatsapp/Chart.yaml new file mode 100644 index 0000000..2cf274c --- /dev/null +++ b/helm/mautrix-whatsapp/Chart.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +name: mautrix-whatsapp +version: 0.1.0 +appVersion: "0.1.0" +description: A Matrix-Whatsapp puppeting bridge. +keywords: + - matrix + - bridge + - whatsapp +maintainers: + - name: Tulir Asokan + email: tulir@maunium.net +sources: + - https://github.com/tulir/mautrix-whatsapp diff --git a/helm/mautrix-whatsapp/requirements.lock b/helm/mautrix-whatsapp/requirements.lock new file mode 100644 index 0000000..c8aa53a --- /dev/null +++ b/helm/mautrix-whatsapp/requirements.lock @@ -0,0 +1,6 @@ +dependencies: +- name: postgresql + repository: https://kubernetes-charts.storage.googleapis.com/ + version: 6.5.0 +digest: sha256:85139e9d4207e49c11c5f84d7920d0135cffd3d427f3f3638d4e51258990de2a +generated: "2019-10-23T22:11:37.005827507+03:00" diff --git a/helm/mautrix-whatsapp/requirements.yaml b/helm/mautrix-whatsapp/requirements.yaml new file mode 100644 index 0000000..1545fe2 --- /dev/null +++ b/helm/mautrix-whatsapp/requirements.yaml @@ -0,0 +1,5 @@ +dependencies: + - name: postgresql + version: 6.5.0 + repository: https://kubernetes-charts.storage.googleapis.com/ + condition: postgresql.enabled diff --git a/helm/mautrix-whatsapp/templates/NOTES.txt b/helm/mautrix-whatsapp/templates/NOTES.txt new file mode 100644 index 0000000..58b07ce --- /dev/null +++ b/helm/mautrix-whatsapp/templates/NOTES.txt @@ -0,0 +1,12 @@ +Your registration file is below. Save it into a YAML file and give the path to that file to synapse: + +id: {{ .Values.appservice.id }} +as_token: {{ .Values.appservice.asToken }} +hs_token: {{ .Values.appservice.hsToken }} +namespaces: + users: + - exclusive: true + regex: "@{{ .Values.bridge.username_template | replace "{{.}}" ".+"}}:{{ .Values.homeserver.domain }}" +url: {{ .Values.appservice.address }} +sender_localpart: {{ .Values.appservice.botUsername }} +rate_limited: false diff --git a/helm/mautrix-whatsapp/templates/_helpers.tpl b/helm/mautrix-whatsapp/templates/_helpers.tpl new file mode 100644 index 0000000..1255560 --- /dev/null +++ b/helm/mautrix-whatsapp/templates/_helpers.tpl @@ -0,0 +1,55 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "mautrix-whatsapp.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-whatsapp.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-whatsapp.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "mautrix-whatsapp.labels" -}} +app.kubernetes.io/name: {{ include "mautrix-whatsapp.name" . }} +helm.sh/chart: {{ include "mautrix-whatsapp.chart" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} + +{{/* +Create the name of the service account to use +*/}} +{{- define "mautrix-whatsapp.serviceAccountName" -}} +{{- if .Values.serviceAccount.create -}} + {{ default (include "mautrix-whatsapp.fullname" .) .Values.serviceAccount.name }} +{{- else -}} + {{ default "default" .Values.serviceAccount.name }} +{{- end -}} +{{- end -}} diff --git a/helm/mautrix-whatsapp/templates/configmap.yaml b/helm/mautrix-whatsapp/templates/configmap.yaml new file mode 100644 index 0000000..9abd656 --- /dev/null +++ b/helm/mautrix-whatsapp/templates/configmap.yaml @@ -0,0 +1,45 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "mautrix-whatsapp.fullname" . }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/name: {{ template "mautrix-whatsapp.name" . }} +data: + config.yaml: | + homeserver: + address: {{ .Values.homeserver.address }} + domain: {{ .Values.homeserver.domain }} + + appservice: + address: http://{{ include "mautrix-whatsapp.fullname" . }}:{{ .Values.service.port }} + + hostname: 0.0.0.0 + port: {{ .Values.service.port }} + + {{- if .Values.postgresql.enabled }} + database: + type: postgres + uri: "postgres://postgres:{{ .Values.postgresql.postgresqlPassword }}@{{ .Release.Name }}-postgresql/{{ .Values.postgresql.postgresqlDatabase }}?sslmode=disable" + {{- else }} + database: + {{- toYaml .Values.appservice.database | nindent 8 }} + {{- end }} + + id: {{ .Values.appservice.id }} + bot: + username: {{ .Values.appservice.botUsername }} + displayname: {{ .Values.appservice.botDisplayname }} + avatar: {{ .Values.appservice.botAvatar }} + + as_token: {{ .Values.appservice.asToken }} + hs_token: {{ .Values.appservice.hsToken }} + + bridge: + {{- toYaml .Values.bridge | nindent 6 }} + + logging: + {{- toYaml .Values.logging | nindent 6 }} + registration.yaml: "" diff --git a/helm/mautrix-whatsapp/templates/deployment.yaml b/helm/mautrix-whatsapp/templates/deployment.yaml new file mode 100644 index 0000000..0bd5581 --- /dev/null +++ b/helm/mautrix-whatsapp/templates/deployment.yaml @@ -0,0 +1,69 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "mautrix-whatsapp.fullname" . }} + labels: + {{- include "mautrix-whatsapp.labels" . | nindent 4 }} +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: {{ include "mautrix-whatsapp.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + {{- if .Values.podAnnotations }} + annotations: + {{- toYaml .Values.podAnnotations | nindent 6 }} + {{- end }} + metadata: + labels: + app.kubernetes.io/name: {{ include "mautrix-whatsapp.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + serviceAccountName: {{ template "mautrix-whatsapp.serviceAccountName" . }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + volumeMounts: + - mountPath: /data + name: config-volume + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP +# livenessProbe: +# httpGet: +# path: /_matrix/mau/live +# port: http +# initialDelaySeconds: 60 +# periodSeconds: 5 +# readinessProbe: +# httpGet: +# path: /_matrix/mau/ready +# port: http +# initialDelaySeconds: 60 +# periodSeconds: 5 + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumes: + - name: config-volume + configMap: + name: {{ template "mautrix-whatsapp.fullname" . }} + + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/helm/mautrix-whatsapp/templates/service.yaml b/helm/mautrix-whatsapp/templates/service.yaml new file mode 100644 index 0000000..94145e7 --- /dev/null +++ b/helm/mautrix-whatsapp/templates/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "mautrix-whatsapp.fullname" . }} + labels: +{{ include "mautrix-whatsapp.labels" . | indent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + app.kubernetes.io/name: {{ include "mautrix-whatsapp.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/helm/mautrix-whatsapp/templates/serviceaccount.yaml b/helm/mautrix-whatsapp/templates/serviceaccount.yaml new file mode 100644 index 0000000..57903c5 --- /dev/null +++ b/helm/mautrix-whatsapp/templates/serviceaccount.yaml @@ -0,0 +1,8 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ template "mautrix-whatsapp.serviceAccountName" . }} + labels: +{{ include "mautrix-whatsapp.labels" . | indent 4 }} +{{- end -}} diff --git a/helm/mautrix-whatsapp/values.yaml b/helm/mautrix-whatsapp/values.yaml new file mode 100644 index 0000000..521129e --- /dev/null +++ b/helm/mautrix-whatsapp/values.yaml @@ -0,0 +1,132 @@ +image: + repository: dock.mau.dev/tulir/mautrix-whatsapp + tag: latest + pullPolicy: IfNotPresent + +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: + +service: + type: ClusterIP + port: 29318 + +resources: {} + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +# Postgres pod configs +postgresql: + enabled: true + postgresqlDatabase: mxtg + persistence: + size: 2Gi + resources: + requests: + memory: 256Mi + cpu: 100m + +# Homeserver details +homeserver: + # The address that this appservice can use to connect to the homeserver. + address: https://example.com + # The domain of the homeserver (for MXIDs, etc). + domain: example.com + +# Application service host/registration related details +# Changing these values requires regeneration of the registration. +appservice: + id: whatsapp + botUsername: whatsappbot + # Display name and avatar for bot. Set to "remove" to remove display name/avatar, leave empty + # to leave display name/avatar as-is. + botDisplayname: WhatsApp bridge bot + botAvatar: mxc://maunium.net/NeXNQarUbrlYBiPCpprYsRqr + + # Authentication tokens for AS <-> HS communication. Autogenerated; do not modify. + asToken: SET TO RANDOM STRING + hsToken: SET TO RANDOM STRING + +# The keys below can be used to override the configs in the base config: +# https://github.com/tulir/mautrix-whatsapp/blob/master/example-config.yaml +# Note that the "appservice" and "homeserver" sections are above and slightly different than the base. + +# Bridge config +bridge: + # Localpart template of MXIDs for WhatsApp users. + # {{.}} is replaced with the phone number of the WhatsApp user. + username_template: whatsapp_{{.}} + + # Number of chats to sync for new users. + initial_chat_sync_count: 10 + # Number of old messages to fill when creating new portal rooms. + initial_history_fill_count: 20 + # Maximum number of chats to sync when recovering from downtime. + # Set to -1 to sync all new chats during downtime. + recovery_chat_sync_limit: -1 + # Whether or not to sync history when recovering from downtime. + recovery_history_backfill: true + # Maximum number of seconds since last message in chat to skip + # syncing the chat in any case. This setting will take priority + # over both recovery_chat_sync_limit and initial_chat_sync_count. + # Default is 3 days = 259200 seconds + sync_max_chat_age: 259200 + + # Whether or not to explicitly set the avatar and room name for private + # chat portal rooms. This can be useful if the previous field works fine, + # but causes room avatar/name bugs. + private_chat_portal_meta: true + + # Allow invite permission for user. User can invite any bots to room with whatsapp + # users (private chat and groups) + allow_user_invite: true + + # Permissions for using the bridge. + # Permitted values: + # relaybot - Talk through the relaybot (if enabled), no access otherwise + # user - Access to use the bridge to chat with a WhatsApp account. + # admin - User level and some additional administration tools + # Permitted keys: + # * - All Matrix users + # domain - All users on that homeserver + # mxid - Specific user + permissions: + "*": relaybot + "example.com": user + "@admin:example.com": admin + + relaybot: + # Whether or not relaybot support is enabled. + enabled: false + # The management room for the bot. This is where all status notifications are posted and + # in this room, you can use `!wa ` instead of `!wa relaybot `. Omitting + # the command prefix completely like in user management rooms is not possible. + management: !foo:example.com + # List of users to invite to all created rooms that include the relaybot. + invites: [] + # The formats to use when sending messages to WhatsApp via the relaybot. + message_formats: + m.text: "{{ .Sender.Displayname }}: {{ .Message }}" + m.notice: "{{ .Sender.Displayname }}: {{ .Message }}" + m.emote: "* {{ .Sender.Displayname }} {{ .Message }}" + m.file: "{{ .Sender.Displayname }} sent a file" + m.image: "{{ .Sender.Displayname }} sent an image" + m.audio: "{{ .Sender.Displayname }} sent an audio file" + m.video: "{{ .Sender.Displayname }} sent a video" + m.location: "{{ .Sender.Displayname }} sent a location"