# ── Build stage ────────────────────────────────────────
# Uses the .NET 8 SDK to restore and compile your project.
# Change "MyCobaltApp.csproj" to match your own .csproj filename.
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY MyCobaltApp.csproj ./
RUN dotnet restore
COPY . .
# IMPORTANT: do NOT add -r linux-x64 or --self-contained here.
# Both flatten the runtimes/ folder and break Chromium path resolution.
RUN dotnet publish -c Release --no-restore -o /app/publish

# ── Runtime stage ─────────────────────────────────────
# Uses the smaller ASP.NET 8 runtime image (Debian Bookworm).
# Installs the native libraries that Chromium needs to run headless.
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
RUN apt-get update && apt-get install -y --no-install-recommends \
    libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 \
    libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 \
    libxrandr2 libgbm1 libpango-1.0-0 libcairo2 \
    libasound2 libxshmfence1 libx11-xcb1 \
    libxfixes3 libxss1 libxtst6 \
    fonts-liberation fonts-noto-color-emoji \
    && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=build /app/publish .
# Ensure the Chromium binary is executable (NuGet does not preserve Unix permissions).
RUN chmod +x ./runtimes/linux-x64/native/chrome 2>/dev/null || true
# Change "MyCobaltApp.dll" to match your own project name.
ENTRYPOINT ["dotnet", "MyCobaltApp.dll"]
