FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
WORKDIR /app
EXPOSE 8080

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

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

COPY . .
WORKDIR "/src/src/Nalu.Web"
RUN dotnet publish "Nalu.Web.csproj" -c Release -o /app/publish \
    --self-contained false \
    /p:UseAppHost=false

FROM base AS final
RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=build /app/publish .
COPY docker-entrypoint.sh /app/docker-entrypoint.sh
RUN chmod +x /app/docker-entrypoint.sh

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

ENTRYPOINT ["/app/docker-entrypoint.sh"]
