apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: backup-mongodb
spec:
  schedule: "0 12 * * *"
  concurrencyPolicy: Forbid
  suspend: false
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 1
  jobTemplate:
    spec:
      template:
        spec:
          restartPolicy: OnFailure
          containers:
          - name: backup-mongodb
            image: gcr.io/toptal-realworld-app/mongodb-backup:latest
            env:
            - name: MONGODB_URI
              valueFrom:
                secretKeyRef:
                  name: mongodb-uri
                  key: MONGODB_URI              
            - name: GCS_BUCKET
              value: gs://toptal-realworld-app-tfstate/env/dev/mongodb-backup/
            volumeMounts:
              - name: gcp-key
                mountPath: /secrets/gcp-key
                readOnly: true
            command:
            - /bin/bash
            - -c
            - gcloud auth activate-service-account --key-file=/secrets/gcp-key/service-account.json; /scripts/backup.sh
          volumes:
            - name: gcp-key
              secret:
                secretName: gcp-key
