apiVersion: apps/v1
kind: Deployment
metadata:
  name: scoutplan-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: scoutplan-app
  minReadySeconds: 5
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 5
      maxUnavailable: 1
  template:
    metadata:
      labels:
        app: scoutplan-app
    spec:
      # initContainers:
      # - name: migrations
      #   image: registry.digitalocean.com/scoutplan/app
      #   command:
      #   - rake
      #   - db:abort_if_pending_migrations
      containers:
        - name: scoutplan-app
          image: registry.digitalocean.com/scoutplan/app
          imagePullPolicy: "Always"
          readinessProbe:
            httpGet:
              path: /
              port: 3000
              scheme: HTTP
            initialDelaySeconds: 60
            periodSeconds: 10
            timeoutSeconds: 60
            failureThreshold: 3
          startupProbe:
            httpGet:
              path: /
              port: 3000
              scheme: HTTP
            initialDelaySeconds: 60
            periodSeconds: 10
            timeoutSeconds: 60
            failureThreshold: 5            
          env:
            - name: GITHUB_RUN_NUMBER
              value: "github-run-number"
            - name: DATABASE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: scoutplan-production
                  key: DATABASE_PASSWORD
            - name: RAILS_MASTER_KEY
              valueFrom:
                secretKeyRef:
                  name: scoutplan-production
                  key: RAILS_MASTER_KEY
            - name: SECRET_KEY_BASE
              valueFrom:
                secretKeyRef:
                  name: scoutplan-production
                  key: SECRET_KEY_BASE
            - name: SKYLIGHT_AUTHENTICATION
              valueFrom:
                secretKeyRef:
                  name: scoutplan-production
                  key: SKYLIGHT_AUTHENTICATION
            - name: SMTP_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: scoutplan-production
                  key: SMTP_PASSWORD
            - name: MAPBOX_TOKEN
              valueFrom:
                secretKeyRef:
                  name: scoutplan-production
                  key: MAPBOX_TOKEN
            - name: MIXPANEL_TOKEN
              valueFrom:
                secretKeyRef:
                  name: scoutplan-production
                  key: MIXPANEL_TOKEN                  
            - name: DO_STORAGE_SECRET
              valueFrom:
                secretKeyRef:
                  name: scoutplan-production
                  key: DO_STORAGE_SECRET
            - name: TWILIO_TOKEN
              valueFrom:
                secretKeyRef:
                  name: scoutplan-production
                  key: TWILIO_TOKEN
          envFrom:
          - configMapRef:
              name: scoutplan-production-config
          ports:
            - containerPort: 3000
