apiVersion: apps/v1 
kind: Deployment 
metadata: 
  name: study-designer 
  labels: 
    app: study-designer 
spec: 
  replicas: 1 
  selector: 
    matchLabels: 
      app: study-designer 
  template: 
    metadata: 
      labels: 
        app: study-designer 
    spec: 
      containers: 
        - name: study-designer 
          image: gcr.io/heroes-hat-dev/study-designer:latest
          securityContext:
            privileged: true
            capabilities:
              add:
                - SYS_ADMIN
          lifecycle:
            postStart:
              exec:
                # The "fda_resources" should eventually come from an environment variable.
                command: ["gcsfuse", "-o", "nonempty", "fda_resources", "/usr/local/tomcat/webapps/fdaResources"]
            preStop:
              exec:
                command: ["fusermount", "-u", "/usr/local/tomcat/webapps/fdaResources"]          
          env: 
            - name: DB_USER 
              valueFrom: 
                secretKeyRef: 
                  name: study-designer-db-credentials 
                  key: username 
            - name: DB_PASS 
              valueFrom: 
                secretKeyRef: 
                  name: study-designer-db-credentials 
                  key: password 
            - name: DB_NAME 
              valueFrom: 
                secretKeyRef: 
                  name: study-designer-db-credentials 
                  key: dbname 
            - name: FROM_EMAIL_ADDRESS
              valueFrom:
                secretKeyRef:
                  name: email-credentials
                  key: email_address
            - name: FROM_EMAIL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: email-credentials
                  key: email_password
            - name: CLIENT_ID
              valueFrom:
                secretKeyRef:
                  name: study-designer-secrets
                  key: CLIENT_ID
            - name: SECRET_KEY
              valueFrom:
                secretKeyRef:
                  name: study-designer-secrets
                  key: SECRET_KEY
            - name: REGISTRATION_SERVER_URL
              value: "user-registration-server-np:50000"
            - name: RESPONSE_SERVER_URL
              value: "response-server-np:50000"
            - name: GOOGLE_APPLICATION_CREDENTIALS
              value: "/secrets/gcloud_key/key.json"
          ports:
          - containerPort: 8080
          readinessProbe:
            httpGet:
              path: /studybuilder/appDetails.do
              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-dev:us-east1:my-studies2=tcp:3306", 
            "-credential_file=/secrets/cloudsql/key.json"] 
          volumeMounts: 
            - name: gcloud-key-volume 
              mountPath: /secrets/cloudsql 
              readOnly: true 
      volumes: 
        - name: gcloud-key-volume
          secret: 
            secretName: study-designer-gcloud-key
