【问题标题】:Microsoft Compiler in DockerDocker 中的 Microsoft 编译器
【发布时间】:2016-08-06 23:17:40
【问题描述】:

我想设置一个 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']

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

我的疑问是:

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

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

  3. 我该如何处理上述工具(编译器、签名工具、压缩工具都需要许可证才能运行)的许可

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

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

请提供您的意见(尝试考虑所有疑问)。

【问题讨论】:

    标签: c++ windows visual-studio docker dockerfile


    【解决方案1】:

    为了清楚起见,您需要 docker for Windows。

    我不是在谈论Docker for Mac and Windows Beta,它将在 Windows 上的 Hyper-V VM 上运行 Linux (Alpine) 主机:它不会运行任何 Windows 映像,仅运行 Linux 映像。

    我说的是 Docker for Windows(提供您的Windows10 has the latest Hyper-V feature)。直到最近,这只能在 Windows Server 2016 TP4 上实现。

    【讨论】:

      【解决方案2】:

      我假设您已经可以运行 Windows 容器,例如。 docker run -it microsoft/windowsservercore

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

      # 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" ]
      

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

      visualcppbuildtools_full.exe /Q /L <LogFile> /Full
      

      【讨论】:

        【解决方案3】:

        仅回答您的第一点:这里有一个文档,我用它作为 Docker 映像编译 Windows C++ 应用程序的起点: Install Build Tools into a Container

        我在 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"]
        

        【讨论】:

        • 这太酷了! visual c++ 2019有更新吗?
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-09-22
        • 1970-01-01
        • 2018-02-06
        • 2012-10-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多