[英]Running “dotnet test” from within a mssql-server docker container
I have a dotnet build process running in docker based on the microsoft/dotnet-framework:4.7.2-sdk
image. 我有一个基于microsoft/dotnet-framework:4.7.2-sdk
映像在docker中运行的dotnet构建过程。
Restore, build and publish works as expected, but my integration tests require SQL Server to be installed on the machine. 还原,生成和发布的工作符合预期,但是我的集成测试要求在计算机上安装SQL Server。
I would like to use a multistage build to run the dotnet test
(or more specifically in my case dotnet xunit
) command within a container based on microsoft/mssql-server-windows-developer:2017-latest
. 我想使用多阶段构建在基于microsoft/mssql-server-windows-developer:2017-latest
的容器中运行dotnet test
(或更具体地,在我的情况下为dotnet xunit
)命令。
But doing that I no longer have access to the dotnet sdk. 但是这样做之后,我将无法再访问dotnet sdk。 How can I run dotnet test
from the second stage of my build. 从构建的第二阶段开始如何运行dotnet test
。
Some like this (not working, the last step fails, because the dotnet command is not recognized): 像这样的一些(不起作用,最后一步失败,因为未识别dotnet命令):
FROM microsoft/dotnet-framework:4.7.2-sdk AS build
WORKDIR /app
# # Copy csproj and restore as distinct layers
COPY ./*.sln ./NuGet.config ./
COPY ./libs ./libs
COPY ./src ./src
WORKDIR /app/src/Tests/
RUN dotnet build
FROM microsoft/mssql-server-windows-developer:2017-latest
WORKDIR /app/
COPY --from=build /app/src/Tests/ .
RUN dotnet xunit
After several unsuccessful attempts of trying to install the dotnet build tools and prerequisites for running the tests on the 'microsoft/mssql-server-windows-developer' image, I found that installing Sql Server on the `microsoft/dotnet-framework:4.7.2-sdk' image was probably easier. 在尝试尝试安装dotnet生成工具并在“ microsoft / mssql-server-windows-developer”映像上运行测试的前提条件进行了几次失败尝试之后,我发现在“ microsoft / dotnet-framework:4.7”上安装了Sql Server。 2 SDK的图像可能更容易。 A lot easier actually. 实际上要容易得多。
Though I followed this guide https://github.com/MicrosoftDocs/visualstudio-docs/blob/master/docs/install/build-tools-container.md is ran in to all kinds of trouble actually running the tests. 尽管我遵循了本指南,但https://github.com/MicrosoftDocs/visualstudio-docs/blob/master/docs/install/build-tools-container.md实际在运行测试时会遇到各种麻烦。
But the other way around works. 但是反之亦然。 Build takes some time, but it works. 构建需要一些时间,但可以。 The start of my Dockerfile is: 我的Dockerfile的开头是:
# The 'docker build' command must be run with '-m 4g' argument for sql server.
FROM microsoft/dotnet-framework:4.7.2-sdk
SHELL [ "powershell.exe", "-Command" ]
RUN curl.exe -L -o sql.box https://go.microsoft.com/fwlink/?linkid=840944
RUN curl.exe -L -o sql.exe https://go.microsoft.com/fwlink/?linkid=840945
RUN Start-Process -Wait -FilePath .\sql.exe -ArgumentList /qs, /x:setup
RUN .\setup\setup.exe /q /ACTION=Install /INSTANCENAME=MSSQLSERVER /FEATURES=SQLEngine /UPDATEENABLED=0 /SQLSVCACCOUNT='NT AUTHORITY\System' /SQLSYSADMINACCOUNTS='BUILTIN\ADMINISTRATORS' /TCPENABLED=1 /NPENABLED=0 /IACCEPTSQLSERVERLICENSETERMS
ENV MSSQL_IS_RUNNING_IN_DOCKER true
The rest is just standard copy/dotnet build/dotnet test stuff. 剩下的只是标准的复制/ dotnet构建/ dotnet测试内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.