Skip to content

Commit 353ff24

Browse files
committed
prepare docker build
1 parent 79d5ae8 commit 353ff24

17 files changed

Lines changed: 963 additions & 11 deletions

.dockerignore

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Dependencies
2+
node_modules
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
7+
# Next.js build output
8+
.next
9+
out
10+
11+
# Environment variables
12+
.env
13+
.env.local
14+
.env.development.local
15+
.env.test.local
16+
.env.production.local
17+
18+
# Testing
19+
coverage
20+
__tests__
21+
*.test.js
22+
*.test.ts
23+
*.test.tsx
24+
jest.config.js
25+
jest.setup.js
26+
27+
# Development files
28+
.vscode
29+
.kiro
30+
dev.log
31+
*.log
32+
33+
# Git
34+
.git
35+
.gitignore
36+
37+
# Docker
38+
Dockerfile
39+
.dockerignore
40+
docker-compose.yml
41+
42+
# Documentation
43+
README.md
44+
*.md
45+
46+
# Misc
47+
.DS_Store
48+
*.tgz
49+
*.tar.gz
50+
51+
# IDE
52+
.idea
53+
*.swp
54+
*.swo
55+
56+
# Temporary files
57+
tmp
58+
temp
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
tags:
9+
- 'v*'
10+
pull_request:
11+
branches:
12+
- main
13+
- master
14+
workflow_dispatch:
15+
16+
env:
17+
REGISTRY: docker.io
18+
IMAGE_NAME: mrorbitman/karaoke-for-jellyfin
19+
20+
jobs:
21+
build-and-push:
22+
runs-on: ubuntu-latest
23+
permissions:
24+
contents: read
25+
packages: write
26+
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v3
33+
34+
- name: Log in to Docker Hub
35+
if: github.event_name != 'pull_request'
36+
uses: docker/login-action@v3
37+
with:
38+
registry: ${{ env.REGISTRY }}
39+
username: ${{ secrets.DOCKERHUB_USERNAME }}
40+
password: ${{ secrets.DOCKERHUB_TOKEN }}
41+
42+
- name: Extract metadata
43+
id: meta
44+
uses: docker/metadata-action@v5
45+
with:
46+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
47+
tags: |
48+
# set latest tag for default branch
49+
type=ref,event=branch
50+
type=ref,event=pr
51+
type=semver,pattern={{version}}
52+
type=semver,pattern={{major}}.{{minor}}
53+
type=semver,pattern={{major}}
54+
type=raw,value=latest,enable={{is_default_branch}}
55+
56+
- name: Build and push Docker image
57+
uses: docker/build-push-action@v5
58+
with:
59+
context: .
60+
platforms: linux/amd64,linux/arm64
61+
push: ${{ github.event_name != 'pull_request' }}
62+
tags: ${{ steps.meta.outputs.tags }}
63+
labels: ${{ steps.meta.outputs.labels }}
64+
cache-from: type=gha
65+
cache-to: type=gha,mode=max
66+
67+
- name: Update Docker Hub description
68+
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
69+
uses: peter-evans/dockerhub-description@v4
70+
with:
71+
username: ${{ secrets.DOCKERHUB_USERNAME }}
72+
password: ${{ secrets.DOCKERHUB_TOKEN }}
73+
repository: ${{ env.IMAGE_NAME }}
74+
readme-filepath: ./README-DOCKERHUB.md

.prettierignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.prettierignore
2+
.gitignore
3+
*.svg
4+
*.png
5+
*.jpg
6+
*.lrc
7+
*.ico
8+
*.log

DOCKER.md

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
# Docker Setup for Karaoke For Jellyfin
2+
3+
This document provides instructions for building and running the Karaoke For Jellyfin application using Docker.
4+
5+
## Quick Start
6+
7+
### Using Docker Compose (Recommended)
8+
9+
1. **Copy the environment file:**
10+
```bash
11+
cp .env.local.example .env.local
12+
```
13+
14+
2. **Edit `.env.local` with your configuration:**
15+
```bash
16+
# Jellyfin Configuration
17+
JELLYFIN_SERVER_URL=http://host.docker.internal:8096
18+
JELLYFIN_API_KEY=your_jellyfin_api_key_here
19+
JELLYFIN_USERNAME=your_jellyfin_username_here
20+
21+
# Lyrics Configuration (adjust paths as needed)
22+
LYRICS_PATH=./lyrics
23+
JELLYFIN_MEDIA_PATH=/path/to/your/jellyfin/media
24+
25+
# Application Configuration
26+
NEXT_PUBLIC_APP_URL=http://localhost:3000
27+
SESSION_SECRET=your_secure_session_secret_here
28+
```
29+
30+
3. **Start the application:**
31+
```bash
32+
docker-compose up -d
33+
```
34+
35+
4. **Access the application:**
36+
- Mobile interface: http://localhost:3000
37+
- TV display: http://localhost:3000/tv
38+
39+
### Using Docker directly
40+
41+
1. **Build the image:**
42+
```bash
43+
docker build -t karaoke-for-jellyfin .
44+
```
45+
46+
2. **Run the container:**
47+
```bash
48+
docker run -d \
49+
--name karaoke-app \
50+
-p 3000:3000 \
51+
-e JELLYFIN_SERVER_URL=http://host.docker.internal:8096 \
52+
-e JELLYFIN_API_KEY=your_api_key \
53+
-e JELLYFIN_USERNAME=your_username \
54+
-e NEXT_PUBLIC_APP_URL=http://localhost:3000 \
55+
-e SESSION_SECRET=your_session_secret \
56+
-v $(pwd)/lyrics:/app/lyrics:ro \
57+
-v /path/to/jellyfin/media:/app/media:ro \
58+
--add-host host.docker.internal:host-gateway \
59+
karaoke-for-jellyfin
60+
```
61+
62+
## Configuration
63+
64+
### Environment Variables
65+
66+
| Variable | Description | Default | Required |
67+
|----------|-------------|---------|----------|
68+
| `JELLYFIN_SERVER_URL` | URL to your Jellyfin server | `http://localhost:8096` | Yes |
69+
| `JELLYFIN_API_KEY` | Jellyfin API key | - | Yes |
70+
| `JELLYFIN_USERNAME` | Jellyfin username | - | Yes |
71+
| `LYRICS_PATH` | Path to lyrics folder | `/app/lyrics` | No |
72+
| `JELLYFIN_MEDIA_PATH` | Path to Jellyfin media | `/app/media` | No |
73+
| `NEXT_PUBLIC_APP_URL` | Public URL of the app | `http://localhost:3000` | No |
74+
| `SESSION_SECRET` | Secret for session management | - | Yes |
75+
76+
### Volume Mounts
77+
78+
- **Lyrics Directory**: Mount your lyrics folder to `/app/lyrics` (read-only)
79+
- **Media Directory**: Mount your Jellyfin media folder to `/app/media` (read-only)
80+
81+
### Network Configuration
82+
83+
The application needs to communicate with your Jellyfin server. There are several ways to configure this:
84+
85+
#### Option 1: Host Gateway (Recommended)
86+
Use `host.docker.internal` in your Jellyfin URL and add the host gateway:
87+
```bash
88+
--add-host host.docker.internal:host-gateway
89+
```
90+
91+
#### Option 2: Host Network
92+
Use host networking to access services on localhost:
93+
```yaml
94+
network_mode: host
95+
```
96+
97+
#### Option 3: External Network
98+
If Jellyfin is running in another container, use a shared network.
99+
100+
## Development
101+
102+
### Development with Docker
103+
104+
For development, you can mount the source code and use hot reloading:
105+
106+
```bash
107+
docker run -it \
108+
--name karaoke-dev \
109+
-p 3000:3000 \
110+
-v $(pwd):/app \
111+
-v /app/node_modules \
112+
-e NODE_ENV=development \
113+
node:18-alpine \
114+
sh -c "cd /app && npm install && npm run dev"
115+
```
116+
117+
### Building for Different Architectures
118+
119+
To build for multiple architectures (useful for deployment on different systems):
120+
121+
```bash
122+
# Build for AMD64 and ARM64
123+
docker buildx build --platform linux/amd64,linux/arm64 -t karaoke-for-jellyfin .
124+
```
125+
126+
## Troubleshooting
127+
128+
### Common Issues
129+
130+
1. **Cannot connect to Jellyfin server**
131+
- Ensure `JELLYFIN_SERVER_URL` is accessible from within the container
132+
- Use `host.docker.internal` instead of `localhost` if Jellyfin is on the host
133+
- Check firewall settings
134+
135+
2. **Lyrics not loading**
136+
- Verify the lyrics directory is mounted correctly
137+
- Check file permissions (container runs as user `nextjs` with UID 1001)
138+
139+
3. **WebSocket connection issues**
140+
- Ensure port 3000 is properly exposed
141+
- Check if reverse proxy is configured correctly for WebSocket upgrades
142+
143+
4. **Permission denied errors**
144+
- The container runs as a non-root user (nextjs:nodejs)
145+
- Ensure mounted volumes have appropriate permissions
146+
147+
### Logs
148+
149+
View application logs:
150+
```bash
151+
# Docker Compose
152+
docker-compose logs -f karaoke-app
153+
154+
# Docker directly
155+
docker logs -f karaoke-app
156+
```
157+
158+
### Health Check
159+
160+
Check if the application is running:
161+
```bash
162+
curl http://localhost:3000/api/health
163+
```
164+
165+
## Production Deployment
166+
167+
### Security Considerations
168+
169+
1. **Use strong session secrets**: Generate a secure random string for `SESSION_SECRET`
170+
2. **Secure API keys**: Store Jellyfin API keys securely (consider using Docker secrets)
171+
3. **Network security**: Use proper firewall rules and consider using a reverse proxy
172+
4. **Regular updates**: Keep the Docker image updated with security patches
173+
174+
### Performance Optimization
175+
176+
1. **Resource limits**: Set appropriate CPU and memory limits
177+
2. **Persistent storage**: Use named volumes for better performance
178+
3. **Reverse proxy**: Use nginx or similar for SSL termination and caching
179+
180+
### Example Production docker-compose.yml
181+
182+
```yaml
183+
version: '3.8'
184+
185+
services:
186+
karaoke-app:
187+
build: .
188+
restart: unless-stopped
189+
ports:
190+
- "127.0.0.1:3000:3000" # Only bind to localhost
191+
environment:
192+
- NODE_ENV=production
193+
- JELLYFIN_SERVER_URL=https://your-jellyfin-server.com
194+
- JELLYFIN_API_KEY_FILE=/run/secrets/jellyfin_api_key
195+
- SESSION_SECRET_FILE=/run/secrets/session_secret
196+
volumes:
197+
- lyrics_data:/app/lyrics:ro
198+
- media_data:/app/media:ro
199+
secrets:
200+
- jellyfin_api_key
201+
- session_secret
202+
deploy:
203+
resources:
204+
limits:
205+
memory: 512M
206+
cpus: '0.5'
207+
208+
volumes:
209+
lyrics_data:
210+
external: true
211+
media_data:
212+
external: true
213+
214+
secrets:
215+
jellyfin_api_key:
216+
external: true
217+
session_secret:
218+
external: true
219+
```
220+
221+
## Support
222+
223+
If you encounter issues with the Docker setup, please check:
224+
1. Docker and Docker Compose versions
225+
2. System requirements and available resources
226+
3. Network connectivity to Jellyfin server
227+
4. File permissions for mounted volumes

0 commit comments

Comments
 (0)