apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgis
spec:
  serviceName: postgis
  replicas: 1
  selector:
    matchLabels: {app: postgis}
  template:
    metadata:
      labels: {app: postgis}
    spec:
      securityContext:
        runAsNonRoot: true
        runAsUser: 70
        runAsGroup: 70
        fsGroup: 70
        fsGroupChangePolicy: OnRootMismatch
        seccompProfile:
          type: RuntimeDefault
      containers:
        - name: postgis
          image: postgis/postgis:18-3.6-alpine@sha256:05d68c7f0f19b9aa0bf7c4a2049b2e8b38b44a63116392b95726a4c913766cf6
          imagePullPolicy: IfNotPresent
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            capabilities:
              drop: ["ALL"]
          env:
            - name: POSTGRES_DB
              valueFrom:
                secretKeyRef:
                  name: who-need-help-local
                  key: POSTGRES_DB
            - name: POSTGRES_USER
              valueFrom:
                secretKeyRef:
                  name: who-need-help-local
                  key: POSTGRES_USER
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: who-need-help-local
                  key: POSTGRES_PASSWORD
          ports:
            - {name: postgres, containerPort: 5432}
          readinessProbe:
            exec:
              command: ["pg_isready", "-U", "postgres", "-d", "who_need_help"]
            periodSeconds: 3
          volumeMounts:
            - {name: data, mountPath: /var/lib/postgresql}
            - {name: runtime, mountPath: /var/run/postgresql}
            - {name: tmp, mountPath: /tmp}
      volumes:
        - name: data
          hostPath:
            path: /var/local/who-need-help/postgres
            type: DirectoryOrCreate
        - name: runtime
          emptyDir: {}
        - name: tmp
          emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  name: postgis
spec:
  selector: {app: postgis}
  ports:
    - {name: postgres, port: 5432, targetPort: postgres}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mailpit
spec:
  replicas: 1
  selector:
    matchLabels: {app: mailpit}
  template:
    metadata:
      labels: {app: mailpit}
    spec:
      securityContext:
        runAsNonRoot: true
        runAsUser: 10001
        runAsGroup: 10001
        seccompProfile:
          type: RuntimeDefault
      containers:
        - name: mailpit
          image: axllent/mailpit:v1.30.4@sha256:5a49a77c5bdbe7c5474450b4f46348d09949df3695257729c93a30369382d4f6
          imagePullPolicy: IfNotPresent
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            capabilities:
              drop: ["ALL"]
          ports:
            - {name: smtp, containerPort: 1025}
            - {name: http, containerPort: 8025}
          volumeMounts:
            - {name: tmp, mountPath: /tmp}
      volumes:
        - name: tmp
          emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  name: mailpit
spec:
  type: NodePort
  selector: {app: mailpit}
  ports:
    - {name: smtp, port: 1025, targetPort: smtp}
    - {name: http, port: 8025, targetPort: http, nodePort: 30227}
