apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: community-api-import
spec:
  schedule: "00 06 * * *"
  concurrencyPolicy: Replace
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 2
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: community-api-import
              image: 754256621582.dkr.ecr.eu-west-2.amazonaws.com/offender-management/offender-management-allocation-manager:latest
              imagePullPolicy: Always
              command: ['sh', '-c', "bundle exec rake community_api:import"]
              resources:
                limits:
                  memory: "1500Mi"
                  cpu: "1000m"
                requests:
                  memory: "500Mi"
                  cpu: "50m"
              envFrom:
                - configMapRef:
                    name: shared-environment
                - secretRef:
                    name: allocation-manager-secrets
              env:
                - name: PROMETHEUS_METRICS
                  value: "off"
                - name: POSTGRES_HOST
                  valueFrom:
                    secretKeyRef:
                      name: allocation-rds-instance-output
                      key: rds_instance_address
                - name: POSTGRES_PASSWORD
                  valueFrom:
                    secretKeyRef:
                      name: allocation-rds-instance-output
                      key: postgres_password
                - name: POSTGRES_NAME
                  valueFrom:
                    secretKeyRef:
                      name: allocation-rds-instance-output
                      key: postgres_name
                - name: POSTGRES_USER
                  valueFrom:
                    secretKeyRef:
                      name: allocation-rds-instance-output
                      key: postgres_user
                - name: REDIS_URL
                  valueFrom:
                    secretKeyRef:
                      name: elasticache-offender-management-allocation-manager-token-cache-preprod
                      key: url
                - name: AWS_ACCESS_KEY_ID
                  valueFrom:
                    secretKeyRef:
                      name: hmpps-domain-events-topic
                      key: access_key_id
                - name: AWS_SECRET_ACCESS_KEY
                  valueFrom:
                    secretKeyRef:
                      name: hmpps-domain-events-topic
                      key: secret_access_key
                - name: DOMAIN_EVENTS_TOPIC_ARN
                  valueFrom:
                    secretKeyRef:
                      name: hmpps-domain-events-topic
                      key: topic_arn
                - name: HMPPS_API_CLIENT_ID
                  valueFrom:
                    secretKeyRef:
                      name: hmpps-auth-secrets
                      key: NOMIS_OAUTH_API_CLIENT_ID
                - name: HMPPS_API_CLIENT_SECRET
                  valueFrom:
                    secretKeyRef:
                      name: hmpps-auth-secrets
                      key: NOMIS_OAUTH_API_CLIENT_SECRET
          restartPolicy: OnFailure

