apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend-webapp
  namespace: hotpocket-development
  labels:
    app.kubernetes.io/app: backend-webapp
spec:
  minReadySeconds: 30
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 1
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  selector:
    matchLabels:
      app.kubernetes.io/app: backend-webapp
  template:
    metadata:
      labels:
        app.kubernetes.io/app: backend-webapp
    spec:
      containers:
        - name: app
          image: hotpocket-backend:latest
          args:
            - "/srv/venv/bin/gunicorn"
            - "-c"
            - "/srv/lib/gunicorn.conf.py"
            - "hotpocket_backend.wsgi:application"
          envFrom:
            - configMapRef:
                name: backend-base-config
            - configMapRef:
                name: backend-webapp-config
          env:
            - name: VAULT_URL
              valueFrom:
                secretKeyRef:
                  name: backend-vault
                  key: url
            - name: VAULT_ROLE_ID
              valueFrom:
                secretKeyRef:
                  name: backend-vault
                  key: role_id
            - name: VAULT_SECRET_ID
              valueFrom:
                secretKeyRef:
                  name: backend-vault
                  key: secret_id
            - name: HOTPOCKET_BACKEND_CREATE_INITIAL_ACCOUNT
              value: "true"
          ports:
            - containerPort: 8000
              name: http
              protocol: TCP
            - containerPort: 8001
              name: healthcheck
              protocol: TCP
          livenessProbe:
            httpGet:
              path: "/"
              port: 8001
            initialDelaySeconds: 5
            periodSeconds: 10
          readinessProbe:
            httpGet:
              path: "/"
              port: 8001
            initialDelaySeconds: 2
            periodSeconds: 5
          volumeMounts:
            - mountPath: /dev/shm
              name: shm
            - mountPath: /srv/run
              name: backend-webapp-srv-run
            - mountPath: /srv/uploads
              name: backend-webapp-srv-uploads
            - name: backend-admin-local-deps
              mountPath: "/srv/lib/requirements.txt"
              subPath: "requirements.txt"
            - name: backend-admin-local-deps
              mountPath: "/srv/etc/entrypoint.d/01-install-extra-deps.sh"
              subPath: "01-install-extra-deps.sh"
            - name: backend-admin-local-deps
              mountPath: "/srv/etc/entrypoint.d/99-collectstatic.sh"
              subPath: "99-collectstatic.sh"
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      volumes:
        - name: shm
          emptyDir:
            medium: Memory
        - name: backend-webapp-srv-run
          emptyDir: {}
        - name: backend-webapp-srv-uploads
          persistentVolumeClaim:
            claimName: backend-uploads
        - name: backend-admin-local-deps
          configMap:
            name: "backend-local-deps"
            defaultMode: 0755
