# Bangladesh Tariff & Trade Intelligence Platform — full stack
# usage:  docker compose up -d
#         docker compose exec api python load_data.py /seed     (first run only)
services:
  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: tariff
      POSTGRES_PASSWORD: ${DB_PASSWORD:-tariff}
      POSTGRES_DB: tariff
    volumes:
      - pgdata:/var/lib/postgresql/data
      - ./db/schema.sql:/docker-entrypoint-initdb.d/01-schema.sql:ro
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U tariff"]
      interval: 5s
      retries: 10

  api:
    build: ./api
    environment:
      DATABASE_URL: postgresql://tariff:${DB_PASSWORD:-tariff}@db:5432/tariff
      JWT_SECRET: ${JWT_SECRET:-change-me-in-production}
      CORS_ORIGINS: ${CORS_ORIGINS:-*}
    volumes:
      - ./db/seed:/seed:ro
    depends_on:
      db:
        condition: service_healthy

  web:
    image: nginx:alpine
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./web:/usr/share/nginx/html:ro
      - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
      # mount TLS certs here in production (or terminate TLS at Cloudflare)
    depends_on:
      - api

volumes:
  pgdata:
