I have following dockerfile which runs my tests:
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
COPY ./ ./
RUN dotnet restore ./mysln.sln -r linux-x64
RUN dotnet build ./tests/mytests/mytests.csproj
ENTRYPOINT ["dotnet", "test", "./tests/mytests/mytests.csproj", "--no-build"]
I'd like to split build and test step, so I don't have entire codebase with obj/bin files in my image (which is executed later, and can be executed multiple times, so there is no reason to build it each time).
For instance:
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
COPY ./ ./
RUN dotnet restore ./mysln.sln -r linux-x64
RUN dotnet build ./tests/mytests/mytests.csproj
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS tests
COPY --from=build ./tests/mytests/ ./tests/mytests/
ENTRYPOINT ["dotnet", "test", "./tests/mytests/mytests.csproj", "--no-build"]
However this does not work for some reason, dotnet test does nothing (no error reported, no std out) - just quits, even though it's running in target image.