From 5bafd4306697f00d175ca04f345fca8efe422204 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Tue, 14 Nov 2017 19:18:21 -0800 Subject: [PATCH 1/7] add required module for docker image --- .../dockerInstall.psm1 | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 tools/releaseBuild/Images/microsoft_powershell_windowsservercore/dockerInstall.psm1 diff --git a/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/dockerInstall.psm1 b/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/dockerInstall.psm1 new file mode 100644 index 00000000000..f551dbcd7e8 --- /dev/null +++ b/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/dockerInstall.psm1 @@ -0,0 +1,111 @@ +function Install-ChocolateyPackage +{ + param( + [Parameter(Mandatory=$true)] + [string] + $PackageName, + + [Parameter(Mandatory=$false)] + [string] + $Executable, + + [string[]] + $ArgumentList, + + [switch] + $Cleanup, + + [int] + $ExecutionTimeout = 2700, + + [string] + $Version + ) + + if(-not(Get-Command -name Choco -ErrorAction SilentlyContinue)) + { + Write-Verbose "Installing Chocolatey provider..." -Verbose + Invoke-WebRequest https://chocolatey.org/install.ps1 -UseBasicParsing | Invoke-Expression + } + + Write-Verbose "Installing $PackageName..." -Verbose + $extraCommand = @() + if($Version) + { + $extraCommand += '--version', $version + } + choco install -y $PackageName --no-progress --execution-timeout=$ExecutionTimeout $ArgumentList $extraCommands + + if($executable) + { + Write-Verbose "Verifing $Executable is in path..." -Verbose + $exeSource = $null + $exeSource = Get-ChildItem -path "$env:ProgramFiles\$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName + if(!$exeSource) + { + Write-Verbose "Falling back to x86 program files..." -Verbose + $exeSource = Get-ChildItem -path "${env:ProgramFiles(x86)}\$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName + } + + if(!$exeSource) + { + Write-Verbose "Falling back to chocolatey..." -Verbose + $exeSource = Get-ChildItem -path "$env:ProgramData\chocolatey\$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName + } + + if(!$exeSource) + { + Write-Verbose "Falling back to the root of the drive..." -Verbose + $exeSource = Get-ChildItem -path "/$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName + } + + if(!$exeSource) + { + throw "$Executable not found" + } + + $exePath = Split-Path -Path $exeSource + Append-Path -path $exePath + } + + if($Cleanup.IsPresent) + { + Remove-Folder -Folder "$env:temp\chocolatey" + } +} + +function Append-Path +{ + param + ( + $path + ) + $machinePathString = [System.Environment]::GetEnvironmentVariable('path',[System.EnvironmentVariableTarget]::Machine) + $machinePath = $machinePathString -split ';' + + if($machinePath -inotcontains $path) + { + $newPath = "$machinePathString;$path" + Write-Verbose "Adding $path to path..." -Verbose + [System.Environment]::SetEnvironmentVariable('path',$newPath,[System.EnvironmentVariableTarget]::Machine) + Write-Verbose "Added $path to path." -Verbose + } + else + { + Write-Verbose "$path already in path." -Verbose + } +} + +function Remove-Folder +{ + param( + [string] + $Folder + ) + + Write-Verbose "Cleaning up $Folder..." -Verbose + $filter = Join-Path -Path $Folder -ChildPath * + [int]$measuredCleanupMB = (Get-ChildItem $filter -Recurse | Measure-Object -Property Length -Sum).Sum / 1MB + Remove-Item -recurse -force $filter -ErrorAction SilentlyContinue + Write-Verbose "Cleaned up $measuredCleanupMB MB from $Folder" -Verbose +} From bfcb0669836ccd5441d5c33520900a0c2eb03d67 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Tue, 14 Nov 2017 21:25:03 -0800 Subject: [PATCH 2/7] update windows build DockerFile to be based on microsoft/windowsservercore --- .../DockerFile | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/DockerFile b/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/DockerFile index 883d4c34d0f..0dadbb77187 100644 --- a/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/DockerFile +++ b/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/DockerFile @@ -1,11 +1,30 @@ # escape=` #0.3.6 (no powershell 6) -FROM travisez13/microsoft.windowsservercore.build-tools:latest +FROM microsoft/windowsservercore LABEL maintainer='PowerShell Team ' LABEL description="This Dockerfile for Windows Server Core with git installed via chocolatey." -SHELL ["powershell"] +SHELL ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-command"] +# Install Git, NuGet and cMake +# Git installs to C:\Program Files\Git +# nuget installs to C:\ProgramData\chocolatey\bin\NuGet.exe +# Cmake installs to C:\Program Files\CMake\ +COPY dockerInstall.psm1 containerFiles/dockerInstall.psm1 +RUN Import-Module ./containerFiles/dockerInstall.psm1; ` + Install-ChocolateyPackage -PackageName git -Executable git.exe; ` + Install-ChocolateyPackage -PackageName nuget.commandline -Executable nuget.exe; ` + Install-ChocolateyPackage -PackageName cmake.install -Executable cmake.exe -Cleanup + +# Install WIX +ADD https://github.com/wixtoolset/wix3/releases/download/wix311rtm/wix311-binaries.zip /wix.zip +COPY wix.psm1 containerFiles/wix.psm1 +RUN Import-Module ./containerFiles/wix.psm1; ` + Install-WixZip -zipPath \wix.Zip COPY PowerShellPackage.ps1 / -ENTRYPOINT ["powershell"] +ADD https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.ps1 \install-powershell.ps1 +RUN new-item -Path 'C:\Program Files\PowerShell\latest' -ItemType Directory; ` + \install-powershell.ps1 -AddToPath -Destination 'C:\Program Files\PowerShell\latest' + +ENTRYPOINT ["C:\\Program Files\\PowerShell\\latest\\pwsh.exe", "-command"] \ No newline at end of file From 2d19e70776a6a28aa21940530266dc44f8839756 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Tue, 14 Nov 2017 22:14:43 -0800 Subject: [PATCH 3/7] add wix install helper --- .../wix.psm1 | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tools/releaseBuild/Images/microsoft_powershell_windowsservercore/wix.psm1 diff --git a/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/wix.psm1 b/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/wix.psm1 new file mode 100644 index 00000000000..26e09f29830 --- /dev/null +++ b/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/wix.psm1 @@ -0,0 +1,24 @@ +Import-Module "$PSScriptRoot\dockerInstall.psm1" + +function Install-WixZip +{ + param($zipPath) + + $targetRoot = "${env:ProgramFiles(x86)}\WiX Toolset xcopy" + $binPath = Join-Path -Path $targetRoot -ChildPath 'bin' + if(-not (Test-Path $targetRoot)) + { + $null = New-Item -Path $targetRoot -ItemType Directory + } + Write-Verbose "Expanding $zipPath to $binPath ..." -Verbose + Expand-Archive -Path $zipPath -DestinationPath $binPath + $docExpandPath = Join-Path -Path $binPath -ChildPath 'doc' + $sdkExpandPath = Join-Path -Path $binPath -ChildPath 'sdk' + $docTargetPath = Join-Path -Path $targetRoot -ChildPath 'doc' + $sdkTargetPath = Join-Path -Path $targetRoot -ChildPath 'sdk' + Write-Verbose "Fixing folder structure ..." -Verbose + Move-Item -Path $docExpandPath -Destination $docTargetPath + Move-Item -Path $sdkExpandPath -Destination $sdkTargetPath + Append-Path -path $binPath + Write-Verbose "Done installing WIX!" +} From 9a7481a0ec6d59cc930249518e3df84410058675 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Tue, 14 Nov 2017 20:25:28 -0800 Subject: [PATCH 4/7] tell docker based build to include Dependant module --- tools/releaseBuild/build.json | 36 +++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/tools/releaseBuild/build.json b/tools/releaseBuild/build.json index c69471575df..7d118122a73 100644 --- a/tools/releaseBuild/build.json +++ b/tools/releaseBuild/build.json @@ -9,7 +9,11 @@ "3968m" ], "DockerFile": ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\DockerFile", - "AdditionalContextFiles" :[ ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1"], + "AdditionalContextFiles" :[ + ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1", + ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\wix.psm1", + ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\dockerInstall.psm1" + ], "DockerImageName": "ps-winsrvcore", "BinaryBucket": "release" }, @@ -22,7 +26,11 @@ "3968m" ], "DockerFile": ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\DockerFile", - "AdditionalContextFiles" :[ ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1"], + "AdditionalContextFiles" :[ + ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1", + ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\wix.psm1", + ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\dockerInstall.psm1" + ], "DockerImageName": "ps-winsrvcore", "BinaryBucket": "release" }, @@ -35,7 +43,11 @@ "3968m" ], "DockerFile": ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\DockerFile", - "AdditionalContextFiles" :[ ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1"], + "AdditionalContextFiles" :[ + ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1", + ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\wix.psm1", + ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\dockerInstall.psm1" + ], "DockerImageName": "ps-winsrvcore", "BinaryBucket": "symbols", "BinariesExpected": 1, @@ -50,7 +62,11 @@ "3968m" ], "DockerFile": ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\DockerFile", - "AdditionalContextFiles" :[ ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1"], + "AdditionalContextFiles" :[ + ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1", + ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\wix.psm1", + ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\dockerInstall.psm1" + ], "DockerImageName": "ps-winsrvcore", "BinaryBucket": "symbols", "BinariesExpected": 1, @@ -65,7 +81,11 @@ "3968m" ], "DockerFile": ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\DockerFile", - "AdditionalContextFiles" :[ ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1"], + "AdditionalContextFiles" :[ + ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1", + ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\wix.psm1", + ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\dockerInstall.psm1" + ], "DockerImageName": "ps-winsrvcore", "BinaryBucket": "signed", "BinariesExpected": 2 @@ -79,7 +99,11 @@ "3968m" ], "DockerFile": ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\DockerFile", - "AdditionalContextFiles" :[ ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1"], + "AdditionalContextFiles" :[ + ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1", + ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\wix.psm1", + ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\dockerInstall.psm1" + ], "DockerImageName": "ps-winsrvcore", "BinaryBucket": "signed", "BinariesExpected": 2 From 63c054d7251d17347c927c676f46002e7c1423b7 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Wed, 15 Nov 2017 13:07:00 -0800 Subject: [PATCH 5/7] remove unneeded assignment to null --- tools/releaseBuild/generatePackgeSigning.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/releaseBuild/generatePackgeSigning.ps1 b/tools/releaseBuild/generatePackgeSigning.ps1 index b7177ed43b5..bb02231f2e8 100644 --- a/tools/releaseBuild/generatePackgeSigning.ps1 +++ b/tools/releaseBuild/generatePackgeSigning.ps1 @@ -42,11 +42,11 @@ function New-FileElement if(Test-Path -Path $file) { $name = Split-Path -Leaf -Path $File - $null = $fileElement = $XmlDoc.CreateElement("file") + $fileElement = $XmlDoc.CreateElement("file") New-Attribute -Name 'src' -value $file -Element $fileElement New-Attribute -Name 'signType' -value $SignType -Element $fileElement New-Attribute -Name 'dest' -value "__OUTPATHROOT__\$name" -Element $fileElement - $null = $job.AppendChild($fileElement) + $null = $job.AppendChild($fileElement) } else { @@ -69,4 +69,4 @@ foreach($file in $AuthenticodeFiles) $signingXml.Save($path) $updateScriptPath = Join-Path -Path $PSScriptRoot -ChildPath 'updateSigning.ps1' -& $updateScriptPath -SigningXmlPath $path \ No newline at end of file +& $updateScriptPath -SigningXmlPath $path From db6c02fca13925552d3dafec028262dfced1934e Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Wed, 15 Nov 2017 18:36:30 -0800 Subject: [PATCH 6/7] Address PR feedback --- .../Images/microsoft_powershell_windowsservercore/DockerFile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/DockerFile b/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/DockerFile index 0dadbb77187..0aa0fe13213 100644 --- a/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/DockerFile +++ b/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/DockerFile @@ -12,8 +12,7 @@ SHELL ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-comma COPY dockerInstall.psm1 containerFiles/dockerInstall.psm1 RUN Import-Module ./containerFiles/dockerInstall.psm1; ` Install-ChocolateyPackage -PackageName git -Executable git.exe; ` - Install-ChocolateyPackage -PackageName nuget.commandline -Executable nuget.exe; ` - Install-ChocolateyPackage -PackageName cmake.install -Executable cmake.exe -Cleanup + Install-ChocolateyPackage -PackageName nuget.commandline -Executable nuget.exe -Cleanup # Install WIX ADD https://github.com/wixtoolset/wix3/releases/download/wix311rtm/wix311-binaries.zip /wix.zip @@ -27,4 +26,4 @@ ADD https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install RUN new-item -Path 'C:\Program Files\PowerShell\latest' -ItemType Directory; ` \install-powershell.ps1 -AddToPath -Destination 'C:\Program Files\PowerShell\latest' -ENTRYPOINT ["C:\\Program Files\\PowerShell\\latest\\pwsh.exe", "-command"] \ No newline at end of file +ENTRYPOINT ["C:\\Program Files\\PowerShell\\latest\\pwsh.exe", "-command"] From b64187a251290944300e9aa099909116f6617a60 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Tue, 28 Nov 2017 12:09:18 -0800 Subject: [PATCH 7/7] address PR comments --- .../microsoft_powershell_windowsservercore/DockerFile | 3 +-- .../dockerInstall.psm1 | 10 ++++++---- .../microsoft_powershell_windowsservercore/wix.psm1 | 8 +++----- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/DockerFile b/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/DockerFile index 0aa0fe13213..110d5bc4995 100644 --- a/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/DockerFile +++ b/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/DockerFile @@ -5,10 +5,9 @@ LABEL maintainer='PowerShell Team ' LABEL description="This Dockerfile for Windows Server Core with git installed via chocolatey." SHELL ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-command"] -# Install Git, NuGet and cMake +# Install Git, and NuGet # Git installs to C:\Program Files\Git # nuget installs to C:\ProgramData\chocolatey\bin\NuGet.exe -# Cmake installs to C:\Program Files\CMake\ COPY dockerInstall.psm1 containerFiles/dockerInstall.psm1 RUN Import-Module ./containerFiles/dockerInstall.psm1; ` Install-ChocolateyPackage -PackageName git -Executable git.exe; ` diff --git a/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/dockerInstall.psm1 b/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/dockerInstall.psm1 index f551dbcd7e8..3f54e2d6105 100644 --- a/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/dockerInstall.psm1 +++ b/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/dockerInstall.psm1 @@ -47,18 +47,20 @@ function Install-ChocolateyPackage $exeSource = Get-ChildItem -path "${env:ProgramFiles(x86)}\$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName } + # Don't search the chocolatey program data until more official locations have been searched if(!$exeSource) { Write-Verbose "Falling back to chocolatey..." -Verbose $exeSource = Get-ChildItem -path "$env:ProgramData\chocolatey\$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName } + # all obvious locations are exhausted, use brute force and search from the root of the filesystem if(!$exeSource) { Write-Verbose "Falling back to the root of the drive..." -Verbose $exeSource = Get-ChildItem -path "/$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName } - + if(!$exeSource) { throw "$Executable not found" @@ -90,10 +92,10 @@ function Append-Path [System.Environment]::SetEnvironmentVariable('path',$newPath,[System.EnvironmentVariableTarget]::Machine) Write-Verbose "Added $path to path." -Verbose } - else + else { Write-Verbose "$path already in path." -Verbose - } + } } function Remove-Folder @@ -107,5 +109,5 @@ function Remove-Folder $filter = Join-Path -Path $Folder -ChildPath * [int]$measuredCleanupMB = (Get-ChildItem $filter -Recurse | Measure-Object -Property Length -Sum).Sum / 1MB Remove-Item -recurse -force $filter -ErrorAction SilentlyContinue - Write-Verbose "Cleaned up $measuredCleanupMB MB from $Folder" -Verbose + Write-Verbose "Cleaned up $measuredCleanupMB MB from $Folder" -Verbose } diff --git a/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/wix.psm1 b/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/wix.psm1 index 26e09f29830..11da58df024 100644 --- a/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/wix.psm1 +++ b/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/wix.psm1 @@ -1,17 +1,15 @@ Import-Module "$PSScriptRoot\dockerInstall.psm1" +# Install using Wix Zip because the MSI requires an older version of dotnet +# which was large and unstable in docker function Install-WixZip { param($zipPath) $targetRoot = "${env:ProgramFiles(x86)}\WiX Toolset xcopy" $binPath = Join-Path -Path $targetRoot -ChildPath 'bin' - if(-not (Test-Path $targetRoot)) - { - $null = New-Item -Path $targetRoot -ItemType Directory - } Write-Verbose "Expanding $zipPath to $binPath ..." -Verbose - Expand-Archive -Path $zipPath -DestinationPath $binPath + Expand-Archive -Path $zipPath -DestinationPath $binPath -Force $docExpandPath = Join-Path -Path $binPath -ChildPath 'doc' $sdkExpandPath = Join-Path -Path $binPath -ChildPath 'sdk' $docTargetPath = Join-Path -Path $targetRoot -ChildPath 'doc'