# ui build
FROM node:10.16.3-alpine as ui-build

# set up working directory
RUN mkdir -p /app
WORKDIR /app

# copy dependency manifests
ADD package.json ./package.json
ADD yarn.lock ./yarn.lock
ADD .npmrc ./.npmrc

# install dependencies
RUN yarn

# add the rest of the app
ADD . .

# compile the app
RUN yarn compile:prod



# server build
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS server-build
WORKDIR /app

# copy csproj
COPY *.csproj ./

# install dependencies
RUN dotnet restore

# copy in the server files
COPY ./Views ./Views
COPY ./Properties ./Properties
COPY ./*.cs ./

# copy in the compiled index.html file
COPY --from=ui-build /app/dist/index.html ./Views/Home/Index.cshtml

# compile the server
RUN dotnet publish -c Release -o out

# server runtime
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
WORKDIR /app

# copy in the compiled server
COPY --from=server-build /app/out .

# copy in the compiled ui
COPY --from=ui-build /app/dist ./dist

# launch the compiled server
ENTRYPOINT ["dotnet", "GrantsConnect.UI.dll"]
EXPOSE 80
