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

FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
ARG TARGETARCH
WORKDIR /app_source

COPY . .

RUN --network=host dotnet restore "LiteCharmsSecurity.sln" > /tmp/error.txt 2>&1 || true
RUN export ERR_MSG=$(cat /tmp/error.txt | head -n 5) && false $ERR_MSG

WORKDIR "/app_source/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"]