services:
  server:
    restart: unless-stopped
    image: gitea/gitea:latest

    environment:
      - USER_UID=1000
      - USER_GID=1000

      - GITEA__database__DB_TYPE=postgres
      - GITEA__database__HOST=db:5432
      - GITEA__database__NAME=${REPODEN_POSTGRES_DB}
      - GITEA__database__USER=${REPODEN_POSTGRES_USER}
      - GITEA__database__PASSWD=${REPODEN_POSTGRES_PASSWORD}

      # IMPORTANT reverse proxy
      - GITEA__server__ROOT_URL=https://repo.luckyden.org/
      - GITEA__server__DOMAIN=repo.luckyden.org
      - GITEA__server__SSH_DOMAIN=repo.luckyden.org
      - GITEA__server__PROTOCOL=http

      - TRUSTED_PROXIES=10.10.0.20
    
    env_file:
      - .env

    volumes:
      - /home/docker/RepoDen/data:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro

    depends_on:
      - db

    ports:
      - 2621:22

    networks:
      tan-network:
        ipv4_address: 10.10.0.90

    labels:
      - traefik.enable=true

      # ROUTER
      - traefik.http.routers.gitea.rule=Host(`repo.luckyden.org`)
      - traefik.http.routers.gitea.entrypoints=websecure
      - traefik.http.routers.gitea.tls.certresolver=cloudflare

      # SERVICE
      - traefik.http.services.gitea.loadbalancer.server.port=3000

      # HEADERS
      - traefik.http.middlewares.gitea.headers.customrequestheaders.X-Forwarded-Proto=https

      # BUFFER (push git volumineux)
      - traefik.http.middlewares.gitea-buffer.buffering.maxRequestBodyBytes=0

      - traefik.http.routers.gitea.middlewares=gitea,gitea-buffer

  db:
    restart: unless-stopped
    image: postgres:14

    environment:
      - POSTGRES_USER=${REPODEN_POSTGRES_USER}
      - POSTGRES_PASSWORD=${REPODEN_POSTGRES_PASSWORD}
      - POSTGRES_DB=${REPODEN_POSTGRES_DB}

    env_file:
      - .env

    volumes:
      - /home/docker/RepoDen/postgres:/var/lib/postgresql/data

    networks:
      tan-network:
        ipv4_address: 10.10.0.91

networks:
  tan-network:
    external: true
