-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create new pre/post migrate jobs #163
Open
timetinytim
wants to merge
5
commits into
main
Choose a base branch
from
improve-db-migrations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
561e757
Create new pre/post migrate jobs
timetinytim 6066bdb
Increment chart version
timetinytim 1d65d1c
Merge branch 'main' into improve-db-migrations
timetinytim f5b9a62
Use all redis env variables for DB migrate
timetinytim e9ef2dd
Add db:prepare step for new installs
timetinytim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" . }} | ||
renchap marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- 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" | ||
renchap marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1 @@ | ||
{{- if .Values.mastodon.hooks.dbMigrate.enabled -}} | ||
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 -}} | ||
{{- include "mastodon.dbMigrateJob" (merge (dict "preDeploy" false ) .) }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{- include "mastodon.dbMigrateJob" (merge (dict "preDeploy" true ) .) }} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be
post-install
? If we do it this way, then on the first install of the chart the sidekiq/web pods will start, then the migration will run, but there will be a time where the schema is empty.pre-install
should be better here?Also on initial install, we do not recommend to run the migrations (it will run every DDL one by one), but to use
db:setup
which will load it all at once. So doing that is probably better?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, it's been a while since I did this from scratch, and forgot about
db:setup
. So that should be run before anything is deployed for the schema, then the pods can be created. I will make that change.Then I have two questions:
db:setup
idempotent? If it is, we can just blindly run it every time and not worry about it. Otherwise, we will have to create some kind of logic to only have it run if we can detect that the database schema is already present.db:setup
is run first on an initial install, is there a problem with runningdb:migrate
as apost-install
hook? I figure it will simply do nothing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should, but I just wiped by dev database running it again, so it looks like it does not? Need more tests on this
Yes, you can run the migrations and nothing will happen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you can run migration pre-install. Because you won't have a database at that point (at least when you use the one from the chart dependencies) 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is true definitely. That's why I've since updated this PR to include an additional job that will run
db:prepare
as apre-install
hook to set up the the database schema (if it's not already there) before anything is installed.