apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
  namespace: matl-online
  labels:
    app: matl-online
    role: web
spec:
  selector:
    matchLabels:
      app: matl-online
      role: web
  template:
    metadata:
      name: web
      namespace: matl-online
      labels:
        app: matl-online
        role: web
    spec:
      containers:
        - name: web
          image: "suever/matl-online:{{ .Values.CommitHash }}"
          command:
            - gunicorn
            - --worker-class=eventlet
            - --bind=0.0.0.0:5000
            # Flask-SocketIO requires only a single worker since eventlet does not
            # have sticky sessions
            - --workers=1
            - --threads=16
            - wsgi:app
          ports:
            - containerPort: 5000
          env:
            - name: SQLALCHEMY_DATABASE_URI
              valueFrom:
                secretKeyRef:
                  key: DATABASE_URI
                  name: secrets
            - name: CELERY_BROKER_URL
              valueFrom:
                secretKeyRef:
                  key: REDIS_URL
                  name: secrets
            - name: CELERY_RESULT_BACKEND
              valueFrom:
                secretKeyRef:
                  key: REDIS_URL
                  name: secrets
            - name: EVENTLET_NO_GREENDNS
              value: "yes"
            - name: SOCKETIO_MESSAGE_QUEUE
              valueFrom:
                secretKeyRef:
                  key: REDIS_URL
                  name: secrets
            - name: MATL_ONLINE_IMGUR_CLIENT_ID
              valueFrom:
                secretKeyRef:
                  key: MATL_ONLINE_IMGUR_CLIENT_ID
                  name: secrets
            - name: MATL_ONLINE_GITHUB_HOOK_SECRET
              valueFrom:
                secretKeyRef:
                  key: MATL_ONLINE_GITHUB_HOOK_SECRET
                  name: secrets
            - name: MATL_ONLINE_ROLLBAR_SERVER_SIDE_TOKEN
              valueFrom:
                secretKeyRef:
                  key: MATL_ONLINE_ROLLBAR_SERVER_SIDE_TOKEN
                  name: secrets
            - name: MATL_ONLINE_ROLLBAR_CLIENT_SIDE_TOKEN
              valueFrom:
                secretKeyRef:
                  key: MATL_ONLINE_ROLLBAR_CLIENT_SIDE_TOKEN
                  name: secrets
            - name: GOOGLE_ANALYTICS_UNIVERSAL_ID
              valueFrom:
                secretKeyRef:
                  key: GOOGLE_ANALYTICS_UNIVERSAL_ID
                  name: secrets
            - name: MATL_ONLINE_ENV
              value: prod
          securityContext:
            runAsNonRoot: true
            runAsUser: 8877
          readinessProbe:
            tcpSocket:
              port: 5000
          livenessProbe:
            tcpSocket:
              port: 5000
          resources:
            requests:
              cpu: 50m
              memory: 128Mi
            limits:
              cpu: 200m
              memory: 256Mi
