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

COPY ["src/MaddoScientisto.Web/MaddoScientisto.Web.csproj", "src/MaddoScientisto.Web/"]
RUN dotnet restore "src/MaddoScientisto.Web/MaddoScientisto.Web.csproj"

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

FROM nginx:1.27-alpine AS runtime
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/publish/wwwroot /usr/share/nginx/html

EXPOSE 80

HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
  CMD wget -qO- http://127.0.0.1/ >/dev/null 2>&1 || exit 1

CMD ["nginx", "-g", "daemon off;"]
