Add Docker support with Dockerfile, docker-compose, and deployment documentation
This commit is contained in:
12
.dockerignore
Normal file
12
.dockerignore
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
node_modules
|
||||||
|
npm-debug.log
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
*.md
|
||||||
|
.DS_Store
|
||||||
|
audio_library
|
||||||
|
artwork
|
||||||
|
*.db
|
||||||
|
.env
|
||||||
|
config.json
|
||||||
|
data
|
||||||
30
Dockerfile
Normal file
30
Dockerfile
Normal file
@@ -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"]
|
||||||
158
README.Docker.md
Normal file
158
README.Docker.md
Normal file
@@ -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
|
||||||
|
```
|
||||||
25
docker-compose.yml
Normal file
25
docker-compose.yml
Normal file
@@ -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
|
||||||
19
docker-entrypoint.sh
Executable file
19
docker-entrypoint.sh
Executable file
@@ -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
|
||||||
Reference in New Issue
Block a user