apiVersion: apps/v1
kind: Deployment
metadata:
  name: gitea
  namespace: gitea
  annotations:
  labels:
    helm.sh/chart: gitea-12.6.0
    app: gitea
    app.kubernetes.io/name: gitea
    app.kubernetes.io/instance: gitea
    app.kubernetes.io/version: "1.26.2"
    version: "1.26.2"
    app.kubernetes.io/managed-by: Helm
spec:
  replicas: 3
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 100%
  selector:
    matchLabels:
      app.kubernetes.io/name: gitea
      app.kubernetes.io/instance: gitea
  template:
    metadata:
      annotations:
        checksum/config: d025c33c5807735bf3de9ab8cdfb6443d4ffaa7331fa0a9c6cdb140c13835319
        checksum/oauth_0: 03073bf48e66f48f622bd02092a5f93bfd06dbcb5fd833aded3b0d40980be93d
      labels:
        helm.sh/chart: gitea-12.6.0
        app: gitea
        app.kubernetes.io/name: gitea
        app.kubernetes.io/instance: gitea
        app.kubernetes.io/version: "1.26.2"
        version: "1.26.2"
        app.kubernetes.io/managed-by: Helm
    spec:
      securityContext:
        fsGroup: 1000
      initContainers:
        - name: init-directories
          image: "registry.hub.docker.com/gitea/gitea:1.26.2-rootless"
          imagePullPolicy: IfNotPresent
          command:
            - "/usr/sbinx/init_directory_structure.sh"
          env:
            - name: GITEA_APP_INI
              value: /data/gitea/conf/app.ini
            - name: GITEA_CUSTOM
              value: /data/gitea
            - name: GITEA_WORK_DIR
              value: /data
            - name: GITEA_TEMP
              value: /tmp/gitea
          volumeMounts:
            - name: init
              mountPath: /usr/sbinx
            - name: temp
              mountPath: /tmp
            - name: data
              mountPath: /data
            - mountPath: /data/gitea/public/assets/css
              name: gitea-themes-storage
              readOnly: false
          resources:
            limits: {}
            requests:
              cpu: 100m
              memory: 128Mi
        - name: init-app-ini
          image: "registry.hub.docker.com/gitea/gitea:1.26.2-rootless"
          imagePullPolicy: IfNotPresent
          command:
            - "/usr/sbinx/config_environment.sh"
          env:
            - name: GITEA_APP_INI
              value: /data/gitea/conf/app.ini
            - name: GITEA_CUSTOM
              value: /data/gitea
            - name: GITEA_WORK_DIR
              value: /data
            - name: GITEA_TEMP
              value: /tmp/gitea
            - name: TMP_EXISTING_ENVS_FILE
              value: /tmp/existing-envs
            - name: ENV_TO_INI_MOUNT_POINT
              value: /env-to-ini-mounts
            - name: GITEA__DATABASE__HOST
              valueFrom:
                secretKeyRef:
                  key: host
                  name: gitea-postgresql-18-cluster-app
            - name: GITEA__DATABASE__NAME
              valueFrom:
                secretKeyRef:
                  key: dbname
                  name: gitea-postgresql-18-cluster-app
            - name: GITEA__DATABASE__USER
              valueFrom:
                secretKeyRef:
                  key: user
                  name: gitea-postgresql-18-cluster-app
            - name: GITEA__DATABASE__PASSWD
              valueFrom:
                secretKeyRef:
                  key: password
                  name: gitea-postgresql-18-cluster-app
            - name: GITEA__INDEXER__ISSUE_INDEXER_CONN_STR
              valueFrom:
                secretKeyRef:
                  key: ISSUE_INDEXER_CONN_STR
                  name: gitea-meilisearch-key
          volumeMounts:
            - name: config
              mountPath: /usr/sbinx
            - name: temp
              mountPath: /tmp
            - name: data
              mountPath: /data
            - name: inline-config-sources
              mountPath: /env-to-ini-mounts/inlines/
            - mountPath: /data/gitea/public/assets/css
              name: gitea-themes-storage
              readOnly: false
          resources:
            limits: {}
            requests:
              cpu: 100m
              memory: 128Mi
        - name: configure-gitea
          image: "registry.hub.docker.com/gitea/gitea:1.26.2-rootless"
          command:
            - "/usr/sbinx/configure_gitea.sh"
          imagePullPolicy: IfNotPresent
          securityContext:
            runAsUser: 1000
          env:
            - name: GITEA_APP_INI
              value: /data/gitea/conf/app.ini
            - name: GITEA_CUSTOM
              value: /data/gitea
            - name: GITEA_WORK_DIR
              value: /data
            - name: GITEA_TEMP
              value: /tmp/gitea
            - name: HOME
              value: /data/gitea/git
            - name: GITEA_OAUTH_KEY_0
              valueFrom:
                secretKeyRef:
                  key: key
                  name: gitea-oidc-authentik
            - name: GITEA_OAUTH_SECRET_0
              valueFrom:
                secretKeyRef:
                  key: secret
                  name: gitea-oidc-authentik
            - name: GITEA_ADMIN_USERNAME
              value: "gitea_admin"
            - name: GITEA_ADMIN_PASSWORD
              value: "r8sA8CPHD9!bt6d"
            - name: GITEA_ADMIN_PASSWORD_MODE
              value: keepUpdated
          volumeMounts:
            - name: init
              mountPath: /usr/sbinx
            - name: temp
              mountPath: /tmp
            - name: data
              mountPath: /data
            - mountPath: /data/gitea/public/assets/css
              name: gitea-themes-storage
              readOnly: false
          resources:
            limits: {}
            requests:
              cpu: 100m
              memory: 128Mi
      terminationGracePeriodSeconds: 60
      containers:
        - name: gitea
          image: "registry.hub.docker.com/gitea/gitea:1.26.2-rootless"
          imagePullPolicy: IfNotPresent
          env:
            - name: SSH_LISTEN_PORT
              value: "22"
            - name: SSH_PORT
              value: "22"
            - name: GITEA_APP_INI
              value: /data/gitea/conf/app.ini
            - name: GITEA_CUSTOM
              value: /data/gitea
            - name: GITEA_WORK_DIR
              value: /data
            - name: GITEA_TEMP
              value: /tmp/gitea
            - name: TMPDIR
              value: /tmp/gitea
            - name: HOME
              value: /data/gitea/git
          ports:
            - name: ssh
              containerPort: 22
            - name: http
              containerPort: 3000
            - name: profiler
              containerPort: 6060
          livenessProbe:
            failureThreshold: 10
            initialDelaySeconds: 200
            periodSeconds: 10
            successThreshold: 1
            tcpSocket:
              port: http
            timeoutSeconds: 1
          readinessProbe:
            failureThreshold: 3
            initialDelaySeconds: 5
            periodSeconds: 10
            successThreshold: 1
            tcpSocket:
              port: http
            timeoutSeconds: 1
          resources:
            requests:
              cpu: 1000m
              memory: 600Mi
          volumeMounts:
            - name: temp
              mountPath: /tmp
            - name: data
              mountPath: /data
            - mountPath: /data/gitea/public/assets/css
              name: gitea-themes-storage
              readOnly: true
            - mountPath: /data/gitea/templates/custom/header.tmpl
              name: gitea-custom-templates
              readOnly: true
              subPath: header.tmpl
      volumes:
        - name: init
          secret:
            secretName: gitea-init
            defaultMode: 110
        - name: config
          secret:
            secretName: gitea
            defaultMode: 110
        - name: gitea-themes-storage
          persistentVolumeClaim:
            claimName: gitea-themes-storage
        - configMap:
            name: gitea-custom-templates
          name: gitea-custom-templates
        - name: inline-config-sources
          secret:
            secretName: gitea-inline-config
        - name: temp
          emptyDir: {}
        - name: data
          persistentVolumeClaim:
            claimName: gitea-shared-storage
