FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build
WORKDIR /source

RUN mkdir Lib
RUN mkdir Greeter
RUN mkdir GreeterLib
RUN mkdir Harness
RUN mkdir Protos
RUN mkdir Client

# copy csproj and restore as distinct layers
COPY Lib/Lib.fsproj Lib/
COPY GreeterLib/GreeterLib.fsproj GreeterLib/
COPY Greeter/Greeter.fsproj Greeter/
COPY Harness/Harness.fsproj Harness/
COPY Client/Client.fsproj Client/
COPY Protos/Protos.csproj Protos/
COPY Test/Test.fsproj Test/
COPY Greeter.sln .
RUN dotnet restore Greeter.sln

# copy and publish app and libraries
COPY . .
# If I use --self-contained false then I don't
# get an exe. Don't understand why.
# And the dotnet restore above doesn't seem to
# restore everything, so --no-restore here fails.
# Also don't understand why.
RUN dotnet publish -r linux-x64 -c release -o /app

# final stage/image
FROM mcr.microsoft.com/dotnet/core/runtime:2.1
WORKDIR /app
COPY --from=build /app .

ENTRYPOINT ["./Greeter", "--forever"]

