# Stage 1: Build the application using the .NET SDK image
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /app

# Copy the solution and projects to restore dependencies
COPY *.sln ./
COPY PollMeMaybe.Api/PollMeMaybe.Api.csproj PollMeMaybe.Api/
COPY PollMeMaybe.Application/PollMeMaybe.Application.csproj PollMeMaybe.Application/
COPY PollMeMaybe.Domain/PollMeMaybe.Domain.csproj PollMeMaybe.Domain/
COPY PollMeMaybe.Infrastructure/PollMeMaybe.Infrastructure.csproj PollMeMaybe.Infrastructure/
COPY PollMeMaybe.Startup/PollMeMaybe.Startup.csproj PollMeMaybe.Startup/
COPY PollMeMaybe.Tests/PollMeMaybe.Tests.csproj PollMeMaybe.Tests/

# Restore the dependencies
RUN dotnet restore

# Copy all files and publish the app in Release mode
COPY . .
RUN dotnet publish PollMeMaybe.Api/PollMeMaybe.Api.csproj -c Release -o /publish

# Stage 2: Create a minimal runtime image
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
WORKDIR /app

# Copy the published files from the build stage
COPY --from=build /publish .

# Entry point to run the application
ENTRYPOINT ["dotnet", "PollMeMaybe.Api.dll"]
