#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

# node version changelog: https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V14.md
# use local node image
ARG NODE_IMAGE=node:14.18.1

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 ["Aeroflot.Flights.Web/Aeroflot.Flights.Web.csproj", "Aeroflot.Flights.Web/"]
COPY ["Aeroflot.Flights.WebApi/Aeroflot.Flights.WebApi.csproj", "Aeroflot.Flights.WebApi/"]
COPY ["Aeroflot.Flights.BL/Aeroflot.Flights.BL.csproj", "Aeroflot.Flights.BL/"]
COPY ["Aeroflot.Common.ApiWrappers/Aeroflot.Common.ApiWrappers.csproj", "Aeroflot.Common.ApiWrappers/"]
COPY ["Aeroflot.Flights.Interfaces/Aeroflot.Flights.Interfaces.csproj", "Aeroflot.Flights.Interfaces/"]
COPY ["Aeroflot.Flights.Entities/Aeroflot.Flights.Entities.csproj", "Aeroflot.Flights.Entities/"]
COPY ["Aeroflot.Flights.DataSpace/Aeroflot.Flights.DataSpace.csproj", "Aeroflot.Flights.DataSpace/"]

RUN dotnet restore "./Aeroflot.Flights.Web/Aeroflot.Flights.Web.csproj"
COPY . .
WORKDIR "/src/Aeroflot.Flights.Web"
RUN dotnet build --no-restore "./Aeroflot.Flights.Web.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish --no-restore "./Aeroflot.Flights.Web.csproj" -c Release -o /app/publish /p:UseAppHost=false

## Build Angular files
FROM ${NODE_IMAGE} as node-build
WORKDIR /src
COPY Aeroflot.Flights.Web/ClientApp .

ARG NPM_PROXY
RUN npm config set registry $NPM_PROXY
RUN npm ci
RUN npm rebuild node-sass
RUN npm run build:prod
## ####

FROM base AS final
# add NTLM support for EWS mail sender
RUN apt-get update && apt-get install -y --no-install-recommends gss-ntlmssp && rm -rf /var/lib/apt/lists/*

WORKDIR /app
#copy .net published files
COPY --from=publish /app/publish .
#copy angular compiled files
COPY --from=node-build /src/dist ./ClientApp/dist
ENTRYPOINT ["dotnet", "Aeroflot.Flights.Web.dll"]