# Build from the repository root:  docker build -f VocaluxeSongServer/Dockerfile -t vocaluxe-song-server .
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
COPY Directory.Build.props NuGet.Config ./
COPY VocaluxeSongServer/VocaluxeSongServer.csproj VocaluxeSongServer/
RUN dotnet restore VocaluxeSongServer/VocaluxeSongServer.csproj
COPY VocaluxeSongServer/ VocaluxeSongServer/
RUN dotnet publish VocaluxeSongServer/VocaluxeSongServer.csproj -c ReleaseLinux --no-restore -o /app

FROM mcr.microsoft.com/dotnet/aspnet:10.0
# Song downloads (USDB source): yt-dlp for audio/video, ffmpeg for merging, deno as the JavaScript runtime
# yt-dlp needs for YouTube. yt-dlp is the newest release at build time; rebuild the image to update it.
RUN apt-get update \
 && apt-get install -y --no-install-recommends ffmpeg ca-certificates curl unzip \
 && curl -fsSL -o /usr/local/bin/yt-dlp https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux \
 && chmod 755 /usr/local/bin/yt-dlp \
 && curl -fsSL -o /tmp/deno.zip https://github.com/denoland/deno/releases/latest/download/deno-x86_64-unknown-linux-gnu.zip \
 && unzip -q /tmp/deno.zip -d /usr/local/bin && chmod 755 /usr/local/bin/deno && rm /tmp/deno.zip \
 && apt-get purge -y unzip && apt-get autoremove -y && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=build /app .
# The song library; must be writable for downloads (new songs go to <library>/Downloads)
VOLUME /songs
ENV Library__Path=/songs \
    HOME=/tmp \
    XDG_CACHE_HOME=/tmp/cache
EXPOSE 8080
# Runs as the user given with --user (on Unraid 99:100 = nobody:users, the owner of the shares)
ENTRYPOINT ["dotnet", "VocaluxeSongServer.dll"]
