services:
  db:
    image: postgres:17-alpine
    restart: always
    environment:
      POSTGRES_USER: gmrelay
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}
      POSTGRES_DB: gmrelay_db
    volumes:
      - pgdata:/var/lib/postgresql/data
    networks:
      - gmrelay
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U gmrelay -d gmrelay_db" ]
      interval: 3s
      timeout: 3s
      retries: 10

  bot:
    image: git.codeanddice.ru/toutsu/gmrelay-bot:1.10.0
    restart: always
    depends_on:
      db:
        condition: service_healthy
    environment:
      - "ConnectionStrings__gmrelaydb=Host=db;Port=5432;Database=gmrelay_db;Username=gmrelay;Password=${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}"
      - "Telegram__BotToken=${TELEGRAM_BOT_TOKEN:?Set TELEGRAM_BOT_TOKEN in .env}"
      - "Telegram__MiniAppUrl=${TELEGRAM_MINI_APP_URL:-}"
    networks:
      - gmrelay

  web:
    image: git.codeanddice.ru/toutsu/gmrelay-web:1.10.0
    restart: always
    depends_on:
      db:
        condition: service_healthy
    environment:
      - "ConnectionStrings__gmrelaydb=Host=db;Port=5432;Database=gmrelay_db;Username=gmrelay;Password=${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}"
      - "Telegram__BotToken=${TELEGRAM_BOT_TOKEN:?Set TELEGRAM_BOT_TOKEN in .env}"
      - "Telegram__BotUsername=${TELEGRAM_BOT_USERNAME:?Set TELEGRAM_BOT_USERNAME in .env}"
      - "Telegram__MiniAppUrl=${TELEGRAM_MINI_APP_URL:-}"
    ports:
      - "${GMRELAY_WEB_PORT:-8080}:8080"
    volumes:
      - web_keys:/app/dataprotection-keys
    networks:
      - gmrelay

volumes:
  pgdata:
    name: ${POSTGRES_VOLUME_NAME:-game_pgdata}
  web_keys:
    name: ${WEB_KEYS_VOLUME_NAME:-gmrelay_web_keys}

networks:
  gmrelay:
    driver: bridge
