version: "{{ compose_version }}"

networks:
  proxy:
    name: "{{ traefik_network }}"
  db:
    name: gitea_db

volumes:
  app:
    name: gitea_app
  db:
    name: gitea_db

services:
  server:
    image: gitea/gitea:{{ gitea_version }}
    container_name: gitea
    environment:
      USER_UID: 1000
      USER_GID: 1000
      # See https://docs.gitea.com/installation/install-with-docker#managing-deployments-with-environment-variables
      GITEA__database__DB_TYPE: postgres
      GITEA__database__DB_HOST: db:5432
      GITEA__database__NAME: gitea
      GITEA__database__USER: gitea
      GITEA__database__PASSWD: "{{ gitea_db_password }}"
      GITEA__DEFAULT__APP_NAME: {{ gitea_name }}
      GITEA__DEFAULT__RUN_MODE: prod
      GITEA__server__DOMAIN: {{ gitea_subdomain }}.{{ domain_name }}
      GITEA__server__SSH_DOMAIN: {{ gitea_subdomain }}.{{ domain_name }}
      GITEA__server__ROOT_URL: https://{{ gitea_subdomain }}.{{ domain_name }}
      GITEA__service__DISABLE_REGISTRATION: "true"
    networks:
      - proxy
      - db
    volumes:
      - app:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "{{ gitea_ssh_host_port }}:22"
    labels:
      traefik.http.routers.gitea.entrypoints: websecure
      traefik.http.routers.gitea.rule: "Host(`{{ gitea_subdomain }}.{{ domain_name }}`)"
      traefik.http.services.gitea.loadbalancer.server.port: 3000
      traefik.enable: true
    restart: unless-stopped

  db:
    image: postgres:{{ postgres_version }}
    container_name: gitea-db
    environment:
      POSTGRES_USER: gitea
      POSTGRES_DB: gitea
      POSTGRES_PASSWORD: "{{ gitea_db_password }}"
    volumes:
      - db:/var/lib/postgresql/data
    networks:
      - db
    restart: unless-stopped