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

COPY ["ITS.Models/", "ITS.Models/"]
COPY ["ITS.Interfaces/", "ITS.Interfaces/"]
COPY ["ITS.Core/", "ITS.Core/"]
COPY ["ITS.SQL/", "ITS.SQL/"]
COPY ["ITS.Storage/", "ITS.Storage/"]
COPY ["ITS.Storage.Dapr/", "ITS.Storage.Dapr/"]
COPY ["ITS.Storage.Azure/", "ITS.Storage.Azure/"]
COPY ["ITS.Web.ReportApi/", "ITS.Web.ReportApi/"]


RUN dotnet restore "ITS.Core/ITS.Core.csproj"
RUN dotnet restore "ITS.Models/ITS.Models.csproj"
RUN dotnet restore "ITS.Interfaces/ITS.Interfaces.csproj"
RUN dotnet restore "ITS.SQL/ITS.SQL.csproj"
RUN dotnet restore "ITS.Storage/ITS.Storage.csproj"
RUN dotnet restore "ITS.Storage.Dapr/ITS.Storage.Dapr.csproj"
RUN dotnet restore "ITS.Storage.Azure/ITS.Storage.Azure.csproj"
RUN dotnet restore "ITS.Web.ReportApi/ITS.Web.ReportApi.csproj"

COPY . .

WORKDIR "/src/"
RUN dotnet restore "ITS.Core/ITS.Core.csproj"
RUN dotnet restore "ITS.Models/ITS.Models.csproj"
RUN dotnet restore "ITS.Interfaces/ITS.Interfaces.csproj"
RUN dotnet restore "ITS.SQL/ITS.SQL.csproj"
RUN dotnet restore "ITS.Storage/ITS.Storage.csproj"
RUN dotnet restore "ITS.Storage.Dapr/ITS.Storage.Dapr.csproj"
RUN dotnet restore "ITS.Storage.Azure/ITS.Storage.Azure.csproj"
RUN dotnet restore "ITS.Web.ReportApi/ITS.Web.ReportApi.csproj"

RUN dotnet build "ITS.Core/ITS.Core.csproj" -c Release -o /ITS.Web.ReportApi
RUN dotnet build "ITS.Models/ITS.Models.csproj" -c Release -o /ITS.Web.ReportApi
RUN dotnet build "ITS.Interfaces/ITS.Interfaces.csproj" -c Release -o /ITS.Web.ReportApi
RUN dotnet build "ITS.SQL/ITS.SQL.csproj" -c Release -o /ITS.Web.ReportApi
RUN dotnet build "ITS.Storage.Azure/ITS.Storage.Azure.csproj" -c Release -o /ITS.Web.ReportApi
RUN dotnet build "ITS.Storage/ITS.Storage.csproj" -c Release -o /ITS.Web.ReportApi
RUN dotnet build "ITS.Storage.Dapr/ITS.Storage.Dapr.csproj" -c Release -o /ITS.Web.ReportApi
RUN dotnet build "ITS.Web.ReportApi/ITS.Web.ReportApi.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "ITS.Web.ReportApi/ITS.Web.ReportApi.csproj" -c Release -o /app

FROM mcr.microsoft.com/dotnet/aspnet:6.0 as final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "ITS.Web.ReportApi.dll"]
