microsoft/Windows-Containers

Can't install buidltools2019 with chocolatey inside container

snpefk opened this issue · 4 comments

Describe the bug

I'm trying to bootstrap LLVM 16 inside Windows container. To do this I need install buildtools 2019. The vs_buildtools.exe utility doesn't work reliably and sometime fails silently without installing anything that leads to broken builds run in runtime. So, I'm trying to use Chocolatey package manager to install Visual Studio 2019 Build Tools 16.11.35.0 package. Installation fails inside Docker container with if you read the comments on the package page, but work successfully if I tried to run on host system (I'm not the only one experience problem, if you read the comments on the package page)

To Reproduce
Here is my Dockerfile

# escape=`

FROM mcr.microsoft.com/windows/servercore:ltsc2019

# Workaround to build image
# See. https://stackoverflow.com/questions/76470752/chocolatey-installation-in-docker-started-to-fail-restart-due-to-net-framework
ENV chocolateyVersion=1.4.0

# Set the shell to PowerShell
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

# Install Chocolatey - a package manager for Windows
RUN Set-ExecutionPolicy Bypass -Scope Process -Force;  `
    [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;  `
    iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'));

# Install build dependencies using Chocolatey
RUN choco install cmake --installargs 'ADD_CMAKE_TO_PATH=User' -y; `
    choco install ninja -y; `
    choco install git -y; `
    choco install python3 --version=3.12.0 -y; `
    # ⬇️ this line leads to broken Docker builds 
    choco install visualstudio2019buildtools --allWorkloads --includeRecommended --includeOptional --passive; 

Expected behavior
Dockerfile successfully builds

Configuration:

  • Edition: [e.g. Windows 11, Windows Server]
  • Base Image being used: Windows Server Core
  • Container engine: docker
  • Container Engine version 24

Hi, @snpefk are you seeing a specific error?

Can you also confirm if you see this issue with Windows Server 2022? We currently do not fix OS issues for WS 2019 since we're past mainstream support (https://learn.microsoft.com/en-us/lifecycle/products/windows-server-2019).

Hi,

We no longer support Windows Server 2019 but LLVM 16 is compatible with Windows Server 2022. I simulated your Dockerfile with the more recent versions and it installed Visual Studio 2022 Build Tools successfully. Here's the updated Dockerfile:

# escape=`

FROM mcr.microsoft.com/windows/servercore:ltsc2022

# Workaround to build image
# See. https://stackoverflow.com/questions/76470752/chocolatey-installation-in-docker-started-to-fail-restart-due-to-net-framework
ENV chocolateyVersion=2.2.2

# Set the shell to PowerShell
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

# Install Chocolatey - a package manager for Windows
RUN Set-ExecutionPolicy Bypass -Scope Process -Force;  `
    [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;  `
    iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'));

# Install build dependencies using Chocolatey
RUN choco install cmake --installargs 'ADD_CMAKE_TO_PATH=User' -y; `
    choco install ninja -y; `
    choco install git -y; `
    choco install python3 --version=3.12.0 -y; `
    # ⬇️ Add yes flag so agrees to installation automatically
    choco install visualstudio2022buildtools --allWorkloads --includeRecommended --includeOptional --passive -y; 

I started up the container and confirmed that Visual Studio 2022 Build Tools was installed by doing the following:

$> & 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe' -version

@snpefk Let me know if something wasn't installed in the container properly. Otherwise, I'll close this Issue for now as everything works with '22.

Hi,

Thanks for your effort. I will check how building on ltsc2022 and with added flag works and report back.