---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: gogs
  labels:
    app: gogs
spec:
  replicas: 1
  selector:
    matchLabels:
      app: gogs
  template:
    metadata:
      labels:
        app: gogs
    spec:
      containers:
      - name: gogs
        image: gogs/gogs
        env:
        - name: PUID
          value: "1000"
        - name: PGID
          value: "1000"
        - name: SOCAT_LINK
          value: "false"
        ports:
        - name: web
          containerPort: 3000
        - name: ssh
          containerPort: 2222
        volumeMounts:
        - name: gogs-data-volume
          mountPath: "/data"
        - name: "gogs-sshd-config"
          mountPath: "/app/gogs/docker/sshd_config"
          subPath: "sshd_config"
        - name: "gogs-appini-config"
          mountPath: "/data/gogs/conf/app.ini"
          subPath: "app.ini"
      volumes:
      - name: gogs-data-volume
        persistentVolumeClaim:
          claimName: gogs-data-pvc
      - name: "gogs-sshd-config"
        configMap:
          name: "gogs-sshd-config"
      - name: "gogs-appini-config"
        configMap:
          name: "gogs-appini-config"
---
apiVersion: v1
kind: Service
metadata:
  name: gogs
spec:
  type: ClusterIP
  ports:
    - name: web
      port: 3000
  selector:
    app: gogs
---
apiVersion: v1
kind: Service
metadata:
  name: gogs-ssh
spec:
  type: ClusterIP
  ports:
    - name: ssh-tcp-svc
      port: 2222
  selector:
    app: gogs
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: gogs-ingress-route
  namespace: default
spec:
  entryPoints:
    - web
  routes:
  - match: (Host(`gogs.dezendorf.net`)||Host(`git.dezendorf.net`))
    kind: Rule
    middlewares:
    - name: redirecthttps
    services:
    - name: gogs
      port: 3000
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: gogs-websecure-route
  namespace: default
spec:
  entryPoints:
    - websecure
  routes:
  - match: (Host(`gogs.dezendorf.net`)||Host(`git.dezendorf.net`))
    kind: Rule
    services:
    - name: gogs
      port: 3000
  tls:
    certResolver: myresolver
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRouteTCP
metadata:
  name: gogs-ssh-route
spec:
  entryPoints:
    - ssh-tcp
  routes:
  - match: HostSNI(`*`)
    priority: 10
    services:
    - name: gogs-ssh
      port: 2222
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: gogs-data-pvc
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: longhorn
  resources:
    requests:
      storage: 500M
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: gogs-sshd-config
  namespace: default
data:
  sshd_config: |
    Port 2222
    AddressFamily any
    ListenAddress 0.0.0.0
    ListenAddress ::
    Protocol 2
    LogLevel INFO
    HostKey /data/ssh/ssh_host_rsa_key
    HostKey /data/ssh/ssh_host_dsa_key
    HostKey /data/ssh/ssh_host_ecdsa_key
    HostKey /data/ssh/ssh_host_ed25519_key
    PermitRootLogin no
    AuthorizedKeysFile .ssh/authorized_keys
    PasswordAuthentication no
    PermitUserEnvironment yes
    AllowUsers git
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: gogs-appini-config
  namespace: default
data:
  app.ini: |
    BRAND_NAME = Gogs
    RUN_USER   = git
    RUN_MODE   = prod
    
    [database]
    TYPE     = sqlite3
    HOST     = 127.0.0.1:5432
    NAME     = gogs
    SCHEMA   = public
    USER     = gogs
    PASSWORD = 
    SSL_MODE = disable
    PATH     = data/gogs.db
    
    [repository]
    ROOT = /data/git/gogs-repositories
    
    [server]
    DOMAIN           = gogs.dezendorf.net
    HTTP_PORT        = 3000
    EXTERNAL_URL     = https://gogs.dezendorf.net/
    DISABLE_SSH      = false
    SSH_PORT         = 2222
    SSH_LISTEN_PORT  = 2222
    START_SSH_SERVER = false
    OFFLINE_MODE     = false
    
    [mailer]
    ENABLED = false
    
    [auth]
    REQUIRE_EMAIL_CONFIRMATION  = false
    DISABLE_REGISTRATION        = false
    ENABLE_REGISTRATION_CAPTCHA = true
    REQUIRE_SIGNIN_VIEW         = false
    
    [user]
    ENABLE_EMAIL_NOTIFICATION = false
    
    [picture]
    DISABLE_GRAVATAR        = false
    ENABLE_FEDERATED_AVATAR = false
    
    [session]
    PROVIDER = file
    
    [log]
    MODE      = file
    LEVEL     = Info
    ROOT_PATH = /app/gogs/log
    
    [security]
    INSTALL_LOCK = true
    SECRET_KEY   = WityxCyHAcBVyLm
