apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: bt-backend-data-updater-$CI_ENVIRONMENT_NAME
  namespace: default
spec:
  concurrencyPolicy: Forbid
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 1
  jobTemplate:
    spec:
      activeDeadlineSeconds: 64800
      template:
        metadata:
          labels:
            component: bt-backend-data-updater-$CI_ENVIRONMENT_NAME
        spec:
          containers:
            - command:
                - ./update-data.sh
              env:
                - name: ENVIRONMENT_NAME
                  value: $CI_ENVIRONMENT_NAME
              envFrom:
                - secretRef:
                    name: bt-backend-$CI_ENVIRONMENT_NAME
              image: $CI_REGISTRY_IMAGE/bt-backend:$CI_COMMIT_BRANCH
              imagePullPolicy: Always
              name: bt-backend-data-updater-$CI_ENVIRONMENT_NAME
              volumeMounts:
                - mountPath: /etc/google
                  name: bt-backend
                  readOnly: true
          restartPolicy: OnFailure
          volumes:
            - name: bt-backend
              secret:
                defaultMode: 420
                items:
                  - key: GOOGLE_APPLICATION_CREDENTIALS_FILE_CONTENTS_BASE64
                    path: auth.json
                secretName: bt-backend-$CI_ENVIRONMENT_NAME
  schedule: 0 9 * * *
