---
services:
  server:
    image: docker.io/gitea/gitea:latest
    container_name: gitea
    environment:
      - USER_UID=1000
      - USER_GID=1000
      # -- Change your database settings here...
      # --> PostgreSQL
      - GITEA__database__DB_TYPE=postgres
      - GITEA__database__HOST=${POSTGRES_HOST:-db}:${POSTGRES_PORT:-5432}
      - GITEA__database__NAME=${POSTGRES_DB:?POSTGRES_DB not set}
      - GITEA__database__USER=${POSTGRES_USER:?POSTGRES_USER not set}
      - GITEA__database__PASSWD=${POSTGRES_PASSWORD:?POSTGRES_PASSWORD not set}
      # -- (Optional) Change your server settings here...
      - GITEA__server__SSH_PORT=1103  # <-- (Optional) Replace with your desired SSH port
      - GITEA__server__ROOT_URL=https://git.byhaider.dev  # <-- Replace with your FQDN
    # --> (Optional) When using traefik...
    networks:
      - traefik-network
    # <--
    # --> (Optional) When using an internal database...
      - postgresql
    # <--
    volumes:
      - gitea-data:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      # --> (Optional) Remove when using traefik...
      # - "3000:3000"
      # <--
      - "1103:22"  # <-- (Optional) Replace with your desired SSH port
      # --> (Optional) When using internal database...
    # depends_on:
    #   - laser-db
    # <--
    # --> (Optional) When using traefik...
    labels:
      - traefik.enable=true

      - "traefik.docker.network=traefik-network"

      - traefik.http.services.gitea.loadbalancer.server.port=3000
      - traefik.http.services.gitea.loadbalancer.server.scheme=http
      
      # - traefik.http.routers.gitea-http.entrypoints=web
      # - traefik.http.routers.gitea-http.rule=Host(`git.byhaider.dev`)

      - traefik.http.routers.gitea-https.rule=Host(`git.byhaider.dev`)
      - traefik.http.routers.gitea-https.entrypoints=websecure
      - traefik.http.routers.gitea-https.tls=true
      - traefik.http.routers.gitea-https.tls.certresolver=cloudflare  # <-- Replace with your certresolver
    # <--
    restart: unless-stopped

# --> When using internal database
# db:
#   image: docker.io/library/postgres:latest
#   container_name: gitea-db
#   environment:
#     - POSTGRES_USER=${POSTGRES_USER:?POSTGRES_USER not set}
#     - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:?POSTGRES_PASSWORD not set}
#     - POSTGRES_DB=${POSTGRES_DB:?POSTGRES_DB not set}
#   networks:
#     - backend
#   volumes:
#     - gitea-db:/var/lib/postgresql/data
#   restart: unless-stopped
# <--

volumes:
  gitea-data:
    driver: local
  # --> When using internal database
  postgresql:
    driver: local
# <--

# --> (Optional) When using traefik...
networks:
  traefik-network:
    external: true
# <--
# --> (Optional) When using an internal database...
  postgresql:
    external: true
# <--
