apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: data-extractor-reporting
spec:
  schedule: "0 1 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          restartPolicy: "Never"
          volumes:
          - name: data-extractor-reports
            configMap:
              name: data-extractor-reports
              defaultMode: 0755
          containers:
          - name: data-extractor-reporting
            image: ministryofjustice/data-engineering-data-extractor:v1
            imagePullPolicy: Always
            args: ["mkdir -p 'export/csv/reports' && psql -v ON_ERROR_STOP=1 --file=/reports/crs_performance_report.sql > 'export/csv/reports/crs_performance_report.csv' && transfer_local_to_s3.sh"]
            volumeMounts:
            - name: data-extractor-reports
              mountPath: /reports/crs_performance_report.sql
              readOnly: true
              subPath: crs_performance_report.sql
            env:
              - name: USE_STATIC_LOCATION
                value: "true"
              - name: PGHOST
                valueFrom:
                  secretKeyRef:
                    name: postgres
                    key: rds_instance_address
              - name: PGDATABASE
                valueFrom:
                  secretKeyRef:
                    name: postgres
                    key: database_name
              - name: PGUSER
                valueFrom:
                  secretKeyRef:
                    name: postgres
                    key: database_username
              - name: PGPASSWORD
                valueFrom:
                  secretKeyRef:
                    name: postgres
                    key: database_password
              - name: S3_DESTINATION
                valueFrom:
                  secretKeyRef:
                    name: reporting-s3-bucket
                    key: destination_bucket
              - name: AWS_ACCESS_KEY_ID
                valueFrom:
                  secretKeyRef:
                    name: reporting-s3-bucket
                    key: access_key_id
              - name: AWS_SECRET_ACCESS_KEY
                valueFrom:
                  secretKeyRef:
                    name: reporting-s3-bucket
                    key: secret_access_key
              - name: AWS_DEFAULT_REGION
                value: eu-west-2
