繁体   English   中英

从mssql-server docker容器中运行“ dotnet测试”

[英]Running “dotnet test” from within a mssql-server docker container

我有一个基于microsoft/dotnet-framework:4.7.2-sdk映像在docker中运行的dotnet构建过程。

还原,生成和发布的工作符合预期,但是我的集成测试要求在计算机上安装SQL Server。

我想使用多阶段构建在基于microsoft/mssql-server-windows-developer:2017-latest的容器中运行dotnet test (或更具体地,在我的情况下为dotnet xunit )命令。

但是这样做之后,我将无法再访问dotnet sdk。 从构建的第二阶段开始如何运行dotnet test

像这样的一些(不起作用,最后一步失败,因为未识别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

在尝试尝试安装dotnet生成工具并在“ microsoft / mssql-server-windows-developer”映像上运行测试的前提条件进行了几次失败尝试之后,我发现在“ microsoft / dotnet-framework:4.7”上安装了Sql Server。 2 SDK的图像可能更容易。 实际上要容易得多。

尽管我遵循了本指南,但https://github.com/MicrosoftDocs/visualstudio-docs/blob/master/docs/install/build-tools-container.md实际在运行测试时会遇到各种麻烦。

但是反之亦然。 构建需要一些时间,但可以。 我的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

剩下的只是标准的复制/ dotnet构建/ dotnet测试内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM