# BMS Service - Deployment Guide ## 📋 Prerequisites - Docker & Docker Compose installed - (Production) Traefik reverse proxy configured with: - Network `traefik-public` - Let's Encrypt certificate resolver named `letsencrypt` - Entrypoints: `web` (80) and `websecure` (443) ## 🚀 Local Development ### 1. Build and Start ```bash docker-compose up --build ``` ### 2. Test the Service ```bash # Health check curl http://localhost:8080/health # Create a bookmark curl -X POST http://localhost:8080/bookmarks \ -H "Content-Type: application/json" \ -d '{ "title": "Example", "url": "https://example.com", "tags": "test,demo", "description": "Test bookmark" }' # Get all bookmarks curl http://localhost:8080/bookmarks ``` ### 3. Stop the Service ```bash docker-compose down ``` To remove data volume as well: ```bash docker-compose down -v ``` ## 🌐 Production Deployment (j4bitzs.cloud) ### 1. Prepare the Server ```bash # Create data directory sudo mkdir -p /opt/bms/data sudo chown 1000:1000 /opt/bms/data ``` ### 2. Build the Image On your build machine or server: ```bash docker build -t bms-service:latest . ``` If deploying to a remote server, push to a registry or save/load the image: ```bash # Option A: Save and transfer docker save bms-service:latest | gzip > bms-service.tar.gz # Transfer to server, then: docker load < bms-service.tar.gz # Option B: Use a registry docker tag bms-service:latest your-registry.com/bms-service:latest docker push your-registry.com/bms-service:latest ``` ### 3. Deploy with Traefik ```bash # Start the service docker-compose -f docker-compose.prod.yml up -d # Check logs docker-compose -f docker-compose.prod.yml logs -f # Verify health curl https://bms.j4bitzs.cloud/health ``` ### 4. Monitor ```bash # Check container status docker ps | grep bms # View logs docker logs -f bms-service # Check Traefik dashboard # Access your Traefik dashboard to verify routing ``` ## 🔧 Configuration Environment variables (set in `.env` or docker-compose): | Variable | Default | Description | |----------|---------|-------------| | `PORT` | `8080` | HTTP port for the service | | `DATABASE_PATH` | `/data/bms.db` | Path to SQLite database file | | `STORAGE_DIR` | `/data` | Directory for notes and files | ## 📊 Health Check The `/health` endpoint verifies: ✅ **Database connectivity** - SQLite connection and ping ✅ **Storage writable** - `/data/notes/` directory is writable Response format: ```json { "status": "ok", "database": "ok", "notes_storage": "ok" } ``` If any check fails, status becomes `degraded` and HTTP 503 is returned. ## 🗄️ Data Persistence - **Local:** Docker volume `bms-data` - **Production:** Host mount at `/opt/bms/data` Database and all note files are stored here. ## 🛡️ Security Notes - Service runs as non-root user (UID 1000) - No sensitive data in environment variables (paths only) - TLS/HTTPS enforced in production via Traefik - Health checks don't expose sensitive information ## 🔄 Updates ```bash # Pull latest code git pull # Rebuild and restart docker-compose -f docker-compose.prod.yml up -d --build # Or with separate build step docker build -t bms-service:latest . docker-compose -f docker-compose.prod.yml up -d ``` ## 🆘 Troubleshooting ### Service won't start ```bash # Check logs docker-compose logs bms # Verify permissions on data directory ls -la /opt/bms/data ``` ### Health check failing ```bash # Check inside container docker exec -it bms-service sh wget -O- http://localhost:8080/health # Check database file ls -la /data/bms.db ``` ### Traefik not routing ```bash # Verify labels docker inspect bms-service | grep -A 20 Labels # Check Traefik logs docker logs traefik | grep bms ``` ## 📚 API Endpoints - `GET /health` - Health check - `POST /bookmarks` - Create bookmark - `GET /bookmarks` - List all bookmarks - `GET /bookmarks/{id}` - Get specific bookmark - `DELETE /bookmarks/{id}` - Delete bookmark - `POST /snippets` - Create snippet - `GET /snippets` - List all snippets - `GET /snippets/{id}` - Get specific snippet - `DELETE /snippets/{id}` - Delete snippet - `POST /notes` - Create note - `GET /notes` - List all notes - `GET /notes/{id}` - Get specific note - `DELETE /notes/{id}` - Delete note - `GET /search?q=query` - Search notes --- **Production URL:** https://bms.j4bitzs.cloud **Health Check:** https://bms.j4bitzs.cloud/health