akborana4 commited on
Commit
d5174df
·
verified ·
1 Parent(s): a0b5ce9

Update Dockerfile

Browse files
Files changed (1) hide show
  1. 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 ffmpeg & yt-dlp fallback ----------
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
- echo "installed yt-dlp from apk"; \
19
  elif apk add --no-cache yt-dlp-core; then \
20
- echo "installed yt-dlp-core from apk"; \
21
  elif curl -fsSL -o /usr/local/bin/yt-dlp https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp; then \
22
- chmod +x /usr/local/bin/yt-dlp; \
23
- echo "downloaded yt-dlp binary to /usr/local/bin/yt-dlp"; \
24
  else \
25
- echo "falling back to pip install yt-dlp at build time"; \
26
- python3 -m pip install --no-cache-dir -U yt-dlp; \
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
- # Put start script directly into image so no external COPY is required
41
- RUN cat > /usr/local/bin/start.sh <<'SH'\n\
42
- #!/bin/sh\n\
43
- set -eu\n\
44
- TMP_BIN=\"/tmp/yt-dlp\"\n\
45
- SYS_BIN=\"$(command -v yt-dlp 2>/dev/null || true)\"\n\
46
- echo \"startup: checking yt-dlp...\"\n\
47
- if curl -fsSL -o \"$TMP_BIN\" \"https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp\"; then\n chmod +x \"$TMP_BIN\" || true\n YTDLP=\"$TMP_BIN\"\n echo \"Using downloaded yt-dlp from $TMP_BIN\"\nelse\n if [ -n \"$SYS_BIN\" ]; then\n YTDLP=\"$SYS_BIN\"\n echo \"Using system yt-dlp at $SYS_BIN\"\n else\n echo \"Warning: yt-dlp not found (neither system install nor /tmp download).\"\n YTDLP=\"\"\n fi\nfi\nif [ -n \"$YTDLP\" ]; then\n echo \"yt-dlp version:\"\n \"$YTDLP\" --version || true\nfi\nexport YTDLP_BIN=\"$YTDLP\"\nif [ -x \"$TMP_BIN\" ]; then\n export PATH=\"/tmp:$PATH\"\nfi\nexec npm start\nSH
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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