79 lines
1.5 KiB
Markdown
79 lines
1.5 KiB
Markdown
# Development and Production Setup Scripts
|
|
|
|
## Start the API Server
|
|
|
|
### Development Mode (with auto-reload)
|
|
```powershell
|
|
# Activate virtual environment
|
|
.\venv\Scripts\Activate.ps1
|
|
|
|
# Start server with hot-reload
|
|
python main.py
|
|
```
|
|
|
|
### Production Mode
|
|
```powershell
|
|
# Activate virtual environment
|
|
.\venv\Scripts\Activate.ps1
|
|
|
|
# Start with uvicorn (better performance)
|
|
uvicorn main:app --host 0.0.0.0 --port 8000 --workers 4
|
|
```
|
|
|
|
## Docker Deployment (Optional)
|
|
|
|
### Create Dockerfile
|
|
```dockerfile
|
|
FROM python:3.11-slim
|
|
|
|
WORKDIR /app
|
|
|
|
COPY requirements.txt .
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
COPY . .
|
|
|
|
# Create directories
|
|
RUN mkdir -p uploads outputs temp
|
|
|
|
EXPOSE 8000
|
|
|
|
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
|
```
|
|
|
|
### Build and Run
|
|
```powershell
|
|
# Build image
|
|
docker build -t document-translator-api .
|
|
|
|
# Run container
|
|
docker run -d -p 8000:8000 -v ${PWD}/uploads:/app/uploads -v ${PWD}/outputs:/app/outputs document-translator-api
|
|
```
|
|
|
|
## Environment Variables for Production
|
|
|
|
```env
|
|
TRANSLATION_SERVICE=google
|
|
DEEPL_API_KEY=your_production_api_key
|
|
MAX_FILE_SIZE_MB=100
|
|
UPLOAD_DIR=/app/uploads
|
|
OUTPUT_DIR=/app/outputs
|
|
```
|
|
|
|
## Monitoring and Logging
|
|
|
|
Add to requirements.txt for production:
|
|
```
|
|
prometheus-fastapi-instrumentator==6.1.0
|
|
python-json-logger==2.0.7
|
|
```
|
|
|
|
## Security Hardening
|
|
|
|
1. Add rate limiting
|
|
2. Implement authentication (JWT/API keys)
|
|
3. Enable HTTPS/TLS
|
|
4. Sanitize file uploads
|
|
5. Implement virus scanning for uploads
|
|
6. Add request validation middleware
|