ARG LOCAL_REGISTRY=127.0.0.1:5001
FROM ${LOCAL_REGISTRY}/mirror/dotnet-sdk:8.0 AS build
WORKDIR /src

COPY food-market.sln global.json Directory.Build.props Directory.Packages.props ./
COPY src/food-market.domain/food-market.domain.csproj src/food-market.domain/
COPY src/food-market.shared/food-market.shared.csproj src/food-market.shared/
COPY src/food-market.application/food-market.application.csproj src/food-market.application/
COPY src/food-market.infrastructure/food-market.infrastructure.csproj src/food-market.infrastructure/
COPY src/food-market.api/food-market.api.csproj src/food-market.api/
COPY src/food-market.pos.core/food-market.pos.core.csproj src/food-market.pos.core/
COPY src/food-market.pos/food-market.pos.csproj src/food-market.pos/

COPY src/ src/
# Single-step restore + publish — раздельные шаги в multi-stage cache
# роняли publish с NETSDK1064 (Microsoft.CodeAnalysis.Analyzers 3.3.3 not
# found) когда в csproj добавлялись новые transitive analyzer-зависимости,
# а первый restore не покрывал их. Теперь restore выполняется внутри publish.
RUN dotnet publish src/food-market.api/food-market.api.csproj -c Release -o /app

FROM ${LOCAL_REGISTRY}/mirror/dotnet-aspnet:8.0 AS runtime
WORKDIR /app

RUN apt-get update && apt-get install -y --no-install-recommends curl \
    && rm -rf /var/lib/apt/lists/*

COPY --from=build /app .

ENV ASPNETCORE_URLS=http://+:8080
ENV ASPNETCORE_ENVIRONMENT=Production
ENV DOTNET_NOLOGO=1
ENV DOTNET_CLI_TELEMETRY_OPTOUT=1

EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s \
  CMD curl -fsS http://localhost:8080/health || exit 1

ENTRYPOINT ["dotnet", "foodmarket.Api.dll"]
