forked from Sefaria/Sefaria-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/s4d'
- Loading branch information
Showing
16 changed files
with
362 additions
and
48 deletions.
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
28 changes: 28 additions & 0 deletions
28
helm-chart/sefaria-project/templates/configmap/create-pg-dumps.yaml
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,28 @@ | ||
{{- if eq .Values.backup.postgres.enabled true }} | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: create-pg-dumps-{{ .Values.deployEnv }} | ||
labels: | ||
deployEnv: "{{ .Values.deployEnv }}" | ||
{{- include "sefaria.labels" . | nindent 4 }} | ||
data: | ||
create-dumps.sh: |- | ||
#!/usr/bin/env bash | ||
DATADIR="/pgdumps/shared_volume" | ||
DUMP_CMD="pg_dump --file $DATADIR/pg.dump --host $DATABASES_HOST --port $DATABASES_PORT" | ||
DUMP_CMD+=" --username $DATABASES_USER" | ||
IF [[ ! $DATABASES_PASSWORD ]]; THEN | ||
DUMP_CMD+=" --no_passowrd" | ||
ELSE | ||
DUMP_CMD+=" --password $DATABASES_PASSWORD" | ||
FI | ||
DUMP_CMD+=" --verbose --format=c --no-owner --section=pre-data --section=data --no-privileges" | ||
DUMP_CMD+=" --no-tablespaces --no-unlogged-table-data 'sefaria_auth'" | ||
eval $DUMP_CMD | ||
tar cvzf "${DATADIR}/postgres_dump.tar.gz" -C "${DATADIR}" ./dump | ||
{{- 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
32 changes: 32 additions & 0 deletions
32
helm-chart/sefaria-project/templates/configmap/upload-pg-dumps.yaml
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,32 @@ | ||
{{- if .Values.backup.postgres.enabled }} | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: upload-pg-dumps-{{ .Values.deployEnv }} | ||
labels: | ||
deployEnv: "{{ .Values.deployEnv }}" | ||
{{- include "sefaria.labels" . | nindent 4 }} | ||
data: | ||
upload-dumps.sh: |- | ||
#!/usr/bin/env bash | ||
set -x | ||
{{- if .Values.backup.postgres.serviceAccount }} | ||
gloud auth activate | ||
{{- else }} | ||
gcloud auth activate-service-account --key-file ${GOOGLE_APPLICATION_CREDENTIALS} | ||
{{- end }} | ||
cd "/pgdumps/shared_volume" | ||
today="$(date +'%d.%m.%y')" | ||
last_month="$(date --date='last month' +'%d.%m.%y')" | ||
gsutil rm "gs://${BUCKET}/${PREFIX}postgres_dump_${last_month}.tar.gz" | ||
if [ -f "postgres_dump.tar.gz" ]; then | ||
echo "uploading private dump" | ||
gsutil cp postgres_dump.tar.gz "gs://${BUCKET}/${PREFIX}postgres_dump_${today}.tar.gz" | ||
else | ||
echo "Private dump missing" | ||
fi | ||
curl -X POST --data-urlencode 'payload={"channel": "#engineering", "username": "Data Archiver", "text": "The {{ .Values.deployEnv }} Postgres Database was routinely dumped to cloud storage: '"$(date)"'", "icon_emoji": ":cloud:"}' ${SLACK_URL} | ||
{{- 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
97 changes: 97 additions & 0 deletions
97
helm-chart/sefaria-project/templates/cronjob/postgres-packup.yaml
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,97 @@ | ||
{{- if eq .Values.backup.postgres.enabled true }} | ||
--- | ||
apiVersion: batch/v1beta1 | ||
kind: CronJob | ||
metadata: | ||
name: {{ .Values.deployEnv }}-postgresbackup | ||
labels: | ||
{{- include "sefaria.labels" . | nindent 4 }} | ||
spec: | ||
concurrencyPolicy: Replace | ||
schedule: "0 0 * * 0" | ||
jobTemplate: | ||
spec: | ||
backoffLimit: 1 | ||
template: | ||
spec: | ||
serviceAccount: {{ .Values.backup.postgres.serviceAccount }} | ||
affinity: | ||
podAffinity: | ||
requiredDuringSchedulingIgnoredDuringExecution: | ||
- labelSelector: | ||
matchExpressions: | ||
- key: app | ||
operator: In | ||
values: | ||
- postgres | ||
topologyKey: kubernetes.io/hostname | ||
tolerations: | ||
- key: schedule-on-database-vm | ||
operator: "Equal" | ||
value: "true" | ||
effect: "NoSchedule" | ||
initContainers: | ||
- name: postgres-dumper | ||
image: postgres:{{ .Values.backup.postgres.version }} | ||
envFrom: | ||
- secretRef: | ||
name: {{ .Values.secrets.localSettings.ref }} | ||
- configMapRef: | ||
name: local-settings-{{ .Values.deployEnv }} | ||
- secretRef: | ||
name: local-settings-secrets-{{ .Values.deployEnv }} | ||
optional: true | ||
volumeMounts: | ||
- name: shared-volume | ||
mountPath: /pgdumps/shared_volume | ||
- name: create-dumps-script | ||
mountPath: /scripts/create-dumps.sh | ||
subPath: create-dumps.sh | ||
readOnly: true | ||
command: ["bash"] | ||
args: ["-c", "/scripts/create-dumps.sh"] | ||
resources: | ||
limits: | ||
memory: "500Mi" | ||
containers: | ||
- name: pgdump-uploader | ||
image: google/cloud-sdk | ||
volumeMounts: | ||
- name: shared-volume | ||
mountPath: /pgdumps/shared_volume | ||
- name: upload-dumps-script | ||
mountPath: /scripts/upload-dumps.sh | ||
subPath: upload-dumps.sh | ||
readOnly: true | ||
env: | ||
- name: PREFIX | ||
value: {{ .Values.backup.postgres.prefix }} | ||
- name: BUCKET | ||
value: {{ .Values.backup.postgres.bucket }} | ||
- name: ARCHIVE_BUCKET | ||
value: {{ .Values.backup.postgres.archiveBucket }} | ||
- name: SLACK_URL | ||
valueFrom: | ||
secretKeyRef: | ||
name: {{ template "sefaria.secrets.slackWebhook" . }} | ||
key: slack-webhook | ||
command: ["bash"] | ||
args: ["-c", "/scripts/upload-dumps.sh"] | ||
resources: | ||
limits: | ||
memory: "500Mi" | ||
restartPolicy: OnFailure | ||
volumes: | ||
- name: create-dumps-script | ||
configMap: | ||
name: create-pg-dumps-{{ .Values.deployEnv }} | ||
defaultMode: 0755 | ||
- name: upload-dumps-script | ||
configMap: | ||
name: upload-pg-dumps-{{ .Values.deployEnv }} | ||
defaultMode: 0755 | ||
- name: shared-volume | ||
emptyDir: {} | ||
successfulJobsHistoryLimit: 1 | ||
failedJobsHistoryLimit: 2 | ||
{{- 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
Oops, something went wrong.