0

I am trying to create a Windows Container which includes C++ compilers and libraries to build our software in GitLab.

This is my Dockerfile to create the windows-build-base container:

# escape=`
# based on https://learn.microsoft.com/de-de/visualstudio/install/build-tools-container?view=vs-2022
FROM mcr.microsoft.com/windows/servercore:ltsc2022

SHELL ["cmd", "/S", "/C"]

USER ContainerAdministrator

RUN `
    curl -SL --output vs_buildtools.exe https://aka.ms/vs/15/release/vs_buildtools.exe `
    `
    && (start /w vs_buildtools.exe --quiet --wait --norestart --nocache `
        --installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\BuildTools" `
        --add Microsoft.VisualStudio.Component.Roslyn.Compiler `
        --add Microsoft.Component.MSBuild `
        --add Microsoft.VisualStudio.Component.CoreBuildTools `
        --add Microsoft.VisualStudio.Workload.MSBuildTools `
        --add Microsoft.VisualStudio.Component.Windows10SDK `
        --add Microsoft.VisualStudio.Component.VC.CoreBuildTools `
        --add Microsoft.VisualStudio.Component.Static.Analysis.Tools `
        --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 `
        --add Microsoft.VisualStudio.Component.VC.Redist.14.Latest `
        --add Microsoft.VisualStudio.Component.Windows10SDK.17763 `
        --add Microsoft.VisualStudio.Component.VC.CMake.Project `
        --add Microsoft.VisualStudio.Component.TestTools.BuildTools `
        --add Microsoft.VisualStudio.Component.VC.ATL `
        --add Microsoft.VisualStudio.Component.VC.ATLMFC `
        --add Microsoft.Net.Component.4.6.1.SDK `
        --add Microsoft.Net.Component.4.6.1.TargetingPack `
        --add Microsoft.VisualStudio.Component.VC.CLI.Support `
        --add Microsoft.VisualStudio.Workload.VCTools `
        || IF "%ERRORLEVEL%"=="3010" EXIT 0) `
    `
    && del /q vs_buildtools.exe

RUN tree /f C:\BuildTools

RUN `
    curl -SL --output git.exe "https://github.com/git-for-windows/git/releases/download/v2.41.0.windows.3/Git-2.41.0.3-64-bit.exe" `
    && (start /w git.exe /SP- /VERYSILENT /NORESTART /NOCANCEL /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS) `
    && del /q git.exe

RUN setx /M PATH "%PATH%;C:\Program Files\Git\bin"

USER ContainerUser

ENTRYPOINT ["C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\Common7\\Tools\\VsDevCmd.bat", "&&", "powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]

As mentioned in this Dockerfile I used https://learn.microsoft.com/de-de/visualstudio/install/build-tools-container?view=vs-2022 as the example but took VS2017 instead.

My GitLab job looks like this:

build:
  image: registry.my.company.com/windows-build-base:1.0
  stage: build
  tags:
    - windows-agent
  variables:
    BZ2_SRC_DIR: C:\bin\src\bzip2
  script:
    - git clone --branch=$BZ2_VERSION git://sourceware.org/git/bzip2.git $BZ2_SRC_DIR
    - cd $BZ2_SRC_DIR
    - nmake -f makefile.msc

But it is not able to find nmake. I added some debug outputs to verify its existence. nmake is available, but the entrypoint does not seem to work. Calling VsDevCmd.bat directly in the GitLab pipeline does not work either.

How do I add the VS vars without spawning a new shell and making it available in my GitLab job script?

Apollo
  • 1,296
  • 2
  • 11
  • 24
  • 1
    Hi @Apollo ! Have you found a solution? Getting the same error, would appreciate any advice – Marisol Aug 08 '23 at 07:47
  • 1
    @Marisol yes, kind of. I run "env" on my pc, saved all env vars, started the x64 native command prompt, saved the output of "env" and diff the diff. Then I set those env vars in my Dockerfile, see: https://gist.github.com/cwansart/b6eac818fc8f9c8467fb62a4cd9b124a – Apollo Aug 08 '23 at 10:02
  • 1
    @Marisol I suspect that the gitlab runner has some configuration hat overrides the entrypoint and always calls powershell.exe. Our admin is on vacation so I wasn't able to ask they. – Apollo Aug 08 '23 at 10:03
  • In my case nmake.exe location simply wasn't included in the path environment variable – Marisol Aug 08 '23 at 16:04
  • @Marisol yes, that was my issue too. That is why I added the paths manually. – Apollo Aug 09 '23 at 06:49

0 Answers0