apiVersion: apps/v1
kind: Deployment
metadata:
  name: prytaneum-server
  labels:
    app: prytaneum-server
  namespace: production
spec:
  selector:
    matchLabels:
      app: prytaneum-server
  replicas: 4
  revisionHistoryLimit: 100
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 50%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: prytaneum-server
    spec:
      containers:
        - name: prytaneum-server
          image: gcr.io/PROJECT_ID/SERVER_IMAGE:TAG
          imagePullPolicy: IfNotPresent
          resources:
            limits:
              cpu: 250m
              memory: 500Mi
            requests:
              cpu: 150m
              memory: 300Mi
          env:
            - name: NODE_ENV
              valueFrom:
                configMapKeyRef:
                  key: NODE_ENV
                  name: prytaneum-server-config
            - name: HOST
              valueFrom:
                configMapKeyRef:
                  key: HOST
                  name: prytaneum-server-config
            - name: SERVER_PORT
              valueFrom:
                configMapKeyRef:
                  key: SERVER_PORT
                  name: prytaneum-server-config
            - name: REDIS_HOST
              valueFrom:
                configMapKeyRef:
                  name: prytaneum-server-config
                  key: REDIS_HOST
            - name: GCP_PROJECT_ID
              valueFrom:
                configMapKeyRef:
                  key: GCP_PROJECT_ID
                  name: prytaneum-server-config
            - name: PUB_SUB_PREFIX
              valueFrom:
                configMapKeyRef:
                  key: PUB_SUB_PREFIX
                  name: prytaneum-server-config
            - name: POD_ID
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: DATABASE_URL
              valueFrom:
                secretKeyRef:
                  key: database_url
                  name: db-secret
            - name: MAILGUN_API_KEY
              valueFrom:
                secretKeyRef:
                  key: api_key
                  name: mailgun-secret
            - name: MAILGUN_DOMAIN
              valueFrom:
                secretKeyRef:
                  key: domain
                  name: mailgun-secret
            - name: MAILGUN_FROM_EMAIL
              valueFrom:
                secretKeyRef:
                  key: from_email
                  name: mailgun-secret
            - name: REDIS_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: REDIS_PASSWORD
                  name: redis-secret
            - name: "GOOGLE_APPLICATION_CREDENTIALS"
              value: "/var/secrets/google/key.json"
          volumeMounts:
            - name: "service-account"
              mountPath: "/var/secrets/google"
      volumes:
        - name: "service-account"
          secret:
            secretName: "pubsub-sa-key"
