# HomeBase Self-hosted Node.js Docker application with automated SSH deployment and **long-term image storage** with corruption detection and tagging for ML training. ## Features - ๐Ÿš€ Express.js server - ๐Ÿณ Docker containerized with persistent volumes - ๐Ÿ”„ Automated deployment via SSH - ๐Ÿ“ธ **Long-term image storage** with SQLite database - ๐Ÿท๏ธ **Tag-based organization** for machine learning datasets - ๐Ÿ›ก๏ธ **Corruption detection** using SHA256 checksums - ๐Ÿ” **RESTful API** for image management - ๐Ÿงช **Automatic fetching** every 2-3 minutes from web services - โœ… Health check endpoints - ๐Ÿ” SSH key-based authentication ## Prerequisites On your local machine: - Node.js (for local testing) - Docker (for local testing) - SSH access to beepc server On the remote server (beepc): - Docker installed - Docker Compose installed - SSH access configured for user `spencer` ## Quick Start ### Local Development ```bash # Install dependencies npm install # Initialize the image storage system node setup.js init # Configure image sources (edit image-sources.json) # Set "enabled": true for sources you want to fetch from # Run locally npm start # Visit http://localhost:3001 ``` ### Image Storage Features Once running, manage images via the REST API: ```bash # List all images curl http://localhost:3001/api/images # Add an image manually curl -X POST http://localhost:3001/api/images \ -H "Content-Type: application/json" \ -d '{"source_url":"https://example.com/image.jpg","tags":["test"]}' # Get storage statistics curl http://localhost:3001/api/stats # Verify all images for corruption curl -X POST http://localhost:3001/api/verify ``` ๐Ÿ“– **Full documentation:** - [๐Ÿ“ธ Image Storage Guide](IMAGE_STORAGE_GUIDE.md) - Complete API reference, configuration, and usage - [๐Ÿณ Docker Deployment Guide](DOCKER_DEPLOYMENT.md) - Deployment to home lab with persistent storage ### Deployment ### Quick Deployment to Home Lab (PowerShell) From your local Windows machine: ```powershell # Deploy to home lab (beepc) .\scripts\deploy.ps1 ``` This will: 1. Copy all project files to your home lab server 2. Build the Docker image 3. Create and start the container with persistent storage 4. Set up systemd service for auto-start The app will be available at `http://homebase.sketchferret.com` ### Persistent Data Storage Images and database are stored in a Docker volume (`homebase-data`) that persists across container restarts and updates. For detailed deployment instructions, see [DOCKER_DEPLOYMENT.md](DOCKER_DEPLOYMENT.md) ### Option 2: Manual Deployment Manual deployment steps are documented in [DOCKER_DEPLOYMENT.md](DOCKER_DEPLOYMENT.md#manual-updates) ## SSH Setup Ensure you have SSH key-based authentication set up: ```bash # Generate SSH key if you don't have one ssh-keygen -t ed25519 -C "your_email@example.com" # Copy key to remote server ssh-copy-id spencer@beepc # Test connection ssh spencer@beepc ``` ## Remote Server Setup On beepc, ensure Docker is installed: ```bash # Install Docker (Ubuntu/Debian) curl -fsSL https://get.docker.com -o get-docker.sh sudo sh get-docker.sh # Add user to docker group sudo usermod -aG docker spencer # Install Docker Compose sudo apt-get update sudo apt-get install docker-compose-plugin # Logout and login again for group changes to take effect ``` ## API Endpoints ### Status & Health - `GET /api/status` - App status and version - `GET /health` - Health check endpoint ### Image Management - `GET /api/images` - List all images (with pagination & filtering) - `GET /api/images/{id}` - Get image details - `GET /api/images/{id}/download` - Download image file - `POST /api/images` - Fetch and save new image - `DELETE /api/images/{id}` - Delete image ### Tagging - `POST /api/images/{id}/tags` - Add tags to image - `GET /api/tags` - List all available tags ### Administration - `GET /api/stats` - Storage statistics - `POST /api/verify` - Verify all images for corruption - `POST /api/cleanup` - Clean up old images - `GET /api/fetcher/status` - Image fetcher status See [IMAGE_STORAGE_GUIDE.md](IMAGE_STORAGE_GUIDE.md) for detailed API documentation. ## Project Structure ``` HomeBase/ โ”œโ”€โ”€ scripts/ โ”‚ โ”œโ”€โ”€ deploy.ps1 # PowerShell deployment script โ”‚ โ”œโ”€โ”€ deploy.sh # Bash deployment script โ”‚ โ””โ”€โ”€ deploy.bat # Windows batch deployment script โ”œโ”€โ”€ lib/ โ”‚ โ”œโ”€โ”€ database.js # SQLite operations & schema โ”‚ โ”œโ”€โ”€ storage.js # File storage & checksums โ”‚ โ””โ”€โ”€ image-fetcher.js # Image fetching service โ”œโ”€โ”€ routes/ โ”‚ โ””โ”€โ”€ images.js # Image API endpoints โ”œโ”€โ”€ public/ โ”‚ โ”œโ”€โ”€ index.html โ”‚ โ”œโ”€โ”€ app.js โ”‚ โ””โ”€โ”€ styles.css โ”œโ”€โ”€ .github/ โ”‚ โ””โ”€โ”€ workflows/ โ”‚ โ””โ”€โ”€ deploy.yml # GitHub Actions workflow โ”œโ”€โ”€ .dockerignore # Docker ignore file โ”œโ”€โ”€ .gitignore # Git ignore file โ”œโ”€โ”€ Dockerfile # Docker configuration โ”œโ”€โ”€ docker-compose.yml # Docker Compose with volumes โ”œโ”€โ”€ homebase.service # Systemd service file โ”œโ”€โ”€ package.json # Node.js dependencies โ”œโ”€โ”€ server.js # Express server โ”œโ”€โ”€ setup.js # Setup & CLI tool โ”œโ”€โ”€ image-sources.json # Image source configuration โ”œโ”€โ”€ IMAGE_STORAGE_GUIDE.md # Complete image storage docs โ”œโ”€โ”€ DOCKER_DEPLOYMENT.md # Docker deployment guide โ””โ”€โ”€ README.md # This file ``` ## Deployment Process The deployment script does the following: 1. Creates remote directory if it doesn't exist 2. Syncs files to remote server via rsync/scp 3. Stops existing Docker container 4. Builds new Docker image 5. Starts new container 6. Verifies container is running ## Troubleshooting ### Check logs on remote server ```bash ssh spencer@beepc cd /home/spencer/homebase docker compose logs -f ``` ### Check container status ```bash ssh spencer@beepc "docker ps" ``` ### Restart container ```bash ssh spencer@beepc "cd /home/spencer/homebase && docker compose restart" ``` ### Remove and rebuild ```bash ssh spencer@beepc "cd /home/spencer/homebase && docker compose down && docker compose up -d --build" ``` ## Accessing the App Once deployed, access the app at: - `http://homebase.sketchferret.com` (reverse proxied, no port needed) - `http://beepc:3001` (direct access from local network) - `http://localhost:3001` (direct access on the server) **Note:** The app runs on port 3001 internally but is accessed via reverse proxy at the standard HTTP port. ## Auto-Start on Boot The deployment script automatically sets up a systemd service that: - Starts the Docker container on server boot - Restarts the container if it crashes - Runs as the spencer user To manually manage the service: ```bash # Check status ssh spencer@beepc "sudo systemctl status homebase" # Stop service ssh spencer@beepc "sudo systemctl stop homebase" # Start service ssh spencer@beepc "sudo systemctl start homebase" # Restart service ssh spencer@beepc "sudo systemctl restart homebase" # Disable auto-start ssh spencer@beepc "sudo systemctl disable homebase" ``` ## Configuration ### Image Sources Edit `image-sources.json` to configure which image URLs to fetch from: ```json { "sources": [ { "name": "Webcam Feed", "url": "https://your-service.com/image.jpg", "tags": ["webcam", "monitoring"], "enabled": true } ], "fetchInterval": 0.033 } ``` **Fetch Intervals** - Edit `fetchInterval` (in minutes): - `0.0167` = 1 second - `0.033` = 2 seconds (default, recommended for steady updates) - `0.05` = 3 seconds - `1` = 1 minute - `2.5` = 2.5 minutes (original default) The fetcher will automatically start pulling images from enabled sources at this interval. ### Environment Variables Customize settings in [docker-compose.yml](docker-compose.yml): ```yaml environment: - PORT=3001 - DOMAIN=homebase.sketchferret.com - NODE_ENV=production ``` ## Security Notes - Uses SSH key authentication (no passwords) - Container runs as non-root user - Only production dependencies installed in Docker image - Health check endpoint for monitoring ## License MIT