Skip to content

Commit

Permalink
Add Job for running migrations
Browse files Browse the repository at this point in the history
Closes #35
  • Loading branch information
mjasion committed Jan 13, 2023
1 parent ae36811 commit 0a21cff
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 10 deletions.
2 changes: 2 additions & 0 deletions charts/studio/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,6 @@ Create the name of the service account to use
{{- define "studio.checkSum" }}
checksum/studio-cm: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
checksum/studio-ca-certificates-cm: {{ include (print $.Template.BasePath "/configmap-ca-cert.yaml") . | sha256sum }}
checksum/studio-migration-job-secret: {{ include (print $.Template.BasePath "/secret-migration-job.yaml") . | sha256sum }}
checksum/studio-secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
{{- end}}
3 changes: 3 additions & 0 deletions charts/studio/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ kind: ConfigMap
metadata:
name: studio
data:
NO_MIGRATE_DB: "1"
WAIT_FOR_MIGRATIONS: "1"
ALLOWED_HOSTS: "*"

{{/* {{- if .Values.studioBackend.ingress.enabled }}*/}}
{{/* {{- range $host := .Values.studioBackend.ingress.hosts }}*/}}
{{/* {{- range .paths }}*/}}
Expand Down
5 changes: 0 additions & 5 deletions charts/studio/templates/deployment-studio-beat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ spec:
protocol: TCP
resources:
{{- toYaml .Values.studioBeat.resources | nindent 12 }}
env:
- name: "NO_MIGRATE_DB"
value: "1"
- name: "WAIT_FOR_MIGRATIONS"
value: "1"
envFrom:
- configMapRef:
name: studio
Expand Down
5 changes: 0 additions & 5 deletions charts/studio/templates/deployment-studio-worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ spec:
protocol: TCP
resources:
{{- toYaml .Values.studioWorker.resources | nindent 12 }}
env:
- name: "NO_MIGRATE_DB"
value: "1"
- name: "WAIT_FOR_MIGRATIONS"
value: "1"
envFrom:
- configMapRef:
name: studio
Expand Down
54 changes: 54 additions & 0 deletions charts/studio/templates/job_db_migration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: batch/v1
kind: Job
metadata:
name: studio-database-migration
labels:
{{- include "studio-backend.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-rollback,pre-upgrade,post-install
"helm.sh/hook-weight": "10"
"helm.sh/hook-delete-policy": hook-succeeded
spec:
template:
metadata:
annotations:
{{- with .Values.studioBackend.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "studio-backend.selectorLabels" . | nindent 8 }}
spec:
restartPolicy: OnFailure
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "studio.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.studioBackend.podSecurityContext | nindent 8 }}
containers:
- name: studio-backend
securityContext:
{{- toYaml .Values.studioBackend.securityContext | nindent 12 }}
image: "{{ .Values.studioBackend.image.repository }}:{{ .Values.studioBackend.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.studioBackend.image.pullPolicy }}
command: [ "/usr/local/bin/python" ]
args: [ "manage.py", "migrate", "--noinput" ]
resources:
{{- toYaml .Values.studioBackend.resources | nindent 12 }}
envFrom:
- secretRef:
name: studio-migration-job
{{- with .Values.studioBackend.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.studioBackend.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.studioBackend.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}

6 changes: 6 additions & 0 deletions charts/studio/templates/secret-migration-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: Secret
metadata:
name: studio-migration-job
data:
DATABASE_URL: "psql://{{ .Values.global.postgres.databaseUser}}:{{ .Values.global.postgres.databasePassword }}@{{ .Values.global.postgres.databaseUrl }}"

0 comments on commit 0a21cff

Please sign in to comment.