FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
COPY . .
RUN dotnet publish src/TwitchArchive.Web -c Release -o /app/publish

FROM mcr.microsoft.com/dotnet/aspnet:10.0
RUN apt-get update && apt-get install -y --no-install-recommends \
    ffmpeg python3-pip rclone curl ca-certificates && rm -rf /var/lib/apt/lists/*
RUN pip3 install --no-cache-dir streamlink
WORKDIR /app
COPY --from=build /app/publish ./
# Download TwitchDownloaderCLI linux-x64 binary (if available)
RUN mkdir -p /app/bin && \
    curl -fsSL -o /app/bin/TwitchDownloaderCLI https://github.com/Franiac/TwitchDownloader/releases/latest/download/TwitchDownloaderCLI-linux-x64 && \
    chmod +x /app/bin/TwitchDownloaderCLI || true
EXPOSE 8080
ENV ASPNETCORE_URLS=http://+:8080
ENTRYPOINT ["dotnet", "TwitchArchive.Web.dll"]
