apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: sessionnet-scraper
  labels:
    app.kubernetes.io/name: sessionnet-scraper-cronjob
    app.kubernetes.io/component: sessionnet-scraper
spec:
  schedule: "5 4 * * *"
  concurrencyPolicy: Replace
  suspend: false
  jobTemplate:
    spec:
      parallelism: 1
      template:
        spec:
          restartPolicy: OnFailure
          volumes:
          - name: scraping-data-volume
            emptyDir: {}
          - name: dotenv
            configMap:
              name: meine-stadt-transparent-dot-env
          initContainers:
          - name: download-and-parse
            image: konstin2/scrape-session:v0.1.1
            args:
            - 'scrape'
            - 'Münster'
            volumeMounts:
            - mountPath: /app/storage
              name: scraping-data-volume
            env:
            - name: SENTRY_DSN
              valueFrom:
                secretKeyRef:
                  name: meine-stadt-transparent-secrets
                  key: sentry_dsn
          containers:
          - name: import-scraped-json
            image: konstin2/meine-stadt-transparent:v0.2.0
            imagePullPolicy: Always
            command:
            - /bin/bash
            - -c
            args:
            - 'set -e &&
              /app/.venv/bin/python /app/manage.py setup &&
              /app/.venv/bin/python /app/manage.py import_json --allow-shrinkage /app/storage/json/Münster.json &&
              /app/.venv/bin/python /app/manage.py notifyusers'
            volumeMounts:
            - mountPath: /app/storage
              name: scraping-data-volume
            - name: dotenv
              mountPath: /app/.env
              subPath: .env
            env:
            - name: DATABASE_URL
              valueFrom:
                secretKeyRef:
                  name: meine-stadt-transparent-secrets
                  key: database_url
            - name: SENTRY_DSN
              valueFrom:
                secretKeyRef:
                  name: meine-stadt-transparent-secrets
                  key: sentry_dsn
            - name: SECRET_KEY
              valueFrom:
                secretKeyRef:
                  name: meine-stadt-transparent-secrets
                  key: secret_key
            - name: MINIO_SECRET_KEY
              valueFrom:
                secretKeyRef:
                  name: minio
                  key: secret-key
            - name: MINIO_ACCESS_KEY
              valueFrom:
                secretKeyRef:
                  name: minio
                  key: access-key
            - name: EMAIL_URL
              valueFrom:
                secretKeyRef:
                  name: meine-stadt-transparent-secrets
                  key: email_url
          imagePullSecrets:
          - name: regcred
