mirror of
https://github.com/mastodon/chart
synced 2025-05-18 04:53:21 +00:00
Create new pre/post migrate jobs
This commit is contained in:
parent
5ef48e7cb8
commit
561e7575d2
75
templates/_db-migrate.tpl
Normal file
75
templates/_db-migrate.tpl
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
{{/* vim: set filetype=mustache: */}}
|
||||||
|
{{/*
|
||||||
|
Spec template for DB migration pre- and post-install/upgrade jobs.
|
||||||
|
*/}}
|
||||||
|
{{- define "mastodon.dbMigrateJob" -}}
|
||||||
|
apiVersion: batch/v1
|
||||||
|
kind: Job
|
||||||
|
metadata:
|
||||||
|
{{- if .preDeploy }}
|
||||||
|
name: {{ include "mastodon.fullname" . }}-db-pre-migrate
|
||||||
|
{{- else }}
|
||||||
|
name: {{ include "mastodon.fullname" . }}-db-post-migrate
|
||||||
|
{{- end }}
|
||||||
|
labels:
|
||||||
|
{{- include "mastodon.labels" . | nindent 4 }}
|
||||||
|
annotations:
|
||||||
|
{{- if .preDeploy }}
|
||||||
|
"helm.sh/hook": pre-upgrade
|
||||||
|
{{- else }}
|
||||||
|
"helm.sh/hook": post-install,post-upgrade
|
||||||
|
{{- end }}
|
||||||
|
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
|
||||||
|
"helm.sh/hook-weight": "-2"
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
name: {{ include "mastodon.fullname" . }}-db-migrate
|
||||||
|
{{- with .Values.jobAnnotations }}
|
||||||
|
annotations:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
|
spec:
|
||||||
|
restartPolicy: Never
|
||||||
|
containers:
|
||||||
|
- name: {{ include "mastodon.fullname" . }}-db-migrate
|
||||||
|
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
|
||||||
|
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
||||||
|
command:
|
||||||
|
- bundle
|
||||||
|
- exec
|
||||||
|
- rake
|
||||||
|
- db:migrate
|
||||||
|
envFrom:
|
||||||
|
- secretRef:
|
||||||
|
name: {{ template "mastodon.secretName" . }}
|
||||||
|
env:
|
||||||
|
- name: "DB_HOST"
|
||||||
|
value: {{ template "mastodon.postgres.host" . }}
|
||||||
|
- name: "DB_PORT"
|
||||||
|
value: {{ template "mastodon.postgres.port" . }}
|
||||||
|
- name: "DB_NAME"
|
||||||
|
value: {{ .Values.postgresql.auth.database }}
|
||||||
|
- name: "DB_USER"
|
||||||
|
value: {{ .Values.postgresql.auth.username }}
|
||||||
|
- name: "DB_PASS"
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ template "mastodon.postgresql.secretName" . }}
|
||||||
|
key: password
|
||||||
|
- name: "REDIS_HOST"
|
||||||
|
value: {{ template "mastodon.redis.host" . }}
|
||||||
|
- name: "REDIS_PORT"
|
||||||
|
value: {{ .Values.redis.port | default "6379" | quote }}
|
||||||
|
- name: "REDIS_DRIVER"
|
||||||
|
value: "ruby"
|
||||||
|
- name: "REDIS_PASSWORD"
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ template "mastodon.redis.secretName" . }}
|
||||||
|
key: redis-password
|
||||||
|
{{- if .preDeploy }}
|
||||||
|
- name: "SKIP_POST_DEPLOYMENT_MIGRATIONS"
|
||||||
|
value: "true"
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
|
@ -121,6 +121,33 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
|
||||||
{{- printf "%s-%s" .Release.Name "postgresql" | trunc 63 | trimSuffix "-" -}}
|
{{- printf "%s-%s" .Release.Name "postgresql" | trunc 63 | trimSuffix "-" -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
|
{{/*
|
||||||
|
Establish which values we will use for remote connections
|
||||||
|
*/}}
|
||||||
|
{{- define "mastodon.postgres.host" -}}
|
||||||
|
{{- if .Values.postgresql.enabled }}
|
||||||
|
{{- printf "%s" (include "mastodon.postgresql.fullname" .) -}}
|
||||||
|
{{- else }}
|
||||||
|
{{- printf "%s" .Values.postgresql.postgresqlHostname -}}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{- define "mastodon.postgres.port" -}}
|
||||||
|
{{- if .Values.postgresql.enabled }}
|
||||||
|
{{- printf "%d" 5432 | int | quote -}}
|
||||||
|
{{- else }}
|
||||||
|
{{- printf "%d" | default 5432 .Values.postgresql.postgresqlPort | int | quote -}}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{- define "mastodon.redis.host" -}}
|
||||||
|
{{- if .Values.redis.enabled }}
|
||||||
|
{{- printf "%s-%s" (include "mastodon.redis.fullname" .) "master" -}}
|
||||||
|
{{- else }}
|
||||||
|
{{- printf "%s" (required "When the redis chart is disabled .Values.redis.hostname is required" .Values.redis.hostname) -}}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
{{/*
|
{{/*
|
||||||
Get the mastodon secret.
|
Get the mastodon secret.
|
||||||
*/}}
|
*/}}
|
||||||
|
|
|
@ -5,13 +5,8 @@ metadata:
|
||||||
labels:
|
labels:
|
||||||
{{- include "mastodon.labels" . | nindent 4 }}
|
{{- include "mastodon.labels" . | nindent 4 }}
|
||||||
data:
|
data:
|
||||||
{{- if .Values.postgresql.enabled }}
|
DB_HOST: {{ template "mastodon.postgres.host" . }}
|
||||||
DB_HOST: {{ template "mastodon.postgresql.fullname" . }}
|
DB_PORT: {{ template "mastodon.postgres.port" . }}
|
||||||
DB_PORT: "5432"
|
|
||||||
{{- else }}
|
|
||||||
DB_HOST: {{ .Values.postgresql.postgresqlHostname }}
|
|
||||||
DB_PORT: {{ .Values.postgresql.postgresqlPort | default "5432" | quote }}
|
|
||||||
{{- end }}
|
|
||||||
DB_NAME: {{ .Values.postgresql.auth.database }}
|
DB_NAME: {{ .Values.postgresql.auth.database }}
|
||||||
DB_POOL: {{ include "mastodon.maxDbPool" . }}
|
DB_POOL: {{ include "mastodon.maxDbPool" . }}
|
||||||
DB_USER: {{ .Values.postgresql.auth.username }}
|
DB_USER: {{ .Values.postgresql.auth.username }}
|
||||||
|
@ -66,11 +61,7 @@ data:
|
||||||
MALLOC_ARENA_MAX: "2"
|
MALLOC_ARENA_MAX: "2"
|
||||||
NODE_ENV: "production"
|
NODE_ENV: "production"
|
||||||
RAILS_ENV: "production"
|
RAILS_ENV: "production"
|
||||||
{{- if .Values.redis.enabled }}
|
REDIS_HOST: {{ template "mastodon.redis.host" . }}
|
||||||
REDIS_HOST: {{ template "mastodon.redis.fullname" . }}-master
|
|
||||||
{{- else }}
|
|
||||||
REDIS_HOST: {{ required "When the redis chart is disabled .Values.redis.hostname is required" .Values.redis.hostname }}
|
|
||||||
{{- end }}
|
|
||||||
REDIS_PORT: {{ .Values.redis.port | default "6379" | quote }}
|
REDIS_PORT: {{ .Values.redis.port | default "6379" | quote }}
|
||||||
{{- if .Values.redis.sidekiq.enabled }}
|
{{- if .Values.redis.sidekiq.enabled }}
|
||||||
{{- if .Values.redis.sidekiq.hostname }}
|
{{- if .Values.redis.sidekiq.hostname }}
|
||||||
|
|
|
@ -1,93 +1 @@
|
||||||
{{- if .Values.mastodon.hooks.dbMigrate.enabled -}}
|
{{- include "mastodon.dbMigrateJob" (merge (dict "preDeploy" false ) .) }}
|
||||||
apiVersion: batch/v1
|
|
||||||
kind: Job
|
|
||||||
metadata:
|
|
||||||
name: {{ include "mastodon.fullname" . }}-db-migrate
|
|
||||||
labels:
|
|
||||||
{{- include "mastodon.labels" . | nindent 4 }}
|
|
||||||
annotations:
|
|
||||||
"helm.sh/hook": post-install,pre-upgrade
|
|
||||||
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
|
|
||||||
"helm.sh/hook-weight": "-2"
|
|
||||||
spec:
|
|
||||||
template:
|
|
||||||
metadata:
|
|
||||||
name: {{ include "mastodon.fullname" . }}-db-migrate
|
|
||||||
{{- with .Values.jobAnnotations }}
|
|
||||||
annotations:
|
|
||||||
{{- toYaml . | nindent 8 }}
|
|
||||||
{{- end }}
|
|
||||||
spec:
|
|
||||||
restartPolicy: Never
|
|
||||||
{{- 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 }}
|
|
||||||
volumes:
|
|
||||||
- name: assets
|
|
||||||
persistentVolumeClaim:
|
|
||||||
claimName: {{ template "mastodon.pvc.assets" . }}
|
|
||||||
- name: system
|
|
||||||
persistentVolumeClaim:
|
|
||||||
claimName: {{ template "mastodon.pvc.system" . }}
|
|
||||||
{{- end }}
|
|
||||||
containers:
|
|
||||||
- name: {{ include "mastodon.fullname" . }}-db-migrate
|
|
||||||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
|
|
||||||
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
|
||||||
command:
|
|
||||||
- bundle
|
|
||||||
- exec
|
|
||||||
- rake
|
|
||||||
- db:migrate
|
|
||||||
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: redis-password
|
|
||||||
{{- if and .Values.redis.sidekiq.enabled .Values.redis.sidekiq.auth.existingSecret }}
|
|
||||||
- name: "SIDEKIQ_REDIS_PASSWORD"
|
|
||||||
valueFrom:
|
|
||||||
secretKeyRef:
|
|
||||||
name: {{ template "mastodon.redis.sidekiq.secretName" . }}
|
|
||||||
key: redis-password
|
|
||||||
{{- 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: redis-password
|
|
||||||
{{- end }}
|
|
||||||
- name: "PORT"
|
|
||||||
value: {{ .Values.mastodon.web.port | quote }}
|
|
||||||
{{- if (not .Values.mastodon.s3.enabled) }}
|
|
||||||
volumeMounts:
|
|
||||||
- name: assets
|
|
||||||
mountPath: /opt/mastodon/public/assets
|
|
||||||
- name: system
|
|
||||||
mountPath: /opt/mastodon/public/system
|
|
||||||
{{- end }}
|
|
||||||
{{- end -}}
|
|
||||||
|
|
1
templates/job-db-pre-migrate.yaml
Normal file
1
templates/job-db-pre-migrate.yaml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{{- include "mastodon.dbMigrateJob" (merge (dict "preDeploy" true ) .) }}
|
Loading…
Reference in New Issue
Block a user