# Build API
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
COPY ASTRAIN.Api/ASTRAIN.Api.csproj ASTRAIN.Api/
COPY ASTRAIN.Shared/ASTRAIN.Shared.csproj ASTRAIN.Shared/
RUN dotnet restore ASTRAIN.Api/ASTRAIN.Api.csproj
COPY ASTRAIN.Api/ ASTRAIN.Api/
COPY ASTRAIN.Shared/ ASTRAIN.Shared/
RUN dotnet publish ASTRAIN.Api/ASTRAIN.Api.csproj -c Release -o /app/publish

# Build Client
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build-client
WORKDIR /src
COPY ASTRAIN.Client/ASTRAIN.Client.csproj ASTRAIN.Client/
COPY ASTRAIN.Shared/ASTRAIN.Shared.csproj ASTRAIN.Shared/
RUN dotnet restore ASTRAIN.Client/ASTRAIN.Client.csproj
COPY ASTRAIN.Client/ ASTRAIN.Client/
COPY ASTRAIN.Shared/ ASTRAIN.Shared/
RUN dotnet publish ASTRAIN.Client/ASTRAIN.Client.csproj -c Release -o /app/client

# Final runtime
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime
WORKDIR /app
RUN mkdir -p /app/Data
COPY --from=build /app/publish/ ./
COPY --from=build-client /app/client/wwwroot ./wwwroot
ENV ASPNETCORE_URLS=http://+:8080
EXPOSE 8080
ENTRYPOINT ["dotnet", "ASTRAIN.Api.dll"]
