Deployment guide for Data Quality Checker API on various platforms.
- Local Deployment
- Docker Deployment
- Production Deployment
- Environment Variables Configuration
- Database Configuration
- Troubleshooting
- Python 3.9, 3.10, or 3.11
- pip (Python package manager)
-
Clone the repository:
git clone <repository-url> cd data-quality-checker
-
Create a virtual environment:
python -m venv venv # Windows venv\Scripts\activate # Linux/Mac source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Configure environment variables:
# Copy the example file cp .env.example .env # Edit .env file as needed
-
Run the application:
uvicorn src.api.main:app --reload --host 0.0.0.0 --port 8000
Or use Makefile:
make run
-
Verify API is working:
- Open browser: http://localhost:8000/docs
- Swagger UI will be available for API testing
-
Create
.envfile from example:cp .env.example .env
-
Build and run containers:
docker-compose up -d
-
Check logs:
docker-compose logs -f api
-
Open API documentation:
# Run in background
docker-compose up -d
# Stop
docker-compose down
# Rebuild and run
docker-compose up -d --build
# View logs
docker-compose logs -f api
# Stop and remove volumes
docker-compose down -v-
Build the image:
docker build -t data-quality-checker . -
Run the container:
docker run -d \ --name data-quality-checker \ -p 8000:8000 \ -v $(pwd)/data/db/db.sqlite3:/app/data/db/db.sqlite3 \ -v $(pwd)/reports:/app/reports \ -v $(pwd)/tmp:/app/tmp \ --env-file .env \ data-quality-checker
-
Update
.envfile:ENVIRONMENT=production LOG_LEVEL=WARNING CORS_ORIGINS=https://yourdomain.com,https://www.yourdomain.com
-
Use production-ready server:
# With gunicorn (recommended) pip install gunicorn gunicorn src.api.main:app -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000 -
Configure reverse proxy (Nginx):
server { listen 80; server_name yourdomain.com; location / { proxy_pass http://localhost:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }
-
Configure SSL (Let's Encrypt):
sudo apt-get install certbot python3-certbot-nginx sudo certbot --nginx -d yourdomain.com
-
Create
Procfile:web: uvicorn src.api.main:app --host 0.0.0.0 --port $PORT -
Deploy:
heroku create your-app-name heroku config:set CORS_ORIGINS=https://yourdomain.com git push heroku main
-
Connect to server via SSH
-
Install Docker:
curl -fsSL https://get.docker.com -o get-docker.sh sudo sh get-docker.sh
-
Clone the repository:
git clone <repository-url> cd data-quality-checker
-
Run via Docker Compose:
docker-compose up -d
CORS_ORIGINS- Comma-separated list of allowed origins for CORS
DATABASE_URL- Database URL (default: SQLite)API_HOST- API host (default: 0.0.0.0)API_PORT- API port (default: 8000)LOG_LEVEL- Logging level (DEBUG, INFO, WARNING, ERROR)ENVIRONMENT- Environment (development/production)
See .env.example for the full list.
SQLite database is created automatically on first run. The db.sqlite3 file will be created in the data/db/ directory.
-
Use PostgreSQL in docker-compose.yml:
- Uncomment the
postgressection indocker-compose.yml
- Uncomment the
-
Update DATABASE_URL:
DATABASE_URL=postgresql://dataquality:changeme@postgres:5432/dataquality
-
Restart services:
docker-compose down docker-compose up -d
-
Use HTTPS:
- Configure SSL/TLS certificate
- Use Let's Encrypt for free certificates
-
Limit CORS:
- Specify only necessary origins in
CORS_ORIGINS - Don't use
*in production
- Specify only necessary origins in
-
Limit file size:
- Configure
MAX_FILE_SIZEin.env - Configure reverse proxy to limit request size
- Configure
-
Use strong passwords:
- If using PostgreSQL, set a strong password
-
Regularly update dependencies:
pip list --outdated pip install --upgrade <package>
Solution:
# Find process on port 8000
# Linux/Mac
lsof -i :8000
kill -9 <PID>
# Windows
netstat -ano | findstr :8000
taskkill /PID <PID> /FSolution:
# Create database manually
python -c "from src.db.database import Base, engine; Base.metadata.create_all(bind=engine)"Solution:
# Check logs
docker-compose logs api
# Rebuild image
docker-compose build --no-cache
docker-compose up -dSolution:
- Ensure
CORS_ORIGINScontains the correct origin - Check that origin matches exactly (including protocol and port)
If you encounter deployment issues:
- Check logs:
docker-compose logs -f api - Check environment variables:
docker-compose config - Ensure all dependencies are installed:
pip install -r requirements.txt
Last updated: 2024