簡體   English   中英

Docker中的Microsoft編譯器

[英]Microsoft Compiler in Docker

我想設置一個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. 我如何處理上述工具的許可 (編譯器,signingtool,compressiontool都需要運行許可證)。

以上工作在我們的組織中完全沒問題。 但是設置機器的過程(安裝和所有上述工具需要花費大量的時間和精力)。 因此,我想創建一個可以部署在裸機上的Docker鏡像,它可以在很短的時間內完成整個構建環境的設置。

這樣做的一個更重要的目的是采用持續交付方法。

請提供相同的輸入(盡量考慮所有的疑慮)。

我假設您已經可以運行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" ]

使用Choco更簡單,但您可以通過下載本機Web安裝程序並以安靜模式運行它來獲得相同的結果,例如:

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

僅回答您的第一點:這里有一個文檔,我用作Docker鏡像編譯Windows C ++應用程序的起點: 將Build Tools安裝到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"]

為了清楚起見,你需要Windows for docker。

我不是在談論Docker for Mac和Windows Beta ,它將在Windows上的Hyper-V VM上運行Linux (Alpine)主機:它不能運行任何Windows映像,只能運行Linux映像。

我在談論Docker for Windows(假設您的Windows10具有最新的Hyper-V功能 )。 直到最近,這只能在Windows Server 2016 TP4上實現

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM