From 73e5951b2e3c13ce84781d28b08cdc1958fb6224 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 22 Dec 2018 20:32:31 +0100 Subject: [PATCH 1/7] PowerShell: fix mixed tabs/spaces Fixed some mixed/tabs spaces for indentation, and used tabs for auto-generated Go code. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 0f8b616c0c8f959ac4b29f29a8716b8cb7ea28fd) Signed-off-by: Sebastiaan van Stijn --- hack/ci/windows.ps1 | 44 +++++++++++++++++++-------------------- hack/make/.go-autogen.ps1 | 12 +++++------ 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/hack/ci/windows.ps1 b/hack/ci/windows.ps1 index b0e64d3ae2..f77e65e128 100644 --- a/hack/ci/windows.ps1 +++ b/hack/ci/windows.ps1 @@ -318,28 +318,26 @@ Try { # Try the internal azure CI image version or Microsoft internal corpnet where the base image is already pre-prepared on the disk, # either through Invoke-DockerCI or, in the case of Azure CI servers, baked into the VHD at the same location. if (Test-Path $("$env:SOURCES_DRIVE`:\baseimages\"+$ControlDaemonBaseImage+".tar")) { - - # An optimization for CI servers to copy it to the D: drive which is an SSD. - if ($env:SOURCES_DRIVE -ne $env:TESTRUN_DRIVE) { - $readBaseFrom=$env:TESTRUN_DRIVE - if (!(Test-Path "$env:TESTRUN_DRIVE`:\baseimages")) { - New-Item "$env:TESTRUN_DRIVE`:\baseimages" -type directory | Out-Null - } - if (!(Test-Path "$env:TESTRUN_DRIVE`:\baseimages\windowsservercore.tar")) { - if (Test-Path "$env:SOURCES_DRIVE`:\baseimages\windowsservercore.tar") { - Write-Host -ForegroundColor Green "INFO: Optimisation - copying $env:SOURCES_DRIVE`:\baseimages\windowsservercore.tar to $env:TESTRUN_DRIVE`:\baseimages" - Copy-Item "$env:SOURCES_DRIVE`:\baseimages\windowsservercore.tar" "$env:TESTRUN_DRIVE`:\baseimages" - } - } - if (!(Test-Path "$env:TESTRUN_DRIVE`:\baseimages\nanoserver.tar")) { - if (Test-Path "$env:SOURCES_DRIVE`:\baseimages\nanoserver.tar") { - Write-Host -ForegroundColor Green "INFO: Optimisation - copying $env:SOURCES_DRIVE`:\baseimages\nanoserver.tar to $env:TESTRUN_DRIVE`:\baseimages" - Copy-Item "$env:SOURCES_DRIVE`:\baseimages\nanoserver.tar" "$env:TESTRUN_DRIVE`:\baseimages" - } - } - $readBaseFrom=$env:TESTRUN_DRIVE - } - + # An optimization for CI servers to copy it to the D: drive which is an SSD. + if ($env:SOURCES_DRIVE -ne $env:TESTRUN_DRIVE) { + $readBaseFrom=$env:TESTRUN_DRIVE + if (!(Test-Path "$env:TESTRUN_DRIVE`:\baseimages")) { + New-Item "$env:TESTRUN_DRIVE`:\baseimages" -type directory | Out-Null + } + if (!(Test-Path "$env:TESTRUN_DRIVE`:\baseimages\windowsservercore.tar")) { + if (Test-Path "$env:SOURCES_DRIVE`:\baseimages\windowsservercore.tar") { + Write-Host -ForegroundColor Green "INFO: Optimisation - copying $env:SOURCES_DRIVE`:\baseimages\windowsservercore.tar to $env:TESTRUN_DRIVE`:\baseimages" + Copy-Item "$env:SOURCES_DRIVE`:\baseimages\windowsservercore.tar" "$env:TESTRUN_DRIVE`:\baseimages" + } + } + if (!(Test-Path "$env:TESTRUN_DRIVE`:\baseimages\nanoserver.tar")) { + if (Test-Path "$env:SOURCES_DRIVE`:\baseimages\nanoserver.tar") { + Write-Host -ForegroundColor Green "INFO: Optimisation - copying $env:SOURCES_DRIVE`:\baseimages\nanoserver.tar to $env:TESTRUN_DRIVE`:\baseimages" + Copy-Item "$env:SOURCES_DRIVE`:\baseimages\nanoserver.tar" "$env:TESTRUN_DRIVE`:\baseimages" + } + } + $readBaseFrom=$env:TESTRUN_DRIVE + } Write-Host -ForegroundColor Green "INFO: Loading"$ControlDaemonBaseImage".tar from disk. This may take some time..." $ErrorActionPreference = "SilentlyContinue" docker load -i $("$readBaseFrom`:\baseimages\"+$ControlDaemonBaseImage+".tar") @@ -962,7 +960,7 @@ Catch [Exception] { } Finally { $ErrorActionPreference="SilentlyContinue" - $global:ProgressPreference=$origProgressPreference + $global:ProgressPreference=$origProgressPreference Write-Host -ForegroundColor Green "INFO: Tidying up at end of run" # Restore the path diff --git a/hack/make/.go-autogen.ps1 b/hack/make/.go-autogen.ps1 index cd4d87c557..a24bee668b 100644 --- a/hack/make/.go-autogen.ps1 +++ b/hack/make/.go-autogen.ps1 @@ -43,12 +43,12 @@ package dockerversion // Default build-time variable for library-import. // This file is overridden on build with build-time informations. const ( - GitCommit string = "'+$CommitString+'" - Version string = "'+$DockerVersion+'" - BuildTime string = "'+$buildDateTime+'" - PlatformName string = "'+$Platform+'" - ProductName string = "'+$Product+'" - DefaultProductLicense string = "'+$DefaultProductLicense+'" + GitCommit string = "'+$CommitString+'" + Version string = "'+$DockerVersion+'" + BuildTime string = "'+$buildDateTime+'" + PlatformName string = "'+$Platform+'" + ProductName string = "'+$Product+'" + DefaultProductLicense string = "'+$DefaultProductLicense+'" ) // AUTOGENERATED FILE; see hack\make\.go-autogen.ps1 From 31d99be110c0a19ffc631355bac58bf8a7b068e1 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 22 Dec 2018 20:40:36 +0100 Subject: [PATCH 2/7] PowerShell: move $null to left-hand for comparisons see https://rencore.com/blog/powershell-null-comparison/ Signed-off-by: Sebastiaan van Stijn (cherry picked from commit b394d25f03ee6ab615e45aad35e6396efd7d7fea) Signed-off-by: Sebastiaan van Stijn --- hack/ci/windows.ps1 | 80 ++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/hack/ci/windows.ps1 b/hack/ci/windows.ps1 index f77e65e128..ff6459543a 100644 --- a/hack/ci/windows.ps1 +++ b/hack/ci/windows.ps1 @@ -125,7 +125,7 @@ Function Nuke-Everything { try { - if ($env:SKIP_ALL_CLEANUP -eq $null) { + if ($null -eq $env:SKIP_ALL_CLEANUP) { Write-Host -ForegroundColor green "INFO: Nuke-Everything..." $containerCount = ($(docker ps -aq | Measure-Object -line).Lines) if (-not $LastExitCode -eq 0) { @@ -160,11 +160,11 @@ Function Nuke-Everything { Stop-Process -Id $p -Force -ErrorAction SilentlyContinue } - if ($pidFile -ne $Null) { + if ($null -ne $pidFile) { Write-Host "INFO: Tidying pidfile $pidfile" if (Test-Path $pidFile) { $p=Get-Content $pidFile -raw - if ($p -ne $null){ + if ($null -ne $p){ Write-Host -ForegroundColor green "INFO: Stopping possible daemon pid $p" taskkill -f -t -pid $p } @@ -190,7 +190,7 @@ Function Nuke-Everything { # Delete the directory using our dangerous utility unless told not to if (Test-Path "$env:TESTRUN_DRIVE`:\$env:TESTRUN_SUBDIR") { - if (($env:SKIP_ZAP_DUT -ne $null) -or ($env:SKIP_ALL_CLEANUP -eq $null)) { + if (($null -ne $env:SKIP_ZAP_DUT) -or ($null -eq $env:SKIP_ALL_CLEANUP)) { Write-Host -ForegroundColor Green "INFO: Nuking $env:TESTRUN_DRIVE`:\$env:TESTRUN_SUBDIR" docker-ci-zap "-folder=$env:TESTRUN_DRIVE`:\$env:TESTRUN_SUBDIR" } else { @@ -256,25 +256,25 @@ Try { Get-ChildItem Env: | Out-String # PR - if (-not ($env:PR -eq $Null)) { echo "INFO: PR#$env:PR (https://github.com/docker/docker/pull/$env:PR)" } + if (-not ($null -eq $env:PR)) { echo "INFO: PR#$env:PR (https://github.com/docker/docker/pull/$env:PR)" } # Make sure docker is installed - if ((Get-Command "docker" -ErrorAction SilentlyContinue) -eq $null) { Throw "ERROR: docker is not installed or not found on path" } + if ($null -eq (Get-Command "docker" -ErrorAction SilentlyContinue)) { Throw "ERROR: docker is not installed or not found on path" } # Make sure docker-ci-zap is installed - if ((Get-Command "docker-ci-zap" -ErrorAction SilentlyContinue) -eq $null) { Throw "ERROR: docker-ci-zap is not installed or not found on path" } + if ($null -eq (Get-Command "docker-ci-zap" -ErrorAction SilentlyContinue)) { Throw "ERROR: docker-ci-zap is not installed or not found on path" } # Make sure SOURCES_DRIVE is set - if ($env:SOURCES_DRIVE -eq $Null) { Throw "ERROR: Environment variable SOURCES_DRIVE is not set" } + if ($null -eq $env:SOURCES_DRIVE) { Throw "ERROR: Environment variable SOURCES_DRIVE is not set" } # Make sure TESTRUN_DRIVE is set - if ($env:TESTRUN_DRIVE -eq $Null) { Throw "ERROR: Environment variable TESTRUN_DRIVE is not set" } + if ($null -eq $env:TESTRUN_DRIVE) { Throw "ERROR: Environment variable TESTRUN_DRIVE is not set" } # Make sure SOURCES_SUBDIR is set - if ($env:SOURCES_SUBDIR -eq $Null) { Throw "ERROR: Environment variable SOURCES_SUBDIR is not set" } + if ($null -eq $env:SOURCES_SUBDIR) { Throw "ERROR: Environment variable SOURCES_SUBDIR is not set" } # Make sure TESTRUN_SUBDIR is set - if ($env:TESTRUN_SUBDIR -eq $Null) { Throw "ERROR: Environment variable TESTRUN_SUBDIR is not set" } + if ($null -eq $env:TESTRUN_SUBDIR) { Throw "ERROR: Environment variable TESTRUN_SUBDIR is not set" } # SOURCES_DRIVE\SOURCES_SUBDIR must be a directory and exist 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" } @@ -420,7 +420,7 @@ Try { New-Item -ItemType Directory "$env:TEMP\localappdata" -ErrorAction SilentlyContinue | Out-Null New-Item -ItemType Directory "$env:TEMP\binary" -ErrorAction SilentlyContinue | Out-Null New-Item -ItemType Directory "$env:TEMP\installer" -ErrorAction SilentlyContinue | Out-Null - if ($env:SKIP_COPY_GO -eq $null) { + if ($null -eq $env:SKIP_COPY_GO) { # Wipe the previous version of GO - we're going to get it out of the image if (Test-Path "$env:TEMP\go") { Remove-Item "$env:TEMP\go" -Recurse -Force -ErrorAction SilentlyContinue | Out-Null } New-Item -ItemType Directory "$env:TEMP\go" -ErrorAction SilentlyContinue | Out-Null @@ -435,15 +435,15 @@ Try { # As of go 1.11, Dockerfile changed to be in the format like "FROM golang:1.11.0 AS base". # If a version number ends with .0 (as in 1.11.0, a convention used in golang docker # image versions), it needs to be removed (i.e. "1.11.0" becomes "1.11"). - if ($goVersionDockerfile -eq $Null) { + if ($null -eq $goVersionDockerfile) { $goVersionDockerfile=$(Get-Content ".\Dockerfile" | Select-String "^FROM golang:") - if ($goVersionDockerfile -ne $Null) { + if ($null -ne $goVersionDockerfile) { $goVersionDockerfile = $goVersionDockerfile.ToString().Split(" ")[1].Split(":")[1] -replace '\.0$','' } } else { $goVersionDockerfile = $goVersionDockerfile.ToString().Split(" ")[2] } - if ($goVersionDockerfile -eq $Null) { + if ($null -eq $goVersionDockerfile) { Throw "ERROR: Failed to extract golang version from Dockerfile" } Write-Host -ForegroundColor Green "INFO: Validating GOLang consistency in Dockerfile.windows..." @@ -452,7 +452,7 @@ Try { } # Build the image - if ($env:SKIP_IMAGE_BUILD -eq $null) { + if ($null -eq $env:SKIP_IMAGE_BUILD) { Write-Host -ForegroundColor Cyan "`n`nINFO: Building the image from Dockerfile.windows at $(Get-Date)..." Write-Host $ErrorActionPreference = "SilentlyContinue" @@ -478,7 +478,7 @@ Try { } # Build the binary in a container unless asked to skip it. - if ($env:SKIP_BINARY_BUILD -eq $null) { + if ($null -eq $env:SKIP_BINARY_BUILD) { Write-Host -ForegroundColor Cyan "`n`nINFO: Building the test binaries at $(Get-Date)..." $ErrorActionPreference = "SilentlyContinue" docker rm -f $COMMITHASH 2>&1 | Out-Null @@ -530,7 +530,7 @@ Try { # Grab the golang installer out of the built image. That way, we know we are consistent once extracted and paths set, # so there's no need to re-deploy on account of an upgrade to the version of GO being used in docker. - if ($env:SKIP_COPY_GO -eq $null) { + if ($null -eq $env:SKIP_COPY_GO) { Write-Host -ForegroundColor Green "INFO: Copying the golang package from the container to $env:TEMP\installer\go.zip..." docker cp "$COMMITHASH`:c`:\go.zip" $env:TEMP\installer\ if (-not($LastExitCode -eq 0)) { @@ -593,7 +593,7 @@ Try { New-Item -ItemType Directory $env:TEMP\daemon -ErrorAction SilentlyContinue | Out-Null # In LCOW mode, for now we need to set an environment variable before starting the daemon under test - if (($env:LCOW_MODE -ne $Null) -or ($env:LCOW_BASIC_MODE -ne $Null)) { + if (($null -ne $env:LCOW_MODE) -or ($null -ne $env:LCOW_BASIC_MODE)) { $env:LCOW_SUPPORTED=1 } @@ -606,13 +606,13 @@ Try { $daemonStarted=1 # In LCOW mode, turn off that variable - if (($env:LCOW_MODE -ne $Null) -or ($env:LCOW_BASIC_MODE -ne $Null)) { + if (($null -ne $env:LCOW_MODE) -or ($null -ne $env:LCOW_BASIC_MODE)) { $env:LCOW_SUPPORTED="" } # Start tailing the daemon under test if the command is installed - if ((Get-Command "tail" -ErrorAction SilentlyContinue) -ne $null) { + if ($null -ne (Get-Command "tail" -ErrorAction SilentlyContinue)) { $tail = start-process "tail" -ArgumentList "-f $env:TEMP\dut.out" -ErrorAction SilentlyContinue } @@ -674,11 +674,11 @@ Try { Write-Host # Don't need Windows images when in LCOW mode. - if (($env:LCOW_MODE -eq $Null) -and ($env:LCOW_BASIC_MODE -eq $Null)) { + if (($null -eq $env:LCOW_MODE) -and ($null -eq $env:LCOW_BASIC_MODE)) { # Default to windowsservercore for the base image used for the tests. The "docker" image # and the control daemon use microsoft/windowsservercore regardless. This is *JUST* for the tests. - if ($env:WINDOWS_BASE_IMAGE -eq $Null) { + if ($null -eq $env:WINDOWS_BASE_IMAGE) { $env:WINDOWS_BASE_IMAGE="microsoft/windowsservercore" } @@ -727,7 +727,7 @@ Try { } # Run the validation tests unless SKIP_VALIDATION_TESTS is defined. - if ($env:SKIP_VALIDATION_TESTS -eq $null) { + if ($null -eq $env:SKIP_VALIDATION_TESTS) { Write-Host -ForegroundColor Cyan "INFO: Running validation tests at $(Get-Date)..." $ErrorActionPreference = "SilentlyContinue" $Duration=$(Measure-Command { hack\make.ps1 -DCO -GoFormat -PkgImports | Out-Host }) @@ -742,8 +742,8 @@ Try { # Note the unit tests won't work in LCOW mode as I turned off loading the base images above. # Run the unit tests inside a container unless SKIP_UNIT_TESTS is defined - if (($env:LCOW_MODE -eq $Null) -and ($env:LCOW_BASIC_MODE -eq $Null)) { - if ($env:SKIP_UNIT_TESTS -eq $null) { + if (($null -eq $env:LCOW_MODE) -and ($null -eq $env:LCOW_BASIC_MODE)) { + if ($null -eq $env:SKIP_UNIT_TESTS) { Write-Host -ForegroundColor Cyan "INFO: Running unit tests at $(Get-Date)..." $ErrorActionPreference = "SilentlyContinue" $Duration=$(Measure-Command {docker run -e DOCKER_GITCOMMIT=$COMMITHASH$CommitUnsupported docker hack\make.ps1 -TestUnit | Out-Host }) @@ -758,8 +758,8 @@ Try { } # Add the Windows busybox image. Needed for WCOW integration tests - if (($env:LCOW_MODE -eq $Null) -and ($env:LCOW_BASIC_MODE -eq $Null)) { - if ($env:SKIP_INTEGRATION_TESTS -eq $null) { + if (($null -eq $env:LCOW_MODE) -and ($null -eq $env:LCOW_BASIC_MODE)) { + if ($null -eq $env:SKIP_INTEGRATION_TESTS) { $ErrorActionPreference = "SilentlyContinue" # Build it regardless while switching between nanoserver and windowsservercore #$bbCount = $(& "$env:TEMP\binary\docker-$COMMITHASH" "-H=$($DASHH_CUT)" images | Select-String "busybox" | Measure-Object -line).Lines @@ -799,8 +799,8 @@ Try { } # Run the WCOW integration tests unless SKIP_INTEGRATION_TESTS is defined - if (($env:LCOW_MODE -eq $Null) -and ($env:LCOW_BASIC_MODE -eq $Null)) { - if ($env:SKIP_INTEGRATION_TESTS -eq $null) { + if (($null -eq $env:LCOW_MODE) -and ($null -eq $env:LCOW_BASIC_MODE)) { + if ($null -eq $env:SKIP_INTEGRATION_TESTS) { Write-Host -ForegroundColor Cyan "INFO: Running integration tests at $(Get-Date)..." $ErrorActionPreference = "SilentlyContinue" @@ -810,7 +810,7 @@ Try { #https://blogs.technet.microsoft.com/heyscriptingguy/2011/09/20/solve-problems-with-external-command-lines-in-powershell/ is useful to see tokenising $c = "go test " $c += "`"-check.v`" " - if ($env:INTEGRATION_TEST_NAME -ne $null) { # Makes is quicker for debugging to be able to run only a subset of the integration tests + if ($null -ne $env:INTEGRATION_TEST_NAME) { # Makes is quicker for debugging to be able to run only a subset of the integration tests $c += "`"-check.f`" " $c += "`"$env:INTEGRATION_TEST_NAME`" " Write-Host -ForegroundColor Magenta "WARN: Only running integration tests matching $env:INTEGRATION_TEST_NAME" @@ -819,7 +819,7 @@ Try { $c += "`"-check.timeout`" " + "`"10m`" " $c += "`"-test.timeout`" " + "`"200m`" " - if ($env:INTEGRATION_IN_CONTAINER -ne $null) { + if ($null -ne $env:INTEGRATION_IN_CONTAINER) { Write-Host -ForegroundColor Green "INFO: Integration tests being run inside a container" # Note we talk back through the containers gateway address # And the ridiculous lengths we have to go to to get the default gateway address... (GetNetIPConfiguration doesn't work in nanoserver) @@ -853,7 +853,7 @@ Try { } } else { # The LCOW version of the tests here - if ($env:SKIP_INTEGRATION_TESTS -eq $null) { + if ($null -eq $env:SKIP_INTEGRATION_TESTS) { Write-Host -ForegroundColor Cyan "INFO: Running LCOW tests at $(Get-Date)..." $ErrorActionPreference = "SilentlyContinue" @@ -868,7 +868,7 @@ Try { # Force to use the test binaries, not the host ones. $env:PATH="$env:TEMP\binary;$env:PATH;" - if ($env:LCOW_BASIC_MODE -ne $null) { + if ($null -ne $env:LCOW_BASIC_MODE) { $wc = New-Object net.webclient try { Write-Host -ForegroundColor green "INFO: Downloading latest execution script..." @@ -891,7 +891,7 @@ Try { #https://blogs.technet.microsoft.com/heyscriptingguy/2011/09/20/solve-problems-with-external-command-lines-in-powershell/ is useful to see tokenising $c = "go test " $c += "`"-check.v`" " - if ($env:INTEGRATION_TEST_NAME -ne $null) { # Makes is quicker for debugging to be able to run only a subset of the integration tests + if ($null -ne $env:INTEGRATION_TEST_NAME) { # Makes is quicker for debugging to be able to run only a subset of the integration tests $c += "`"-check.f`" " $c += "`"$env:INTEGRATION_TEST_NAME`" " Write-Host -ForegroundColor Magenta "WARN: Only running LCOW integration tests matching $env:INTEGRATION_TEST_NAME" @@ -935,7 +935,7 @@ Try { # Stop the daemon under test if (Test-Path "$env:TEMP\docker.pid") { $p=Get-Content "$env:TEMP\docker.pid" -raw - if (($p -ne $null) -and ($daemonStarted -eq 1)) { + if (($null -ne $p) -and ($daemonStarted -eq 1)) { Write-Host -ForegroundColor green "INFO: Stopping daemon under test" taskkill -f -t -pid $p #sleep 5 @@ -964,14 +964,14 @@ Finally { Write-Host -ForegroundColor Green "INFO: Tidying up at end of run" # Restore the path - if ($origPath -ne $null) { $env:PATH=$origPath } + if ($null -ne $origPath) { $env:PATH=$origPath } # Restore the DOCKER_HOST - if ($origDOCKER_HOST -ne $null) { $env:DOCKER_HOST=$origDOCKER_HOST } + if ($null -ne $origDOCKER_HOST) { $env:DOCKER_HOST=$origDOCKER_HOST } # Restore the GOROOT and GOPATH variables - if ($origGOROOT -ne $null) { $env:GOROOT=$origGOROOT } - if ($origGOPATH -ne $null) { $env:GOPATH=$origGOPATH } + if ($null -ne $origGOROOT) { $env:GOROOT=$origGOROOT } + if ($null -ne $origGOPATH) { $env:GOPATH=$origGOPATH } # Dump the daemon log if asked to if ($daemonStarted -eq 1) { From 4f0911d9122bf73d7efb90a50444cd6e52a09a96 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 22 Dec 2018 20:44:41 +0100 Subject: [PATCH 3/7] PowerShell: remove aliases, use their real commands instead This patch replaces PowerShell aliases for their real commands, see https://blogs.technet.microsoft.com/heyscriptingguy/2012/04/21/when-you-should-use-powershell-aliases/ For example; - use `Get-Location` instead of `pwd` - use `Set-Location` instead of `cd` - use `ForEach-Object` instead of the `%` shorthand - use `Write-Output` instead of `echo` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 6130c89ccec5262c25b91b3226a6ef2240bfde3b) Signed-off-by: Sebastiaan van Stijn --- hack/ci/windows.ps1 | 14 +++++++------- hack/make.ps1 | 10 +++++----- hack/make/.go-autogen.ps1 | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/hack/ci/windows.ps1 b/hack/ci/windows.ps1 index ff6459543a..4443019584 100644 --- a/hack/ci/windows.ps1 +++ b/hack/ci/windows.ps1 @@ -256,7 +256,7 @@ Try { Get-ChildItem Env: | Out-String # PR - if (-not ($null -eq $env:PR)) { echo "INFO: PR#$env:PR (https://github.com/docker/docker/pull/$env:PR)" } + if (-not ($null -eq $env:PR)) { Write-Output "INFO: PR#$env:PR (https://github.com/docker/docker/pull/$env:PR)" } # Make sure docker is installed if ($null -eq (Get-Command "docker" -ErrorAction SilentlyContinue)) { Throw "ERROR: docker is not installed or not found on path" } @@ -291,12 +291,12 @@ Try { } # Make sure we start at the root of the sources - cd "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker" - Write-Host -ForegroundColor Green "INFO: Running in $(pwd)" + Set-Location "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker" + Write-Host -ForegroundColor Green "INFO: Running in $(Get-Location)" # Make sure we are in repo if (-not (Test-Path -PathType Leaf -Path ".\Dockerfile.windows")) { - Throw "$(pwd) does not contain Dockerfile.windows!" + Throw "$(Get-Location) does not contain Dockerfile.windows!" } Write-Host -ForegroundColor Green "INFO: docker/docker repository was found" @@ -835,7 +835,7 @@ Try { "`$env`:PATH`='c`:\target;'+`$env:PATH`; `$env:DOCKER_HOST`='tcp`://'+(ipconfig | select -last 1).Substring(39)+'`:2357'; c:\target\runIntegrationCLI.ps1" | Out-Host } ) } else { Write-Host -ForegroundColor Green "INFO: Integration tests being run from the host:" - cd "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker\integration-cli" + Set-Location "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker\integration-cli" $env:DOCKER_HOST=$DASHH_CUT $env:PATH="$env:TEMP\binary;$env:PATH;" # Force to use the test binaries, not the host ones. Write-Host -ForegroundColor Green "INFO: $c" @@ -901,7 +901,7 @@ Try { $c += "`"-test.timeout`" " + "`"200m`" " Write-Host -ForegroundColor Green "INFO: LCOW Integration tests being run from the host:" - cd "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker\integration-cli" + Set-Location "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker\integration-cli" Write-Host -ForegroundColor Green "INFO: $c" Write-Host -ForegroundColor Green "INFO: DOCKER_HOST at $DASHH_CUT" # Explicit to not use measure-command otherwise don't get output as it goes @@ -988,7 +988,7 @@ Finally { Copy-Item "$env:TEMP\dut.err" "$TEMPORIG\CIDUT.log" -Force -ErrorAction SilentlyContinue } - cd "$env:SOURCES_DRIVE\$env:SOURCES_SUBDIR" -ErrorAction SilentlyContinue + Set-Location "$env:SOURCES_DRIVE\$env:SOURCES_SUBDIR" -ErrorAction SilentlyContinue Nuke-Everything $Dur=New-TimeSpan -Start $StartTime -End $(Get-Date) Write-Host -ForegroundColor $FinallyColour "`nINFO: executeCI.ps1 exiting at $(date). Duration $dur`n" diff --git a/hack/make.ps1 b/hack/make.ps1 index f15f8ef225..6221e364d6 100644 --- a/hack/make.ps1 +++ b/hack/make.ps1 @@ -218,7 +218,7 @@ Function Validate-DCO($headCommit, $upstreamCommit) { if ($LASTEXITCODE -ne 0) { Throw "Failed git log --format" } $commits = $($commits -split '\s+' -match '\S') $badCommits=@() - $commits | %{ + $commits | ForEach-Object{ # Skip commits with no content such as merge commits etc if ($(git log -1 --format=format: --name-status $_).Length -gt 0) { # Ignore exit code on next call - always process regardless @@ -244,7 +244,7 @@ Function Validate-PkgImports($headCommit, $upstreamCommit) { # Get a list of go source-code files which have changed under pkg\. Ignore exit code on next call - always process regardless $files=@(); $files = Invoke-Expression "git diff $upstreamCommit...$headCommit --diff-filter=ACMR --name-only -- `'pkg\*.go`'" - $badFiles=@(); $files | %{ + $badFiles=@(); $files | ForEach-Object{ $file=$_ # For the current changed file, get its list of dependencies, sorted and uniqued. $imports = Invoke-Expression "go list -e -f `'{{ .Deps }}`' $file" @@ -255,13 +255,13 @@ Function Validate-PkgImports($headCommit, $upstreamCommit) { -NotMatch "^github.com/docker/docker/vendor" ` -Match "^github.com/docker/docker" ` -Replace "`n", "" - $imports | % { $badFiles+="$file imports $_`n" } + $imports | ForEach-Object{ $badFiles+="$file imports $_`n" } } if ($badFiles.Length -eq 0) { Write-Host 'Congratulations! ".\pkg\*.go" is safely isolated from internal code.' } else { $e = "`nThese files import internal code: (either directly or indirectly)`n" - $badFiles | %{ $e+=" - $_"} + $badFiles | ForEach-Object{ $e+=" - $_"} Throw $e } } @@ -297,7 +297,7 @@ Function Validate-GoFormat($headCommit, $upstreamCommit) { Write-Host 'Congratulations! All Go source files are properly formatted.' } else { $e = "`nThese files are not properly gofmt`'d:`n" - $badFiles | %{ $e+=" - $_`n"} + $badFiles | ForEach-Object{ $e+=" - $_`n"} $e+= "`nPlease reformat the above files using `"gofmt -s -w`" and commit the result." Throw $e } diff --git a/hack/make/.go-autogen.ps1 b/hack/make/.go-autogen.ps1 index a24bee668b..8334b11fef 100644 --- a/hack/make/.go-autogen.ps1 +++ b/hack/make/.go-autogen.ps1 @@ -55,7 +55,7 @@ const ( ' # Write the file without BOM - $outputFile="$(pwd)\dockerversion\version_autogen.go" + $outputFile="$(Get-Location)\dockerversion\version_autogen.go" if (Test-Path $outputFile) { Remove-Item $outputFile } [System.IO.File]::WriteAllText($outputFile, $fileContents, (New-Object System.Text.UTF8Encoding($False))) From 431dc221e3a22b9f97d691dffcc815a5998c0a34 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 22 Dec 2018 21:29:26 +0100 Subject: [PATCH 4/7] PowerShell: Go-version check; only select the first match Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 755d3057ab8917c37e33bb5aa60c37cbe51285dd) Signed-off-by: Sebastiaan van Stijn --- hack/ci/windows.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hack/ci/windows.ps1 b/hack/ci/windows.ps1 index 4443019584..9dde9501e8 100644 --- a/hack/ci/windows.ps1 +++ b/hack/ci/windows.ps1 @@ -429,14 +429,14 @@ Try { Write-Host -ForegroundColor Green "INFO: Location for testing is $env:TEMP" # CI Integrity check - ensure Dockerfile.windows and Dockerfile go versions match - $goVersionDockerfileWindows=$(Get-Content ".\Dockerfile.windows" | Select-String "^ENV GO_VERSION").ToString().Replace("ENV GO_VERSION=","").Replace("\","").Replace("``","").Trim() - $goVersionDockerfile=$(Get-Content ".\Dockerfile" | Select-String "^ENV GO_VERSION") + $goVersionDockerfileWindows=$(Get-Content ".\Dockerfile.windows" | Select-String "^ENV GO_VERSION" | Select-object -First 1).ToString().Replace("ENV GO_VERSION=","").Replace("\","").Replace("``","").Trim() + $goVersionDockerfile=$(Get-Content ".\Dockerfile" | Select-String "^ENV GO_VERSION" | Select-object -First 1) # As of go 1.11, Dockerfile changed to be in the format like "FROM golang:1.11.0 AS base". # If a version number ends with .0 (as in 1.11.0, a convention used in golang docker # image versions), it needs to be removed (i.e. "1.11.0" becomes "1.11"). if ($null -eq $goVersionDockerfile) { - $goVersionDockerfile=$(Get-Content ".\Dockerfile" | Select-String "^FROM golang:") + $goVersionDockerfile=$(Get-Content ".\Dockerfile" | Select-String "^FROM golang:" | Select-object -First 1) if ($null -ne $goVersionDockerfile) { $goVersionDockerfile = $goVersionDockerfile.ToString().Split(" ")[1].Split(":")[1] -replace '\.0$','' } From 74fe2c044f56e58356e9f598e5b08d94e676bbd4 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 22 Dec 2018 22:49:33 +0100 Subject: [PATCH 5/7] PowerShell: fix "Nuke-Everything" failing to remove images I noticed this error in CI: ``` 20:37:25 INFO: Non-base image count on control daemon to delete is 9 20:37:25 "docker rmi" requires at least 1 argument. 20:37:25 See 'docker rmi --help'. 20:37:25 20:37:25 Usage: docker rmi [OPTIONS] IMAGE [IMAGE...] 20:37:25 20:37:25 Remove one or more images ``` Which indicated that the PowerShell script managed to find images to delete, but not actually passing the images to `docker rmi`. The reason for this failing was that the script attempted to convert the collection/array to a string, which produces; ```powershell Write-Output $(docker images --format "{{.Repository}}:{{.ID}}" | ` >> select-string -NotMatch "windowsservercore" | ` >> select-string -NotMatch "nanoserver" | ` >> select-string -NotMatch "docker" ` >> ).ToString() System.Object[] ``` Which, when trying to split by the chosen separator (`:`), will return the same; ```powershell Write-Output "System.Object[]".Split(":")[0] ``` This patch: - Adds an intermediate variable (`$allImages`) to make the code better readable - Switches the separator to `#`, to prevent breaking on images pulled from a repository with a port in its name (`myregistry:5000/my/image`) - Switches to use a comma-separated list for `-NotMatch` (for readability) Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 5580b79813d3a5d2a7b83bcf1607839a5b0f468d) Signed-off-by: Sebastiaan van Stijn --- hack/ci/windows.ps1 | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/hack/ci/windows.ps1 b/hack/ci/windows.ps1 index 9dde9501e8..9a49b52f31 100644 --- a/hack/ci/windows.ps1 +++ b/hack/ci/windows.ps1 @@ -136,18 +136,14 @@ Function Nuke-Everything { if ($(docker ps -aq | Measure-Object -line).Lines -gt 0) { docker rm -f $(docker ps -aq) } - $imageCount=($(docker images --format "{{.Repository}}:{{.ID}}" | ` - select-string -NotMatch "windowsservercore" | ` - select-string -NotMatch "nanoserver" | ` - select-string -NotMatch "docker" | ` - Measure-Object -line).Lines) + + $allImages = $(docker images --format "{{.Repository}}#{{.ID}}") + $toRemove = ($allImages | Select-String -NotMatch "windowsservercore","nanoserver","docker") + $imageCount = ($toRemove | Measure-Object -line).Lines + if ($imageCount -gt 0) { Write-Host -Foregroundcolor green "INFO: Non-base image count on control daemon to delete is $imageCount" - docker rmi -f ` - $(docker images --format "{{.Repository}}:{{.ID}}" | ` - select-string -NotMatch "windowsservercore" | ` - select-string -NotMatch "nanoserver" | ` - select-string -NotMatch "docker").ToString().Split(":")[1] + docker rmi -f ($toRemove | Foreach-Object { $_.ToString().Split("#")[1] }) } } else { Write-Host -ForegroundColor Magenta "WARN: Skipping cleanup of images and containers" From d5a0ffa172a012e388d5b31edf332acc264b39b6 Mon Sep 17 00:00:00 2001 From: John Howard Date: Tue, 5 Feb 2019 09:17:40 -0800 Subject: [PATCH 6/7] Windows CI: Dump possible panic log Signed-off-by: John Howard (cherry picked from commit bc80e8df3e6300354305f81a4c0c48b855a1776b) Signed-off-by: Sebastiaan van Stijn --- hack/ci/windows.ps1 | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/hack/ci/windows.ps1 b/hack/ci/windows.ps1 index 9a49b52f31..290a0143c3 100644 --- a/hack/ci/windows.ps1 +++ b/hack/ci/windows.ps1 @@ -105,7 +105,7 @@ if ($env:BUILD_TAG -match "-WoW") { $env:LCOW_MODE="" } # ------------------------------------------------------------------------------------------- -$SCRIPT_VER="28-Aug-2018 09:33 PDT" +$SCRIPT_VER="05-Feb-2019 09:03 PDT" $FinallyColour="Cyan" #$env:DOCKER_DUT_DEBUG="yes" # Comment out to not be in debug mode @@ -625,7 +625,6 @@ Try { $tries-- if ($tries -le 0) { - $DumpDaemonLog=1 Throw "ERROR: Failed to get a response from the daemon under test" } Write-Host -NoNewline "." @@ -641,7 +640,6 @@ Try { $ErrorActionPreference = "Stop" if ($LastExitCode -ne 0) { Throw "ERROR: The daemon under test does not appear to be running." - $DumpDaemonLog=1 } Write-Host @@ -653,7 +651,6 @@ Try { $ErrorActionPreference = "Stop" if ($LastExitCode -ne 0) { Throw "ERROR: The daemon under test does not appear to be running." - $DumpDaemonLog=1 } Write-Host @@ -665,7 +662,6 @@ Try { $ErrorActionPreference = "Stop" if ($LastExitCode -ne 0) { Throw "ERROR: The daemon under test does not appear to be running." - $DumpDaemonLog=1 } Write-Host @@ -788,7 +784,6 @@ Try { $ErrorActionPreference = "Stop" if ($LastExitCode -ne 0) { Throw "ERROR: The daemon under test does not appear to be running." - $DumpDaemonLog=1 } Write-Host } @@ -923,7 +918,6 @@ Try { $ErrorActionPreference = "Stop" if ($LastExitCode -ne 0) { Throw "ERROR: The daemon under test does not appear to be running." - $DumpDaemonLog=1 } Write-Host } @@ -969,19 +963,19 @@ Finally { if ($null -ne $origGOROOT) { $env:GOROOT=$origGOROOT } if ($null -ne $origGOPATH) { $env:GOPATH=$origGOPATH } - # Dump the daemon log if asked to - if ($daemonStarted -eq 1) { - if ($dumpDaemonLog -eq 1) { - Write-Host -ForegroundColor Cyan "----------- DAEMON LOG ------------" - Get-Content "$env:TEMP\dut.err" -ErrorAction SilentlyContinue | Write-Host -ForegroundColor Cyan - Write-Host -ForegroundColor Cyan "----------- END DAEMON LOG --------" - } + # Dump the daemon log. This will include any possible panic stack in the .err. + if (($daemonStarted -eq 1) -and ($(Get-Item "$env:TEMP\dut.err").Length -gt 0)) { + Write-Host -ForegroundColor Cyan "----------- DAEMON LOG ------------" + Get-Content "$env:TEMP\dut.err" -ErrorAction SilentlyContinue | Write-Host -ForegroundColor Cyan + Write-Host -ForegroundColor Cyan "----------- END DAEMON LOG --------" } # Save the daemon under test log if ($daemonStarted -eq 1) { - Write-Host -ForegroundColor Green "INFO: Saving daemon under test log ($env:TEMP\dut.err) to $TEMPORIG\CIDUT.log" - Copy-Item "$env:TEMP\dut.err" "$TEMPORIG\CIDUT.log" -Force -ErrorAction SilentlyContinue + Write-Host -ForegroundColor Green "INFO: Saving daemon under test log ($env:TEMP\dut.out) to $TEMPORIG\CIDUT.out" + Copy-Item "$env:TEMP\dut.out" "$TEMPORIG\CIDUT.out" -Force -ErrorAction SilentlyContinue + Write-Host -ForegroundColor Green "INFO: Saving daemon under test log ($env:TEMP\dut.err) to $TEMPORIG\CIDUT.err" + Copy-Item "$env:TEMP\dut.err" "$TEMPORIG\CIDUT.err" -Force -ErrorAction SilentlyContinue } Set-Location "$env:SOURCES_DRIVE\$env:SOURCES_SUBDIR" -ErrorAction SilentlyContinue From 74f9183764f7ce1c54223288addfcdd901c86a27 Mon Sep 17 00:00:00 2001 From: xichengliudui <1693291525@qq.com> Date: Tue, 26 Feb 2019 13:50:04 -0500 Subject: [PATCH 7/7] Delete duplicate words MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit update pull request Signed-off-by: “xichengliudui” <“liuduidui@beyondcent.com”> (cherry picked from commit 1d62807db3bcbb3d793a5bb396d17aa62a59537c) Signed-off-by: Sebastiaan van Stijn --- client/client.go | 2 +- hack/ci/windows.ps1 | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client/client.go b/client/client.go index 5031502acf..3b548ae3c7 100644 --- a/client/client.go +++ b/client/client.go @@ -90,7 +90,7 @@ type Client struct { // If the request is non-GET return `ErrRedirect`. Otherwise use the last response. // // Go 1.8 changes behavior for HTTP redirects (specifically 301, 307, and 308) in the client . -// The Docker client (and by extension docker API client) can be made to to send a request +// The Docker client (and by extension docker API client) can be made to send a request // like POST /containers//start where what would normally be in the name section of the URL is empty. // This triggers an HTTP 301 from the daemon. // In go 1.8 this 301 will be converted to a GET request, and ends up getting a 404 from the daemon. diff --git a/hack/ci/windows.ps1 b/hack/ci/windows.ps1 index 290a0143c3..c2c937f4cb 100644 --- a/hack/ci/windows.ps1 +++ b/hack/ci/windows.ps1 @@ -374,7 +374,7 @@ Try { Write-Host -ForegroundColor Green "---------------------------------------------------------------------------" Write-Host -ForegroundColor Green " Failed to get a response from the control daemon. It may be down." Write-Host -ForegroundColor Green " Try re-running this CI job, or ask on #docker-maintainers on docker slack" - Write-Host -ForegroundColor Green " to see if the the daemon is running. Also check the service configuration." + Write-Host -ForegroundColor Green " to see if the daemon is running. Also check the service configuration." Write-Host -ForegroundColor Green " DOCKER_HOST is set to $DOCKER_HOST." Write-Host -ForegroundColor Green "---------------------------------------------------------------------------" Write-Host @@ -554,7 +554,7 @@ Try { $env:GOROOT="$env:TEMP\go" Write-Host -ForegroundColor Green "INFO: $(go version)" - # Work out the the -H parameter for the daemon under test (DASHH_DUT) and client under test (DASHH_CUT) + # Work out the -H parameter for the daemon under test (DASHH_DUT) and client under test (DASHH_CUT) #$DASHH_DUT="npipe:////./pipe/$COMMITHASH" # Can't do remote named pipe #$ip = (resolve-dnsname $env:COMPUTERNAME -type A -NoHostsFile -LlmnrNetbiosOnly).IPAddress # Useful to tie down $DASHH_CUT="tcp://127.0.0.1`:2357" # Not a typo for 2375! @@ -813,7 +813,7 @@ Try { if ($null -ne $env:INTEGRATION_IN_CONTAINER) { Write-Host -ForegroundColor Green "INFO: Integration tests being run inside a container" # Note we talk back through the containers gateway address - # And the ridiculous lengths we have to go to to get the default gateway address... (GetNetIPConfiguration doesn't work in nanoserver) + # And the ridiculous lengths we have to go to get the default gateway address... (GetNetIPConfiguration doesn't work in nanoserver) # 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... # Not the prettiest, but it works. $c | Out-File -Force "$env:TEMP\binary\runIntegrationCLI.ps1"