diff --git a/.gitignore b/.gitignore index b0f060c..5b7d5b8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,8 @@ /build /dist -*.yaml +config.yaml +registration.yaml !example-config.yaml *.log diff --git a/helm/mautrix-twilio/.editorconfig b/helm/mautrix-twilio/.editorconfig new file mode 100644 index 0000000..d2097f2 --- /dev/null +++ b/helm/mautrix-twilio/.editorconfig @@ -0,0 +1,2 @@ +[*.{yaml,yml}] +indent_size = 2 diff --git a/helm/mautrix-twilio/.helmignore b/helm/mautrix-twilio/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/helm/mautrix-twilio/.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-twilio/Chart.yaml b/helm/mautrix-twilio/Chart.yaml new file mode 100644 index 0000000..bb67fec --- /dev/null +++ b/helm/mautrix-twilio/Chart.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +name: mautrix-twilio +version: 0.1.0 +appVersion: "0.1.0" +description: A Matrix-Twilio relaybot bridge. +keywords: + - matrix + - bridge + - twilio + - whatsapp +maintainers: + - name: Tulir Asokan + email: tulir@maunium.net +sources: + - https://github.com/tulir/mautrix-twilio diff --git a/helm/mautrix-twilio/templates/NOTES.txt b/helm/mautrix-twilio/templates/NOTES.txt new file mode 100644 index 0000000..cc345a0 --- /dev/null +++ b/helm/mautrix-twilio/templates/NOTES.txt @@ -0,0 +1,21 @@ +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 "{userid}" ".+"}}:{{ .Values.homeserver.domain }}" + {{- if .Values.appservice.communityID }} + group_id: {{ .Values.appservice.communityID }} + {{- end }} + aliases: + - exclusive: true + regex: "@{{ .Values.bridge.alias_template | replace "{groupname}" ".+"}}:{{ .Values.homeserver.domain }}" + {{- if .Values.appservice.communityID }} + group_id: {{ .Values.appservice.communityID }} + {{- end }} +url: {{ .Values.appservice.address }} +sender_localpart: {{ .Values.appservice.botUsername }} +rate_limited: false diff --git a/helm/mautrix-twilio/templates/_helpers.tpl b/helm/mautrix-twilio/templates/_helpers.tpl new file mode 100644 index 0000000..06ce910 --- /dev/null +++ b/helm/mautrix-twilio/templates/_helpers.tpl @@ -0,0 +1,55 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "mautrix-twilio.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-twilio.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-twilio.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "mautrix-twilio.labels" -}} +app.kubernetes.io/name: {{ include "mautrix-twilio.name" . }} +helm.sh/chart: {{ include "mautrix-twilio.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-twilio.serviceAccountName" -}} +{{- if .Values.serviceAccount.create -}} + {{ default (include "mautrix-twilio.fullname" .) .Values.serviceAccount.name }} +{{- else -}} + {{ default "default" .Values.serviceAccount.name }} +{{- end -}} +{{- end -}} diff --git a/helm/mautrix-twilio/templates/configmap.yaml b/helm/mautrix-twilio/templates/configmap.yaml new file mode 100644 index 0000000..6a5dc4c --- /dev/null +++ b/helm/mautrix-twilio/templates/configmap.yaml @@ -0,0 +1,51 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "mautrix-twilio.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-twilio.name" . }} +data: + config.yaml: | + homeserver: + address: {{ .Values.homeserver.address }} + public_address: {{ .Values.homeserver.publicAddress }} + domain: {{ .Values.homeserver.domain }} + verify_ssl: {{ .Values.homeserver.verifySSL }} + + appservice: + address: http://{{ include "mautrix-twilio.fullname" . }}:{{ .Values.service.port }} + + hostname: 0.0.0.0 + port: {{ .Values.service.port }} + max_body_size: {{ .Values.appservice.maxBodySize }} + + database: {{ .Values.appservice.database }} + + public: + {{- toYaml .Values.appservice.public | nindent 8 }} + + provisioning: + {{- toYaml .Values.appservice.provisioning | nindent 8 }} + + id: {{ .Values.appservice.id }} + bot_username: {{ .Values.appservice.botUsername }} + bot_displayname: {{ .Values.appservice.botDisplayname }} + bot_avatar: {{ .Values.appservice.botAvatar }} + + community_id: {{ .Values.appservice.communityID }} + + as_token: {{ .Values.appservice.asToken }} + hs_token: {{ .Values.appservice.hsToken }} + + bridge: + {{- toYaml .Values.bridge | nindent 6 }} + + twilio: + {{- toYaml .Values.twilio | nindent 6 }} + + logging: + {{- toYaml .Values.logging | nindent 6 }} + registration.yaml: "" diff --git a/helm/mautrix-twilio/templates/deployment.yaml b/helm/mautrix-twilio/templates/deployment.yaml new file mode 100644 index 0000000..2e744ab --- /dev/null +++ b/helm/mautrix-twilio/templates/deployment.yaml @@ -0,0 +1,65 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "mautrix-twilio.fullname" . }} + labels: + {{- include "mautrix-twilio.labels" . | nindent 4 }} +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: {{ include "mautrix-twilio.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-twilio.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + serviceAccountName: {{ template "mautrix-twilio.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: / +# port: http +# readinessProbe: +# httpGet: +# path: / +# port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumes: + - name: config-volume + configMap: + name: {{ template "mautrix-twilio.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-twilio/templates/service.yaml b/helm/mautrix-twilio/templates/service.yaml new file mode 100644 index 0000000..f429fb4 --- /dev/null +++ b/helm/mautrix-twilio/templates/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "mautrix-twilio.fullname" . }} + labels: +{{ include "mautrix-twilio.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-twilio.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/helm/mautrix-twilio/templates/serviceaccount.yaml b/helm/mautrix-twilio/templates/serviceaccount.yaml new file mode 100644 index 0000000..9c9bf72 --- /dev/null +++ b/helm/mautrix-twilio/templates/serviceaccount.yaml @@ -0,0 +1,8 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ template "mautrix-twilio.serviceAccountName" . }} + labels: +{{ include "mautrix-twilio.labels" . | indent 4 }} +{{- end -}} diff --git a/helm/mautrix-twilio/values.yaml b/helm/mautrix-twilio/values.yaml new file mode 100644 index 0000000..e993b07 --- /dev/null +++ b/helm/mautrix-twilio/values.yaml @@ -0,0 +1,117 @@ +image: + repository: dock.mau.dev/tulir/mautrix-twilio + 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: 29322 + +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: {} + +# Homeserver details +homeserver: + # The address that this appservice can use to connect to the homeserver. + address: https://example.com + # The address that Twilio can use to download media from the homeserver. + publicAddress: https://matrix.example.com + # The domain of the homeserver (for MXIDs, etc). + domain: example.com + # Whether or not to verify the SSL certificate of the homeserver. + # Only applies if address starts with https:// + verifySSL: true + +# Application service host/registration related details +# Changing these values requires regeneration of the registration. +appservice: + # The full URI to the database. SQLite and Postgres are fully supported. + # Other DBMSes supported by SQLAlchemy may or may not work. + # Format examples: + # SQLite: sqlite:///filename.db + # Postgres: postgres://username:password@hostname/dbname + database: postgres://username:password@hostname/dbname + + # The maximum body size of appservice API requests (from the homeserver) in mebibytes + # Usually 1 is enough, but on high-traffic bridges you might need to increase this to avoid 413s + maxBodySize: 1 + + id: twilio + botUsername: twiliobot + # Display name and avatar for bot. Set to "remove" to remove display name/avatar, leave empty + # to leave display name/avatar as-is. + botDisplayname: Twilio bridge bot + botAvatar: mxc://maunium.net/FYuKJHaCrSeSpvBJfHwgYylP + + # Community ID for bridged users (changes registration file) and rooms. + # Must be created manually. + communityID: false + + # 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-twilio/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 remote users. + # {userid} is replaced with the phone number of the user (plain/E.164 international format). + username_template: "twilio_whatsapp_{userid}" + # Displayname template for remote users. + # {displayname} is replaced with the phone number of the user (human-readable international format). + alias_template: "twilio_whatsapp_{groupname}" + + # List of users to always invite to newly created portal rooms. + invite_users: [] + + # Permissions for using the bridge. + # Permitted values: + # user - Use the bridge with puppeting. + # admin - Use and administrate the bridge. + # Permitted keys: + # * - All Matrix users + # domain - All users on that homeserver + # mxid - Specific user + permissions: + "example.com": "user" + "@admin:example.com": "admin" + +# Twilio webhook settings. +twilio: + # Twilio account ID + account_id: AC1082dcd0e9ae51404f6cae3581edfbff + # Twilio phone number to send messages from. + sender_id: whatsapp:+1415550199 + # Your Twilio auth token (get from Twilio dashboard front page) + secret: 2035141f21a001604e763c009aa3be4c + # Path prefix for webhook endpoints. Subpaths are /status and /receive. + # Note that the webhook must be put behind a reverse proxy with https. + webhook_path: /twilio