apiVersion: batch/v1
kind: Job
metadata:
  name: import-autoencoded-sc-job
spec:
  template:
    spec:
      containers:
      - name: autoencoded-sc-importer
        image: gcr.io/devenv-215523/annotated-object-importer:${IMPORTER_VERSION}
        imagePullPolicy: Always
        command: ["java", "-Xms256M", "-Xmx1G", "-jar", "/app/annotated-object-importer.jar", "datasets"]
        resources:
          requests:
            memory: "1G"
          limits:
            memory: "1G"
        env:
          - name: JVM_OPTS
            value: "-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap"
          - name: ID_URLS
            value: dataset>http://gcp.wenglab.org/sc-autoencoded/cells.txt|genes>http://gcp.wenglab.org/sc-autoencoded/genes.txt
          - name: COORDINATE_JSON_URLS
            value: dataset=latent>http://gcp.wenglab.org/sc-autoencoded/latent.json
          - name: MATRIX_JSON_URLS
            value: dataset=raw>http://gcp.wenglab.org/sc-autoencoded/raw.json;normalized>http://gcp.wenglab.org/sc-autoencoded/normalized.json;decoded>http://gcp.wenglab.org/sc-autoencoded/decoded.json
          - name: DB_SCHEMA
            value: "${DB_SCHEMA}"
          - name: DB_URL
            value: "jdbc:postgresql://127.0.0.1:5432/annotated-datasets-db"
          - name: DB_USERNAME
            valueFrom:
              secretKeyRef:
                name: annotated-datasets-db-credentials
                key: username
          - name: DB_PASSWORD
            valueFrom:
              secretKeyRef:
                name: annotated-datasets-db-credentials
                key: password
      - name: cloudsql-proxy
        image: gcr.io/cloudsql-docker/gce-proxy:1.11
        command: ["/cloud_sql_proxy",
                  "-instances=devenv-215523:us-east1:annotated-datasets-instance=tcp:5432",
                  "-credential_file=/secrets/cloudsql/staging-service-account.json"]
        securityContext:
          runAsUser: 2  # non-root user
          allowPrivilegeEscalation: false
        volumeMounts:
          - name: service-account-key
            mountPath: /secrets/cloudsql
            readOnly: true
      volumes:
        - name: service-account-key
          secret:
            secretName: service-account-key
      restartPolicy: Never
