FROM node:20-slim
# yt-dlp is intentionally opt-in. Enabling its image build alone does not make
# acquisition live: the worker additionally requires explicit runtime gates.
ARG INSTALL_YTDLP=false
# Debian's yt-dlp package lags years behind and fails on current YouTube, so
# take the self-contained upstream binary instead. It bundles its own Python.
# ponytail: tracks latest; pin the tag here if a release ever breaks the loop.
RUN apt-get update && apt-get install -y ffmpeg curl unzip \
    && if [ "$INSTALL_YTDLP" = "true" ]; then \
         curl -fsSL https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux \
           -o /usr/bin/yt-dlp \
         && chmod 755 /usr/bin/yt-dlp \
         && /usr/bin/yt-dlp --version \
         # YouTube guards some formats with an obfuscated JS challenge that
         # yt-dlp must execute. Deno is the only runtime it enables by default,
         # and without one those videos fail extraction.
         && curl -fsSL https://deno.land/install.sh | DENO_INSTALL=/usr/local sh -s -- --yes \
         && deno --version; \
       fi \
    && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY package*.json ./
RUN npm install --legacy-peer-deps
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "run", "start"]
