FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0 AS build
ARG TARGETARCH
WORKDIR /src
COPY ["src/LiteCharmsSecurity.STS.Identity/LiteCharmsSecurity.STS.Identity.csproj", "src/LiteCharmsSecurity.STS.Identity/"]
COPY ["src/LiteCharmsSecurity.Admin.EntityFramework.Shared/LiteCharmsSecurity.Admin.EntityFramework.Shared.csproj", "src/LiteCharmsSecurity.Admin.EntityFramework.Shared/"]
COPY ["src/LiteCharmsSecurity.Shared/LiteCharmsSecurity.Shared.csproj", "src/LiteCharmsSecurity.Shared/"]

ENV NUGET_CERT_REVOCATION_MODE=offline
RUN dotnet restore "src/LiteCharmsSecurity.STS.Identity/LiteCharmsSecurity.STS.Identity.csproj" --source "https://nexus.khongisa.co.za/repository/nuget-group/index.json" --verbosity detailed

COPY . .
WORKDIR "src/LiteCharmsSecurity.STS.Identity"
RUN dotnet build "LiteCharmsSecurity.STS.Identity.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "LiteCharmsSecurity.STS.Identity.csproj" -c Release --no-restore -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENV ASPNETCORE_FORWARDEDHEADERS_ENABLED=true
ENTRYPOINT ["dotnet", "LiteCharmsSecurity.STS.Identity.dll"]