This commit is contained in:
@@ -82,6 +82,15 @@ BROWSER_INSTANCE_TIMEOUT_MINUTES=10 # Force close old browser/page instances af
|
||||
CACHE_EXPIRY_HOURS=36 # Cache expiry in hours (default: 36)
|
||||
CLEANUP_CRON=0 3 * * * # Cache cleanup schedule (default: daily at 3 AM)
|
||||
RATE_LIMIT_MINUTE=60 # Requests per minute (default: 60)
|
||||
|
||||
# Database Configuration
|
||||
# If all PostgreSQL credentials are provided, PostgreSQL will be used
|
||||
# Otherwise, SQLite will be used as fallback
|
||||
POSTGRES_HOST= # PostgreSQL host (optional)
|
||||
POSTGRES_PORT=5432 # PostgreSQL port (default: 5432)
|
||||
POSTGRES_DB= # PostgreSQL database name (optional)
|
||||
POSTGRES_USER= # PostgreSQL username (optional)
|
||||
POSTGRES_PASSWORD= # PostgreSQL password (optional)
|
||||
```
|
||||
|
||||
## API Endpoints
|
||||
@@ -138,11 +147,13 @@ python monitor.py your-api-key 30 http://localhost:8000 cleanup
|
||||
|
||||
## Docker Usage
|
||||
|
||||
### Using SQLite (Default)
|
||||
|
||||
```bash
|
||||
# Build the image
|
||||
docker build -t playwright-api .
|
||||
|
||||
# Run with environment variables
|
||||
# Run with SQLite (default)
|
||||
docker run -d \
|
||||
--name playwright-api \
|
||||
-p 8000:8000 \
|
||||
@@ -153,6 +164,58 @@ docker run -d \
|
||||
playwright-api
|
||||
```
|
||||
|
||||
### Using PostgreSQL
|
||||
|
||||
```bash
|
||||
# Run with PostgreSQL
|
||||
docker run -d \
|
||||
--name playwright-api \
|
||||
-p 8000:8000 \
|
||||
-e API_KEY=your-api-key \
|
||||
-e MAX_BROWSERS=3 \
|
||||
-e BROWSER_TTL=1800 \
|
||||
-e POSTGRES_HOST=your-postgres-host \
|
||||
-e POSTGRES_PORT=5432 \
|
||||
-e POSTGRES_DB=your-database-name \
|
||||
-e POSTGRES_USER=your-username \
|
||||
-e POSTGRES_PASSWORD=your-password \
|
||||
playwright-api
|
||||
```
|
||||
|
||||
### Using Docker Compose with PostgreSQL
|
||||
|
||||
```yaml
|
||||
version: "3.8"
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:15
|
||||
environment:
|
||||
POSTGRES_DB: playwright_cache
|
||||
POSTGRES_USER: playwright_user
|
||||
POSTGRES_PASSWORD: your_password
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
ports:
|
||||
- "5432:5432"
|
||||
|
||||
playwright-api:
|
||||
build: .
|
||||
ports:
|
||||
- "8000:8000"
|
||||
environment:
|
||||
API_KEY: your-api-key
|
||||
POSTGRES_HOST: postgres
|
||||
POSTGRES_PORT: 5432
|
||||
POSTGRES_DB: playwright_cache
|
||||
POSTGRES_USER: playwright_user
|
||||
POSTGRES_PASSWORD: your_password
|
||||
depends_on:
|
||||
- postgres
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
```
|
||||
|
||||
## Testing the Migration
|
||||
|
||||
To verify that the Playwright migration works correctly:
|
||||
@@ -196,12 +259,37 @@ This will test:
|
||||
2. Check Docker build logs for browser installation
|
||||
3. Verify system dependencies are installed
|
||||
|
||||
## Database Configuration
|
||||
|
||||
The API supports both SQLite and PostgreSQL for caching:
|
||||
|
||||
### SQLite (Default)
|
||||
|
||||
- **Automatic**: Used when no PostgreSQL credentials are provided
|
||||
- **File-based**: Database stored in `/db/cache.db` (or `cache.db` as fallback)
|
||||
- **Simple setup**: No additional services required
|
||||
- **Suitable for**: Development, testing, and small deployments
|
||||
|
||||
### PostgreSQL
|
||||
|
||||
- **Configured via environment variables**: Set all PostgreSQL credentials to enable
|
||||
- **Better performance**: For high-traffic applications
|
||||
- **Scalable**: Can handle concurrent connections better
|
||||
- **Suitable for**: Production deployments, high-traffic scenarios
|
||||
|
||||
### Migration
|
||||
|
||||
- **Automatic detection**: The system automatically chooses the database based on configuration
|
||||
- **No data migration needed**: Each database type maintains its own cache
|
||||
- **Backward compatible**: Existing SQLite setups continue to work unchanged
|
||||
|
||||
## Performance Tips
|
||||
|
||||
1. **Use caching**: The API caches results for 36 hours by default
|
||||
2. **Monitor resources**: Use the monitoring script to track usage
|
||||
3. **Adjust limits**: Tune `MAX_BROWSERS` and `MAX_CONCURRENT_OPERATIONS` based on your server capacity
|
||||
4. **Regular cleanup**: The system automatically recycles browsers every 30 minutes
|
||||
5. **Database choice**: Use PostgreSQL for high-traffic production deployments
|
||||
|
||||
## Logs
|
||||
|
||||
|
||||
Reference in New Issue
Block a user