#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-bionic AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-bionic AS build
WORKDIR /src

COPY ["squirrowse.web/squirrowse.web.csproj", "squirrowse.web/"]
COPY ["squirrowse.core/squirrowse.core.csproj", "squirrowse.core/"]
COPY ["squirrowse.db/squirrowse.db.csproj", "squirrowse.db/"]
COPY ["squirrowse.web/NuGet.Config", "squirrowse.core/"]
COPY ["squirrowse.web/NuGet.Config", "squirrowse.web/"]
COPY ["squirrowse.web/NuGet.Config", "squirrowse.db/"]
COPY . .
RUN dotnet restore "squirrowse.web/squirrowse.web.csproj" --configfile ./NuGet.Config

WORKDIR "/src/squirrowse.web"
RUN dotnet build "squirrowse.web.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "squirrowse.web.csproj" -c Release -o /app/publish

FROM base AS final
RUN apt-get update
RUN apt-get install -y libgtk2.0-dev
RUN apt-get -y update
RUN apt-get -y install wget unzip build-essential checkinstall cmake pkg-config yasm git gfortran libjpeg8-dev libpng-dev software-properties-common
RUN add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
RUN apt-get -y update && apt -y install libjasper1 libtiff-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine2-dev libv4l-dev
RUN apt-get -y install libgtk2.0-dev libtbb-dev libatlas-base-dev libvorbis-dev libxvidcore-dev libopencore-amrnb-dev libopencore-amrwb-dev libavresample-dev x264 v4l-utils libwebp-dev tesseract-ocr libtesseract-dev libleptonica-dev

WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "squirrowse.web.dll"]