---
apiVersion: batch/v1
kind: Job
metadata:
  name: init-azure-pg-job
  labels:
    app: init-azure-pg-job
    git/branch: ${BRANCH_NAME}
    git/commit: ${COMMIT}
    gitlab/job: "${JOB_ID}"
spec:
  template:
    metadata:
      labels:
        app: init-azure-pg-job
        git/branch: ${BRANCH_NAME}
        git/commit: ${COMMIT}
        gitlab/job: "${JOB_ID}"
    spec:
      containers:
        - name: init-azure-pg-job
          image: postgres:10-alpine
          command:
            - sh
          args:
            - -c
            - |
              sh -x /mnt/script/init-db.sh
          resources:
            requests:
              cpu: 0m
              memory: 256Mi
            limits:
              cpu: 500m
              memory: 256Mi
          env:
            - name: PGSSLMODE
              value: "require"
            - name: BRANCH_HASH
              value: ${BRANCH_HASH}
            - name: POSTGRES_DATABASE_EMJPM
              value: "${POSTGRES_DATABASE_EMJPM}"
            - name: PGUSER
              value: ${EMJPM_PG_USER}
            - name: PGHOST
              value: ${PG_HOST}
            - name: PGPASSWORD
              value: "${EMJPM_PG_PASSWORD}"
          volumeMounts:
            - mountPath: "/mnt/script"
              name: script
      restartPolicy: Never
      volumes:
        - name: script
          configMap:
            name: ${K8S_PROJECT}-init-db-${BRANCH_HASH}
