From 1f33e9aa396fc6baf2abe3a71f76382904fb09b2 Mon Sep 17 00:00:00 2001 From: Jim Grady Date: Wed, 21 Sep 2022 14:56:37 -0400 Subject: [PATCH] Fix db scripts (#1736) * Check for empty response before converting to int * Fix restore script to specify directory for backup files Also: - remove WORKING_DIR from database image - Change backups so that jobs (& logs) are visible for 1 day - Add pull secret for database image --- .gitignore | 1 + database/Dockerfile | 2 +- .../charts/database/templates/database.yaml | 11 ++++++++++- .../templates/cronjob-daily-backup.yaml | 2 +- maintenance/scripts/combine_restore.py | 14 +++++++++----- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index cfb4f0f655..8518a1ff1a 100644 --- a/.gitignore +++ b/.gitignore @@ -94,6 +94,7 @@ database/semantic_domains/* _*.yml _*.yaml _*.j2 +deploy/scripts/setup_files/**/dev_*.yaml # Emacs backup files (this is Jim's fault) *~ diff --git a/database/Dockerfile b/database/Dockerfile index 16068ab191..eae50d4b01 100644 --- a/database/Dockerfile +++ b/database/Dockerfile @@ -1,6 +1,6 @@ FROM mongo:5.0 -WORKDIR /app +WORKDIR / RUN mkdir /data/semantic-domains diff --git a/deploy/helm/thecombine/charts/database/templates/database.yaml b/deploy/helm/thecombine/charts/database/templates/database.yaml index 71bbf013f4..9d63cd8fc6 100644 --- a/deploy/helm/thecombine/charts/database/templates/database.yaml +++ b/deploy/helm/thecombine/charts/database/templates/database.yaml @@ -30,7 +30,12 @@ spec: matchLabels: combine-component: database strategy: - type: Recreate + type: {{ .Values.global.updateStrategy }} +{{- if eq "RollingUpdate" .Values.global.updateStrategy }} + rollingUpdate: + maxSurge: 1 + maxUnavailable: 0 +{{- end }} template: metadata: creationTimestamp: null @@ -48,6 +53,10 @@ spec: - mountPath: /data/db name: database-data restartPolicy: Always +{{- if ne .Values.global.pullSecretName "None" }} + imagePullSecrets: + - name: {{ .Values.global.pullSecretName }} +{{- end }} volumes: - name: database-data persistentVolumeClaim: diff --git a/deploy/helm/thecombine/charts/maintenance/templates/cronjob-daily-backup.yaml b/deploy/helm/thecombine/charts/maintenance/templates/cronjob-daily-backup.yaml index 00904b28a7..7aeda10e98 100644 --- a/deploy/helm/thecombine/charts/maintenance/templates/cronjob-daily-backup.yaml +++ b/deploy/helm/thecombine/charts/maintenance/templates/cronjob-daily-backup.yaml @@ -11,7 +11,7 @@ spec: metadata: creationTimestamp: null spec: - ttlSecondsAfterFinished: 300 + ttlSecondsAfterFinished: 86400 template: metadata: creationTimestamp: null diff --git a/maintenance/scripts/combine_restore.py b/maintenance/scripts/combine_restore.py index 866eb078ab..3f17bb6ed4 100755 --- a/maintenance/scripts/combine_restore.py +++ b/maintenance/scripts/combine_restore.py @@ -101,10 +101,12 @@ def main() -> None: for i, backup_entry in enumerate(aws_backup_list): print(f"{i+1}: {backup_entry[1]} ({backup_entry[0]})") - backup_num = int( - input("Enter the number of the backup you would like to restore (0 = None):") + response = input( + "Enter the number of the backup you would like to restore (0 = None):" ) - if backup_num == 0: + if response: + backup_num = int(response) + if not response or backup_num == 0: print("No backup selected. Exiting.") sys.exit(0) backup = aws_backup_list[backup_num - 1][1] @@ -123,10 +125,11 @@ def main() -> None: if not db_pod: print("Cannot find the database container.", file=sys.stderr) sys.exit(1) + db_files_subdir = os.environ["db_files_subdir"] combine.kubectl( [ "cp", - os.environ["db_files_subdir"], + db_files_subdir, f"{db_pod}:/", ] ) @@ -138,6 +141,7 @@ def main() -> None: "--drop", "--gzip", "--quiet", + f"--dir=/{db_files_subdir}", ], ) combine.exec( @@ -145,7 +149,7 @@ def main() -> None: [ "rm", "-rf", - os.environ["db_files_subdir"], + f"/{db_files_subdir}", ], )