FROM mcr.microsoft.com/dotnet/aspnet:7.0.1-bullseye-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false

FROM mcr.microsoft.com/dotnet/sdk:7.0.101-bullseye-slim AS build

RUN mkdir -p /usr/share/man/man1/
RUN apt-get update && apt-get install default-jre dos2unix -y && \
apt-get install -yq --no-install-recommends \ 
xvfb libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \ 
libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \ 
libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 \ 
libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 \ 
libnss3 libegl1 libgles2  libssl1.0-dev libx11-xcb-dev libxcb-icccm4-dev libxcb-image0-dev \
libxcb-keysyms1-dev libxcb-randr0-dev libxcb-render-util0-dev libxcb-render0-dev libxcb-shm0-dev \
libxcb-util0-dev libxcb-xfixes0-dev libxcb-xkb-dev libxcb1-dev libxfixes-dev libxrandr-dev libxrender-dev

RUN apt-get update -y && apt-get install libfontconfig -y
RUN echo "deb http://httpredir.debian.org/debian buster main contrib non-free" > /etc/apt/sources.list \ 
    && echo "deb http://httpredir.debian.org/debian buster-updates main contrib non- free" >> /etc/apt/sources.list \
    && echo "deb http://security.debian.org/ buster/updates main contrib non-free" >> /etc/apt/sources.list \
    && echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections \
    && apt-get update \
    && apt-get install -y \
        fonts-arphic-ukai \
        fonts-arphic-uming \
        fonts-ipafont-mincho \
        fonts-ipafont-gothic \
        fonts-unfonts-core \
        ttf-wqy-zenhei \
        ttf-mscorefonts-installer \
    && apt-get clean \
    && apt-get autoremove -y \
    && rm -rf /var/lib/apt/lists/*

ENV LANG="en_US.UTF-8" 
ENV PATH="$PATH:/root/.dotnet/tools"
ENV DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0

ENV NUGET_PLUGIN_HANDSHAKE_TIMEOUT_IN_SECONDS=30
ENV NUGET_PLUGIN_REQUEST_TIMEOUT_IN_SECONDS=30 

WORKDIR /src
COPY ["src/ExploreSyncFusion/ExploreSyncFusion.csproj", "src/ExploreSyncFusion/"]
COPY ["src/ExploreSyncFusion.Contracts/ExploreSyncFusion.Contracts.csproj", "src/ExploreSyncFusion.Contracts/"]
RUN dotnet restore "src/ExploreSyncFusion/ExploreSyncFusion.csproj"
COPY . .
WORKDIR "src/ExploreSyncFusion"
RUN dotnet build "ExploreSyncFusion.csproj" -c Release -o /app/build

FROM build AS test
WORKDIR /src

FROM test AS publish
WORKDIR "/src/src/ExploreSyncFusion.Pdf"
RUN dotnet publish "ExploreSyncFusion.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .

ENTRYPOINT ["dotnet", "ExploreSyncFusion.dll"]