Skip to content

Commit

Permalink
Don't create a postgres pod if we are using external DB
Browse files Browse the repository at this point in the history
  • Loading branch information
iamjazzar committed Jun 14, 2021
1 parent f23df62 commit f945040
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 103 deletions.
2 changes: 1 addition & 1 deletion charts/dashboard/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ apiVersion: v2
name: dashboard
description: Dashboard for Saleor
type: application
version: 0.2.9
version: 0.2.10
appVersion: 0.4.0
7 changes: 4 additions & 3 deletions charts/saleor/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ apiVersion: v2
name: saleor
description: Saleor Graphql E-commerce Helm Chart
type: application
version: 0.2.9
version: 0.2.10
appVersion: 0.4.0
dependencies:
- name: storefront
version: ^0.2.9
version: ^0.2.10
repository: file://../storefront
- name: dashboard
version: ^0.2.9
version: ^0.2.10
repository: file://../dashboard
- name: postgresql
version: ^8.10.5
repository: https://charts.bitnami.com/bitnami
condition: global.postgresql.enabled
- name: redis
version: ^10.7.1
repository: https://charts.bitnami.com/bitnami
190 changes: 92 additions & 98 deletions charts/saleor/templates/init-db.yaml
Original file line number Diff line number Diff line change
@@ -1,101 +1,95 @@
{{/*
Don't create a postgres pod if we are using external DB
*/}}

{{- if not .Values.postgresHost -}}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "saleor.fullname" . }}-migrate
labels:
{{- include "saleor.labels" . | nindent 4 }}
annotations:
helm.sh/hook: pre-upgrade,post-install
spec:
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "saleor.fullname" . }}-migrate
labels:
{{- include "saleor.labels" . | nindent 4 }}
annotations:
helm.sh/hook: pre-upgrade,post-install
spec:
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "saleor.selectorLabels" . | nindent 8 }}
spec:
restartPolicy: OnFailure
shareProcessNamespace: true
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "saleor.selectorLabels" . | nindent 8 }}
spec:
restartPolicy: OnFailure
shareProcessNamespace: true
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "saleor.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
volumes:
- name: service-account
secret:
secretName: {{ .Values.GACRedentialsSecretName }}
containers:
- name: {{ .Chart.Name }}-migration
securityContext:
{{- toYaml .Values.migrate.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: ["/bin/sh", "-c"]
args:
- |
python manage.py migrate && \
python manage.py collectstatic --noinput;
sql_proxy_pid=$(pgrep cloud_sql_proxy) && kill -INT $sql_proxy_pid;
env:
- name: DATABASE_URL
value: {{ template "saleor.postgresql" . }}
- name: SECRET_KEY
valueFrom:
secretKeyRef:
name: {{ .Values.secretKey.name }}
key: {{ .Values.secretKey.key }}
- name: DB_USER
valueFrom:
secretKeyRef:
name: {{ .Values.databaseSecret }}
key: username
- name: DB_PASS
valueFrom:
secretKeyRef:
name: {{ .Values.databaseSecret }}
key: password
- name: DB_NAME
valueFrom:
secretKeyRef:
name: {{ .Values.databaseSecret }}
key: database
volumeMounts:
- name: service-account
mountPath: {{ .Values.GACRedentialsDir }}
resources:
{{- toYaml .Values.migrate.hook.resources | nindent 12 }}
- name: cloud-sql-proxy
image: gcr.io/cloudsql-docker/gce-proxy:1.17
command:
- "/cloud_sql_proxy"
- "-instances={{ .Values.connectionName }}=tcp:{{ .Values.databasePort }}"
- "-credential_file={{ .Values.GACRedentialsPath }}"
securityContext:
runAsNonRoot: true
volumeMounts:
serviceAccountName: {{ include "saleor.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
volumes:
- name: service-account
secret:
secretName: {{ .Values.GACRedentialsSecretName }}
containers:
- name: {{ .Chart.Name }}-migration
securityContext:
{{- toYaml .Values.migrate.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: ["/bin/sh", "-c"]
args:
- |
python manage.py migrate && \
python manage.py collectstatic --noinput;
sql_proxy_pid=$(pgrep cloud_sql_proxy) && kill -INT $sql_proxy_pid;
env:
- name: DATABASE_URL
value: {{ template "saleor.postgresql" . }}
- name: SECRET_KEY
valueFrom:
secretKeyRef:
name: {{ .Values.secretKey.name }}
key: {{ .Values.secretKey.key }}
- name: DB_USER
valueFrom:
secretKeyRef:
name: {{ .Values.databaseSecret }}
key: username
- name: DB_PASS
valueFrom:
secretKeyRef:
name: {{ .Values.databaseSecret }}
key: password
- name: DB_NAME
valueFrom:
secretKeyRef:
name: {{ .Values.databaseSecret }}
key: database
volumeMounts:
- name: service-account
mountPath: {{ .Values.GACRedentialsDir }}
readOnly: true
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
resources:
{{- toYaml .Values.migrate.hook.resources | nindent 12 }}
- name: cloud-sql-proxy
image: gcr.io/cloudsql-docker/gce-proxy:1.17
command:
- "/cloud_sql_proxy"
- "-instances={{ .Values.connectionName }}=tcp:{{ .Values.databasePort }}"
- "-credential_file={{ .Values.GACRedentialsPath }}"
securityContext:
runAsNonRoot: true
volumeMounts:
- name: service-account
mountPath: {{ .Values.GACRedentialsDir }}
readOnly: true
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
1 change: 1 addition & 0 deletions charts/saleor/values.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
global:
postgresql:
enabled: true # Flag to enable/disable postgres subchart
postgresqlDatabase: saleor
postgresqlUsername: postgres
postgresqlPassword: saleor
Expand Down
2 changes: 1 addition & 1 deletion charts/storefront/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ apiVersion: v2
name: storefront
description: Storefont Saleor
type: application
version: 0.2.9
version: 0.2.10
appVersion: 0.4.0

0 comments on commit f945040

Please sign in to comment.