FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

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

COPY ["BMA.EHR.Domain/BMA.EHR.Domain.csproj", "BMA.EHR.Domain/"]
COPY ["BMA.EHR.Application/BMA.EHR.Application.csproj", "BMA.EHR.Application/"]
COPY ["BMA.EHR.Infrastructure/BMA.EHR.Infrastructure.csproj", "BMA.EHR.Infrastructure/"]
COPY ["BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj", "BMA.EHR.Report.Service/"]

COPY ./BMA.EHR.Report.Service/Components ./BMA.EHR.Report.Service/Components
COPY ./BMA.EHR.Report.Service/nuget.config ./BMA.EHR.Report.Service/

RUN dotnet restore "BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj"
COPY . .
WORKDIR "/src/BMA.EHR.Report.Service"
RUN dotnet build "BMA.EHR.Report.Service.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "BMA.EHR.Report.Service.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final

RUN apt-get update && apt-get -y install fontconfig && apt-get install -y --allow-unauthenticated libgdiplus libc6-dev libx11-dev && rm -rf /var/lib/apt/lists/*
COPY ./BMA.EHR.Report.Service/Fonts/THSarabunIT.ttf /usr/share/fonts/truetype/
COPY ./BMA.EHR.Report.Service/Fonts/THSarabunITBold.ttf /usr/share/fonts/truetype/
COPY ./BMA.EHR.Report.Service/Fonts/THSarabunITItalic.ttf /usr/share/fonts/truetype/
COPY ./BMA.EHR.Report.Service/Fonts/THSarabunITBoldItalic.ttf /usr/share/fonts/truetype/
COPY ./BMA.EHR.Report.Service/Fonts/THSarabunNew.ttf /usr/share/fonts/truetype/
COPY ./BMA.EHR.Report.Service/Fonts/THSarabunNewBold.ttf /usr/share/fonts/truetype/
COPY ./BMA.EHR.Report.Service/Fonts/THSarabunNewItalic.ttf /usr/share/fonts/truetype/
COPY ./BMA.EHR.Report.Service/Fonts/THSarabunNewBoldItalic.ttf /usr/share/fonts/truetype/

COPY ./BMA.EHR.Report.Service/Fonts/THSarabun.ttf /usr/share/fonts/truetype/
COPY ./BMA.EHR.Report.Service/Fonts/THSarabunBold.ttf /usr/share/fonts/truetype/
COPY ./BMA.EHR.Report.Service/Fonts/THSarabunItalic.ttf /usr/share/fonts/truetype/
COPY ./BMA.EHR.Report.Service/Fonts/THSarabunBoldItalic.ttf /usr/share/fonts/truetype/
RUN fc-cache -f -v

WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "BMA.EHR.Report.Service.dll"]