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

FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:10.0 AS build
ARG TARGETARCH
WORKDIR /src
COPY ["src/LiteCharmsSecurity.Admin.Api/LiteCharmsSecurity.Admin.Api.csproj", "src/LiteCharmsSecurity.Admin.Api/"]
COPY ["src/LiteCharmsSecurity.Admin.EntityFramework.Shared/LiteCharmsSecurity.Admin.EntityFramework.Shared.csproj", "src/LiteCharmsSecurity.Admin.EntityFramework.Shared/"]
COPY ["src/LiteCharmsSecurity.Admin.EntityFramework.SqlServer/LiteCharmsSecurity.Admin.EntityFramework.SqlServer.csproj", "src/LiteCharmsSecurity.Admin.EntityFramework.SqlServer/"]
COPY ["src/LiteCharmsSecurity.Shared/LiteCharmsSecurity.Shared.csproj", "src/LiteCharmsSecurity.Shared/"]
COPY ["src/LiteCharmsSecurity.Admin.EntityFramework.PostgreSQL/LiteCharmsSecurity.Admin.EntityFramework.PostgreSQL.csproj", "src/LiteCharmsSecurity.Admin.EntityFramework.PostgreSQL/"]
RUN dotnet restore -a $TARGETARCH "src/LiteCharmsSecurity.Admin.Api/LiteCharmsSecurity.Admin.Api.csproj"
COPY . .
WORKDIR "/src/src/LiteCharmsSecurity.Admin.Api"
RUN dotnet build -a $TARGETARCH "LiteCharmsSecurity.Admin.Api.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish -a $TARGETARCH "LiteCharmsSecurity.Admin.Api.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.Admin.Api.dll"]
