File size: 2,029 Bytes
6423ff2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
FROM python:3.11-slim AS frontend-builder

# Install Node.js
RUN apt-get update && apt-get install -y curl && \
    curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
    apt-get install -y nodejs && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /frontend

# Copy frontend files
COPY frontend/package.json frontend/pnpm-lock.yaml* frontend/package-lock.json* ./

# Install dependencies
RUN npm install

# Copy source
COPY frontend/ .

# Use the space config for export
COPY frontend/next.config.space.js ./next.config.js

# Build
RUN npm run build

# ============================================ 
# Final Runtime Stage
# ============================================ 
FROM python:3.11-slim

WORKDIR /app

# Set env vars
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PIP_NO_CACHE_DIR=1 \
    PORT=7860 \
    DATABASE_URL="sqlite+aiosqlite:///./storage/audioforge.db" \
    REDIS_URL="redis://localhost:6379/0" \
    MUSICGEN_DEVICE="cuda" \
    BARK_DEVICE="cuda"

# Install system dependencies
# git is required for installing dependencies from git (audiocraft)
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    git \
    ffmpeg \
    libsndfile1 \
    redis-server \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy backend dependency file
COPY backend/pyproject.toml .

# Install Python dependencies (including ML)
RUN pip install --upgrade pip && \
    pip install uv && \
    uv pip install --system -e ".[ml]"

# Setup storage
RUN mkdir -p /app/storage/audio/music \
    /app/storage/audio/vocals \
    /app/storage/audio/mixed \
    /app/storage/audio/mastered \
    /app/storage/models

# Copy backend code
COPY backend/app ./app
COPY backend/app_hf.py ./app_hf.py

# Copy frontend build to static
COPY --from=frontend-builder /frontend/out /app/static

# Copy entrypoint
COPY entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh

# Create user
RUN useradd -m -u 1000 user
RUN chown -R user:user /app
USER user

CMD ["/app/entrypoint.sh"]