apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: matomo-pvc
  namespace: pidoka-hf-matomo
  annotations:
    argocd.argoproj.io/sync-wave: "1"
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: longhorn
  resources:
    requests:
      storage: 1Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: matomo-db-pvc
  namespace: pidoka-hf-matomo
  annotations:
    argocd.argoproj.io/sync-wave: "1"
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: longhorn
  resources:
    requests:
      storage: 1Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: matomo-db
  namespace: pidoka-hf-matomo
  labels:
    app: matomo-db
  annotations:
    argocd.argoproj.io/sync-wave: "3"
spec:
  replicas: 1
  selector:
    matchLabels:
      app: matomo-db
  template:
    metadata:
      labels:
        app: matomo-db
    spec:
      containers:
        - name: mariadb
          image: docker.io/library/mariadb@sha256:e0236fc6386e7eacd9359e59d0a078bd7aa0d18280d36d13061121bedeaee903
          env:
            # Keep MYSQL_* for compatibility with older MariaDB images.
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: matomo-secret
                  key: MYSQL_ROOT_PASSWORD
            - name: MYSQL_DATABASE
              valueFrom:
                secretKeyRef:
                  name: matomo-secret
                  key: MYSQL_DATABASE
            - name: MYSQL_USER
              valueFrom:
                secretKeyRef:
                  name: matomo-secret
                  key: MYSQL_USER
            - name: MYSQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: matomo-secret
                  key: MYSQL_PASSWORD
            # MariaDB current images require MARIADB_* names.
            - name: MARIADB_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: matomo-secret
                  key: MYSQL_ROOT_PASSWORD
            - name: MARIADB_DATABASE
              valueFrom:
                secretKeyRef:
                  name: matomo-secret
                  key: MYSQL_DATABASE
            - name: MARIADB_USER
              valueFrom:
                secretKeyRef:
                  name: matomo-secret
                  key: MYSQL_USER
            - name: MARIADB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: matomo-secret
                  key: MYSQL_PASSWORD
          ports:
            - containerPort: 3306
          volumeMounts:
            - name: matomo-db-storage
              mountPath: /var/lib/mysql
      volumes:
        - name: matomo-db-storage
          persistentVolumeClaim:
            claimName: matomo-db-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: matomo-db
  namespace: pidoka-hf-matomo
spec:
  selector:
    app: matomo-db
  ports:
    - protocol: TCP
      port: 3306
      targetPort: 3306
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: matomo
  namespace: pidoka-hf-matomo
  labels:
    app: matomo
  annotations:
    argocd.argoproj.io/sync-wave: "4"
spec:
  replicas: 1
  selector:
    matchLabels:
      app: matomo
  template:
    metadata:
      labels:
        app: matomo
    spec:
      containers:
        - name: matomo
          image: docker.io/library/matomo@sha256:21b8bae018cd51a05f36bc6beac3861bb314d131df690c47bba1648aad2b8d7e
          env:
            - name: MATOMO_DATABASE_HOST
              valueFrom:
                secretKeyRef:
                  name: matomo-secret
                  key: MATOMO_DATABASE_HOST
            - name: MATOMO_DATABASE_DBNAME
              valueFrom:
                secretKeyRef:
                  name: matomo-secret
                  key: MATOMO_DATABASE_DBNAME
            - name: MATOMO_DATABASE_USERNAME
              valueFrom:
                secretKeyRef:
                  name: matomo-secret
                  key: MATOMO_DATABASE_USERNAME
            - name: MATOMO_DATABASE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: matomo-secret
                  key: MATOMO_DATABASE_PASSWORD
          ports:
            - containerPort: 80
          volumeMounts:
            - name: matomo-storage
              mountPath: /var/www/html
      volumes:
        - name: matomo-storage
          persistentVolumeClaim:
            claimName: matomo-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: matomo
  namespace: pidoka-hf-matomo
spec:
  selector:
    app: matomo
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: matomo-ingress
  namespace: pidoka-hf-matomo
  annotations:
    argocd.argoproj.io/sync-wave: "5"
spec:
  ingressClassName: traefik
  rules:
    - host: matomo.heckenfels.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: matomo
                port:
                  number: 80
