mirror of
https://github.com/xboxeer/NScrapy.git
synced 2026-10-18 13:42:20 +08:00
f53d6b78dc
- Add NScrapy.Cli project using Spectre.Console.Cli - Implement 'nscrapy new' command for generating spider projects from templates - Support basic and distributed spider templates - Configurable output directory and force overwrite - Implement 'nscrapy run' command for spider execution - Support single, spider, and downloader roles - Distributed mode with Redis configuration via CLI args - Configuration priority: CLI args > ENV > JSON - Update Dockerfiles to package CLI instead of raw DLLs - Update docker-compose.yml to use CLI commands
114 lines
3.7 KiB
YAML
114 lines
3.7 KiB
YAML
# =============================================================================
|
|
# NScrapy Docker Compose - Three Deployment Modes
|
|
# =============================================================================
|
|
# Mode 1 - local-only:
|
|
# Redis disabled. Single spider runs locally without Redis.
|
|
# Usage: docker compose up -d spider
|
|
#
|
|
# Mode 2 - local-redis:
|
|
# Uses a local Redis container for distributed scraping.
|
|
# All services on the same Docker network.
|
|
# Usage: docker compose --profile local-redis up -d
|
|
#
|
|
# Mode 3 - managed-redis:
|
|
# Uses an external Redis (e.g., Azure Redis Cache, ElastiCache).
|
|
# Configure REDIS_HOST, REDIS_PASSWORD, REDIS_PORT, REDIS_USESSL via .env.
|
|
# Usage: docker compose up -d
|
|
# =============================================================================
|
|
|
|
services:
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Spider Service
|
|
# - Runs the NScrapy CLI spider node
|
|
# - Command format: nscrapy run <spider-name> [options]
|
|
# - Environment variables override CLI args (lowest priority)
|
|
# - Scale with: docker-compose up -d --scale spider=3
|
|
# ---------------------------------------------------------------------------
|
|
spider:
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile.Spider
|
|
container_name: nscrapy-spider
|
|
command: run ${SPIDER_NAME:-MySpider} --role spider --distributed
|
|
environment:
|
|
# Redis configuration
|
|
- REDIS_HOST=${REDIS_HOST:-redis}
|
|
- REDIS_PORT=${REDIS_PORT:-6379}
|
|
- REDIS_PASSWORD=${REDIS_PASSWORD:-}
|
|
- REDIS_USESSL=${REDIS_USESSL:-false}
|
|
# Spider settings
|
|
- NSCRAPY_CONCURRENCY=${CONCURRENCY:-5}
|
|
- NSCRAPY_RECEIVER_QUEUE=${RECEIVER_QUEUE:-nscrapy:requests}
|
|
- NSCRAPY_RESPONSE_QUEUE=${RESPONSE_QUEUE:-nscrapy:responses}
|
|
# CLI will set these automatically when --distributed is used
|
|
- REDIS_ENABLED=true
|
|
volumes:
|
|
# Mount config file (optional, CLI args take priority)
|
|
- ./appsettings.spider.json:/app/appsettings.json:ro
|
|
depends_on:
|
|
- redis
|
|
networks:
|
|
- nscrapy-net
|
|
restart: unless-stopped
|
|
profiles:
|
|
- local-redis
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Downloader Service
|
|
# - Runs the NScrapy CLI downloader node
|
|
# - Command format: nscrapy run --role downloader
|
|
# - Scale with: docker-compose up -d --scale downloader=4
|
|
# ---------------------------------------------------------------------------
|
|
downloader:
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile.Downloader
|
|
container_name: nscrapy-downloader
|
|
command: run --role downloader
|
|
environment:
|
|
# Redis configuration
|
|
- REDIS_HOST=${REDIS_HOST:-redis}
|
|
- REDIS_PORT=${REDIS_PORT:-6379}
|
|
- REDIS_PASSWORD=${REDIS_PASSWORD:-}
|
|
- REDIS_USESSL=${REDIS_USESSL:-false}
|
|
# CLI settings
|
|
- NSCRAPY_RECEIVER_QUEUE=${RECEIVER_QUEUE:-nscrapy:requests}
|
|
- NSCRAPY_RESPONSE_QUEUE=${RESPONSE_QUEUE:-nscrapy:responses}
|
|
- REDIS_ENABLED=true
|
|
volumes:
|
|
- ./appsettings.downloader.json:/app/appsettings.json:ro
|
|
depends_on:
|
|
- redis
|
|
networks:
|
|
- nscrapy-net
|
|
restart: unless-stopped
|
|
profiles:
|
|
- local-redis
|
|
deploy:
|
|
replicas: 1
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Local Redis (only used in local-redis mode)
|
|
# ---------------------------------------------------------------------------
|
|
redis:
|
|
image: redis:7-alpine
|
|
container_name: nscrapy-redis
|
|
ports:
|
|
- "6379:6379"
|
|
volumes:
|
|
- redis-data:/data
|
|
command: redis-server --appendonly yes
|
|
networks:
|
|
- nscrapy-net
|
|
restart: unless-stopped
|
|
profiles:
|
|
- local-redis
|
|
|
|
networks:
|
|
nscrapy-net:
|
|
driver: bridge
|
|
|
|
volumes:
|
|
redis-data:
|