# Base image for runtime
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
USER app
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

# Build stage for ASP.NET Core
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["YatzyGame/YatzyGame.csproj", "YatzyGame/"]
COPY ["YatzyLibrary/YatzyLibrary.csproj", "YatzyLibrary/"]
RUN dotnet restore "YatzyGame/YatzyGame.csproj"
COPY . .
WORKDIR "/src/YatzyGame"
RUN dotnet build "YatzyGame.csproj" -c $BUILD_CONFIGURATION -o /app/build

# Publish ASP.NET Core app
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "YatzyGame.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# Final runtime stage
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "YatzyGame.dll"]
