# TODO: Rename this from study-meta-data to study-server.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: study-meta-data
  labels:
    app: study-meta-data
spec:
  replicas: 1
  selector:
    matchLabels:
      app: study-meta-data
  template:
    metadata:
      labels:
        app: study-meta-data
      annotations:
        sidecar.istio.io/inject: "true"
    spec:
      containers:
        - name: study-meta-data
          image: gcr.io/heroes-hat-unc-dev-apps/study-meta-data:latest
          env:
            - name: DB_USER
              valueFrom:
                secretKeyRef:
                  name: study-meta-data-db-credentials
                  key: username
            - name: DB_PASS
              valueFrom:
                secretKeyRef:
                  name: study-meta-data-db-credentials
                  key: password
            - name: DB_NAME
              valueFrom:
                secretKeyRef:
                  name: study-meta-data-db-credentials
                  key: dbname
            - name: CLIENT_ID
              valueFrom:
                secretKeyRef:
                  name: study-meta-data-secrets
                  key: CLIENT_ID
            - name: SECRET_KEY
              valueFrom:
                secretKeyRef:
                  name: study-meta-data-secrets
                  key: SECRET_KEY
            - name: BASE_URL
              valueFrom:
                secretKeyRef:
                  name: study-meta-data-secrets
                  key: BASE_URL
            - name: RESPONSE_SERVER
              value: "response-server-np:50000"
            - name: USER_REGISTRATION_SERVER
              value: "user-registration-server-np:50000"
            - name: GOOGLE_APPLICATION_CREDENTIALS
              value: "/secrets/gcloud_key/key.json"
          ports:
          - containerPort: 8080
          readinessProbe:
            httpGet:
              path: /StudyMetaData/ping
              port: 8080
          volumeMounts:
          - name: gcloud-key-volume
            mountPath: /secrets/gcloud_key
            readOnly: true
        - name: cloudsql-proxy
          image: gcr.io/cloudsql-docker/gce-proxy:latest
          command: ["/cloud_sql_proxy",
            "-instances=heroes-hat-unc-dev-data:us-east1:my-studies=tcp:3306",
            "-credential_file=/secrets/gcloud_key/key.json"]
          volumeMounts:
          - name: gcloud-key-volume
            mountPath: /secrets/gcloud_key
            readOnly: true
      volumes:
      - name: gcloud-key-volume
        secret:
          secretName: study-meta-data-gcloud-key
