---
apiVersion: apps/v1
kind: Deployment

metadata:
  name: matomo-server
  labels:
    app.kubernetes.io/name: matomo
    app.kubernetes.io/component: server

spec:
  replicas: 1
  revisionHistoryLimit: 3

  strategy:
    type: Recreate

  selector:
    matchLabels:
      app.kubernetes.io/name: matomo
      app.kubernetes.io/component: server

  template:
    metadata:
      labels:
        app.kubernetes.io/name: matomo
        app.kubernetes.io/component: server

    spec:
      enableServiceLinks: false

      initContainers:
        - name: checks
          image: matomo-checks
          imagePullPolicy: IfNotPresent

          securityContext:
            allowPrivilegeEscalation: false

          command:
            - sh
            - -c
            - |
              echo "Waiting for database to become ready..."
              wait-for-it -t 120 ${MATOMO_DATABASE_HOST}
              echo "OK ✓"

          envFrom:
            - configMapRef:
                name: matomo-server

          resources:
            limits:
              cpu: 10m
              memory: 16Mi
            requests:
              cpu: 10m
              memory: 16Mi

      containers:
        - name: server
          image: matomo-server
          imagePullPolicy: IfNotPresent

          envFrom:
            - configMapRef:
                name: matomo-server
            - secretRef:
                name: matomo-server

          ports:
            - name: http
              containerPort: 80

          volumeMounts:
            - name: data
              mountPath: /var/www/html

      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: matomo-server
...
