apiVersion: apps/v1
kind: Deployment
metadata:
  name: django
  namespace: vorgabenui
spec:
  replicas: 1
  selector:
    matchLabels:
      app: django
  template:
    metadata:
      labels:
        app: django
    spec:
      securityContext:
        fsGroup: 99
        fsGroupChangePolicy: "OnRootMismatch"
      initContainers:
        - name: loader
          image: git.baumann.gr/adebaumann/vui-data-loader:0.11
          securityContext:
            runAsUser: 99
          command: [ "sh","-c","if [ ! -f /data/db.sqlite3 ] || [ ! -s /data/db.sqlite3 ]; then cp preload/preload.sqlite3 /data/db.sqlite3 && echo 'Database copied from preload'; else echo 'Existing database preserved'; fi" ]
          volumeMounts:
            - name: data
              mountPath: /data
      containers:
        - name: web
          image: git.baumann.gr/adebaumann/vui:0.988
          imagePullPolicy: Always
          securityContext:
            runAsUser: 99
          env:
          # Secret configuration
          - name: VORGABENUI_SECRET
            valueFrom:
              secretKeyRef:
                name: vorgabenui-secrets
                key: vorgabenui_secret
          # ConfigMap configuration
          - name: DEBUG
            valueFrom:
              configMapKeyRef:
                name: django-config
                key: DEBUG
          - name: DJANGO_ALLOWED_HOSTS
            valueFrom:
              configMapKeyRef:
                name: django-config
                key: DJANGO_ALLOWED_HOSTS
          - name: DJANGO_SETTINGS_MODULE
            valueFrom:
              configMapKeyRef:
                name: django-config
                key: DJANGO_SETTINGS_MODULE
          - name: VERSION
            valueFrom:
              configMapKeyRef:
                name: django-config
                key: VERSION
          ports:
            - containerPort: 8000
          volumeMounts:
            - name: data
              mountPath: /app/data
          readinessProbe:
            httpGet:
              path: /
              port: 8000
            initialDelaySeconds: 5
            periodSeconds: 10
            timeoutSeconds: 2
            failureThreshold: 6
          livenessProbe:
            httpGet:
              path: /
              port: 8000
            initialDelaySeconds: 20
            periodSeconds: 20
            timeoutSeconds: 2
            failureThreshold: 3
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: django-data-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: django
  namespace: vorgabenui
spec:
  type: ClusterIP
  selector:
    app: django
  ports:
    - name: http
      protocol: TCP
      port: 8000
      targetPort: 8000

