# docker-compose.yml
#
# Development compose file for ServChan.
# Recommended for local development and testing (live code reload via bind mount + node --watch).
#
# Start dev:
#   docker compose up --build
#
# For PRODUCTION use the override file instead:
#   docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d --build
#
# See docker-compose.prod.yml for details on the production setup
# (production stage, no source mount, dedicated logs volume, NODE_ENV=production).

services:
  bot:
    build:
      context: .
      target: development
    container_name: servchan-bot
    restart: unless-stopped
    ports:
      - "1458:1458"
    env_file:
      - .env
    volumes:
      - .:/app
      - /app/node_modules
      - ./data:/app/data
    environment:
      - NODE_ENV=development
      # Reach collabFinder on the Docker network (see networks below).
      # Overrides CS_API_BASE from .env — the public URL often fails inside
      # containers when bot.joesjavajoint.com resolves to this host (hairpin).
      - CS_API_BASE_INTERNAL=http://collabfinder:1800

    networks:
      - default
      - collabnet

    # Healthcheck hits /health so DB connectivity is part of the signal.
    # /healthz still exists as a pure liveness probe if you want to fall back.
    healthcheck:
      test: ["CMD-SHELL", "node -e \"require('http').get('http://localhost:1458/health', (r) => process.exit(r.statusCode === 200 ? 0 : 1)).on('error', () => process.exit(1))\""]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

# Shared with collabFinder (docker compose in ../collabFinder).
# Create it by starting collabFinder first: cd ../collabFinder && docker compose up -d
networks:
  collabnet:
    external: true
    name: collabfinder_collabnet