# Build context: repo root (includes GerbilManager.ServiceDefaults).
# docker build -f GerbilManagerWebAPI/Dockerfile -t gerbilmanager-api .

FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src

# Restore: project files only for layer-cache efficiency.
COPY GerbilManager.ServiceDefaults/GerbilManager.ServiceDefaults.csproj GerbilManager.ServiceDefaults/
COPY GerbilManagerWebAPI/GerbilManagerWebAPI.csproj GerbilManagerWebAPI/
RUN dotnet restore GerbilManagerWebAPI/GerbilManagerWebAPI.csproj

# Full source copy + publish.
COPY GerbilManager.ServiceDefaults/ GerbilManager.ServiceDefaults/
COPY GerbilManagerWebAPI/ GerbilManagerWebAPI/
WORKDIR /src/GerbilManagerWebAPI
RUN dotnet publish GerbilManagerWebAPI.csproj -c Release -o /app/publish /p:UseAppHost=false

FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final
WORKDIR /app
# curl für den Container-Healthcheck (das Basis-Image bringt weder curl noch wget mit;
# ohne dieses würde der compose-Healthcheck dauerhaft fehlschlagen und api nie "healthy").
RUN apt-get update \
    && apt-get install -y --no-install-recommends curl \
    && rm -rf /var/lib/apt/lists/*
# .NET 10 containers default to ASPNETCORE_HTTP_PORTS=8080 bound on all interfaces.
EXPOSE 8080
COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "GerbilManagerWebAPI.dll"]
