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