diff --git a/docs/DOCKER_USAGE.md b/docs/DOCKER_USAGE.md new file mode 100644 index 0000000..f0ea6dd --- /dev/null +++ b/docs/DOCKER_USAGE.md @@ -0,0 +1,186 @@ +# Baby Monitor - Self-Contained Docker Image + +This Docker image is a self-contained service ready for deployment with all optional dependencies pre-installed. + +## Quick Start + +```bash +docker run -p 8000:8000 baby-monitor +``` + +Access the application at `http://localhost:8000` + +## Features + +This image includes all optional dependencies: + +- ✅ **Redis** support for distributed token storage +- ✅ **PostgreSQL** support for scalable database backend +- ✅ **SQLite** built-in for single-instance deployments + +## Configuration + +Configure the service using environment variables: + +### Basic Configuration + +| Variable | Default | Description | +| ---------------- | ------------ | --------------------------------------- | +| `ENVIRONMENT` | `production` | Set to `development` to enable API docs | +| `DATA_DIR` | `/data` | Directory for SQLite database | +| `ADMIN_USERNAME` | `admin` | Admin username | +| `ADMIN_PASSWORD` | _(required)_ | Admin password (required in production) | + +### Redis Configuration (Optional) + +| Variable | Description | +| ----------- | --------------------------------------------------- | +| `REDIS_URI` | Redis connection URI (e.g., `redis://redis:6379/0`) | + +When `REDIS_URI` is set, the application uses Redis for token storage instead of in-memory storage. + +### PostgreSQL Configuration (Optional) + +_Coming soon_ + +## Examples + +### Basic Deployment + +```bash +docker run -d \ + -p 8000:8000 \ + -e ADMIN_PASSWORD=your_secure_password \ + -v ./data:/data \ + baby-monitor +``` + +### With Redis + +```bash +# Start Redis +docker run -d --name redis redis:7-alpine + +# Start Baby Monitor with Redis +docker run -d \ + -p 8000:8000 \ + -e ADMIN_PASSWORD=your_secure_password \ + -e REDIS_URI=redis://redis:6379/0 \ + --link redis \ + baby-monitor +``` + +### Using Docker Compose + +```yaml +version: "3.8" + +services: + app: + image: baby-monitor + ports: + - "8000:8000" + environment: + - ADMIN_PASSWORD=your_secure_password + - REDIS_URI=redis://redis:6379/0 + volumes: + - ./data:/data + depends_on: + - redis + + redis: + image: redis:7-alpine + volumes: + - redis-data:/data + +volumes: + redis-data: +``` + +## Health Checks + +The image provides several endpoints for monitoring: + +- `GET /health` - Basic health check (returns `{"status": "healthy"}`) +- `GET /ready` - Readiness check for orchestration +- `GET /info` - Service information including installed features + +Example: + +```bash +curl http://localhost:8000/info +``` + +Response: + +```json +{ + "service": "baby-monitor", + "version": "0.1.0", + "features": { + "redis": true, + "postgresql": true + }, + "config": { + "environment": "production", + "data_dir": "/data", + "redis_configured": true + } +} +``` + +## Volumes + +- `/data` - Persistent storage for SQLite database + +Mount this directory to preserve data across container restarts: + +```bash +docker run -v /path/on/host:/data baby-monitor +``` + +## Ports + +- `8000` - HTTP API server + +## Security Notes + +1. **Always set `ADMIN_PASSWORD`** in production +2. Use **strong passwords** (minimum 16 characters) +3. Run behind a **reverse proxy** with HTTPS +4. Use **Redis** for multi-instance deployments +5. **Back up** the `/data` directory regularly + +## Troubleshooting + +### Check installed features + +```bash +curl http://localhost:8000/info +``` + +### View logs + +```bash +docker logs +``` + +### Verify Redis connection + +Look for startup message: + +```bash +✓ Connected to Redis at redis://... +``` + +### Test authentication + +```bash +curl -X POST http://localhost:8000/api/login \ + -H "Content-Type: application/json" \ + -d '{"username":"admin","password":"your_password"}' +``` + +## Support + +For issues and feature requests, please visit the project repository. diff --git a/docs/TOKEN_STORAGE.md b/docs/TOKEN_STORAGE.md new file mode 100644 index 0000000..9b43596 --- /dev/null +++ b/docs/TOKEN_STORAGE.md @@ -0,0 +1,89 @@ +# Token Storage Configuration + +The application automatically detects and uses the appropriate token storage backend based on environment variables. + +## In-Memory Storage (Default) + +By default, tokens are stored in memory. This is suitable for: + +- Development +- Single-instance deployments +- Testing + +**No configuration needed** - this is the default behavior. + +## Redis Storage (Production Recommended) + +For production deployments with multiple instances, use Redis for shared token storage. + +### Setup + +1. **Install Redis dependency:** + + ```bash + uv sync --extra redis + # or + pip install redis>=5.0.0 + ``` + +2. **Set environment variable:** + + ```bash + export REDIS_URI=redis://localhost:6379/0 + ``` + +3. **Start the application:** + The app will automatically detect Redis and use it for token storage. + +### Docker Compose with Redis + +Uncomment the Redis service in `docker-compose.yml`: + +```yaml +services: + app: + environment: + - REDIS_URI=redis://redis:6379/0 + + redis: + image: redis:7-alpine + volumes: + - redis-data:/data + +volumes: + redis-data: +``` + +Then run: + +```bash +docker compose up +``` + +### Verification + +On startup, the application will print: + +- `✓ Connected to Redis at redis://...` - Using Redis +- `ℹ Using in-memory token storage` - Using in-memory + +### Error Handling + +**Important**: If `REDIS_URI` is set, the application **requires** a successful Redis connection. It will **not** fall back to in-memory storage. + +If Redis connection fails, the application will exit with a clear error message: + +``` +RuntimeError: Failed to connect to Redis at redis://localhost:6379. +Ensure Redis is running and accessible. +``` + +This prevents silent failures in production environments where Redis is expected. + +### Benefits of Redis + +- ✅ **Shared storage** across multiple app instances +- ✅ **Automatic expiration** with TTL +- ✅ **Persistent** (with proper Redis configuration) +- ✅ **Scalable** for high-traffic applications +- ✅ **Drop-in replacement** - no code changes needed