apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: fb-datastore-cron-db-sweeper-{{ .Values.environmentName }}
  namespace: hmcts-complaints-formbuilder-adapter-{{ .Values.environmentName }}
spec:
  schedule: "0 * * * *"
  successfulJobsHistoryLimit: 0
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hmcts-complaints-formbuilder-adapter-{{ .Values.environmentName }}
            image: "754256621582.dkr.ecr.eu-west-2.amazonaws.com/formbuilder/hmcts-complaints-formbuilder-adapter-api:{{ .Values.circleSha1 }}"
            args:
            - /bin/sh
            - -c
            - bundle exec rake sweep:attachments
            securityContext:
              runAsUser: 1001
            imagePullPolicy: Always
            env:
              - name: HOST
                value: hmcts-complaints-formbuilder-adapter-{{ .Values.environmentName }}.apps.live-1.cloud-platform.service.justice.gov.uk
              - name: RAILS_LOG_TO_STDOUT
                value: "true"
              - name: OPTICS_ENDPOINT
                valueFrom:
                  secretKeyRef:
                    name: hmcts-complaints-formbuilder-adapter-secrets-{{ .Values.environmentName }}
                    key: optics_endpoint
              - name: SECRET_KEY_BASE
                valueFrom:
                  secretKeyRef:
                    name: hmcts-complaints-formbuilder-adapter-secrets-{{ .Values.environmentName }}
                    key: secret_key_base
              - name: JWE_SHARED_KEY
                valueFrom:
                  secretKeyRef:
                    name: hmcts-complaints-formbuilder-adapter-secrets-{{ .Values.environmentName }}
                    key: jwe_shared_key
              - name: OPTICS_SECRET_KEY
                valueFrom:
                  secretKeyRef:
                    name: hmcts-complaints-formbuilder-adapter-secrets-{{ .Values.environmentName }}
                    key: optics_secret_key
              - name: OPTICS_API_KEY
                valueFrom:
                  secretKeyRef:
                    name: hmcts-complaints-formbuilder-adapter-secrets-{{ .Values.environmentName }}
                    key: optics_api_key
              - name: SENTRY_DSN
                valueFrom:
                  secretKeyRef:
                    name: hmcts-complaints-formbuilder-adapter-secrets-{{ .Values.environmentName }}
                    key: sentry_dsn
              - name: METRICS_AUTH_PASSWORD
                valueFrom:
                  secretKeyRef:
                    name: hmcts-complaints-formbuilder-adapter-secrets-{{ .Values.environmentName }}
                    key: metrics_auth_password
              - name: METRICS_AUTH_USERNAME
                valueFrom:
                  secretKeyRef:
                    name: hmcts-complaints-formbuilder-adapter-secrets-{{ .Values.environmentName }}
                    key: metrics_auth_username
              - name: DATABASE_URL
                valueFrom:
                  secretKeyRef:
                    name: rds-instance-hmcts-complaints-adapter-{{ .Values.environmentName }}
                    key: url
          restartPolicy: Never
