apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: gitea
  namespace: cwx
spec:
  selector:
    matchLabels:
      app: gitea
  serviceName: gitea
  replicas: 1
  template:
    metadata:
      labels:
        app: gitea
    spec:
      containers:
      - name: gitea
        image: registry.services.wait/cwx/gitea:1.20.2
        env:
          - name: USER_UID
            value: "1000"
          - name: USER_GID
            value: "1000"
          - name: DB_TYPE
            value: mysql
          - name: DB_HOST
            value: 10.2.1.5:3306
          - name: DB_NAME
            value: gitea
          - name: DB_USER
            value: gitea
          - name: DB_PASSWD
            value: passw0rd
          - name: APP_NAME
            value: WaitCode
          - name: RUN_MODE
            value: prod
          - name: DOMAIN
            value: git.services.wait
          - name: SSH_DOMAIN
            value: git.services.wait
          - name: SSH_PORT
            value: "10022"
          - name: SSH_LISTEN_PORT
            value: "10022"
          - name: DISABLE_REGISTRATION
            value: "true"
          - name: REQUIRE_SIGNIN_VIEW
            value: "true"
          - name: ROOT_URL
            value: https://git.services.wait/
          - name: OFFLINE_MODE
            value: "true"
        volumeMounts:
          - name: data
            mountPath: /data
          - name: timezone
            mountPath: /etc/timezone
            readOnly: true
          - name: localtime
            mountPath: /etc/localtime
            readOnly: true
          - name: ca
            mountPath: /etc/ssl/certs/cwxCA.pem
            subPath: cwxCA.pem
            readOnly: true
        resources:
          limits:
            cpu: "200m"
            memory: "300Mi"
        ports:
        - containerPort: 3000
          name: web
        - containerPort: 10022
          name: ssh
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: pvc-nfs-gitea
        - name: timezone
          hostPath:
            path: /etc/timezone
        - name: localtime
          hostPath:
            path: /etc/localtime
        - name: ca
          secret:
            secretName: cwx-ca-pem
---
apiVersion: v1
kind: Service
metadata:
  name: gitea
  namespace: cwx
spec:
  selector:
    app: gitea
  clusterIP: None
  ports:
  - port: 80
    name: web
    targetPort: 3000
  - port: 22
    name: ssh
    targetPort: 10022
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: giteaweb
  namespace: cwx
  annotations:
    kubernetes.io/ingress.class: "traefik-class"
spec:
  entryPoints:
    - https
  routes:
    - match: Host(`git.services.wait`)
      kind: Rule
      services:
        - name: gitea
          namespace: cwx
          port: 80
  tls:
    secretName: key-services-wait
---
apiVersion: traefik.io/v1alpha1
kind: IngressRouteTCP
metadata:
  name: giteassh
  namespace: cwx
  annotations:
    kubernetes.io/ingress.class: "traefik-class"
spec:
  entryPoints:
    - giteassh
  routes:
    - match: HostSNI(`*`)
      services:
        - name: gitea
          port: 22
          namespace: cwx
