apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: monthreport
spec:
  concurrencyPolicy: Forbid
  schedule: "05 0 1 * *"  # At 00:05 on day-of-month 1
  jobTemplate:
    spec:
      backoffLimit: 0
      template:
        spec:
          volumes:
            - name: backup-scripts
              configMap:
                name: backup-scripts
          initContainers:
          - name: dayreport
            image: docker.io/library/postgres:13.0
            imagePullPolicy: IfNotPresent
            envFrom:
              - configMapRef:
                  name: backup-config
            command:
              - sh
              - -c
              - psql -d "postgresql://$DATABASE_USER:$DATABASE_PASSWORD@$DATABASE_HOST_NAME:$PORT_NUMBER/$DATABASE_NAME" -c "SELECT generate_report('month');"
          containers:
            - name: monthemail
              image: quay.io/operate-first/curator-s3-sync:latest
              imagePullPolicy: IfNotPresent
              envFrom:
                - secretRef:
                    name: email-credentials
                - configMapRef:
                    name: backup-config
              command:
                - python3
                - /scripts/send_email.py
                - day
              volumeMounts:
                - name: backup-scripts
                  mountPath: /scripts
          restartPolicy: Never
