-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
55 lines (47 loc) · 2.97 KB
/
Dockerfile
File metadata and controls
55 lines (47 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# escape=`
FROM mcr.microsoft.com/windows/servercore:ltsc2022
# Set Chef version as build argument with default value
ARG CHEF_VERSION=18.8.11
ARG INSTALL_DUMPBIN=False
ENV INSTALL_DUMPBIN=${INSTALL_DUMPBIN}
# Set up PowerShell execution policy
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
# Conditionally install Visual Studio Build Tools for dumpbin
RUN if ($env:INSTALL_DUMPBIN -eq 'True') { `
Write-Host 'Installing Visual Studio Build Tools for dumpbin...'; `
Write-Host 'Downloading installer...'; `
Invoke-WebRequest -Uri 'https://aka.ms/vs/17/release/vs_buildtools.exe' -OutFile 'vs_buildtools.exe'; `
Write-Host 'Running VS Build Tools installer (this will take several minutes)...'; `
$process = Start-Process vs_buildtools.exe -ArgumentList '--quiet', '--wait', '--norestart', '--nocache', '--installPath', \"${env:ProgramFiles(x86)}\Microsoft Visual Studio\2022\BuildTools\", '--add', 'Microsoft.VisualStudio.Workload.VCTools', '--includeRecommended' -Wait -PassThru; `
Write-Host \"Installer exit code: $($process.ExitCode)\"; `
Remove-Item vs_buildtools.exe -Force -ErrorAction SilentlyContinue; `
Write-Host 'Attempting to add dumpbin to PATH if it was installed...'; `
$vsPath = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC'; `
if (Test-Path $vsPath) { `
$msvcVersion = (Get-ChildItem $vsPath | Sort-Object Name -Descending | Select-Object -First 1).Name; `
$dumpbinPath = Join-Path (Join-Path (Join-Path $vsPath $msvcVersion) 'bin\Hostx64') 'x64'; `
[Environment]::SetEnvironmentVariable('PATH', $env:PATH + ';' + $dumpbinPath, [EnvironmentVariableTarget]::Machine); `
Write-Host \"Added dumpbin to PATH: $dumpbinPath\"; `
} else { `
Write-Host 'VS Build Tools directory not found - dumpbin may not be available'; `
} `
} else { `
Write-Host 'Skipping Visual Studio Build Tools installation (INSTALL_DUMPBIN=False)'; `
}
# Install Chef via Omnitruck
RUN Write-Host \"Installing Chef version $env:CHEF_VERSION...\"; `
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; `
$script = (New-Object System.Net.WebClient).DownloadString('https://omnitruck.chef.io/install.ps1'); `
$script = $script -replace '^\[Console\]::OutputEncoding.*$', '' -replace 'New-Object -typename System.Text.ASCIIEncoding', 'New-Object -typename System.Text.UTF8Encoding'; `
Invoke-Expression $script; `
Install-Project -project chef -version $env:CHEF_VERSION -channel stable
# Accept Chef license
ENV CHEF_LICENSE=accept-silent
# Create directories for Chef
RUN New-Item -ItemType Directory -Force -Path C:\chef; `
New-Item -ItemType Directory -Force -Path C:\cookbooks; `
New-Item -ItemType Directory -Force -Path C:\shared
# Set working directory
WORKDIR C:\chef
# Default command
CMD ["powershell"]