apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: parliamentary-questions
  name: parliamentary-questions
spec:
  replicas: 4
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 0
      maxSurge: 1
  selector:
    matchLabels:
      app: parliamentary-questions
  template:
    metadata:
      labels:
        app: parliamentary-questions
    spec:
      containers:
        - name: parliamentary-questions-rails-app
          command: ["./docker/entrypoint-webapp.sh"]
          env:
            - name: DB_HOST
              valueFrom:
                secretKeyRef:
                  key: rds_instance_address
                  name: parliamentary-questions-staging-rds
            - name: PGPASSWORD
              valueFrom:
                secretKeyRef:
                  key: database_password
                  name: parliamentary-questions-staging-rds
            - name: PGUSER
              valueFrom:
                secretKeyRef:
                  key: database_username
                  name: parliamentary-questions-staging-rds
            - name: REDIS_URL
              valueFrom:
                secretKeyRef:
                  name: parliamentary-questions-elasticache-redis-output
                  key: url
            - name: REDIS_AUTH_TOKEN
              valueFrom:
                secretKeyRef:
                  name: parliamentary-questions-elasticache-redis-output
                  key: auth_token
          envFrom:
            - configMapRef:
                name: environment-variables
            - secretRef:
                name: pq-secrets
          readinessProbe:
            httpGet:
              path: /ping.json
              port: 3000
              httpHeaders:
                - name: X-Forwarded-Proto
                  value: https
                - name: X-Forwarded-Ssl
                  value: "on"
            initialDelaySeconds: 40
            periodSeconds: 60
            timeoutSeconds: 2
          livenessProbe:
            httpGet:
              path: /ping.json
              port: 3000
              httpHeaders:
                - name: X-Forwarded-Proto
                  value: https
                - name: X-Forwarded-Ssl
                  value: "on"
            initialDelaySeconds: 40
            periodSeconds: 60
            timeoutSeconds: 2
          imagePullPolicy: Always
          ports:
            - containerPort: 3000
