Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +59 -15
Dockerfile
CHANGED
|
@@ -2,49 +2,93 @@
|
|
| 2 |
FROM node:18-alpine AS client
|
| 3 |
WORKDIR /app/client
|
| 4 |
|
|
|
|
| 5 |
COPY client/package.json ./
|
| 6 |
RUN npm install
|
| 7 |
COPY client/ ./
|
| 8 |
RUN npm run build
|
| 9 |
|
| 10 |
-
# ---------- 2) Build the Node server with
|
| 11 |
FROM node:18-alpine AS server
|
| 12 |
WORKDIR /app/server
|
| 13 |
|
|
|
|
| 14 |
RUN apk add --no-cache python3 py3-pip ffmpeg curl ca-certificates
|
| 15 |
|
|
|
|
|
|
|
| 16 |
RUN set -eux; \
|
| 17 |
if apk add --no-cache yt-dlp; then \
|
| 18 |
-
|
| 19 |
elif apk add --no-cache yt-dlp-core; then \
|
| 20 |
-
|
| 21 |
elif curl -fsSL -o /usr/local/bin/yt-dlp https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp; then \
|
| 22 |
-
|
| 23 |
-
|
| 24 |
else \
|
| 25 |
-
|
| 26 |
-
|
| 27 |
fi; \
|
|
|
|
| 28 |
command -v yt-dlp >/dev/null 2>&1 && yt-dlp --version || true
|
| 29 |
|
|
|
|
| 30 |
COPY server/package.json ./
|
| 31 |
RUN npm install
|
| 32 |
COPY server/ ./
|
| 33 |
|
|
|
|
| 34 |
RUN mkdir -p ../client/dist
|
| 35 |
COPY --from=client /app/client/dist ../client/dist
|
| 36 |
|
|
|
|
| 37 |
ENV NODE_ENV=production
|
| 38 |
ENV PORT=3000
|
| 39 |
|
| 40 |
-
#
|
| 41 |
-
|
| 42 |
-
#
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
RUN chmod +x /usr/local/bin/start.sh
|
| 49 |
|
| 50 |
EXPOSE 3000
|
|
|
|
| 2 |
FROM node:18-alpine AS client
|
| 3 |
WORKDIR /app/client
|
| 4 |
|
| 5 |
+
# Install client dependencies and build
|
| 6 |
COPY client/package.json ./
|
| 7 |
RUN npm install
|
| 8 |
COPY client/ ./
|
| 9 |
RUN npm run build
|
| 10 |
|
| 11 |
+
# ---------- 2) Build the Node server with yt-dlp & ffmpeg (fallbacks) ----------
|
| 12 |
FROM node:18-alpine AS server
|
| 13 |
WORKDIR /app/server
|
| 14 |
|
| 15 |
+
# Core runtime tools: python, pip (for build-time fallback), ffmpeg, curl, ca-certificates
|
| 16 |
RUN apk add --no-cache python3 py3-pip ffmpeg curl ca-certificates
|
| 17 |
|
| 18 |
+
# Try a few build-time ways to provide yt-dlp (preferred order):
|
| 19 |
+
# 1) apk (yt-dlp or yt-dlp-core), 2) download standalone binary to /usr/local/bin, 3) pip install at build time
|
| 20 |
RUN set -eux; \
|
| 21 |
if apk add --no-cache yt-dlp; then \
|
| 22 |
+
echo "installed yt-dlp from apk"; \
|
| 23 |
elif apk add --no-cache yt-dlp-core; then \
|
| 24 |
+
echo "installed yt-dlp-core from apk"; \
|
| 25 |
elif curl -fsSL -o /usr/local/bin/yt-dlp https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp; then \
|
| 26 |
+
chmod +x /usr/local/bin/yt-dlp; \
|
| 27 |
+
echo "downloaded standalone yt-dlp to /usr/local/bin/yt-dlp"; \
|
| 28 |
else \
|
| 29 |
+
echo "falling back to pip install at build time"; \
|
| 30 |
+
python3 -m pip install --no-cache-dir -U yt-dlp; \
|
| 31 |
fi; \
|
| 32 |
+
# sanity check (non-fatal)
|
| 33 |
command -v yt-dlp >/dev/null 2>&1 && yt-dlp --version || true
|
| 34 |
|
| 35 |
+
# Install server dependencies and copy server source
|
| 36 |
COPY server/package.json ./
|
| 37 |
RUN npm install
|
| 38 |
COPY server/ ./
|
| 39 |
|
| 40 |
+
# Bring in client build
|
| 41 |
RUN mkdir -p ../client/dist
|
| 42 |
COPY --from=client /app/client/dist ../client/dist
|
| 43 |
|
| 44 |
+
# Environment
|
| 45 |
ENV NODE_ENV=production
|
| 46 |
ENV PORT=3000
|
| 47 |
|
| 48 |
+
# Runtime start script:
|
| 49 |
+
# - Attempts to download latest standalone yt-dlp to /tmp (writable on HF/Spaces)
|
| 50 |
+
# - If download succeeds, it will be used; otherwise falls back to system yt-dlp (from apk/pip/binary)
|
| 51 |
+
# - Exposes the resolved path in $YTDLP_BIN and puts /tmp in PATH if a downloaded binary exists
|
| 52 |
+
RUN cat > /usr/local/bin/start.sh <<'SH'
|
| 53 |
+
#!/bin/sh
|
| 54 |
+
set -eu
|
| 55 |
+
|
| 56 |
+
TMP_BIN="/tmp/yt-dlp"
|
| 57 |
+
SYS_BIN="$(command -v yt-dlp 2>/dev/null || true)"
|
| 58 |
+
|
| 59 |
+
echo "startup: checking yt-dlp..."
|
| 60 |
+
|
| 61 |
+
# Try to download the standalone binary into /tmp (writable on many restricted platforms)
|
| 62 |
+
if curl -fsSL -o "$TMP_BIN" "https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp"; then
|
| 63 |
+
chmod +x "$TMP_BIN" || true
|
| 64 |
+
YTDLP="$TMP_BIN"
|
| 65 |
+
echo "Using downloaded yt-dlp from $TMP_BIN"
|
| 66 |
+
else
|
| 67 |
+
if [ -n "$SYS_BIN" ]; then
|
| 68 |
+
YTDLP="$SYS_BIN"
|
| 69 |
+
echo "Using system yt-dlp at $SYS_BIN"
|
| 70 |
+
else
|
| 71 |
+
echo "Warning: yt-dlp not found (neither system install nor /tmp download)."
|
| 72 |
+
YTDLP=""
|
| 73 |
+
fi
|
| 74 |
+
fi
|
| 75 |
+
|
| 76 |
+
if [ -n "$YTDLP" ]; then
|
| 77 |
+
echo "yt-dlp version:"
|
| 78 |
+
"$YTDLP" --version || true
|
| 79 |
+
fi
|
| 80 |
+
|
| 81 |
+
export YTDLP_BIN="$YTDLP"
|
| 82 |
+
|
| 83 |
+
# If we downloaded to /tmp, put /tmp first on PATH so `yt-dlp` resolves to the downloaded binary
|
| 84 |
+
if [ -x "$TMP_BIN" ]; then
|
| 85 |
+
export PATH="/tmp:$PATH"
|
| 86 |
+
fi
|
| 87 |
+
|
| 88 |
+
# Finally start the app
|
| 89 |
+
exec npm start
|
| 90 |
+
SH
|
| 91 |
+
|
| 92 |
RUN chmod +x /usr/local/bin/start.sh
|
| 93 |
|
| 94 |
EXPOSE 3000
|