apiVersion: apps/v1
kind: Deployment
metadata:
  name: memote-webservice-production
spec:
  selector:
    matchLabels:
      app: memote-webservice
      env: production
  replicas: 1
  template:
    metadata:
      labels:
        app: memote-webservice
        env: production
    spec:
      containers:
      - name: web
        image: gcr.io/dd-decaf-cfbf6/memote-webservice:master
        imagePullPolicy: Always
        ports:
        - containerPort: 8000
        env:
        - name: ENVIRONMENT
          value: production
        - name: FLASK_APP
          value: src/memote_webservice/wsgi.py
        - name: SCRIPT_NAME
          value: /memote-webservice
        - name: ALLOWED_ORIGINS
          value: https://memote.dd-decaf.eu,*
        - name: MAX_CONTENT_LENGTH
          value: "26214400"  # 25 MB is the size of Recon3D.
        - name: REDIS_URL
          value: redis://localhost:6379/0
        - name: SENTRY_DSN
          valueFrom:
            secretKeyRef:
              name: memote-webservice
              key: SENTRY_DSN
        - name: SECRET_KEY
          valueFrom:
            secretKeyRef:
              name: memote-webservice
              key: SECRET_KEY
        command: ["gunicorn", "-c", "gunicorn.py", "memote_webservice.wsgi:app"]
        resources:
          requests:
            cpu: "1m"
          limits:
            cpu: "1000m"
            memory: "500Mi"
      - name: worker
        image: gcr.io/dd-decaf-cfbf6/memote-webservice:master
        imagePullPolicy: Always
        securityContext:
          runAsUser: 1000
          allowPrivilegeEscalation: false
        env:
        - name: REDIS_URL
          value: redis://localhost:6379/0
        command: ["celery", "-A", "memote_webservice.tasks", "worker", "--loglevel=info"]
        resources:
          requests:
            cpu: "1m"
          limits:
            cpu: "1000m"
            memory: "2Gi"
      - name: flower
        image: gcr.io/dd-decaf-cfbf6/memote-webservice:master
        imagePullPolicy: Always
        ports:
        - containerPort: 5555
        env:
        - name: REDIS_URL
          value: redis://localhost:6379/0
        - name: FLOWER_USERNAME
          valueFrom:
            secretKeyRef:
              name: memote-webservice
              key: FLOWER_USERNAME
        - name: FLOWER_PASSWORD
          valueFrom:
            secretKeyRef:
              name: memote-webservice
              key: FLOWER_PASSWORD
        command: ["celery", "flower", "-A", "memote_webservice", "--broker=redis://localhost:6379/0", "--basic_auth=$(FLOWER_USERNAME):$(FLOWER_PASSWORD)"]
        resources:
          requests:
            cpu: "1m"
          limits:
            cpu: "500m"
            memory: "128Mi"
      - name: cache
        image: redis:4.0-alpine
        resources:
          requests:
            cpu: "1m"
          limits:
            cpu: "1000m"
            memory: "2Gi"
        volumeMounts:
          - mountPath: "/data"
            name: memote-webservice-production
      volumes:
        - name: memote-webservice-production
          persistentVolumeClaim:
           claimName: memote-webservice-production
