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 16, 2023
1 parent 871fc59 commit 26bb5f7
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 10 deletions.
1 change: 1 addition & 0 deletions charts/studio/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,5 @@ Create the name of the service account to use
checksum/configmap-studio: {{ include (print $.Template.BasePath "/configmap-studio.yaml") . | sha256sum }}
checksum/configmap-ca-cert: {{ include (print $.Template.BasePath "/configmap-ca-cert.yaml") . | sha256sum }}
checksum/secret-studio: {{ include (print $.Template.BasePath "/secret-studio.yaml") . | sha256sum }}
checksum/studio-migration-job-secret: {{ include (print $.Template.BasePath "/secret-migration-job.yaml") . | sha256sum }}
{{- end }}
2 changes: 2 additions & 0 deletions charts/studio/templates/configmap-studio.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ kind: ConfigMap
metadata:
name: studio
data:
NO_MIGRATE_DB: "1"
WAIT_FOR_MIGRATIONS: "1"
ALLOWED_HOSTS: "*"
API_URL: "http{{ if $.Values.studioBackend.ingress.tlsEnabled }}s{{ end }}://{{ .Values.studioBackend.ingress.host }}/"
UI_URL: "http{{ if $.Values.studioUi.ingress.tlsEnabled }}s{{ end }}://{{ .Values.studioUi.ingress.host }}/"
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 26bb5f7

Please sign in to comment.