version: "3.7"

services:
  gitea:
    image: gitea/gitea:1.21.10
    container_name: gitea
    environment:
      - USER_UID=1000
      - USER_GID=1000
      - GITEA__database__DB_TYPE=postgres
      - GITEA__database__HOST=gitea-db:5432
      - GITEA__database__NAME=gitea
      - GITEA__database__USER=gitea
      - GITEA__database__PASSWD=gitea
    restart: unless-stopped
    volumes:
      - ${APP_DATA_DIR}/data/gitea:/data
    ports:
      - ${APP_PORT}:3000
      - "222:22"
    depends_on:
      - gitea-db
    networks:
      - tipi_main_network
    labels:
      # Main
      traefik.enable: true
      traefik.http.middlewares.gitea-web-redirect.redirectscheme.scheme: https
      traefik.http.services.gitea.loadbalancer.server.port: 3000
      # Web
      traefik.http.routers.gitea-insecure.rule: Host(`${APP_DOMAIN}`)
      traefik.http.routers.gitea-insecure.entrypoints: web
      traefik.http.routers.gitea-insecure.service: gitea
      traefik.http.routers.gitea-insecure.middlewares: gitea-web-redirect
      # Websecure
      traefik.http.routers.gitea.rule: Host(`${APP_DOMAIN}`)
      traefik.http.routers.gitea.entrypoints: websecure
      traefik.http.routers.gitea.service: gitea
      traefik.http.routers.gitea.tls.certresolver: myresolver
      # Local domain
      traefik.http.routers.gitea-local-insecure.rule: Host(`gitea.${LOCAL_DOMAIN}`)
      traefik.http.routers.gitea-local-insecure.entrypoints: web
      traefik.http.routers.gitea-local-insecure.service: gitea
      traefik.http.routers.gitea-local-insecure.middlewares: gitea-web-redirect
      # Local domain secure
      traefik.http.routers.gitea-local.rule: Host(`gitea.${LOCAL_DOMAIN}`)
      traefik.http.routers.gitea-local.entrypoints: websecure
      traefik.http.routers.gitea-local.service: gitea
      traefik.http.routers.gitea-local.tls: true

  gitea-db:
    container_name: gitea-db
    image: postgres:14
    restart: unless-stopped
    environment:
      - POSTGRES_USER=gitea
      - POSTGRES_PASSWORD=gitea
      - POSTGRES_DB=gitea
    volumes:
      - ${APP_DATA_DIR}/data/postgres:/var/lib/postgresql/data
    networks:
      - tipi_main_network
