# Back end (Linux container): ASP.NET Core API on port 8080
# Stage 1: restore and publish with the full SDK
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
COPY TasksApi.csproj .
RUN dotnet restore
COPY . .
RUN dotnet publish -c Release -o /out --no-restore

# Stage 2: only the ASP.NET Core runtime and the published app
FROM mcr.microsoft.com/dotnet/aspnet:10.0
WORKDIR /app
ENV DATA_DIR=/data
# The volume is mounted at /data; the image's non-root "app" user must be able to write there
RUN mkdir -p /data && chown "$APP_UID" /data
COPY --from=build /out .
USER $APP_UID
EXPOSE 8080
HEALTHCHECK --interval=15s --timeout=5s --start-period=10s --retries=3 CMD ["dotnet", "TasksApi.dll", "--health"]
ENTRYPOINT ["dotnet", "TasksApi.dll"]
