Repository navigation
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
192 lines (171 loc) · 4.33 KB
/
Copy pathdocker-compose.yml
File metadata and controls
192 lines (171 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
version: '3.8'
services:
# Redis for rate limiting and caching (optional but recommended)
redis:
image: redis:7-alpine
container_name: scraper-redis
ports:
- "6379:6379"
volumes:
- redis-data:/data
command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 3
start_period: 5s
networks:
- scraper-network
restart: unless-stopped
deploy:
restart_policy:
condition: on-failure
delay: 1s
max_attempts: 5
window: 30s
# Web Scraping API - Main Service
api:
build:
context: .
dockerfile: Dockerfile
container_name: scraper-api
ports:
- "8000:8000"
environment:
# API Configuration
- API_HOST=0.0.0.0
- API_PORT=8000
- API_WORKERS=4
- DEBUG=False
# Rate Limiting - Optimized for 50+ req/min
- MAX_SEARCH_REQUESTS_PER_MINUTE=120
- MAX_WEBSITE_REQUESTS_PER_MINUTE=60
- MAX_CONCURRENT_REQUESTS=100
- CONNECTION_POOL_SIZE=100
# Redis Configuration (optional)
- USE_REDIS=true
- REDIS_HOST=redis
- REDIS_PORT=6379
- REDIS_DB=0
# Proxy Configuration - Auto-fetch enabled
- USE_PROXY=true
- PROXY_ROTATION=true
- PROXY_TIMEOUT=10
- AUTO_FETCH_PROXIES=true
- PROXY_FETCH_INTERVAL=300
- MIN_WORKING_PROXIES=10
# Add custom proxies (comma-separated): CUSTOM_PROXIES=http://proxy1:8080,socks5://proxy2:1080
- CUSTOM_PROXIES=
# Captcha Solving
- ENABLE_CAPTCHA_SOLVER=true
- CAPTCHA_TIMEOUT=30
- CAPTCHA_MAX_RETRIES=3
# Request Configuration - Optimized for speed
- REQUEST_TIMEOUT=15
- MAX_RETRIES=2
- RETRY_DELAY=0.5
# Scraping Configuration
- JAVASCRIPT_RENDERING=true
- BROWSER_HEADLESS=true
- PAGE_LOAD_TIMEOUT=15
# Search Engine Fallback
- ENABLE_FALLBACK=true
- FALLBACK_ORDER=google,duckduckgo,bing,yahoo
# Fingerprint Randomization
- RANDOMIZE_FINGERPRINT=true
# Logging
- LOG_LEVEL=INFO
- LOG_FILE=logs/scraper.log
volumes:
- ./config:/app/config
- ./logs:/app/logs
depends_on:
redis:
condition: service_healthy
networks:
- scraper-network
restart: unless-stopped
# Healthcheck for faster recovery
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
interval: 10s
timeout: 5s
retries: 3
start_period: 30s
# Resource limits for production with faster restart
deploy:
restart_policy:
condition: on-failure
delay: 1s
max_attempts: 10
window: 60s
resources:
limits:
cpus: '4'
memory: 4G
reservations:
cpus: '2'
memory: 2G
# Development mode (with hot-reload)
api-dev:
build:
context: .
dockerfile: Dockerfile
container_name: scraper-api-dev
ports:
- "8001:8000"
environment:
- API_HOST=0.0.0.0
- API_PORT=8000
- DEBUG=True
- LOG_LEVEL=DEBUG
- USE_REDIS=false
- USE_PROXY=true
- AUTO_FETCH_PROXIES=true
- ENABLE_CAPTCHA_SOLVER=true
- ENABLE_FALLBACK=true
volumes:
- ./app:/app/app
- ./config:/app/config
- ./logs:/app/logs
networks:
- scraper-network
profiles:
- dev
# Faster healthcheck for development
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
interval: 5s
timeout: 3s
retries: 3
start_period: 15s
deploy:
restart_policy:
condition: on-failure
delay: 1s
max_attempts: 5
window: 30s
# Nginx reverse proxy (optional, for production)
nginx:
image: nginx:alpine
container_name: scraper-nginx
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./ssl:/etc/nginx/ssl:ro
depends_on:
- api
networks:
- scraper-network
restart: unless-stopped
profiles:
- production
volumes:
redis-data:
driver: local
networks:
scraper-network:
driver: bridge