apiVersion: batch/v1
kind: CronJob
metadata:
  name: backend-job-migrations
  namespace: hotpocket-development
  labels:
    app.kubernetes.io/app: backend-job-migrations
spec:
  concurrencyPolicy: "Forbid"
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 1
  startingDeadlineSeconds: 180
  schedule: "* * * * *"
  suspend: true
  jobTemplate:
    spec:
      backoffLimit: 1
      completions: 1
      parallelism: 1
      template:
        spec:
          containers:
            - name: migrations
              image: hotpocket-backend:latest
              args:
                - "./manage.py"
                - "migrate"
              envFrom:
                - configMapRef:
                    name: backend-base-config
                - configMapRef:
                    name: backend-webapp-config
              env:
                - name: VAULT_URL
                  valueFrom:
                    secretKeyRef:
                      name: backend-vault
                      key: url
                - name: VAULT_ROLE_ID
                  valueFrom:
                    secretKeyRef:
                      name: backend-vault
                      key: role_id
                - name: VAULT_SECRET_ID
                  valueFrom:
                    secretKeyRef:
                      name: backend-vault
                      key: secret_id
              volumeMounts:
                - mountPath: /dev/shm
                  name: shm
                - mountPath: /srv/run
                  name: backend-webapp-srv-run
                - mountPath: /srv/uploads
                  name: backend-webapp-srv-uploads
                - name: backend-admin-local-deps
                  mountPath: "/srv/lib/requirements.txt"
                  subPath: "requirements.txt"
                - name: backend-admin-local-deps
                  mountPath: "/srv/etc/entrypoint.d/01-install-extra-deps.sh"
                  subPath: "01-install-extra-deps.sh"
          dnsPolicy: ClusterFirst
          restartPolicy: Never
          volumes:
            - name: shm
              emptyDir:
                medium: Memory
            - name: backend-webapp-srv-run
              emptyDir: {}
            - name: backend-webapp-srv-uploads
              emptyDir: {}
            - name: backend-admin-local-deps
              configMap:
                name: "backend-local-deps"
                defaultMode: 0755
