apiVersion: apps/v1
kind: Deployment
metadata:
  name: eduroom-backend-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: eduroom-backend-deployment
  template:
    metadata:
      labels:
        app: eduroom-backend-deployment
    spec:
      restartPolicy: Always
      volumes:
        - name: pg-cloud-sql-sa
          secret:
            secretName: pg-cloud-sql-service-account
        - name: gcs-service-account-key
          secret:
            secretName: gcs-key
      containers:
      - name: cloud-sql-proxy-deployment
        image: gcr.io/cloudsql-docker/gce-proxy:1.17
        # resources:
        #   limits:
        #     memory: "128Mi"
        #     cpu: "500m"
        command:
          - "/cloud_sql_proxy"
          - "-instances=macbigduck:asia-southeast1:eduroom-postgres-development=tcp:5432"
          - "-credential_file=/secrets/service_account.json"
        securityContext:
          runAsNonRoot: true
        volumeMounts:
            - name: pg-cloud-sql-sa
              mountPath: /secrets/
              readOnly: true
      - name: eduroom-backend-deployment
        image: asia.gcr.io/macbigduck/eduroom-backend
        # resources:
        #   limits:
        #     memory: "128Mi"
        #     cpu: "500m"
        ports:
        - containerPort: 5000
        volumeMounts:
          - name: gcs-service-account-key
            mountPath: /etc/secret
            readOnly: true
        envFrom:
          - secretRef:
              name: prod-secret
          - configMapRef:
              name: prod-configmap
        env:
          - name: DB_USER
            valueFrom:
              secretKeyRef:
                  name: prod-secret
                  key: POSTGRES_USER
                  optional: false
          - name: DB_PASSWORD
            valueFrom:
              secretKeyRef:
                  name: prod-secret
                  key: POSTGRES_PASSWORD
                  optional: false
          - name: DB_HOST
            valueFrom:
              secretKeyRef:
                  name: prod-secret
                  key: POSTGRES_HOST
                  optional: false
          - name: DB_PORT
            valueFrom:
              configMapKeyRef:
                  name: prod-configmap
                  key: POSTGRES_PORT
                  optional: false
          - name: DB_NAME
            valueFrom:
              secretKeyRef:
                  name: prod-secret
                  key: POSTGRES_DB
                  optional: false