# Build stage: restore + publish the .NET 8 Web API
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS api-build
WORKDIR /src

# Restore first (better layer caching) using only the project file
COPY UatRelease.Api/UatRelease.Api.csproj UatRelease.Api/
RUN dotnet restore UatRelease.Api/UatRelease.Api.csproj

# Copy the rest of the API source and publish
COPY UatRelease.Api/ UatRelease.Api/
RUN dotnet publish UatRelease.Api/UatRelease.Api.csproj -c Release -o /app/publish --no-restore

# Runtime stage
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=api-build /app/publish .
ENV ASPNETCORE_URLS=http://+:8080
EXPOSE 8080
ENTRYPOINT ["dotnet", "UatRelease.Api.dll"]
