Skip to content

tpowell-progress/compare-chef-on-windows

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chef Version Testing with Windows Docker Containers

This project sets up Windows Docker containers with Windows Server Core 2022 and tests different Chef versions (18.8.11 vs 18.8.46) by installing them via Omnitruck and running a test recipe.

Prerequisites

  • Windows 10/11 or Windows Server with Docker Desktop installed
  • Docker configured for Windows containers
  • PowerShell 5.1 or later

Project Structure

.
+-- Dockerfile                          # Windows Server Core 2022 with Chef installation
+-- docker-compose.yml                  # Multi-container setup for both Chef versions
+-- run-test.ps1                        # Main test script
+-- cookbooks/
    +-- test_recipe/
        +-- metadata.rb                 # Recipe metadata
        +-- recipes/
            +-- default.rb              # Test recipe that outputs Chef version
+-- shared/                             # Mounted volume for output files
    +-- chef-{version}.txt              # Generated by containers

Quick Start

Option 1: Using the PowerShell Script (Recommended)

Test Two Versions (Default)

Run the main test script with default versions:

.\run-test.ps1

Or specify custom Chef versions:

.\run-test.ps1 -ChefVersion1 "18.8.11" -ChefVersion2 "18.8.46"

Test a Single Version

.\run-test.ps1 -ChefVersion1 "18.8.11" -SingleVersion

Test with an MSI File

Place your Chef MSI file in the project root and run:

.\run-test.ps1 -MsiFile "chef-18.8.11-1-x64.msi"

Or with a full path:

.\run-test.ps1 -MsiFile "C:\downloads\chef-18.8.11-1-x64.msi"

Enable DLL Diagnostics

Search for DLLs without running dumpbin:

.\run-test.ps1 -FindDLLs

Search for DLLs and analyze Chef.PowerShell.Wrapper.dll with dumpbin:

.\run-test.ps1 -FindDLLs -UseDumpbin

The script will search for the following DLLs:

  • KERNEL32.dll
  • VCRUNTIME140.dll
  • api-ms-win-crt-runtime-l1-1-0.dll
  • api-ms-win-crt-heap-l1-1-0.dll
  • MSVCP140.dll
  • mscoree.dll

Note: Using -UseDumpbin will install Visual Studio Build Tools (~6GB) which significantly increases build time. Use this only when you need detailed dependency analysis.

Option 2: Using Docker Compose

# Build both images
docker-compose build

# Run both containers
docker-compose up

# Check results
Get-ChildItem .\shared\chef-*.txt | ForEach-Object { Write-Host "=== $($_.Name) ==="; Get-Content $_ }

Option 3: Manual Docker Commands

# Create shared directory
New-Item -ItemType Directory -Path .\shared -Force

# Build and run Chef 18.8.11
docker build --build-arg CHEF_VERSION=18.8.11 -t chef-test:18.8.11 .
docker run --rm -v "${PWD}\shared:C:\shared" -v "${PWD}\cookbooks:C:\cookbooks" chef-test:18.8.11 powershell -Command "chef-client -z -o recipe[test_recipe] --chef-license accept-silent"

# Build and run Chef 18.8.46
docker build --build-arg CHEF_VERSION=18.8.46 -t chef-test:18.8.46 .
docker run --rm -v "${PWD}\shared:C:\shared" -v "${PWD}\cookbooks:C:\cookbooks" chef-test:18.8.46 powershell -Command "chef-client -z -o recipe[test_recipe] --chef-license accept-silent"

# Check results
Get-ChildItem .\shared\chef-*.txt | ForEach-Object { Get-Content $_ }

What the Script Does

  1. Creates Shared Volume: Sets up a directory for output files
  2. Builds Docker Images: Creates Windows Server Core 2022 images with specified Chef versions installed via:
    • Omnitruck (default for version numbers)
    • MSI file (when using -MsiFile parameter)
  3. Runs Containers: Executes Chef client in zero mode with the test recipe
  4. Searches for DLLs (optional, with -FindDLLs flag):
    • Chef.PowerShell.Wrapper.dll (in C:\opscode\chef)
    • KERNEL32.dll
    • VCRUNTIME140.dll
    • api-ms-win-crt-runtime-l1-1-0.dll
    • api-ms-win-crt-heap-l1-1-0.dll
    • MSVCP140.dll
    • mscoree.dll
  5. Runs dumpbin (optional, with -UseDumpbin flag): Analyzes Chef.PowerShell.Wrapper.dll dependencies
  6. Test Recipe Execution: The recipe runs a PowerShell script that:
    • Retrieves the current Chef version
    • Optionally searches for DLLs and runs diagnostic tools
    • Outputs version and diagnostic information to a file on the shared volume
    • File is named chef-{version}.txt
  7. Validates Results: Checks the shared volume for output files and displays their contents

Usage Modes

Two Version Comparison (Default)

Compare two Chef versions installed via Omnitruck:

.\run-test.ps1 -ChefVersion1 "18.8.11" -ChefVersion2 "18.8.46"

Single Version Test

Test a single Chef version:

.\run-test.ps1 -ChefVersion1 "17.10.0" -SingleVersion

MSI Installation Test

Test a Chef MSI installer:

.\run-test.ps1 -MsiFile "chef-18.8.11-1-x64.msi"

With DLL Diagnostics

Test with DLL search (fast):

.\run-test.ps1 -FindDLLs

Test with DLL search and dumpbin analysis (slow, installs VS Build Tools):

.\run-test.ps1 -FindDLLs -UseDumpbin

Combine with MSI testing:

.\run-test.ps1 -MsiFile "chef-18.8.11-1-x64.msi" -FindDLLs -UseDumpbin

Output Files

Each container generates a file named chef-{version}.txt in the shared directory containing:

  • Chef version
  • Installation method (Omnitruck or MSI)
  • Computer name (container name)
  • Timestamp
  • Chef client path
  • Chef.PowerShell.Wrapper.dll search results (if -FindDLLs is used)
  • Other DLL search results (if -FindDLLs is used)
  • Dumpbin dependency analysis (if -UseDumpbin is used)

Example output file content:

Chef Version: 18.8.11
Installation Method: Omnitruck
Computer Name: CONTAINER123
Timestamp: 2025-10-22 10:30:45
Chef Client Path: C:\opscode\chef\bin\chef-client

Chef.PowerShell.Wrapper.dll Search Results (Pre-Chef Run):
  Path: C:\opscode\chef\embedded\lib\ruby\gems\3.1.0\gems\chef-powershell-18.1.0\bin\ruby_bin_folder\AMD64\Chef.PowerShell.Wrapper.dll
  Size: 12345 bytes
  LastWriteTime: 10/22/2025 10:15:30

Dumpbin Output:
Microsoft (R) COFF/PE Dumper Version 14.35.32215.0
...

DLL Search Results:
KERNEL32.dll found at:
  C:\Windows\System32\KERNEL32.dll
VCRUNTIME140.dll found at:
  C:\opscode\chef\embedded\bin\VCRUNTIME140.dll
...

Troubleshooting

Docker is in Linux mode

Switch Docker to Windows containers:

& $Env:ProgramFiles\Docker\Docker\DockerCli.exe -SwitchDaemon

Build fails with network errors

Ensure you have internet access and TLS 1.2 is enabled:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Containers fail to start

Check Docker is running and Windows containers are available:

docker info
docker version

Customization

To test different Chef versions, modify the run-test.ps1 parameters or update docker-compose.yml:

args:
  CHEF_VERSION: "17.10.0"  # Change to desired version

Additional Testing Scripts

run-ruby-test.ps1

Tests chef-powershell gem installation in a Windows Server Core 2022 Docker container with Ruby installed via RubyInstaller2. This script is useful for testing chef-powershell gem compatibility with specific Ruby versions without a full Chef installation.

Features:

  • Installs Ruby+Devkit from RubyInstaller2 (default: 3.1.7)
  • Caches Docker images by Ruby version to avoid re-downloading Ruby on subsequent runs
  • Supports installing chef-powershell from RubyGems (specific version or latest)
  • Supports installing chef-powershell from a local .gem file
  • Runs test suite from test-chef-ps.rb to validate gem functionality
  • Provides interactive debugging session in the container after tests complete

Usage:

Install latest chef-powershell:

.\run-ruby-test.ps1

Install specific chef-powershell version:

.\run-ruby-test.ps1 -ChefPowerShellVersion "1.0.38"

Install from local gem file:

.\run-ruby-test.ps1 -ChefPowerShellGemPath ".\chef-powershell-1.0.38.gem"

Use different Ruby version:

.\run-ruby-test.ps1 -RubyVersion "3.2.0"

Keep container running after tests:

.\run-ruby-test.ps1 -KeepContainer

What it does:

  1. Checks if a Docker image exists for the specified Ruby version
  2. If not, creates a new image by:
    • Starting a Windows Server Core 2022 container
    • Downloading and installing Ruby+Devkit with silent installation
    • Committing the container as a tagged image (e.g., ruby-devkit:3.1.7-windows)
  3. Installs chef-powershell gem from RubyGems or local file
  4. Copies and runs test-chef-ps.rb test suite
  5. Drops into an interactive PowerShell session for debugging

run-simple-test.ps1

Tests Chef MSI installations in a Windows Server Core 2022 Docker container and validates chef-powershell functionality using Chef's embedded Ruby.

Features:

  • Installs Chef from an MSI file
  • Runs a test Chef recipe to verify installation
  • Automatically executes test-chef-ps.rb test suite using Chef's embedded Ruby
  • Provides interactive debugging on test failures
  • Validates chef-powershell gem works with Chef's embedded Ruby environment

Usage:

Test with Chef MSI file:

.\run-simple-test.ps1 -MsiFile "chef-18.8.11-1-x64.msi"

With full path:

.\run-simple-test.ps1 -MsiFile "C:\downloads\chef-18.8.46-1-x64.msi"

What it does:

  1. Creates a Windows Server Core 2022 container with shared volume
  2. Copies the MSI file into the container
  3. Installs Chef from the MSI file
  4. Runs chef-client with a test recipe to verify Chef works
  5. Copies test-chef-ps.rb to the shared volume
  6. Executes the test suite using Chef's embedded Ruby (C:\opscode\chef\embedded\bin\ruby.exe)
  7. Reports test results and provides interactive debugging if tests fail

test-chef-ps.rb

Shared Ruby test suite used by both run-ruby-test.ps1 and run-simple-test.ps1 to validate chef-powershell gem functionality.

Tests performed:

  • Lists all installed gems matching 'powershell'
  • Displays chef-powershell gem specification (version, authors, install location, etc.)
  • Loads the chef-powershell gem
  • Executes PowerShell commands via the gem (Get-Date, Get-Process, Get-ChildItem)
  • Validates output from PowerShell commands

This modular test file ensures consistent validation across different installation methods (standalone Ruby vs Chef's embedded Ruby).

Cleanup

Remove generated images and containers:

# Remove containers
docker-compose down

# Remove images
docker rmi chef-test:18.8.11 chef-test:18.8.46
docker rmi ruby-devkit:3.1.7-windows

# Clean shared directory
Remove-Item .\shared\chef-*.txt

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published