---
apiVersion: batch/v1
kind: Job
metadata:
  name: ${K8S_PROJECT}-backup-before-${BRANCH_HASH}
  labels:
    app: ${K8S_PROJECT}-backup-before-${BRANCH_HASH}
    git/branch: ${BRANCH_NAME}
    git/commit: ${COMMIT}
    gitlab/job: "${JOB_ID}"
spec:
  template:
    spec:
      containers:
        #
        #
        #
        - name: backup
          image: postgres:10-alpine
          command:
            - sh
          args:
            - -c
            - |
              sh -x /mnt/script/backup.sh ;
          resources:
            requests:
              cpu: 10m
              memory: 32Mi
            limits:
              cpu: 100m
              memory: 64Mi
          env:
            - name: CRONJOB_STATUS_DIR
              value: /var/lib/cronjob/status
            - name: DUMP_DIR
              value: /mnt/data
            - name: DUMP_DEV_DIR
              value: /mnt/dev-data
            - name: PGDATABASE
              value: emjpm
            - name: PGUSER
              value: ${ADMIN_PG_USER}
            - name: PGHOST
              value: ${PG_HOST}
            - name: PGPASSWORD
              value: "${ADMIN_PG_PASSWORD}"
          volumeMounts:
            - mountPath: "/mnt/data"
              name: data
            - mountPath: "/mnt/dev-data"
              name: dev-data
            - mountPath: "/mnt/script"
              name: script
        #
        #
      restartPolicy: Never
      volumes:
        - name: script
          configMap:
            name: ${K8S_PROJECT}-backup-configmap-${BRANCH_HASH}
        - name: data
          azureFile:
            secretName: ${K8S_PROJECT}-azure-storage-${BRANCH_HASH}
            shareName: ${K8S_PROJECT}-backup-restore
            readOnly: false
        - name: dev-data
          azureFile:
            secretName: ${K8S_PROJECT}-azure-storage-dev
            shareName: ${K8S_PROJECT}-backup-restore
            readOnly: false
