apiVersion: apps/v1
kind: Deployment
metadata:
  name: obljubadeladolg-deployment
  labels:
    app: obljubadeladolg
spec:
  replicas: 1
  selector:
    matchLabels:
      app: obljubadeladolg
  template:
    metadata:
      labels:
        app: obljubadeladolg
    spec:
      securityContext:
        fsGroup: 1000
      volumes:
        - name: obljubadeladolg-persistent-storage
          persistentVolumeClaim:
            claimName: obljubadeladolg-pvc
      initContainers:
        # - name: fixmanifest
        #   image: obljubadeladolg
        #   volumeMounts:
        #     - name: obljubadeladolg-persistent-storage
        #       mountPath: /pvc
        #   command:
        #     - rm
        #     - /pvc/static/staticfiles.json
        #   env:
        #     - name: DJANGO_SETTINGS_MODULE
        #       value: obljubadeladolg.settings.production
        #   envFrom:
        #     - secretRef:
        #         name: obljubadeladolg-credentials
        - name: collectstatic
          image: obljubadeladolg
          volumeMounts:
            - name: obljubadeladolg-persistent-storage
              mountPath: /pvc
          command:
            - python
            - manage.py
            - collectstatic
            - --no-input
          env:
            - name: DJANGO_SETTINGS_MODULE
              value: obljubadeladolg.settings.production
          envFrom:
            - secretRef:
                name: obljubadeladolg-credentials
          resources:
            requests:
              memory: 1Gi
              cpu: 500m
            limits:
              memory: 1Gi
              cpu: 500m
        - name: migrate
          image: obljubadeladolg
          command:
            - python
            - manage.py
            - migrate
          env:
            - name: DJANGO_SETTINGS_MODULE
              value: obljubadeladolg.settings.production
          envFrom:
            - secretRef:
                name: obljubadeladolg-credentials
          resources:
            requests:
              memory: 1Gi
              cpu: 500m
            limits:
              memory: 1Gi
              cpu: 500m
      containers:
        - name: obljubadeladolg
          image: obljubadeladolg
          volumeMounts:
            - name: obljubadeladolg-persistent-storage
              mountPath: /pvc
          command:
            - gunicorn
            - obljubadeladolg.wsgi:application
            - -b
            - 0.0.0.0:8000
            - --log-level
            - DEBUG
          ports:
            - containerPort: 8000
          envFrom:
              - secretRef:
                  name: obljubadeladolg-credentials
          env:
            - name: DJANGO_SETTINGS_MODULE
              value: obljubadeladolg.settings.production
            # - name: DJANGO_DEBUG
            #   value: 'True'
          resources:
            requests:
              memory: 1Gi
              cpu: 1000m
            limits:
              memory: 1Gi
              cpu: 1000m
        - name: obljubadeladolg-nginx
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          image: nginx:alpine
          volumeMounts:
            - name: obljubadeladolg-persistent-storage
              mountPath: /usr/share/nginx/html
          resources:
            requests:
              memory: 500Mi
              cpu: 300m
            limits:
              memory: 500Mi
              cpu: 300m
