Upload 2 files
Browse files- Dockerfile +82 -0
- docker-entrypoint-youduo.sh +18 -0
Dockerfile
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ============ Source Stage ============
|
| 2 |
+
FROM alpine/git AS source
|
| 3 |
+
|
| 4 |
+
WORKDIR /repo
|
| 5 |
+
RUN git clone --recurse-submodules --depth=1 \
|
| 6 |
+
https://github.com/liuzhao1225/YouDub-webui.git . \
|
| 7 |
+
&& rm -rf .git
|
| 8 |
+
|
| 9 |
+
# ============ Frontend Build Stage ============
|
| 10 |
+
FROM node:20-slim AS frontend-builder
|
| 11 |
+
|
| 12 |
+
WORKDIR /build
|
| 13 |
+
COPY --from=source /repo/apps/web/ .
|
| 14 |
+
|
| 15 |
+
# Create basic auth middleware (WEB_USERNAME / WEB_PASSWORD at runtime)
|
| 16 |
+
RUN mkdir -p src && cat > src/middleware.ts << 'MIDEOF'
|
| 17 |
+
import { NextRequest, NextResponse } from "next/server";
|
| 18 |
+
|
| 19 |
+
export function middleware(req: NextRequest) {
|
| 20 |
+
const password = process.env.WEB_PASSWORD;
|
| 21 |
+
if (!password) return NextResponse.next();
|
| 22 |
+
|
| 23 |
+
const header = req.headers.get("authorization");
|
| 24 |
+
if (header) {
|
| 25 |
+
const [user, pwd] = atob(header.slice(6)).split(":");
|
| 26 |
+
if (user === (process.env.WEB_USERNAME || "admin") && pwd === password)
|
| 27 |
+
return NextResponse.next();
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
return new NextResponse("Unauthorized", {
|
| 31 |
+
status: 401,
|
| 32 |
+
headers: { "WWW-Authenticate": "Basic realm=\"YouDub WebUI\"" },
|
| 33 |
+
});
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
export const config = { matcher: "/:path*" };
|
| 37 |
+
MIDEOF
|
| 38 |
+
|
| 39 |
+
RUN npm ci && npm run build
|
| 40 |
+
|
| 41 |
+
# ============ Runtime Stage ============
|
| 42 |
+
FROM python:3.12-slim-bookworm
|
| 43 |
+
|
| 44 |
+
WORKDIR /app
|
| 45 |
+
|
| 46 |
+
# Install system runtime deps
|
| 47 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 48 |
+
ffmpeg curl ca-certificates build-essential \
|
| 49 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 50 |
+
|
| 51 |
+
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
|
| 52 |
+
&& apt-get install -y nodejs \
|
| 53 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 54 |
+
|
| 55 |
+
# Copy entire source tree
|
| 56 |
+
COPY --from=source /repo/ .
|
| 57 |
+
|
| 58 |
+
# Install Python dependencies
|
| 59 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 60 |
+
|
| 61 |
+
# Overlay built frontend artifacts
|
| 62 |
+
COPY --from=frontend-builder /build/.next apps/web/.next
|
| 63 |
+
COPY --from=frontend-builder /build/node_modules apps/web/node_modules
|
| 64 |
+
|
| 65 |
+
# Create runtime data directories
|
| 66 |
+
RUN mkdir -p data workfolder
|
| 67 |
+
|
| 68 |
+
# Install entrypoint
|
| 69 |
+
COPY docker-entrypoint-youduo.sh /usr/local/bin/docker-entrypoint.sh
|
| 70 |
+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
| 71 |
+
|
| 72 |
+
EXPOSE 7860
|
| 73 |
+
|
| 74 |
+
ENV DEVICE=cpu
|
| 75 |
+
ENV WORKFOLDER=./workfolder
|
| 76 |
+
ENV MODEL_CACHE_DIR=./data/modelscope
|
| 77 |
+
ENV BACKEND_PORT=8000
|
| 78 |
+
ENV FRONTEND_PORT=7860
|
| 79 |
+
ENV WEB_USERNAME=admin
|
| 80 |
+
ENV WEB_PASSWORD=admin
|
| 81 |
+
|
| 82 |
+
ENTRYPOINT ["docker-entrypoint.sh"]
|
docker-entrypoint-youduo.sh
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
|
| 4 |
+
BACKEND_PORT="${BACKEND_PORT:-8000}"
|
| 5 |
+
FRONTEND_PORT="${FRONTEND_PORT:-7860}"
|
| 6 |
+
|
| 7 |
+
# Create default .env from example if not mounted/provided
|
| 8 |
+
if [ ! -f .env ] && [ -f .env.example ]; then
|
| 9 |
+
cp .env.example .env
|
| 10 |
+
echo "[entrypoint] Created .env from .env.example"
|
| 11 |
+
fi
|
| 12 |
+
|
| 13 |
+
# Start backend API in background
|
| 14 |
+
uvicorn backend.app.main:app --host 0.0.0.0 --port "$BACKEND_PORT" &
|
| 15 |
+
|
| 16 |
+
# Start frontend (proxies /api/* to backend on 127.0.0.1:BACKEND_PORT)
|
| 17 |
+
export NEXT_SERVER_API_BASE_URL="http://127.0.0.1:${BACKEND_PORT}"
|
| 18 |
+
exec npm --prefix apps/web run start -- --port "$FRONTEND_PORT" --hostname 0.0.0.0
|