apiVersion: apps/v1
kind: Deployment
metadata:
  name: response-server-ws
  labels:
    app: response-server-ws
spec:
  replicas: 1
  selector:
    matchLabels:
      app: response-server
  template:
    metadata:
      labels:
        app: response-server
      annotations:
        sidecar.istio.io/inject: "true"
    spec:
      containers:
        - name: response-server-ws
          image: gcr.io/heroes-hat-unc-dev-apps/response-server-ws:latest
          env:
            - name: DB_USER
              valueFrom:
                secretKeyRef:
                  name: response-server-db-credentials
                  key: username
            - name: DB_PASS
              valueFrom:
                secretKeyRef:
                  name: response-server-db-credentials
                  key: password
            - name: DB_NAME
              valueFrom:
                secretKeyRef:
                  name: response-server-db-credentials
                  key: dbname
            - name: FIRESTORE_PROJECT_ID
              value: "heroes-hat-unc-dev-firebase"
            - name: AUTH_SERVER_NP_URL
              value: "auth-server-np:50000"
            - name: REGISTRATION_CLIENT_ID
              valueFrom:
                secretKeyRef:
                  key: REGISTRATION_CLIENT_ID
                  name: response-server-secrets
            - name: REGISTRATION_CLIENT_SECRET
              valueFrom:
                secretKeyRef:
                  key: REGISTRATION_CLIENT_SECRET
                  name: response-server-secrets
            - name: WCP_USER
              valueFrom:
                secretKeyRef:
                  key: WCP_USER
                  name: response-server-secrets
            - name: WCP_PASS
              valueFrom:
                secretKeyRef:
                  key: WCP_PASS
                  name: response-server-secrets
            - name: WCP_STUDY_METADATA_SERVER_URL
              value: "study-meta-data-np:50000"
            - name: REGISTRATION_SERVER_URL
              value: "user-registration-server-np:50000"
            - name: GOOGLE_APPLICATION_CREDENTIALS
              value: "/secrets/gcloud_key/key.json"
          ports:
          - containerPort: 8080
          readinessProbe:
            httpGet:
              path: /mystudies-response-server/health
              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: response-server-gcloud-key
