Docker中的Microsoft编译器

vin*_*jan 14 c++ windows visual-studio docker dockerfile

我想设置一个Docker容器,以支持完全用C++编写的代码库构建,并且生成的应用程序仅在Windows上运行.

为此,我需要设置一个容器来复制我们当前的构建环境以支持构建.

我需要创建一个像下面这样的Dockerfile来构建这样一个容器:

请将以下内容视为伪代码Dockerfile(忽略apt-get并考虑Windows中的任何其他实用程序以从命令行安装工具):

FROM: Windows10 // A base windows kernel 

RUN apt-get install -y VisualStudio // Installing the Visual Studio for compilation of C++ files

RUN apt-get install -y cygwin // Since I am using some cygwin utlities in build process

RUN apt-get install -y SigningTool // A tool I need to sign the exe

RUN apt-get install -y CompressionTool // A tool I need to compress the exe

RUN apt-get install -y BuildSystem // Custom in-house build system to generate the builds of the source code

CMD ['BuildSystem debug']
Run Code Online (Sandbox Code Playgroud)

注意:我们的组织中有一个自定义构建系统(而不是使用GNU Make)来执行构建.debug是提供给构建系统的目标,因为我想构建一个调试可执行文件.

我的怀疑是:

  1. 如何安装VisualStudio编译器(或在Windows上运行的任何其他编译器)

  2. 如何托管 SigningTool,CompressionTool和其他可执行文件(在Docker Trusted Registry上 ;是否可以在DTR上托管可执行文件)

  3. 我如何处理上述工具的许可(编译器,signingtool,compressiontool都需要运行许可证).

以上工作在我们的组织中完全没问题.但是设置机器的过程(安装和所有上述工具需要花费大量的时间和精力).因此,我想创建一个可以部署在裸机上的Docker镜像,它可以在很短的时间内完成整个构建环境的设置.

这样做的一个更重要的目的是采用持续交付方法.

请提供相同的输入(尽量考虑所有的疑虑).

Iva*_*van 7

我假设您已经可以运行Windows容器了. docker run -it microsoft/windowsservercore

这是我使用Chocolatey在Docker容器中安装Visual C++ Build Tools 2015的Dockerfile:

# escape=`

FROM microsoft/windowsservercore

# Install chocolatey
RUN @powershell -NoProfile -ExecutionPolicy unrestricted -Command "(iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))) >$null 2>&1"

# Install Visual C++ Build Tools, as per: https://chocolatey.org/packages/visualcpp-build-tools
RUN choco install visualcpp-build-tools -version 14.0.25420.1 -y

# Add msbuild to PATH
RUN setx /M PATH "%PATH%;C:\Program Files (x86)\MSBuild\14.0\bin"

# Test msbuild can be accessed without path
RUN msbuild -version

CMD [ "cmd.exe" ]
Run Code Online (Sandbox Code Playgroud)

使用Choco更简单,但您可以通过下载本机Web安装程序并以安静模式运行它来获得相同的结果,例如:

visualcppbuildtools_full.exe /Q /L <LogFile> /Full
Run Code Online (Sandbox Code Playgroud)


Cap*_*pet 6

仅回答您的第一点:这里有一个文档,我将其用作 Docker 映像编译 Windows C++ 应用程序的起点: 将构建工具安装到容器中

我在 Windows Server 2016 上运行 Docker 并编译一个针对 XP 的遗留应用程序。

我的最终Dockerfile看起来像这样:

# Use the latest Windows Server Core image.
FROM microsoft/windowsservercore

# Download the Visual Studio 2017 installer outside of the PATH.
# This is required for Windows SDK 7.1A (XP targetting)
ADD https://aka.ms/vs/15/release/vs_professional.exe C:\\TEMP\\vs_professional.exe

# Add C:\Bin to PATH and install Build Tools with components we need
RUN setx /m PATH "%PATH%;C:\Bin" \
&& C:\TEMP\vs_professional.exe --quiet --wait --norestart --nocache \
    --add Microsoft.VisualStudio.Component.Static.Analysis.Tools \
    --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 \
    --add Microsoft.VisualStudio.Component.VC.CMake.Project \
    --add Microsoft.VisualStudio.Component.VC.CoreBuildTools \
    --add Microsoft.VisualStudio.Component.VC.ATLMFC \
    --add Microsoft.VisualStudio.Component.VC.ATL \
    --add Microsoft.VisualStudio.Component.Windows10SDK.16299.Desktop \
    --add Microsoft.VisualStudio.Component.Windows10SDK.16299.UWP \
    --add Microsoft.VisualStudio.Component.Windows10SDK.16299.UWP.Native \
    --add Microsoft.VisualStudio.Component.Windows10SDK \
    --add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81 \
    --add Microsoft.VisualStudio.Component.VC.Redist.14.Latest \
    --add Microsoft.Component.VC.Runtime.UCRTSDK \
    --add Microsoft.VisualStudio.Component.WinXP \
|| IF "%ERRORLEVEL%"=="3010" EXIT 0

# Start developer command prompt with any other commands specified.
ENTRYPOINT "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat" &&

# Default to PowerShell if no other command specified.
CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]
Run Code Online (Sandbox Code Playgroud)


Von*_*onC 1

需要明确的是,为此您需要 Windows 版 docker。

我说的不是Mac 和 Windows Beta 版的 Docker,它将在 Windows 上的 Hyper-V VM 上运行Linux (Alpine) 主机:它不会运行任何 Windows 映像,只能运行 Linux 映像。

我说的是Windows版的Docker(前提是你的Windows10有最新的Hyper-V功能)。直到最近,这只能在Windows Server 2016 TP4上实现。