version: '3.8'

services:
  postgres:
    image: postgres:16-alpine
    container_name: rmtpw-postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: rmtpw
      POSTGRES_PASSWORD: rmtpw_password
      POSTGRES_DB: rmtpocketwatcher
    ports:
      - "5441:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U rmtpw -d rmtpocketwatcher"]
      interval: 10s
      timeout: 5s
      retries: 5

  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: rmtpw-backend
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      DATABASE_URL: postgresql://rmtpw:rmtpw_password@postgres:5441/rmtpocketwatcher?schema=public
      PORT: 3000
      HOST: 0.0.0.0
      NODE_ENV: production
      SCRAPE_INTERVAL_MINUTES: 5
      SCRAPER_HEADLESS: "true"
      SCRAPER_TIMEOUT: 30000
      SCRAPER_MAX_RETRIES: 3
    ports:
      - "3043:3000"
    volumes:
      - ./backend:/app
      - /app/node_modules
      - /app/dist
    command: sh -c "npm run db:push && npm start"

volumes:
  postgres_data:
    driver: local
