apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mautic-db-pvc
  namespace: hf-mautic
  annotations:
    argocd.argoproj.io/sync-wave: "1"
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: longhorn
  resources:
    requests:
      storage: 10Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mautic-data-pvc
  namespace: hf-mautic
  annotations:
    argocd.argoproj.io/sync-wave: "1"
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: longhorn
  resources:
    requests:
      storage: 5Gi
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mautic-db
  namespace: hf-mautic
  labels:
    app: mautic-db
  annotations:
    argocd.argoproj.io/sync-wave: "3"
spec:
  serviceName: mautic-db
  replicas: 1
  selector:
    matchLabels:
      app: mautic-db
  template:
    metadata:
      labels:
        app: mautic-db
    spec:
      containers:
        - name: mariadb
          image: docker.io/library/mariadb:10.11
          args:
            - --character-set-server=utf8mb4
            - --collation-server=utf8mb4_unicode_ci
            - --sql-mode=
          env:
            - name: MARIADB_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mautic-secret
                  key: MARIADB_ROOT_PASSWORD
            - name: MARIADB_DATABASE
              valueFrom:
                secretKeyRef:
                  name: mautic-secret
                  key: MARIADB_DATABASE
            - name: MARIADB_USER
              valueFrom:
                secretKeyRef:
                  name: mautic-secret
                  key: MARIADB_USER
            - name: MARIADB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mautic-secret
                  key: MARIADB_PASSWORD
          ports:
            - containerPort: 3306
              name: mysql
          readinessProbe:
            tcpSocket:
              port: mysql
            initialDelaySeconds: 10
            periodSeconds: 10
          volumeMounts:
            - name: mautic-db-storage
              mountPath: /var/lib/mysql
      volumes:
        - name: mautic-db-storage
          persistentVolumeClaim:
            claimName: mautic-db-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: mautic-db
  namespace: hf-mautic
spec:
  selector:
    app: mautic-db
  ports:
    - name: mysql
      protocol: TCP
      port: 3306
      targetPort: mysql
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mautic
  namespace: hf-mautic
  labels:
    app: mautic
  annotations:
    argocd.argoproj.io/sync-wave: "4"
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mautic
  template:
    metadata:
      labels:
        app: mautic
    spec:
      containers:
        - name: mautic
          image: docker.io/mautic/mautic:5-apache
          env:
            - name: DOCKER_MAUTIC_ROLE
              value: mautic_web
            - name: DOCKER_MAUTIC_RUN_MIGRATIONS
              value: "true"
            - name: DOCKER_MAUTIC_LOAD_TEST_DATA
              value: "false"
            - name: MAUTIC_DB_HOST
              valueFrom:
                secretKeyRef:
                  name: mautic-secret
                  key: MAUTIC_DB_HOST
            - name: MAUTIC_DB_PORT
              valueFrom:
                secretKeyRef:
                  name: mautic-secret
                  key: MAUTIC_DB_PORT
            - name: MAUTIC_DB_DATABASE
              valueFrom:
                secretKeyRef:
                  name: mautic-secret
                  key: MAUTIC_DB_DATABASE
            - name: MAUTIC_DB_USER
              valueFrom:
                secretKeyRef:
                  name: mautic-secret
                  key: MAUTIC_DB_USER
            - name: MAUTIC_DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mautic-secret
                  key: MAUTIC_DB_PASSWORD
            - name: MAUTIC_SITE_URL
              valueFrom:
                secretKeyRef:
                  name: mautic-secret
                  key: MAUTIC_SITE_URL
            - name: MAUTIC_TRUSTED_PROXIES
              valueFrom:
                secretKeyRef:
                  name: mautic-secret
                  key: MAUTIC_TRUSTED_PROXIES
            - name: MAUTIC_SECRET_KEY
              valueFrom:
                secretKeyRef:
                  name: mautic-secret
                  key: MAUTIC_SECRET_KEY
            - name: PHP_INI_VALUE_MEMORY_LIMIT
              value: 512M
            - name: PHP_INI_VALUE_UPLOAD_MAX_FILESIZE
              value: 128M
            - name: PHP_INI_VALUE_POST_MAX_FILESIZE
              value: 128M
          ports:
            - containerPort: 80
              name: http
          readinessProbe:
            httpGet:
              path: /
              port: http
            initialDelaySeconds: 30
            periodSeconds: 15
          volumeMounts:
            - name: mautic-data
              mountPath: /var/www/html/config
              subPath: config
            - name: mautic-data
              mountPath: /var/www/html/var/logs
              subPath: logs
            - name: mautic-data
              mountPath: /var/www/html/docroot/media
              subPath: media
      volumes:
        - name: mautic-data
          persistentVolumeClaim:
            claimName: mautic-data-pvc
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mautic-cron
  namespace: hf-mautic
  labels:
    app: mautic-cron
  annotations:
    argocd.argoproj.io/sync-wave: "5"
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mautic-cron
  template:
    metadata:
      labels:
        app: mautic-cron
    spec:
      containers:
        - name: mautic-cron
          image: docker.io/mautic/mautic:5-apache
          env:
            - name: DOCKER_MAUTIC_ROLE
              value: mautic_cron
            - name: MAUTIC_DB_HOST
              valueFrom:
                secretKeyRef:
                  name: mautic-secret
                  key: MAUTIC_DB_HOST
            - name: MAUTIC_DB_PORT
              valueFrom:
                secretKeyRef:
                  name: mautic-secret
                  key: MAUTIC_DB_PORT
            - name: MAUTIC_DB_DATABASE
              valueFrom:
                secretKeyRef:
                  name: mautic-secret
                  key: MAUTIC_DB_DATABASE
            - name: MAUTIC_DB_USER
              valueFrom:
                secretKeyRef:
                  name: mautic-secret
                  key: MAUTIC_DB_USER
            - name: MAUTIC_DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mautic-secret
                  key: MAUTIC_DB_PASSWORD
            - name: MAUTIC_SITE_URL
              valueFrom:
                secretKeyRef:
                  name: mautic-secret
                  key: MAUTIC_SITE_URL
            - name: MAUTIC_SECRET_KEY
              valueFrom:
                secretKeyRef:
                  name: mautic-secret
                  key: MAUTIC_SECRET_KEY
          volumeMounts:
            - name: mautic-data
              mountPath: /var/www/html/config
              subPath: config
            - name: mautic-data
              mountPath: /var/www/html/var/logs
              subPath: logs
            - name: mautic-data
              mountPath: /var/www/html/docroot/media
              subPath: media
      volumes:
        - name: mautic-data
          persistentVolumeClaim:
            claimName: mautic-data-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: mautic
  namespace: hf-mautic
spec:
  selector:
    app: mautic
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: http
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: mautic-ingress
  namespace: hf-mautic
  annotations:
    argocd.argoproj.io/sync-wave: "6"
spec:
  ingressClassName: traefik
  rules:
    - host: mautic.heckenfels.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: mautic
                port:
                  number: 80
