apiVersion: apps/v1
kind: Deployment
metadata:
  name: svc-questionnaires
  namespace: sdv-mvp-__CI_COMMIT_DOWN_REF_NAME__
  labels:
    worker: "no"
spec:
  replicas: 10
  selector:
    matchLabels:
      app: svc-questionnaires
      tier: web
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0%
  template:
    metadata:
      labels:
        app: svc-questionnaires
        track: stable
        tier: web
    spec:
      imagePullSecrets:
        - name: gitlab-auth
      containers:
        - name: svc-questionnaires
          imagePullPolicy: Always
          image: registry.gitlab.com/researchable/sport-data-valley/mvp/svc-questionnaires:__CI_COMMIT_SHA__
          resources:
            limits:
              memory: "1.5Gi"
            requests:
              memory: "768Mi"
          env:
          - name: RAILS_ENV
            value: production
          - name: RACK_ENV
            value: production
          - name: NODE_ENV
            value: production
          - name: REVISION
            value: __CI_COMMIT_SHA__
          - name: APPSIGNAL_APP_ENV
            value: __CI_COMMIT_DOWN_REF_NAME__
          - name: APPSIGNAL_ACTIVE
            value: "true"
          - name: PAPERTRAIL_PROGRAM
            value: questionnaires
          - name: APPSIGNAL_PUSH_API_KEY
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___APPSIGNAL_PUSH_API_KEY
          - name: PUSH_SUBSCRIPTION_URL
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___PUSH_SUBSCRIPTION_URL
          - name: BASE_PLATFORM_URL
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___BASE_PLATFORM_URL
          - name: DATABASE_URL
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___DATABASE_URL
          - name: SECRET_KEY_BASE
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___SECRET_KEY_BASE
          - name: HOST_URL
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___HOST_URL
          - name: HOST_DOMAIN
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___HOST_URL
          - name: INFO_EMAIL
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___INFO_EMAIL
          - name: FEEDBACK_EMAIL
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___FEEDBACK_EMAIL
          - name: MESSAGEBIRD_ACCESS_KEY
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___MESSAGEBIRD_ACCESS_KEY
          - name: MESSAGEBIRD_SEND_FROM
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___MESSAGEBIRD_SEND_FROM
          - name: PERSON_SALT
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___PERSON_SALT
          - name: STOP_SUBSCRIPTION_SALT
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___STOP_SUBSCRIPTION_SALT
          - name: ADMIN_USERNAME
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___ADMIN_USERNAME
          - name: ADMIN_PASSWORD
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___ADMIN_PASSWORD
          - name: MAILGUN_API_KEY
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___MAILGUN_API_KEY
          - name: MAILGUN_DOMAIN
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___MAILGUN_DOMAIN
          - name: FROM_EMAIL_ADDRESS
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___FROM_EMAIL_ADDRESS
          - name: AUTH0_CLIENT_ID
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___AUTH0_CLIENT_ID
          - name: AUTH0_DOMAIN
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___AUTH0_DOMAIN
          - name: AUTH0_CLIENT_SECRET
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___AUTH0_CLIENT_SECRET
          - name: AUTH0_REDIRECT_URL
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___AUTH0_REDIRECT_URL
          - name: AUTH0_AUDIENCE
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___AUTH0_AUDIENCE
          - name: AUTH0_SIGNING_CERTIFICATE
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___AUTH0_SIGNING_CERTIFICATE
          - name: REDIS_URL
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___REDIS_URL
          - name: TEST_PHONE_NUMBERS
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___TEST_PHONE_NUMBERS
          - name: SNITCH_KEY
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___SNITCH_KEY
          - name: API_KEY
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___API_KEY
          - name: API_SECRET
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___API_SECRET
          - name: IP_HASH_SALT
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___IP_HASH_SALT
          - name: INFO_SITE_URL
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___INFO_SITE_URL
          - name: TOKEN_SIGNATURE_ALGORITHM
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___TOKEN_SIGNATURE_ALGORITHM
          - name: PAPERTRAIL_PORT
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___PAPERTRAIL_PORT
          - name: PAPERTRAIL_HOST
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___PAPERTRAIL_HOST
          - name: RAILS_SERVE_STATIC_FILES
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___RAILS_SERVE_STATIC_FILES
          - name: MAILGUN_API_HOST
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___MAILGUN_API_HOST
          - name: MONGODB_URI
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___MONGODB_URI
          - name: PROJECT_START_DATE
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___PROJECT_START_DATE
          - name: PROJECT_END_DATE
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___PROJECT_END_DATE
          - name: PROJECT_NAME
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___PROJECT_NAME
          - name: SITE_LOCATION
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___SITE_LOCATION
          - name: WEB_CONCURRENCY
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___WEB_CONCURRENCY
          - name: RAILS_MAX_THREADS
            valueFrom:
              secretKeyRef:
                name: svc-questionnaires-secret
                key: __CI_COMMIT_REF_NAME___RAILS_MAX_THREADS
          ports:
          - containerPort: 3000
            protocol: TCP
          # The readiness probe is triggered after the startup probe. We
          # already found that the pod was ready, hence 1 initial delay. After
          # that it will poll every 30 seconds, and if it fails twice, the pod
          # is killed.
          readinessProbe:
            httpGet:
              path: /status
              port: 3000
              scheme: HTTP
            initialDelaySeconds: 1
            timeoutSeconds: 5
            periodSeconds: 30
            successThreshold: 1
            failureThreshold: 2
          # The startup probe is triggered when starting up the application. It
          # waits for 20 seconds before it starts polling. The polling will
          # happen every 5 seconds, and will continue for 60 tries. That is, if
          # the pod is not ready within 60*5+20 seconds, it wont be started.
          startupProbe:
            httpGet:
              path: /status
              port: 3000
              scheme: HTTP
            initialDelaySeconds: 20
            timeoutSeconds: 4
            periodSeconds: 5
            successThreshold: 1
            failureThreshold: 60

