From 2ca35620d988f4099bbd2204b02c87b20f93ed9a Mon Sep 17 00:00:00 2001 From: Paul Bailey Date: Sun, 7 Dec 2025 23:47:07 +0000 Subject: [PATCH] Add Docker support with Dockerfile, docker-compose, and deployment documentation --- .dockerignore | 12 ++++ Dockerfile | 30 ++++++++ README.Docker.md | 158 +++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 25 +++++++ docker-entrypoint.sh | 19 ++++++ 5 files changed, 244 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 README.Docker.md create mode 100644 docker-compose.yml create mode 100755 docker-entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..359574b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +node_modules +npm-debug.log +.git +.gitignore +*.md +.DS_Store +audio_library +artwork +*.db +.env +config.json +data diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9f98fc3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +# Use Node.js LTS +FROM node:20-alpine + +# Install dependencies for native modules +RUN apk add --no-cache python3 make g++ + +# Create app directory +WORKDIR /app + +# Copy package files +COPY package*.json ./ + +# Install dependencies +RUN npm ci --only=production + +# Copy application code +COPY . . + +# Create directories for data +RUN mkdir -p /data/artwork /data/music + +# Expose port +EXPOSE 4000 + +# Health check +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ + CMD node -e "require('http').get('http://localhost:4000/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})" + +# Start the server +CMD ["npm", "start"] diff --git a/README.Docker.md b/README.Docker.md new file mode 100644 index 0000000..c02f649 --- /dev/null +++ b/README.Docker.md @@ -0,0 +1,158 @@ +# Docker Deployment Guide + +## Quick Start + +### 1. Build the Docker image + +```bash +docker build -t carplay-audio-server . +``` + +### 2. Run with Docker Compose (Recommended) + +Edit `docker-compose.yml` and update the music library path: + +```yaml +volumes: + - /path/to/your/music:/data/music:ro # Change this! +``` + +Then start: + +```bash +docker-compose up -d +``` + +### 3. Run with Docker directly + +```bash +docker run -d \ + --name carplay-audio \ + -p 4000:4000 \ + -v /path/to/your/music:/data/music:ro \ + -v $(pwd)/data/artwork:/app/artwork \ + -v $(pwd)/data/database:/app \ + carplay-audio-server +``` + +## Initial Setup + +### Scan your library + +```bash +# Using docker-compose +docker-compose exec carplay-audio npm run scan + +# Using docker +docker exec carplay-audio npm run scan +``` + +### Access the admin panel + +Open your browser to: `http://localhost:4000` + +### Configure Amperfy + +- **Server URL**: `http://YOUR-SERVER-IP:4000` +- **Username**: `admin` +- **Password**: `admin` + +## Configuration + +### Environment Variables + +- `PORT` - Server port (default: 4000) +- `NODE_ENV` - Environment (production/development) +- `SCAN_ON_START` - Set to "true" to scan library on container start + +### Volumes + +- `/data/music` - Your music library (read-only) +- `/app/artwork` - Extracted album artwork +- `/app/audio_server.db` - SQLite database +- `/app/config.json` - Server configuration + +## Management + +### View logs + +```bash +docker-compose logs -f carplay-audio +``` + +### Restart server + +```bash +docker-compose restart carplay-audio +``` + +### Stop server + +```bash +docker-compose down +``` + +### Update and rebuild + +```bash +git pull +docker-compose down +docker-compose build +docker-compose up -d +``` + +## Behind Reverse Proxy + +If using nginx or Cloudflare Tunnel, configure it to proxy to `http://localhost:4000`. + +Example nginx config: + +```nginx +location / { + proxy_pass http://localhost:4000; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; +} +``` + +## Troubleshooting + +### Container won't start + +Check logs: +```bash +docker-compose logs carplay-audio +``` + +### Music not showing + +Rescan the library: +```bash +docker-compose exec carplay-audio npm run scan +``` + +### Permission issues + +Ensure the music directory is readable: +```bash +chmod -R 755 /path/to/your/music +``` + +## Production Deployment + +1. **Change default credentials** in `src/routes/subsonic.js` +2. **Use HTTPS** via reverse proxy +3. **Set up automatic backups** of the database +4. **Monitor logs** for errors +5. **Set resource limits** in docker-compose.yml: + +```yaml +deploy: + resources: + limits: + cpus: '2' + memory: 1G +``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a659a55 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: '3.8' + +services: + carplay-audio: + build: . + container_name: carplay-audio-server + restart: unless-stopped + ports: + - "4000:4000" + volumes: + # Mount your music library (change the left path to your music folder) + - /Volumes/Data/Music:/data/music:ro + # Persistent data (database, artwork, config) + - ./data/artwork:/app/artwork + - ./data/database:/app + - ./config.json:/app/config.json + environment: + - NODE_ENV=production + - PORT=4000 + healthcheck: + test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:4000/health"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..e1ee65a --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,19 @@ +#!/bin/sh +set -e + +# Create config if it doesn't exist +if [ ! -f /app/config.json ]; then + echo '{"libraryPath":"/data/music","port":4000}' > /app/config.json +fi + +# Run database initialization +node -e "import('./src/database/db.js').then(m => m.initDatabase())" + +# Check if we need to scan the library +if [ ! -f /app/audio_server.db ] || [ "$SCAN_ON_START" = "true" ]; then + echo "Scanning music library..." + node src/scripts/scanLibrary.js /data/music || true +fi + +# Start the server +exec npm start