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

COPY ["src/Ikar.Server/Ikar.Server.csproj", "src/Ikar.Server/"]
COPY ["src/Ikar.Shared/Ikar.Shared.csproj", "src/Ikar.Shared/"]
RUN dotnet restore "src/Ikar.Server/Ikar.Server.csproj"

COPY . .
RUN dotnet publish "src/Ikar.Server/Ikar.Server.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime
RUN apt-get update \
    && apt-get install -y --no-install-recommends curl \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app
ENV ASPNETCORE_ENVIRONMENT=Production
ENV ASPNETCORE_URLS=http://+:5099

COPY --from=build /app/publish .

EXPOSE 5099

HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
    CMD curl --fail http://127.0.0.1:5099/health || exit 1

ENTRYPOINT ["dotnet", "Ikar.Server.dll"]
