# Use the official .NET 8 SDK image to build the app
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src

# Copy csproj and restore as distinct layers
COPY *.sln ./
COPY WmsEventDispatcher.Worker/*.csproj WmsEventDispatcher.Worker/
COPY WmsEventDispatcher.Api/*.csproj WmsEventDispatcher.Api/
COPY WmsEventDispatcher.Application/*.csproj WmsEventDispatcher.Application/
COPY WmsEventDispatcher.Infrastructure/*.csproj WmsEventDispatcher.Infrastructure/
COPY WmsEventDispatcher.Domain/*.csproj WmsEventDispatcher.Domain/
COPY WmsEventDispatcher.Interfaces/*.csproj WmsEventDispatcher.Interfaces/
COPY WmsEventDispatcher.SharedKernel/*.csproj WmsEventDispatcher.SharedKernel/
COPY WmsEventDispatcher.UnitTests/*.csproj WmsEventDispatcher.UnitTests/
COPY WmsEventDispatcher.IntegrationTests/*.csproj WmsEventDispatcher.IntegrationTests/
RUN dotnet restore

# Copy everything else and build
COPY . .
WORKDIR /src/WmsEventDispatcher.Worker
RUN dotnet publish -c Debug -o /app/publish

# Use the official .NET 8 runtime image for the final container
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
WORKDIR /app
COPY --from=build /app/publish .
EXPOSE 80
ENV ASPNETCORE_URLS=http://+:80
ENTRYPOINT ["dotnet", "WmsEventDispatcher.Worker.dll"]