apiVersion: apps/v1
kind: Deployment
metadata:
  name: nextcloud-prod
  labels:
    app.kubernetes.io/name: nextcloud-prod
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: nextcloud-prod
  template:
    metadata:
      labels:
        app.kubernetes.io/name: nextcloud-prod
    spec:
      initContainers:
        - name: wait-database
          image: busybox:1.35.0
          imagePullPolicy: IfNotPresent
          command:
            - sh
          args:
            - -c
            - >-
              until nc -w 1 -v $MYSQL_HOST:3306 || nc -w 1 -v $POSTGRES_HOST:5432;
              do echo "Waiting for database";
              done
          envFrom:
            - secretRef:
                name: nextcloud-prod-secrets
        - name: wait-redis
          image: busybox:1.35.0
          imagePullPolicy: IfNotPresent
          command:
            - sh
          args:
            - -c
            - >-
              until nc -w 1 -v $REDIS_HOST:$REDIS_HOST_PORT;
              do echo "Waiting for Redis";
              done
          envFrom:
            - secretRef:
                name: nextcloud-prod-secrets
      containers:
        - name: nextcloud-prod
          image: nextcloud:23.0.0-apache
          imagePullPolicy: IfNotPresent
          resources:
            requests:
              cpu: 100m
              memory: 150Mi
          ports:
            - name: http
              protocol: TCP
              containerPort: 80
          volumeMounts:
            - name: nextcloud-prod-config
              mountPath: /var/www/html
            - name: nextcloud-prod-data
              mountPath: /var/www/data
          startupProbe:
            httpGet:
              path: /status.php
              port: http
              httpHeaders:
                - name: Host
                  value: nextcloud.${SECRET_DOMAIN_2}
            initialDelaySeconds: 10
            timeoutSeconds: 5
            periodSeconds: 20
            successThreshold: 1
            failureThreshold: 30
          livenessProbe:
            httpGet:
              path: /status.php
              port: http
              httpHeaders:
                - name: Host
                  value: nextcloud.${SECRET_DOMAIN_2}
            initialDelaySeconds: 10
            timeoutSeconds: 5
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /status.php
              port: http
              httpHeaders:
                - name: Host
                  value: nextcloud.${SECRET_DOMAIN_2}
            initialDelaySeconds: 10
            timeoutSeconds: 5
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 3
          envFrom:
            - secretRef:
                name: nextcloud-prod-secrets
        - name: nextcloud-prod-cron
          image: nextcloud:23.0.0-apache
          imagePullPolicy: IfNotPresent
          command:
            - /cron.sh
          volumeMounts:
            - name: nextcloud-prod-config
              mountPath: /var/www/html
            - name: nextcloud-prod-data
              mountPath: /var/www/data
      volumes:
        - name: nextcloud-prod-config
          persistentVolumeClaim:
            claimName: nextcloud-prod-config
        - name: nextcloud-prod-data
          persistentVolumeClaim:
            claimName: nextcloud-prod-data
