FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src

# Copy project file first to take advantage of Docker layer caching
COPY ["CharacterApi.csproj", "./"]
RUN dotnet restore "CharacterApi.csproj"

# Copy the remaining source and publish
COPY . .
RUN dotnet publish "CharacterApi.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
WORKDIR /app
COPY --from=build /app/publish .

ENV ASPNETCORE_URLS=http://+:8080 \
    ASPNETCORE_ENVIRONMENT=Production

EXPOSE 8080

ENTRYPOINT ["dotnet", "CharacterApi.dll"]
