# Balinyaar API — build context is `server/` (see the root docker-compose.yml).
#
# The csproj/props files are copied on their own first so `dotnet restore` lands in a layer that only
# re-runs when a project reference or package version actually changes; the source copy below it churns
# on every commit. Directory.Packages.props is the central version manifest — restore fails without it.

FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src

COPY Directory.Packages.props ./
COPY src/API/Baya.Web.Api/Baya.Web.Api.csproj                                       src/API/Baya.Web.Api/
COPY src/API/Baya.WebFramework/Baya.WebFramework.csproj                             src/API/Baya.WebFramework/
COPY src/API/Plugins/Baya.Web.Plugins.Grpc/Baya.Web.Plugins.Grpc.csproj             src/API/Plugins/Baya.Web.Plugins.Grpc/
COPY src/Core/Baya.Application/Baya.Application.csproj                              src/Core/Baya.Application/
COPY src/Core/Baya.Domain/Baya.Domain.csproj                                        src/Core/Baya.Domain/
COPY src/Infrastructure/Baya.Infrastructure.CrossCutting/Baya.Infrastructure.CrossCutting.csproj   src/Infrastructure/Baya.Infrastructure.CrossCutting/
COPY src/Infrastructure/Baya.Infrastructure.Identity/Baya.Infrastructure.Identity.csproj           src/Infrastructure/Baya.Infrastructure.Identity/
COPY src/Infrastructure/Baya.Infrastructure.Monitoring/Baya.Infrastructure.Monitoring.csproj       src/Infrastructure/Baya.Infrastructure.Monitoring/
COPY src/Infrastructure/Baya.Infrastructure.Persistence/Baya.Infrastructure.Persistence.csproj     src/Infrastructure/Baya.Infrastructure.Persistence/
COPY src/Shared/Baya.SharedKernel/Baya.SharedKernel.csproj                          src/Shared/Baya.SharedKernel/

RUN dotnet restore src/API/Baya.Web.Api/Baya.Web.Api.csproj

COPY . .
RUN dotnet publish src/API/Baya.Web.Api/Baya.Web.Api.csproj \
    -c Release -o /app/publish /p:UseAppHost=false --no-restore

FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final
WORKDIR /app
COPY --from=build /app/publish .

# TLS is terminated by Caddy; the API speaks plain HTTP on the shared container network only.
ENV ASPNETCORE_URLS=http://+:8080
EXPOSE 8080

# Written to by the Serilog file sink (Development) and the local-disk object storage seam — both are
# bind-mounted in compose so an image rebuild doesn't discard uploaded verification documents.
RUN mkdir -p /app/logs /app/data/object-storage

ENTRYPOINT ["dotnet", "Baya.Web.Api.dll"]
