FROM python:3.12-alpine

# Install ffmpeg and dcron (lightweight cron daemon for Alpine)
RUN apk add --no-cache ffmpeg dcron

WORKDIR /app

# Install Python dependencies
COPY app/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy application code and static files
COPY app/ .

# Downloads are stored here (mount a host volume to persist them)
RUN mkdir -p /downloads

# Setup Cronjob (fails)
RUN echo "0 4 * * * pip install --upgrade yt-dlp >> /var/log/yt-dlp-upgrade.log 2>&1" | crontab -

EXPOSE 8080

# Launch
CMD uvicorn main:app --host 0.0.0.0 --port 8080