github.com/docker/engine@v22.0.0-20211208180946-d456264580cf+incompatible/hack/ci/windows.ps1 (about) 1 # WARNING: When editing this file, consider submitting a PR to 2 # https://github.com/kevpar/docker-w2wCIScripts/blob/master/runCI/executeCI.ps1, and make sure that 3 # https://github.com/kevpar/docker-w2wCIScripts/blob/master/runCI/Invoke-DockerCI.ps1 isn't broken. 4 # Validate using a test context in Jenkins, then copy/paste into Jenkins production. 5 # 6 # Jenkins CI scripts for Windows to Windows CI (Powershell Version) 7 # By John Howard (@jhowardmsft) January 2016 - bash version; July 2016 Ported to PowerShell 8 9 $ErrorActionPreference = 'Stop' 10 $StartTime=Get-Date 11 12 Write-Host -ForegroundColor Red "DEBUG: print all environment variables to check how Jenkins runs this script" 13 $allArgs = [Environment]::GetCommandLineArgs() 14 Write-Host -ForegroundColor Red $allArgs 15 Write-Host -ForegroundColor Red "----------------------------------------------------------------------------" 16 17 # ------------------------------------------------------------------------------------------- 18 # When executed, we rely on four variables being set in the environment: 19 # 20 # [The reason for being environment variables rather than parameters is historical. No reason 21 # why it couldn't be updated.] 22 # 23 # SOURCES_DRIVE is the drive on which the sources being tested are cloned from. 24 # This should be a straight drive letter, no platform semantics. 25 # For example 'c' 26 # 27 # SOURCES_SUBDIR is the top level directory under SOURCES_DRIVE where the 28 # sources are cloned to. There are no platform semantics in this 29 # as it does not include slashes. 30 # For example 'gopath' 31 # 32 # Based on the above examples, it would be expected that Jenkins 33 # would clone the sources being tested to 34 # SOURCES_DRIVE\SOURCES_SUBDIR\src\github.com\docker\docker, or 35 # c:\gopath\src\github.com\docker\docker 36 # 37 # TESTRUN_DRIVE is the drive where we build the binary on and redirect everything 38 # to for the daemon under test. On an Azure D2 type host which has 39 # an SSD temporary storage D: drive, this is ideal for performance. 40 # For example 'd' 41 # 42 # TESTRUN_SUBDIR is the top level directory under TESTRUN_DRIVE where we redirect 43 # everything to for the daemon under test. For example 'CI'. 44 # Hence, the daemon under test is run under 45 # TESTRUN_DRIVE\TESTRUN_SUBDIR\CI-<CommitID> or 46 # d:\CI\CI-<CommitID> 47 # 48 # Optional environment variables help in CI: 49 # 50 # BUILD_NUMBER + BRANCH_NAME are optional variables to be added to the directory below TESTRUN_SUBDIR 51 # to have individual folder per CI build. If some files couldn't be 52 # cleaned up and we want to re-run the build in CI. 53 # Hence, the daemon under test is run under 54 # TESTRUN_DRIVE\TESTRUN_SUBDIR\PR-<PR-Number>\<BuildNumber> or 55 # d:\CI\PR-<PR-Number>\<BuildNumber> 56 # 57 # In addition, the following variables can control the run configuration: 58 # 59 # DOCKER_DUT_DEBUG if defined starts the daemon under test in debug mode. 60 # 61 # DOCKER_STORAGE_OPTS comma-separated list of optional storage driver options for the daemon under test 62 # examples: 63 # DOCKER_STORAGE_OPTS="size=40G" 64 # 65 # SKIP_VALIDATION_TESTS if defined skips the validation tests 66 # 67 # SKIP_UNIT_TESTS if defined skips the unit tests 68 # 69 # SKIP_INTEGRATION_TESTS if defined skips the integration tests 70 # 71 # SKIP_COPY_GO if defined skips copy the go installer from the image 72 # 73 # DOCKER_DUT_HYPERV if default daemon under test default isolation is hyperv 74 # 75 # INTEGRATION_TEST_NAME to only run partial tests eg "TestInfo*" will only run 76 # any tests starting "TestInfo" 77 # 78 # SKIP_BINARY_BUILD if defined skips building the binary 79 # 80 # SKIP_ZAP_DUT if defined doesn't zap the daemon under test directory 81 # 82 # SKIP_IMAGE_BUILD if defined doesn't build the 'docker' image 83 # 84 # INTEGRATION_IN_CONTAINER if defined, runs the integration tests from inside a container. 85 # As of July 2016, there are known issues with this. 86 # 87 # SKIP_ALL_CLEANUP if defined, skips any cleanup at the start or end of the run 88 # 89 # WINDOWS_BASE_IMAGE if defined, uses that as the base image. Note that the 90 # docker integration tests are also coded to use the same 91 # environment variable, and if no set, defaults to microsoft/windowsservercore 92 # 93 # WINDOWS_BASE_IMAGE_TAG if defined, uses that as the tag name for the base image. 94 # if no set, defaults to latest 95 # 96 # ------------------------------------------------------------------------------------------- 97 # 98 # Jenkins Integration. Add a Windows Powershell build step as follows: 99 # 100 # Write-Host -ForegroundColor green "INFO: Jenkins build step starting" 101 # $CISCRIPT_DEFAULT_LOCATION = "https://raw.githubusercontent.com/moby/moby/master/hack/ci/windows.ps1" 102 # $CISCRIPT_LOCAL_LOCATION = "$env:TEMP\executeCI.ps1" 103 # Write-Host -ForegroundColor green "INFO: Removing cached execution script" 104 # Remove-Item $CISCRIPT_LOCAL_LOCATION -Force -ErrorAction SilentlyContinue 2>&1 | Out-Null 105 # $wc = New-Object net.webclient 106 # try { 107 # Write-Host -ForegroundColor green "INFO: Downloading latest execution script..." 108 # $wc.Downloadfile($CISCRIPT_DEFAULT_LOCATION, $CISCRIPT_LOCAL_LOCATION) 109 # } 110 # catch [System.Net.WebException] 111 # { 112 # Throw ("Failed to download: $_") 113 # } 114 # & $CISCRIPT_LOCAL_LOCATION 115 # ------------------------------------------------------------------------------------------- 116 117 118 $SCRIPT_VER="05-Feb-2019 09:03 PDT" 119 $FinallyColour="Cyan" 120 121 #$env:DOCKER_DUT_DEBUG="yes" # Comment out to not be in debug mode 122 #$env:SKIP_UNIT_TESTS="yes" 123 #$env:SKIP_VALIDATION_TESTS="yes" 124 #$env:SKIP_ZAP_DUT="" 125 #$env:SKIP_BINARY_BUILD="yes" 126 #$env:INTEGRATION_TEST_NAME="" 127 #$env:SKIP_IMAGE_BUILD="yes" 128 #$env:SKIP_ALL_CLEANUP="yes" 129 #$env:INTEGRATION_IN_CONTAINER="yes" 130 #$env:WINDOWS_BASE_IMAGE="" 131 #$env:SKIP_COPY_GO="yes" 132 #$env:INTEGRATION_TESTFLAGS="-test.v" 133 134 Function Nuke-Everything { 135 $ErrorActionPreference = 'SilentlyContinue' 136 137 try { 138 139 if ($null -eq $env:SKIP_ALL_CLEANUP) { 140 Write-Host -ForegroundColor green "INFO: Nuke-Everything..." 141 $containerCount = ($(docker ps -aq | Measure-Object -line).Lines) 142 if (-not $LastExitCode -eq 0) { 143 Throw "ERROR: Failed to get container count from control daemon while nuking" 144 } 145 146 Write-Host -ForegroundColor green "INFO: Container count on control daemon to delete is $containerCount" 147 if ($(docker ps -aq | Measure-Object -line).Lines -gt 0) { 148 docker rm -f $(docker ps -aq) 149 } 150 151 $allImages = $(docker images --format "{{.Repository}}#{{.ID}}") 152 $toRemove = ($allImages | Select-String -NotMatch "servercore","nanoserver","docker","busybox") 153 $imageCount = ($toRemove | Measure-Object -line).Lines 154 155 if ($imageCount -gt 0) { 156 Write-Host -Foregroundcolor green "INFO: Non-base image count on control daemon to delete is $imageCount" 157 docker rmi -f ($toRemove | Foreach-Object { $_.ToString().Split("#")[1] }) 158 } 159 } else { 160 Write-Host -ForegroundColor Magenta "WARN: Skipping cleanup of images and containers" 161 } 162 163 # Kill any spurious daemons. The '-' is IMPORTANT otherwise will kill the control daemon! 164 $pids=$(get-process | where-object {$_.ProcessName -like 'dockerd-*'}).id 165 foreach ($p in $pids) { 166 Write-Host "INFO: Killing daemon with PID $p" 167 Stop-Process -Id $p -Force -ErrorAction SilentlyContinue 168 } 169 170 if ($null -ne $pidFile) { 171 Write-Host "INFO: Tidying pidfile $pidfile" 172 if (Test-Path $pidFile) { 173 $p=Get-Content $pidFile -raw 174 if ($null -ne $p){ 175 Write-Host -ForegroundColor green "INFO: Stopping possible daemon pid $p" 176 taskkill -f -t -pid $p 177 } 178 Remove-Item "$env:TEMP\docker.pid" -force -ErrorAction SilentlyContinue 179 } 180 } 181 182 # Kill any spurious containerd. 183 $pids=$(get-process | where-object {$_.ProcessName -like 'containerd'}).id 184 foreach ($p in $pids) { 185 Write-Host "INFO: Killing containerd with PID $p" 186 Stop-Process -Id $p -Force -ErrorAction SilentlyContinue 187 } 188 189 Stop-Process -name "cc1" -Force -ErrorAction SilentlyContinue 2>&1 | Out-Null 190 Stop-Process -name "link" -Force -ErrorAction SilentlyContinue 2>&1 | Out-Null 191 Stop-Process -name "compile" -Force -ErrorAction SilentlyContinue 2>&1 | Out-Null 192 Stop-Process -name "ld" -Force -ErrorAction SilentlyContinue 2>&1 | Out-Null 193 Stop-Process -name "go" -Force -ErrorAction SilentlyContinue 2>&1 | Out-Null 194 Stop-Process -name "git" -Force -ErrorAction SilentlyContinue 2>&1 | Out-Null 195 Stop-Process -name "git-remote-https" -Force -ErrorAction SilentlyContinue 2>&1 | Out-Null 196 Stop-Process -name "integration-cli.test" -Force -ErrorAction SilentlyContinue 2>&1 | Out-Null 197 Stop-Process -name "tail" -Force -ErrorAction SilentlyContinue 2>&1 | Out-Null 198 199 # Detach any VHDs 200 gwmi msvm_mountedstorageimage -namespace root/virtualization/v2 -ErrorAction SilentlyContinue | foreach-Object {$_.DetachVirtualHardDisk() } 201 202 # Stop any compute processes 203 Get-ComputeProcess | Stop-ComputeProcess -Force 204 205 # Delete the directory using our dangerous utility unless told not to 206 if (Test-Path "$env:TESTRUN_DRIVE`:\$env:TESTRUN_SUBDIR") { 207 if (($null -ne $env:SKIP_ZAP_DUT) -or ($null -eq $env:SKIP_ALL_CLEANUP)) { 208 Write-Host -ForegroundColor Green "INFO: Nuking $env:TESTRUN_DRIVE`:\$env:TESTRUN_SUBDIR" 209 docker-ci-zap "-folder=$env:TESTRUN_DRIVE`:\$env:TESTRUN_SUBDIR" 210 } else { 211 Write-Host -ForegroundColor Magenta "WARN: Skip nuking $env:TESTRUN_DRIVE`:\$env:TESTRUN_SUBDIR" 212 } 213 } 214 215 # TODO: This should be able to be removed in August 2017 update. Only needed for RS1 Production Server workaround - Psched 216 $reg = "HKLM:\System\CurrentControlSet\Services\Psched\Parameters\NdisAdapters" 217 $count=(Get-ChildItem $reg | Measure-Object).Count 218 if ($count -gt 0) { 219 Write-Warning "There are $count NdisAdapters leaked under Psched\Parameters" 220 Write-Warning "Cleaning Psched..." 221 Get-ChildItem $reg | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue | Out-Null 222 } 223 224 # TODO: This should be able to be removed in August 2017 update. Only needed for RS1 225 $reg = "HKLM:\System\CurrentControlSet\Services\WFPLWFS\Parameters\NdisAdapters" 226 $count=(Get-ChildItem $reg | Measure-Object).Count 227 if ($count -gt 0) { 228 Write-Warning "There are $count NdisAdapters leaked under WFPLWFS\Parameters" 229 Write-Warning "Cleaning WFPLWFS..." 230 Get-ChildItem $reg | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue | Out-Null 231 } 232 } catch { 233 # Don't throw any errors onwards Throw $_ 234 } 235 } 236 237 Try { 238 Write-Host -ForegroundColor Cyan "`nINFO: executeCI.ps1 starting at $(date)`n" 239 Write-Host -ForegroundColor Green "INFO: Script version $SCRIPT_VER" 240 Set-PSDebug -Trace 0 # 1 to turn on 241 $origPath="$env:PATH" # so we can restore it at the end 242 $origDOCKER_HOST="$DOCKER_HOST" # So we can restore it at the end 243 $origGOROOT="$env:GOROOT" # So we can restore it at the end 244 $origGOPATH="$env:GOPATH" # So we can restore it at the end 245 246 # Turn off progress bars 247 $origProgressPreference=$global:ProgressPreference 248 $global:ProgressPreference='SilentlyContinue' 249 250 # Git version 251 Write-Host -ForegroundColor Green "INFO: Running $(git version)" 252 253 # OS Version 254 $bl=(Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name BuildLabEx).BuildLabEx 255 $a=$bl.ToString().Split(".") 256 $Branch=$a[3] 257 $WindowsBuild=$a[0]+"."+$a[1]+"."+$a[4] 258 Write-Host -ForegroundColor green "INFO: Branch:$Branch Build:$WindowsBuild" 259 260 # List the environment variables 261 Write-Host -ForegroundColor green "INFO: Environment variables:" 262 Get-ChildItem Env: | Out-String 263 264 # PR 265 if (-not ($null -eq $env:PR)) { Write-Output "INFO: PR#$env:PR (https://github.com/docker/docker/pull/$env:PR)" } 266 267 # Make sure docker is installed 268 if ($null -eq (Get-Command "docker" -ErrorAction SilentlyContinue)) { Throw "ERROR: docker is not installed or not found on path" } 269 270 # Make sure docker-ci-zap is installed 271 if ($null -eq (Get-Command "docker-ci-zap" -ErrorAction SilentlyContinue)) { Throw "ERROR: docker-ci-zap is not installed or not found on path" } 272 273 # Make sure Windows Defender is disabled 274 $defender = $false 275 Try { 276 $status = Get-MpComputerStatus 277 if ($status) { 278 if ($status.RealTimeProtectionEnabled) { 279 $defender = $true 280 } 281 } 282 } Catch {} 283 if ($defender) { Write-Host -ForegroundColor Magenta "WARN: Windows Defender real time protection is enabled, which may cause some integration tests to fail" } 284 285 # Make sure SOURCES_DRIVE is set 286 if ($null -eq $env:SOURCES_DRIVE) { Throw "ERROR: Environment variable SOURCES_DRIVE is not set" } 287 288 # Make sure TESTRUN_DRIVE is set 289 if ($null -eq $env:TESTRUN_DRIVE) { Throw "ERROR: Environment variable TESTRUN_DRIVE is not set" } 290 291 # Make sure SOURCES_SUBDIR is set 292 if ($null -eq $env:SOURCES_SUBDIR) { Throw "ERROR: Environment variable SOURCES_SUBDIR is not set" } 293 294 # Make sure TESTRUN_SUBDIR is set 295 if ($null -eq $env:TESTRUN_SUBDIR) { Throw "ERROR: Environment variable TESTRUN_SUBDIR is not set" } 296 297 # SOURCES_DRIVE\SOURCES_SUBDIR must be a directory and exist 298 if (-not (Test-Path -PathType Container "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR")) { Throw "ERROR: $env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR must be an existing directory" } 299 300 # Create the TESTRUN_DRIVE\TESTRUN_SUBDIR if it does not already exist 301 New-Item -ItemType Directory -Force -Path "$env:TESTRUN_DRIVE`:\$env:TESTRUN_SUBDIR" -ErrorAction SilentlyContinue | Out-Null 302 303 Write-Host -ForegroundColor Green "INFO: Sources under $env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\..." 304 Write-Host -ForegroundColor Green "INFO: Test run under $env:TESTRUN_DRIVE`:\$env:TESTRUN_SUBDIR\..." 305 306 # Check the intended source location is a directory 307 if (-not (Test-Path -PathType Container "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker" -ErrorAction SilentlyContinue)) { 308 Throw "ERROR: $env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker is not a directory!" 309 } 310 311 # Make sure we start at the root of the sources 312 Set-Location "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker" 313 Write-Host -ForegroundColor Green "INFO: Running in $(Get-Location)" 314 315 # Make sure we are in repo 316 if (-not (Test-Path -PathType Leaf -Path ".\Dockerfile.windows")) { 317 Throw "$(Get-Location) does not contain Dockerfile.windows!" 318 } 319 Write-Host -ForegroundColor Green "INFO: docker/docker repository was found" 320 321 # Make sure microsoft/windowsservercore:latest image is installed in the control daemon. On public CI machines, windowsservercore.tar and nanoserver.tar 322 # are pre-baked and tagged appropriately in the c:\baseimages directory, and can be directly loaded. 323 # Note - this script will only work on 10B (Oct 2016) or later machines! Not 9D or previous due to image tagging assumptions. 324 # 325 # On machines not on Microsoft corpnet, or those which have not been pre-baked, we have to docker pull the image in which case it will 326 # will come in directly as microsoft/windowsservercore:latest. The ultimate goal of all this code is to ensure that whatever, 327 # we have microsoft/windowsservercore:latest 328 # 329 # Note we cannot use (as at Oct 2016) nanoserver as the control daemons base image, even if nanoserver is used in the tests themselves. 330 331 $ErrorActionPreference = "SilentlyContinue" 332 $ControlDaemonBaseImage="windowsservercore" 333 334 $readBaseFrom="c" 335 if ($((docker images --format "{{.Repository}}:{{.Tag}}" | Select-String $("microsoft/"+$ControlDaemonBaseImage+":latest") | Measure-Object -Line).Lines) -eq 0) { 336 # Try the internal azure CI image version or Microsoft internal corpnet where the base image is already pre-prepared on the disk, 337 # either through Invoke-DockerCI or, in the case of Azure CI servers, baked into the VHD at the same location. 338 if (Test-Path $("$env:SOURCES_DRIVE`:\baseimages\"+$ControlDaemonBaseImage+".tar")) { 339 # An optimization for CI servers to copy it to the D: drive which is an SSD. 340 if ($env:SOURCES_DRIVE -ne $env:TESTRUN_DRIVE) { 341 $readBaseFrom=$env:TESTRUN_DRIVE 342 if (!(Test-Path "$env:TESTRUN_DRIVE`:\baseimages")) { 343 New-Item "$env:TESTRUN_DRIVE`:\baseimages" -type directory | Out-Null 344 } 345 if (!(Test-Path "$env:TESTRUN_DRIVE`:\baseimages\windowsservercore.tar")) { 346 if (Test-Path "$env:SOURCES_DRIVE`:\baseimages\windowsservercore.tar") { 347 Write-Host -ForegroundColor Green "INFO: Optimisation - copying $env:SOURCES_DRIVE`:\baseimages\windowsservercore.tar to $env:TESTRUN_DRIVE`:\baseimages" 348 Copy-Item "$env:SOURCES_DRIVE`:\baseimages\windowsservercore.tar" "$env:TESTRUN_DRIVE`:\baseimages" 349 } 350 } 351 if (!(Test-Path "$env:TESTRUN_DRIVE`:\baseimages\nanoserver.tar")) { 352 if (Test-Path "$env:SOURCES_DRIVE`:\baseimages\nanoserver.tar") { 353 Write-Host -ForegroundColor Green "INFO: Optimisation - copying $env:SOURCES_DRIVE`:\baseimages\nanoserver.tar to $env:TESTRUN_DRIVE`:\baseimages" 354 Copy-Item "$env:SOURCES_DRIVE`:\baseimages\nanoserver.tar" "$env:TESTRUN_DRIVE`:\baseimages" 355 } 356 } 357 $readBaseFrom=$env:TESTRUN_DRIVE 358 } 359 Write-Host -ForegroundColor Green "INFO: Loading"$ControlDaemonBaseImage".tar from disk. This may take some time..." 360 $ErrorActionPreference = "SilentlyContinue" 361 docker load -i $("$readBaseFrom`:\baseimages\"+$ControlDaemonBaseImage+".tar") 362 $ErrorActionPreference = "Stop" 363 if (-not $LastExitCode -eq 0) { 364 Throw $("ERROR: Failed to load $readBaseFrom`:\baseimages\"+$ControlDaemonBaseImage+".tar") 365 } 366 Write-Host -ForegroundColor Green "INFO: docker load of"$ControlDaemonBaseImage" completed successfully" 367 } else { 368 # We need to docker pull it instead. It will come in directly as microsoft/imagename:latest 369 Write-Host -ForegroundColor Green $("INFO: Pulling $($env:WINDOWS_BASE_IMAGE):$env:WINDOWS_BASE_IMAGE_TAG from docker hub. This may take some time...") 370 $ErrorActionPreference = "SilentlyContinue" 371 docker pull "$($env:WINDOWS_BASE_IMAGE):$env:WINDOWS_BASE_IMAGE_TAG" 372 $ErrorActionPreference = "Stop" 373 if (-not $LastExitCode -eq 0) { 374 Throw $("ERROR: Failed to docker pull $($env:WINDOWS_BASE_IMAGE):$env:WINDOWS_BASE_IMAGE_TAG.") 375 } 376 Write-Host -ForegroundColor Green $("INFO: docker pull of $($env:WINDOWS_BASE_IMAGE):$env:WINDOWS_BASE_IMAGE_TAG completed successfully") 377 Write-Host -ForegroundColor Green $("INFO: Tagging $($env:WINDOWS_BASE_IMAGE):$env:WINDOWS_BASE_IMAGE_TAG as microsoft/$ControlDaemonBaseImage") 378 docker tag "$($env:WINDOWS_BASE_IMAGE):$env:WINDOWS_BASE_IMAGE_TAG" microsoft/$ControlDaemonBaseImage 379 } 380 } else { 381 Write-Host -ForegroundColor Green "INFO: Image"$("microsoft/"+$ControlDaemonBaseImage+":latest")"is already loaded in the control daemon" 382 } 383 384 # Inspect the pulled image to get the version directly 385 $ErrorActionPreference = "SilentlyContinue" 386 $imgVersion = $(docker inspect $("microsoft/"+$ControlDaemonBaseImage) --format "{{.OsVersion}}") 387 $ErrorActionPreference = "Stop" 388 Write-Host -ForegroundColor Green $("INFO: Version of microsoft/"+$ControlDaemonBaseImage+":latest is '"+$imgVersion+"'") 389 390 # Provide the docker version for debugging purposes. 391 Write-Host -ForegroundColor Green "INFO: Docker version of control daemon" 392 Write-Host 393 $ErrorActionPreference = "SilentlyContinue" 394 docker version 395 $ErrorActionPreference = "Stop" 396 if (-not($LastExitCode -eq 0)) { 397 Write-Host 398 Write-Host -ForegroundColor Green "---------------------------------------------------------------------------" 399 Write-Host -ForegroundColor Green " Failed to get a response from the control daemon. It may be down." 400 Write-Host -ForegroundColor Green " Try re-running this CI job, or ask on #docker-maintainers on docker slack" 401 Write-Host -ForegroundColor Green " to see if the daemon is running. Also check the service configuration." 402 Write-Host -ForegroundColor Green " DOCKER_HOST is set to $DOCKER_HOST." 403 Write-Host -ForegroundColor Green "---------------------------------------------------------------------------" 404 Write-Host 405 Throw "ERROR: The control daemon does not appear to be running." 406 } 407 Write-Host 408 409 # Same as above, but docker info 410 Write-Host -ForegroundColor Green "INFO: Docker info of control daemon" 411 Write-Host 412 $ErrorActionPreference = "SilentlyContinue" 413 docker info 414 $ErrorActionPreference = "Stop" 415 if (-not($LastExitCode -eq 0)) { 416 Throw "ERROR: The control daemon does not appear to be running." 417 } 418 Write-Host 419 420 # Get the commit has and verify we have something 421 $ErrorActionPreference = "SilentlyContinue" 422 $COMMITHASH=$(git rev-parse --short HEAD) 423 $ErrorActionPreference = "Stop" 424 if (-not($LastExitCode -eq 0)) { 425 Throw "ERROR: Failed to get commit hash. Are you sure this is a docker repository?" 426 } 427 Write-Host -ForegroundColor Green "INFO: Commit hash is $COMMITHASH" 428 429 # Nuke everything and go back to our sources after 430 Nuke-Everything 431 cd "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker" 432 433 # Redirect to a temporary location. 434 $TEMPORIG=$env:TEMP 435 if ($null -eq $env:BUILD_NUMBER) { 436 $env:TEMP="$env:TESTRUN_DRIVE`:\$env:TESTRUN_SUBDIR\CI-$COMMITHASH" 437 } else { 438 # individual temporary location per CI build that better matches the BUILD_URL 439 $env:TEMP="$env:TESTRUN_DRIVE`:\$env:TESTRUN_SUBDIR\$env:BRANCH_NAME\$env:BUILD_NUMBER" 440 } 441 $env:LOCALAPPDATA="$env:TEMP\localappdata" 442 $errorActionPreference='Stop' 443 New-Item -ItemType Directory "$env:TEMP" -ErrorAction SilentlyContinue | Out-Null 444 New-Item -ItemType Directory "$env:TEMP\userprofile" -ErrorAction SilentlyContinue | Out-Null 445 New-Item -ItemType Directory "$env:TEMP\testresults" -ErrorAction SilentlyContinue | Out-Null 446 New-Item -ItemType Directory "$env:TEMP\testresults\unittests" -ErrorAction SilentlyContinue | Out-Null 447 New-Item -ItemType Directory "$env:TEMP\localappdata" -ErrorAction SilentlyContinue | Out-Null 448 New-Item -ItemType Directory "$env:TEMP\binary" -ErrorAction SilentlyContinue | Out-Null 449 New-Item -ItemType Directory "$env:TEMP\installer" -ErrorAction SilentlyContinue | Out-Null 450 if ($null -eq $env:SKIP_COPY_GO) { 451 # Wipe the previous version of GO - we're going to get it out of the image 452 if (Test-Path "$env:TEMP\go") { Remove-Item "$env:TEMP\go" -Recurse -Force -ErrorAction SilentlyContinue | Out-Null } 453 New-Item -ItemType Directory "$env:TEMP\go" -ErrorAction SilentlyContinue | Out-Null 454 } 455 456 Write-Host -ForegroundColor Green "INFO: Location for testing is $env:TEMP" 457 458 # CI Integrity check - ensure Dockerfile.windows and Dockerfile go versions match 459 $goVersionDockerfileWindows=(Select-String -Path ".\Dockerfile.windows" -Pattern "^ARG[\s]+GO_VERSION=(.*)$").Matches.groups[1].Value 460 $goVersionDockerfile=(Select-String -Path ".\Dockerfile" -Pattern "^ARG[\s]+GO_VERSION=(.*)$").Matches.groups[1].Value 461 462 if ($null -eq $goVersionDockerfile) { 463 Throw "ERROR: Failed to extract golang version from Dockerfile" 464 } 465 Write-Host -ForegroundColor Green "INFO: Validating GOLang consistency in Dockerfile.windows..." 466 if (-not ($goVersionDockerfile -eq $goVersionDockerfileWindows)) { 467 Throw "ERROR: Mismatched GO versions between Dockerfile and Dockerfile.windows. Update your PR to ensure that both files are updated and in sync. $goVersionDockerfile $goVersionDockerfileWindows" 468 } 469 470 # Build the image 471 if ($null -eq $env:SKIP_IMAGE_BUILD) { 472 Write-Host -ForegroundColor Cyan "`n`nINFO: Building the image from Dockerfile.windows at $(Get-Date)..." 473 Write-Host 474 $ErrorActionPreference = "SilentlyContinue" 475 $Duration=$(Measure-Command { docker build --build-arg=GO_VERSION -t docker -f Dockerfile.windows . | Out-Host }) 476 $ErrorActionPreference = "Stop" 477 if (-not($LastExitCode -eq 0)) { 478 Throw "ERROR: Failed to build image from Dockerfile.windows" 479 } 480 Write-Host -ForegroundColor Green "INFO: Image build ended at $(Get-Date). Duration`:$Duration" 481 } else { 482 Write-Host -ForegroundColor Magenta "WARN: Skipping building the docker image" 483 } 484 485 # Following at the moment must be docker\docker as it's dictated by dockerfile.Windows 486 $contPath="$COMMITHASH`:c`:\gopath\src\github.com\docker\docker\bundles" 487 488 # After https://github.com/docker/docker/pull/30290, .git was added to .dockerignore. Therefore 489 # we have to calculate unsupported outside of the container, and pass the commit ID in through 490 # an environment variable for the binary build 491 $CommitUnsupported="" 492 if ($(git status --porcelain --untracked-files=no).Length -ne 0) { 493 $CommitUnsupported="-unsupported" 494 } 495 496 # Build the binary in a container unless asked to skip it. 497 if ($null -eq $env:SKIP_BINARY_BUILD) { 498 Write-Host -ForegroundColor Cyan "`n`nINFO: Building the test binaries at $(Get-Date)..." 499 $ErrorActionPreference = "SilentlyContinue" 500 docker rm -f $COMMITHASH 2>&1 | Out-Null 501 if ($CommitUnsupported -ne "") { 502 Write-Host "" 503 Write-Warning "This version is unsupported because there are uncommitted file(s)." 504 Write-Warning "Either commit these changes, or add them to .gitignore." 505 git status --porcelain --untracked-files=no | Write-Warning 506 Write-Host "" 507 } 508 $Duration=$(Measure-Command {docker run --name $COMMITHASH -e DOCKER_GITCOMMIT=$COMMITHASH$CommitUnsupported docker hack\make.ps1 -Daemon -Client | Out-Host }) 509 $ErrorActionPreference = "Stop" 510 if (-not($LastExitCode -eq 0)) { 511 Throw "ERROR: Failed to build binary" 512 } 513 Write-Host -ForegroundColor Green "INFO: Binaries build ended at $(Get-Date). Duration`:$Duration" 514 515 # Copy the binaries and the generated version_autogen.go out of the container 516 $ErrorActionPreference = "SilentlyContinue" 517 docker cp "$contPath\docker.exe" $env:TEMP\binary\ 518 if (-not($LastExitCode -eq 0)) { 519 Throw "ERROR: Failed to docker cp the client binary (docker.exe) to $env:TEMP\binary" 520 } 521 docker cp "$contPath\dockerd.exe" $env:TEMP\binary\ 522 if (-not($LastExitCode -eq 0)) { 523 Throw "ERROR: Failed to docker cp the daemon binary (dockerd.exe) to $env:TEMP\binary" 524 } 525 526 docker cp "$COMMITHASH`:c`:\gopath\bin\gotestsum.exe" $env:TEMP\binary\ 527 if (-not (Test-Path "$env:TEMP\binary\gotestsum.exe")) { 528 Throw "ERROR: gotestsum.exe not found...." ` 529 } 530 531 docker cp "$COMMITHASH`:c`:\containerd\bin\containerd.exe" $env:TEMP\binary\ 532 if (-not (Test-Path "$env:TEMP\binary\containerd.exe")) { 533 Throw "ERROR: containerd.exe not found...." ` 534 } 535 docker cp "$COMMITHASH`:c`:\containerd\bin\containerd-shim-runhcs-v1.exe" $env:TEMP\binary\ 536 if (-not (Test-Path "$env:TEMP\binary\containerd-shim-runhcs-v1.exe")) { 537 Throw "ERROR: containerd-shim-runhcs-v1.exe not found...." ` 538 } 539 540 $ErrorActionPreference = "Stop" 541 542 # Copy the built dockerd.exe to dockerd-$COMMITHASH.exe so that easily spotted in task manager. 543 Write-Host -ForegroundColor Green "INFO: Copying the built daemon binary to $env:TEMP\binary\dockerd-$COMMITHASH.exe..." 544 Copy-Item $env:TEMP\binary\dockerd.exe $env:TEMP\binary\dockerd-$COMMITHASH.exe -Force -ErrorAction SilentlyContinue 545 546 # Copy the built docker.exe to docker-$COMMITHASH.exe 547 Write-Host -ForegroundColor Green "INFO: Copying the built client binary to $env:TEMP\binary\docker-$COMMITHASH.exe..." 548 Copy-Item $env:TEMP\binary\docker.exe $env:TEMP\binary\docker-$COMMITHASH.exe -Force -ErrorAction SilentlyContinue 549 550 } else { 551 Write-Host -ForegroundColor Magenta "WARN: Skipping building the binaries" 552 } 553 554 Write-Host -ForegroundColor Green "INFO: Copying dockerversion from the container..." 555 $ErrorActionPreference = "SilentlyContinue" 556 docker cp "$contPath\..\dockerversion\version_autogen.go" "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker\dockerversion" 557 if (-not($LastExitCode -eq 0)) { 558 Throw "ERROR: Failed to docker cp the generated version_autogen.go to $env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker\dockerversion" 559 } 560 $ErrorActionPreference = "Stop" 561 562 # Grab the golang installer out of the built image. That way, we know we are consistent once extracted and paths set, 563 # so there's no need to re-deploy on account of an upgrade to the version of GO being used in docker. 564 if ($null -eq $env:SKIP_COPY_GO) { 565 Write-Host -ForegroundColor Green "INFO: Copying the golang package from the container to $env:TEMP\installer\go.zip..." 566 docker cp "$COMMITHASH`:c`:\go.zip" $env:TEMP\installer\ 567 if (-not($LastExitCode -eq 0)) { 568 Throw "ERROR: Failed to docker cp the golang installer 'go.zip' from container:c:\go.zip to $env:TEMP\installer" 569 } 570 $ErrorActionPreference = "Stop" 571 572 # Extract the golang installer 573 Write-Host -ForegroundColor Green "INFO: Extracting go.zip to $env:TEMP\go" 574 $Duration=$(Measure-Command { Expand-Archive $env:TEMP\installer\go.zip $env:TEMP -Force | Out-Null}) 575 Write-Host -ForegroundColor Green "INFO: Extraction ended at $(Get-Date). Duration`:$Duration" 576 } else { 577 Write-Host -ForegroundColor Magenta "WARN: Skipping copying and extracting golang from the image" 578 } 579 580 # Set the GOPATH 581 Write-Host -ForegroundColor Green "INFO: Updating the golang and path environment variables" 582 $env:GOPATH="$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR" 583 Write-Host -ForegroundColor Green "INFO: GOPATH=$env:GOPATH" 584 585 # Set the path to have: 586 # - the version of go from the image at the front 587 # - the test binaries, not the host ones. 588 $env:PATH="$env:TEMP\go\bin;$env:TEMP\binary;$env:PATH" 589 590 # Set the GOROOT to be our copy of go from the image 591 $env:GOROOT="$env:TEMP\go" 592 Write-Host -ForegroundColor Green "INFO: $(go version)" 593 594 # Work out the -H parameter for the daemon under test (DASHH_DUT) and client under test (DASHH_CUT) 595 #$DASHH_DUT="npipe:////./pipe/$COMMITHASH" # Can't do remote named pipe 596 #$ip = (resolve-dnsname $env:COMPUTERNAME -type A -NoHostsFile -LlmnrNetbiosOnly).IPAddress # Useful to tie down 597 $DASHH_CUT="tcp://127.0.0.1`:2357" # Not a typo for 2375! 598 $DASHH_DUT="tcp://0.0.0.0:2357" # Not a typo for 2375! 599 600 # Arguments for the daemon under test 601 $dutArgs=@() 602 $dutArgs += "-H $DASHH_DUT" 603 $dutArgs += "--data-root $env:TEMP\daemon" 604 $dutArgs += "--pidfile $env:TEMP\docker.pid" 605 606 # Save the PID file so we can nuke it if set 607 $pidFile="$env:TEMP\docker.pid" 608 609 # Arguments: Are we starting the daemon under test in debug mode? 610 if (-not ("$env:DOCKER_DUT_DEBUG" -eq "")) { 611 Write-Host -ForegroundColor Green "INFO: Running the daemon under test in debug mode" 612 $dutArgs += "-D" 613 } 614 615 # Arguments: Are we starting the daemon under test in containerd mode? 616 if (-not ("$env:DOCKER_WINDOWS_CONTAINERD_RUNTIME" -eq "")) { 617 Write-Host -ForegroundColor Green "INFO: Running the daemon under test in containerd mode" 618 $dutArgs += "--containerd \\.\pipe\containerd-containerd" 619 } 620 621 # Arguments: Are we starting the daemon under test with Hyper-V containers as the default isolation? 622 if (-not ("$env:DOCKER_DUT_HYPERV" -eq "")) { 623 Write-Host -ForegroundColor Green "INFO: Running the daemon under test with Hyper-V containers as the default" 624 $dutArgs += "--exec-opt isolation=hyperv" 625 } 626 627 # Arguments: Allow setting optional storage-driver options 628 # example usage: DDOCKER_STORAGE_OPTS="size=40G" 629 if (-not ("$env:DOCKER_STORAGE_OPTS" -eq "")) { 630 Write-Host -ForegroundColor Green "INFO: Running the daemon under test with storage-driver options ${env:DOCKER_STORAGE_OPTS}" 631 $env:DOCKER_STORAGE_OPTS.Split(",") | ForEach-Object { 632 $dutArgs += "--storage-opt $_" 633 } 634 } 635 636 # Start the daemon under test, ensuring everything is redirected to folders under $TEMP. 637 # Important - we launch the -$COMMITHASH version so that we can kill it without 638 # killing the control daemon. 639 Write-Host -ForegroundColor Green "INFO: Starting a daemon under test..." 640 Write-Host -ForegroundColor Green "INFO: Args: $dutArgs" 641 New-Item -ItemType Directory $env:TEMP\daemon -ErrorAction SilentlyContinue | Out-Null 642 643 # Start containerd first 644 if (-not ("$env:DOCKER_WINDOWS_CONTAINERD_RUNTIME" -eq "")) { 645 Start-Process "$env:TEMP\binary\containerd.exe" ` 646 -ArgumentList "--log-level debug" ` 647 -RedirectStandardOutput "$env:TEMP\containerd.out" ` 648 -RedirectStandardError "$env:TEMP\containerd.err" 649 Write-Host -ForegroundColor Green "INFO: Containerd started successfully." 650 } 651 652 # Cannot fathom why, but always writes to stderr.... 653 Start-Process "$env:TEMP\binary\dockerd-$COMMITHASH" ` 654 -ArgumentList $dutArgs ` 655 -RedirectStandardOutput "$env:TEMP\dut.out" ` 656 -RedirectStandardError "$env:TEMP\dut.err" 657 Write-Host -ForegroundColor Green "INFO: Process started successfully." 658 $daemonStarted=1 659 660 # Start tailing the daemon under test if the command is installed 661 if ($null -ne (Get-Command "tail" -ErrorAction SilentlyContinue)) { 662 Write-Host -ForegroundColor green "INFO: Start tailing logs of the daemon under tests" 663 $tail = Start-Process "tail" -ArgumentList "-f $env:TEMP\dut.out" -PassThru -ErrorAction SilentlyContinue 664 } 665 666 # Verify we can get the daemon under test to respond 667 $tries=20 668 Write-Host -ForegroundColor Green "INFO: Waiting for the daemon under test to start..." 669 while ($true) { 670 $ErrorActionPreference = "SilentlyContinue" 671 & "$env:TEMP\binary\docker-$COMMITHASH" "-H=$($DASHH_CUT)" version 2>&1 | Out-Null 672 $ErrorActionPreference = "Stop" 673 if ($LastExitCode -eq 0) { 674 break 675 } 676 677 $tries-- 678 if ($tries -le 0) { 679 Throw "ERROR: Failed to get a response from the daemon under test" 680 } 681 Write-Host -NoNewline "." 682 sleep 1 683 } 684 Write-Host -ForegroundColor Green "INFO: Daemon under test started and replied!" 685 686 # Provide the docker version of the daemon under test for debugging purposes. 687 Write-Host -ForegroundColor Green "INFO: Docker version of the daemon under test" 688 Write-Host 689 $ErrorActionPreference = "SilentlyContinue" 690 & "$env:TEMP\binary\docker-$COMMITHASH" "-H=$($DASHH_CUT)" version 691 $ErrorActionPreference = "Stop" 692 if ($LastExitCode -ne 0) { 693 Throw "ERROR: The daemon under test does not appear to be running." 694 } 695 Write-Host 696 697 # Same as above but docker info 698 Write-Host -ForegroundColor Green "INFO: Docker info of the daemon under test" 699 Write-Host 700 $ErrorActionPreference = "SilentlyContinue" 701 & "$env:TEMP\binary\docker-$COMMITHASH" "-H=$($DASHH_CUT)" info 702 $ErrorActionPreference = "Stop" 703 if ($LastExitCode -ne 0) { 704 Throw "ERROR: The daemon under test does not appear to be running." 705 } 706 Write-Host 707 708 # Same as above but docker images 709 Write-Host -ForegroundColor Green "INFO: Docker images of the daemon under test" 710 Write-Host 711 $ErrorActionPreference = "SilentlyContinue" 712 & "$env:TEMP\binary\docker-$COMMITHASH" "-H=$($DASHH_CUT)" images 713 $ErrorActionPreference = "Stop" 714 if ($LastExitCode -ne 0) { 715 Throw "ERROR: The daemon under test does not appear to be running." 716 } 717 Write-Host 718 719 # Default to windowsservercore for the base image used for the tests. The "docker" image 720 # and the control daemon use microsoft/windowsservercore regardless. This is *JUST* for the tests. 721 if ($null -eq $env:WINDOWS_BASE_IMAGE) { 722 $env:WINDOWS_BASE_IMAGE="microsoft/windowsservercore" 723 } 724 if ($null -eq $env:WINDOWS_BASE_IMAGE_TAG) { 725 $env:WINDOWS_BASE_IMAGE_TAG="latest" 726 } 727 728 # Lowercase and make sure it has a microsoft/ prefix 729 $env:WINDOWS_BASE_IMAGE = $env:WINDOWS_BASE_IMAGE.ToLower() 730 if (! $($env:WINDOWS_BASE_IMAGE -Split "/")[0] -match "microsoft") { 731 Throw "ERROR: WINDOWS_BASE_IMAGE should start microsoft/ or mcr.microsoft.com/" 732 } 733 734 Write-Host -ForegroundColor Green "INFO: Base image for tests is $env:WINDOWS_BASE_IMAGE" 735 736 $ErrorActionPreference = "SilentlyContinue" 737 if ($((& "$env:TEMP\binary\docker-$COMMITHASH" "-H=$($DASHH_CUT)" images --format "{{.Repository}}:{{.Tag}}" | Select-String "$($env:WINDOWS_BASE_IMAGE):$env:WINDOWS_BASE_IMAGE_TAG" | Measure-Object -Line).Lines) -eq 0) { 738 # Try the internal azure CI image version or Microsoft internal corpnet where the base image is already pre-prepared on the disk, 739 # either through Invoke-DockerCI or, in the case of Azure CI servers, baked into the VHD at the same location. 740 if (Test-Path $("c:\baseimages\"+$($env:WINDOWS_BASE_IMAGE -Split "/")[1]+".tar")) { 741 Write-Host -ForegroundColor Green "INFO: Loading"$($env:WINDOWS_BASE_IMAGE -Split "/")[1]".tar from disk into the daemon under test. This may take some time..." 742 $ErrorActionPreference = "SilentlyContinue" 743 & "$env:TEMP\binary\docker-$COMMITHASH" "-H=$($DASHH_CUT)" load -i $("$readBaseFrom`:\baseimages\"+$($env:WINDOWS_BASE_IMAGE -Split "/")[1]+".tar") 744 $ErrorActionPreference = "Stop" 745 if (-not $LastExitCode -eq 0) { 746 Throw $("ERROR: Failed to load $readBaseFrom`:\baseimages\"+$($env:WINDOWS_BASE_IMAGE -Split "/")[1]+".tar into daemon under test") 747 } 748 Write-Host -ForegroundColor Green "INFO: docker load of"$($env:WINDOWS_BASE_IMAGE -Split "/")[1]" into daemon under test completed successfully" 749 } else { 750 # We need to docker pull it instead. It will come in directly as microsoft/imagename:tagname 751 Write-Host -ForegroundColor Green $("INFO: Pulling "+$env:WINDOWS_BASE_IMAGE+":"+$env:WINDOWS_BASE_IMAGE_TAG+" from docker hub into daemon under test. This may take some time...") 752 $ErrorActionPreference = "SilentlyContinue" 753 & "$env:TEMP\binary\docker-$COMMITHASH" "-H=$($DASHH_CUT)" pull "$($env:WINDOWS_BASE_IMAGE):$env:WINDOWS_BASE_IMAGE_TAG" 754 $ErrorActionPreference = "Stop" 755 if (-not $LastExitCode -eq 0) { 756 Throw $("ERROR: Failed to docker pull $($env:WINDOWS_BASE_IMAGE):$env:WINDOWS_BASE_IMAGE_TAG into daemon under test.") 757 } 758 Write-Host -ForegroundColor Green $("INFO: docker pull of $($env:WINDOWS_BASE_IMAGE):$env:WINDOWS_BASE_IMAGE_TAG into daemon under test completed successfully") 759 Write-Host -ForegroundColor Green $("INFO: Tagging $($env:WINDOWS_BASE_IMAGE):$env:WINDOWS_BASE_IMAGE_TAG as microsoft/$ControlDaemonBaseImage in daemon under test") 760 & "$env:TEMP\binary\docker-$COMMITHASH" "-H=$($DASHH_CUT)" tag "$($env:WINDOWS_BASE_IMAGE):$env:WINDOWS_BASE_IMAGE_TAG" microsoft/$ControlDaemonBaseImage 761 } 762 } else { 763 Write-Host -ForegroundColor Green "INFO: Image $($env:WINDOWS_BASE_IMAGE):$env:WINDOWS_BASE_IMAGE_TAG is already loaded in the daemon under test" 764 } 765 766 767 # Inspect the pulled or loaded image to get the version directly 768 $ErrorActionPreference = "SilentlyContinue" 769 $dutimgVersion = $(&"$env:TEMP\binary\docker-$COMMITHASH" "-H=$($DASHH_CUT)" inspect "$($env:WINDOWS_BASE_IMAGE):$env:WINDOWS_BASE_IMAGE_TAG" --format "{{.OsVersion}}") 770 $ErrorActionPreference = "Stop" 771 Write-Host -ForegroundColor Green $("INFO: Version of $($env:WINDOWS_BASE_IMAGE):$env:WINDOWS_BASE_IMAGE_TAG is '"+$dutimgVersion+"'") 772 773 # Run the validation tests unless SKIP_VALIDATION_TESTS is defined. 774 if ($null -eq $env:SKIP_VALIDATION_TESTS) { 775 Write-Host -ForegroundColor Cyan "INFO: Running validation tests at $(Get-Date)..." 776 $ErrorActionPreference = "SilentlyContinue" 777 $Duration=$(Measure-Command { hack\make.ps1 -DCO -GoFormat -PkgImports | Out-Host }) 778 $ErrorActionPreference = "Stop" 779 if (-not($LastExitCode -eq 0)) { 780 Throw "ERROR: Validation tests failed" 781 } 782 Write-Host -ForegroundColor Green "INFO: Validation tests ended at $(Get-Date). Duration`:$Duration" 783 } else { 784 Write-Host -ForegroundColor Magenta "WARN: Skipping validation tests" 785 } 786 787 # Run the unit tests inside a container unless SKIP_UNIT_TESTS is defined 788 if ($null -eq $env:SKIP_UNIT_TESTS) { 789 $ContainerNameForUnitTests = $COMMITHASH + "_UnitTests" 790 Write-Host -ForegroundColor Cyan "INFO: Running unit tests at $(Get-Date)..." 791 $ErrorActionPreference = "SilentlyContinue" 792 $Duration=$(Measure-Command {docker run --name $ContainerNameForUnitTests -e DOCKER_GITCOMMIT=$COMMITHASH$CommitUnsupported docker hack\make.ps1 -TestUnit | Out-Host }) 793 $TestRunExitCode = $LastExitCode 794 $ErrorActionPreference = "Stop" 795 796 # Saving where jenkins will take a look at..... 797 New-Item -Force -ItemType Directory bundles | Out-Null 798 $unitTestsContPath="$ContainerNameForUnitTests`:c`:\gopath\src\github.com\docker\docker\bundles" 799 $JunitExpectedContFilePath = "$unitTestsContPath\junit-report-unit-tests.xml" 800 docker cp $JunitExpectedContFilePath "bundles" 801 if (-not($LastExitCode -eq 0)) { 802 Throw "ERROR: Failed to docker cp the unit tests report ($JunitExpectedContFilePath) to bundles" 803 } 804 805 if (Test-Path "bundles\junit-report-unit-tests.xml") { 806 Write-Host -ForegroundColor Magenta "INFO: Unit tests results(bundles\junit-report-unit-tests.xml) exist. pwd=$pwd" 807 } else { 808 Write-Host -ForegroundColor Magenta "ERROR: Unit tests results(bundles\junit-report-unit-tests.xml) do not exist. pwd=$pwd" 809 } 810 811 if (-not($TestRunExitCode -eq 0)) { 812 Throw "ERROR: Unit tests failed" 813 } 814 Write-Host -ForegroundColor Green "INFO: Unit tests ended at $(Get-Date). Duration`:$Duration" 815 } else { 816 Write-Host -ForegroundColor Magenta "WARN: Skipping unit tests" 817 } 818 819 # Add the Windows busybox image. Needed for WCOW integration tests 820 if ($null -eq $env:SKIP_INTEGRATION_TESTS) { 821 Write-Host -ForegroundColor Green "INFO: Building busybox" 822 $ErrorActionPreference = "SilentlyContinue" 823 $(& "$env:TEMP\binary\docker-$COMMITHASH" "-H=$($DASHH_CUT)" build -t busybox --build-arg WINDOWS_BASE_IMAGE --build-arg WINDOWS_BASE_IMAGE_TAG "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker\contrib\busybox\" | Out-Host) 824 $ErrorActionPreference = "Stop" 825 if (-not($LastExitCode -eq 0)) { 826 Throw "ERROR: Failed to build busybox image" 827 } 828 829 Write-Host -ForegroundColor Green "INFO: Docker images of the daemon under test" 830 Write-Host 831 $ErrorActionPreference = "SilentlyContinue" 832 & "$env:TEMP\binary\docker-$COMMITHASH" "-H=$($DASHH_CUT)" images 833 $ErrorActionPreference = "Stop" 834 if ($LastExitCode -ne 0) { 835 Throw "ERROR: The daemon under test does not appear to be running." 836 } 837 Write-Host 838 } 839 840 # Run the WCOW integration tests unless SKIP_INTEGRATION_TESTS is defined 841 if ($null -eq $env:SKIP_INTEGRATION_TESTS) { 842 Write-Host -ForegroundColor Cyan "INFO: Running integration tests at $(Get-Date)..." 843 $ErrorActionPreference = "SilentlyContinue" 844 845 # Location of the daemon under test. 846 $env:OrigDOCKER_HOST="$env:DOCKER_HOST" 847 848 #https://blogs.technet.microsoft.com/heyscriptingguy/2011/09/20/solve-problems-with-external-command-lines-in-powershell/ is useful to see tokenising 849 $jsonFilePath = "..\\bundles\\go-test-report-intcli-tests.json" 850 $xmlFilePath = "..\\bundles\\junit-report-intcli-tests.xml" 851 $c = "gotestsum --format=standard-verbose --jsonfile=$jsonFilePath --junitfile=$xmlFilePath -- " 852 if ($null -ne $env:INTEGRATION_TEST_NAME) { # Makes is quicker for debugging to be able to run only a subset of the integration tests 853 $c += "`"-test.run`" " 854 $c += "`"$env:INTEGRATION_TEST_NAME`" " 855 Write-Host -ForegroundColor Magenta "WARN: Only running integration tests matching $env:INTEGRATION_TEST_NAME" 856 } 857 $c += "`"-tags`" " + "`"autogen`" " 858 $c += "`"-test.timeout`" " + "`"200m`" " 859 860 if ($null -ne $env:INTEGRATION_IN_CONTAINER) { 861 Write-Host -ForegroundColor Green "INFO: Integration tests being run inside a container" 862 # Note we talk back through the containers gateway address 863 # And the ridiculous lengths we have to go to get the default gateway address... (GetNetIPConfiguration doesn't work in nanoserver) 864 # I just could not get the escaping to work in a single command, so output $c to a file and run that in the container instead... 865 # Not the prettiest, but it works. 866 $c | Out-File -Force "$env:TEMP\binary\runIntegrationCLI.ps1" 867 $Duration= $(Measure-Command { & docker run ` 868 --rm ` 869 -e c=$c ` 870 --workdir "c`:\gopath\src\github.com\docker\docker\integration-cli" ` 871 -v "$env:TEMP\binary`:c:\target" ` 872 docker ` 873 "`$env`:PATH`='c`:\target;'+`$env:PATH`; `$env:DOCKER_HOST`='tcp`://'+(ipconfig | select -last 1).Substring(39)+'`:2357'; c:\target\runIntegrationCLI.ps1" | Out-Host } ) 874 } else { 875 $env:DOCKER_HOST=$DASHH_CUT 876 $env:GO111MODULE="off" 877 Write-Host -ForegroundColor Green "INFO: DOCKER_HOST at $DASHH_CUT" 878 879 $ErrorActionPreference = "SilentlyContinue" 880 Write-Host -ForegroundColor Cyan "INFO: Integration API tests being run from the host:" 881 $start=(Get-Date); Invoke-Expression ".\hack\make.ps1 -TestIntegration"; $Duration=New-Timespan -Start $start -End (Get-Date) 882 $IntTestsRunResult = $LastExitCode 883 $ErrorActionPreference = "Stop" 884 if (-not($IntTestsRunResult -eq 0)) { 885 Throw "ERROR: Integration API tests failed at $(Get-Date). Duration`:$Duration" 886 } 887 888 $ErrorActionPreference = "SilentlyContinue" 889 Write-Host -ForegroundColor Green "INFO: Integration CLI tests being run from the host:" 890 Write-Host -ForegroundColor Green "INFO: $c" 891 Set-Location "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker\integration-cli" 892 # Explicit to not use measure-command otherwise don't get output as it goes 893 $start=(Get-Date); Invoke-Expression $c; $Duration=New-Timespan -Start $start -End (Get-Date) 894 } 895 $ErrorActionPreference = "Stop" 896 if (-not($LastExitCode -eq 0)) { 897 Throw "ERROR: Integration CLI tests failed at $(Get-Date). Duration`:$Duration" 898 } 899 Write-Host -ForegroundColor Green "INFO: Integration tests ended at $(Get-Date). Duration`:$Duration" 900 } else { 901 Write-Host -ForegroundColor Magenta "WARN: Skipping integration tests" 902 } 903 904 # Docker info now to get counts (after or if jjh/containercounts is merged) 905 if ($daemonStarted -eq 1) { 906 Write-Host -ForegroundColor Green "INFO: Docker info of the daemon under test at end of run" 907 Write-Host 908 $ErrorActionPreference = "SilentlyContinue" 909 & "$env:TEMP\binary\docker-$COMMITHASH" "-H=$($DASHH_CUT)" info 910 $ErrorActionPreference = "Stop" 911 if ($LastExitCode -ne 0) { 912 Throw "ERROR: The daemon under test does not appear to be running." 913 } 914 Write-Host 915 } 916 917 # Stop the daemon under test 918 if (Test-Path "$env:TEMP\docker.pid") { 919 $p=Get-Content "$env:TEMP\docker.pid" -raw 920 if (($null -ne $p) -and ($daemonStarted -eq 1)) { 921 Write-Host -ForegroundColor green "INFO: Stopping daemon under test" 922 taskkill -f -t -pid $p 923 #sleep 5 924 } 925 Remove-Item "$env:TEMP\docker.pid" -force -ErrorAction SilentlyContinue 926 } 927 928 # Stop the tail process (if started) 929 if ($null -ne $tail) { 930 Write-Host -ForegroundColor green "INFO: Stop tailing logs of the daemon under tests" 931 Stop-Process -InputObject $tail -Force 932 } 933 934 Write-Host -ForegroundColor Green "INFO: executeCI.ps1 Completed successfully at $(Get-Date)." 935 } 936 Catch [Exception] { 937 $FinallyColour="Red" 938 Write-Host -ForegroundColor Red ("`r`n`r`nERROR: Failed '$_' at $(Get-Date)") 939 Write-Host -ForegroundColor Red ($_.InvocationInfo.PositionMessage) 940 Write-Host "`n`n" 941 942 # Exit to ensure Jenkins captures it. Don't do this in the ISE or interactive Powershell - they will catch the Throw onwards. 943 if ( ([bool]([Environment]::GetCommandLineArgs() -Like '*-NonInteractive*')) -and ` 944 ([bool]([Environment]::GetCommandLineArgs() -NotLike "*Powershell_ISE.exe*"))) { 945 exit 1 946 } 947 Throw $_ 948 } 949 Finally { 950 $ErrorActionPreference="SilentlyContinue" 951 $global:ProgressPreference=$origProgressPreference 952 Write-Host -ForegroundColor Green "INFO: Tidying up at end of run" 953 954 # Restore the path 955 if ($null -ne $origPath) { $env:PATH=$origPath } 956 957 # Restore the DOCKER_HOST 958 if ($null -ne $origDOCKER_HOST) { $env:DOCKER_HOST=$origDOCKER_HOST } 959 960 # Restore the GOROOT and GOPATH variables 961 if ($null -ne $origGOROOT) { $env:GOROOT=$origGOROOT } 962 if ($null -ne $origGOPATH) { $env:GOPATH=$origGOPATH } 963 964 # Dump the daemon log. This will include any possible panic stack in the .err. 965 if (($daemonStarted -eq 1) -and ($(Get-Item "$env:TEMP\dut.err").Length -gt 0)) { 966 Write-Host -ForegroundColor Cyan "----------- DAEMON LOG ------------" 967 Get-Content "$env:TEMP\dut.err" -ErrorAction SilentlyContinue | Write-Host -ForegroundColor Cyan 968 Write-Host -ForegroundColor Cyan "----------- END DAEMON LOG --------" 969 } 970 971 # Save the daemon under test log 972 if ($daemonStarted -eq 1) { 973 Set-Location "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker" 974 Write-Host -ForegroundColor Green "INFO: Saving daemon under test log ($env:TEMP\dut.out) to bundles\CIDUT.out" 975 Copy-Item "$env:TEMP\dut.out" "bundles\CIDUT.out" -Force -ErrorAction SilentlyContinue 976 Write-Host -ForegroundColor Green "INFO: Saving daemon under test log ($env:TEMP\dut.err) to bundles\CIDUT.err" 977 Copy-Item "$env:TEMP\dut.err" "bundles\CIDUT.err" -Force -ErrorAction SilentlyContinue 978 979 Write-Host -ForegroundColor Green "INFO: Saving containerd logs to bundles" 980 if (Test-Path -Path "$env:TEMP\containerd.out") { 981 Copy-Item "$env:TEMP\containerd.out" "bundles\containerd.out" -Force -ErrorAction SilentlyContinue 982 Copy-Item "$env:TEMP\containerd.err" "bundles\containerd.err" -Force -ErrorAction SilentlyContinue 983 } else { 984 "" | Out-File -FilePath "bundles\containerd.out" 985 "" | Out-File -FilePath "bundles\containerd.err" 986 } 987 } 988 989 Set-Location "$env:SOURCES_DRIVE\$env:SOURCES_SUBDIR" -ErrorAction SilentlyContinue 990 Nuke-Everything 991 992 # Restore the TEMP path 993 if ($null -ne $TEMPORIG) { $env:TEMP="$TEMPORIG" } 994 995 $Dur=New-TimeSpan -Start $StartTime -End $(Get-Date) 996 Write-Host -ForegroundColor $FinallyColour "`nINFO: executeCI.ps1 exiting at $(date). Duration $dur`n" 997 }