Skip to content

Commit

Permalink
Merge pull request #77 from small-hack/add-tootctl-elastic-search-index
Browse files Browse the repository at this point in the history
add a cron job for updating elastic search indexing
  • Loading branch information
jessebot authored Oct 25, 2024
2 parents 2cbe818 + 9f675ad commit 7ea39be
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 6 deletions.
2 changes: 1 addition & 1 deletion charts/mastodon/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 9.5.2
version: 9.6.0

# renovate: image=ghcr.io/mastodon/mastodon
appVersion: v4.3.1
Expand Down
7 changes: 5 additions & 2 deletions charts/mastodon/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# mastodon

![Version: 9.5.2](https://img.shields.io/badge/Version-9.5.2-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v4.3.1](https://img.shields.io/badge/AppVersion-v4.3.1-informational?style=flat-square)
![Version: 9.6.0](https://img.shields.io/badge/Version-9.6.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v4.3.1](https://img.shields.io/badge/AppVersion-v4.3.1-informational?style=flat-square)

Mastodon is a free, open-source social network server based on ActivityPub.

Expand Down Expand Up @@ -51,7 +51,10 @@ Mastodon is a free, open-source social network server based on ActivityPub.
| mastodon.alternate_domains | list | `[]` | If you have multiple domains pointed at your Mastodon server, this setting will allow Mastodon to recognize itself when users are addressed using those other domains. |
| mastodon.authorizedFetch | bool | `false` | Enables "Secure Mode" for more details see: https://docs.joinmastodon.org/admin/config/#authorized_fetch |
| mastodon.createAdmin | object | `{"existingSecret":"","secretKeys":{"emailKey":"email","passwordKey":"password","usernameKey":"username"}}` | create an initial administrator user; the password is autogenerated and will have to be reset |
| mastodon.cron.removeMedia | object | `{}` | run `tootctl media remove` every week |
| mastodon.cron.removeMedia.enabled | bool | `true` | run `tootctl media remove` on a cron schedule |
| mastodon.cron.removeMedia.schedule | string | `"0 0 * * 0"` | run once a week |
| mastodon.cron.updateSearchIndexMappings.enabled | bool | `true` | |
| mastodon.cron.updateSearchIndexMappings.schedule | string | `"0 * * * *"` | run once an hour |
| mastodon.deepl.apiKeySecretRef.key | string | `""` | |
| mastodon.deepl.apiKeySecretRef.name | string | `""` | |
| mastodon.deepl.enabled | bool | `false` | |
Expand Down
5 changes: 5 additions & 0 deletions charts/mastodon/dev-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ mastodon:
enabled: true
# @ignored
schedule: "0 0 * * 0"
updateSearchIndexMappings:
# -- run `tootctl search deploy --only=instances accounts tags statuses public_statuses` on a cron schedule
enabled: true
# -- run once an hour
schedule: "0 * * * *"
# -- available locales: https://github.com/mastodon/mastodon/blob/main/config/application.rb#L71
locale: en
local_domain: mastodon.local
Expand Down
144 changes: 144 additions & 0 deletions charts/mastodon/templates/cronjob-elastic-search-index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{{ if .Values.mastodon.cron.updateSearchIndexMappings.enabled -}}
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ include "mastodon.fullname" . }}-update-search-index-mappings
labels:
{{- include "mastodon.labels" . | nindent 4 }}
spec:
schedule: {{ .Values.mastodon.cron.updateSearchIndexMappings.schedule }}
jobTemplate:
spec:
template:
metadata:
name: {{ include "mastodon.fullname" . }}-update-search-index-mappings
{{- with .Values.jobAnnotations }}
annotations:
{{- toYaml . | nindent 12 }}
{{- end }}
spec:
restartPolicy: OnFailure
{{- if not .Values.mastodon.s3.enabled }}
# ensure we run on the same node as the other rails components; only
# required when using PVCs that are ReadWriteOnce
{{- if or (eq "ReadWriteOnce" .Values.mastodon.persistence.assets.accessMode) (eq "ReadWriteOnce" .Values.mastodon.persistence.system.accessMode) }}
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app.kubernetes.io/part-of
operator: In
values:
- rails
topologyKey: kubernetes.io/hostname
{{- end }}
{{- end }}
{{- with (default .Values.podSecurityContext .Values.mastodon.web.podSecurityContext) }}
# hello
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- if or .Values.mastodon.extraVolumes (not .Values.mastodon.s3.enabled) }}
volumes:
{{- if .Values.mastodon.extraVolumes }}
{{- toYaml .Values.mastodon.extraVolumes | nindent 12}}
{{- end }}
{{- if not .Values.mastodon.s3.enabled }}
- name: assets
persistentVolumeClaim:
claimName: {{ template "mastodon.pvc.assets" . }}
- name: system
persistentVolumeClaim:
claimName: {{ template "mastodon.pvc.system" . }}
{{- end }}
{{- end }}
containers:
- name: {{ include "mastodon.fullname" . }}-update-search-index-mappings
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- bin/tootctl
- |
search deploy --only=instances accounts tags statuses public_statuses
envFrom:
- configMapRef:
name: {{ include "mastodon.fullname" . }}-env
- secretRef:
name: {{ template "mastodon.secretName" . }}
env:
- name: "DB_PASS"
valueFrom:
secretKeyRef:
name: {{ template "mastodon.postgresql.secretName" . }}
key: password
- name: "REDIS_PASSWORD"
valueFrom:
secretKeyRef:
name: {{ template "mastodon.redis.secretName" . }}
key: {{ .Values.redis.auth.existingSecretPasswordKey }}
{{- if and .Values.redis.sidekiq.enabled .Values.redis.sidekiq.auth.existingSecret }}
- name: "SIDEKIQ_REDIS_PASSWORD"
valueFrom:
secretKeyRef:
name: {{ template "mastodon.redis.sidekiq.secretName" . }}
key: {{ .Values.redis.auth.existingSecretPasswordKey }}
{{- end }}
{{- if and .Values.redis.cache.enabled .Values.redis.cache.auth.existingSecret }}
- name: "CACHE_REDIS_PASSWORD"
valueFrom:
secretKeyRef:
name: {{ template "mastodon.redis.cache.secretName" . }}
key: {{ .Values.redis.auth.existingSecretPasswordKey }}
{{- end }}
- name: "PORT"
value: {{ .Values.mastodon.web.port | quote }}
{{- if (and .Values.mastodon.s3.enabled .Values.mastodon.s3.existingSecret) }}
{{- if .Values.mastodon.s3.secretKeys.s3Hostname }}
- name: "S3_HOSTNAME"
valueFrom:
secretKeyRef:
name: {{ .Values.mastodon.s3.existingSecret }}
key: {{ .Values.mastodon.s3.secretKeys.s3Hostname }}
{{- end }}
- name: "S3_ENDPOINT"
valueFrom:
secretKeyRef:
name: {{ .Values.mastodon.s3.existingSecret }}
key: {{ .Values.mastodon.s3.secretKeys.s3Endpoint }}
{{- if .Values.mastodon.s3.secretKeys.s3Region }}
- name: "S3_REGION"
valueFrom:
secretKeyRef:
name: {{ .Values.mastodon.s3.existingSecret }}
key: {{ .Values.mastodon.s3.secretKeys.s3Region }}
{{- end }}
- name: "S3_BUCKET"
valueFrom:
secretKeyRef:
name: {{ .Values.mastodon.s3.existingSecret }}
key: {{ .Values.mastodon.s3.secretKeys.s3Bucket }}
- name: "AWS_ACCESS_KEY_ID"
valueFrom:
secretKeyRef:
name: {{ .Values.mastodon.s3.existingSecret }}
key: {{ .Values.mastodon.s3.secretKeys.s3AccessKeyID }}
- name: "AWS_SECRET_ACCESS_KEY"
valueFrom:
secretKeyRef:
name: {{ .Values.mastodon.s3.existingSecret }}
key: {{ .Values.mastodon.s3.secretKeys.s3AccessKey }}
{{- end }}
{{- if or .Values.mastodon.extraVolumeMounts (not .Values.mastodon.s3.enabled) }}
volumeMounts:
{{- if not .Values.mastodon.s3.enabled }}
- name: assets
mountPath: /opt/mastodon/public/assets
- name: system
mountPath: /opt/mastodon/public/system
{{- end }}
{{- if .Values.mastodon.extraVolumeMounts }}
{{- toYaml .Values.mastodon.extraVolumeMounts | nindent 16 }}
{{- end }}
{{- end }}
{{- end }}
10 changes: 7 additions & 3 deletions charts/mastodon/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,16 @@ mastodon:
env: {}

cron:
# -- run `tootctl media remove` every week
removeMedia:
# @ignored
# -- run `tootctl media remove` on a cron schedule
enabled: true
# @ignored
# -- run once a week
schedule: "0 0 * * 0"
updateSearchIndexMappings:
# -- run `tootctl search deploy --only=instances accounts tags statuses public_statuses` on a cron schedule
enabled: true
# -- run once an hour
schedule: "0 * * * *"
# -- available locales: https://github.com/mastodon/mastodon/blob/main/config/application.rb#L71
locale: en
local_domain: mastodon.local
Expand Down

0 comments on commit 7ea39be

Please sign in to comment.