# .NET Core SDK
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS aspnetcore-build

# Install Node.js + npm (Node 18 LTS, required for TypeScript)
RUN apt-get update && apt-get install -y curl gnupg \
    && curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
    && apt-get install -y nodejs

# Copy Projects
COPY LCU.WebApps.Internal.DocumentManager/LCU.WebApps.Internal.DocumentManager.csproj ./source/LCU.WebApps.Internal.DocumentManager/

# Install Credential Provider and set env variables to enable Nuget restore with auth
ARG PAT=vvqu3q252m5kqwptu4tavha4ghk4svhmwsahb2kvlu22ogiegt6q
RUN curl -L https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh  | sh
#RUN wget -qO- https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh | bash
ENV NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED=true
ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS="{\"endpointCredentials\": [{\"endpoint\":\"https://landmarkcu.pkgs.visualstudio.com/_packaging/LCU-Internal/nuget/v3/index.json\", \"password\":\"${PAT}\"}]}"

# .NET Core Restore, use auth'd feed
RUN dotnet restore  -s "https://landmarkcu.pkgs.visualstudio.com/_packaging/LCU-Internal/nuget/v3/index.json" -s "https://api.nuget.org/v3/index.json" ./source/LCU.WebApps.Internal.DocumentManager/LCU.WebApps.Internal.DocumentManager.csproj

# Copy All Files
COPY . ./source/

# .NET Core Publish
FROM aspnetcore-build AS publish
RUN dotnet publish ./source/LCU.WebApps.Internal.DocumentManager/LCU.WebApps.Internal.DocumentManager.csproj -c Release -o /dist

# ASP.NET Core
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine3.20
RUN apk add --no-cache icu-libs && apk add --no-cache tzdata;
WORKDIR /app
COPY  --from=publish /dist .

# ENVIRONMENT VALUES
ENV TZ=America/Chicago
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
ENV ASPNETCORE_ENVIRONMENT=Development
ENV ASPNETCORE_FORWARDEDHEADERS_ENABLED=true

ENTRYPOINT ["dotnet", "LCU.WebApps.Internal.DocumentManager.dll"]