apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    name: prep-api
  name: prep-api
  namespace: prep
spec:
  progressDeadlineSeconds: 2147483647
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      name: prep-api
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        name: prep-api
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: type
                    operator: In
                    values:
                      - webapps
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - podAffinityTerm:
                labelSelector:
                  matchExpressions:
                    - key: name
                      operator: In
                      values:
                        - prep-api
                topologyKey: kubernetes.io/hostname
              weight: 100
      containers:
        - args:
            - start
          env:
            - name: RAILS_LOG_TO_STDOUT
              value: "true"
            - name: RACK_ENV
              value: production
            - name: RAILS_ENV
              value: production
            - name: PORT
              value: "3000"
            - name: RAILS_SERVE_STATIC_FILES
              value: "true"
            - name: APIGATEWAY_URL
              value: https://production-api.globalforestwatch.org
            - name: AUTH_USERNAME
              valueFrom:
                secretKeyRef:
                  key: PREP_MANAGER_AUTH_USERNAME
                  name: appsecrets
            - name: AUTH_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: PREP_MANAGER_AUTH_PASSWORD
                  name: appsecrets
            - name: POSTGRES_URL
              valueFrom:
                secretKeyRef:
                  key: PREP_MANAGER_POSTGRES_URL
                  name: dbsecrets
            - name: S3_BUCKET_NAME
              value: wri-api-backups
            - name: S3_PATH
              value: prep/production
            - name: AWS_REGION
              value: us-east-1
            - name: AWS_ACCESS_KEY_ID
              valueFrom:
                secretKeyRef:
                  key: S3_ACCESS_KEY_ID
                  name: mssecrets
            - name: AWS_SECRET_ACCESS_KEY
              valueFrom:
                secretKeyRef:
                  key: S3_SECRET_ACCESS_KEY
                  name: mssecrets
          image: gfwdockerhub/prep-api
          imagePullPolicy: Always
          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /health
              port: 3000
              scheme: HTTP
            initialDelaySeconds: 30
            periodSeconds: 15
            successThreshold: 1
            timeoutSeconds: 5
          name: prep-api
          ports:
            - containerPort: 3000
              protocol: TCP
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /health
              port: 3000
              scheme: HTTP
            initialDelaySeconds: 30
            periodSeconds: 15
            successThreshold: 1
            timeoutSeconds: 5
          resources:
            limits:
              cpu: "1"
              memory: 512M
            requests:
              cpu: 500m
              memory: 256M
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      imagePullSecrets:
        - name: regcred
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
