From e97958f83af9f50f78ed732fc83c6e9af6c8e591 Mon Sep 17 00:00:00 2001 From: Jim Truher Date: Fri, 6 Apr 2018 17:51:54 -0700 Subject: [PATCH 1/4] First set of files for vsts build --- tools/releaseBuild/Image/DockerFile | 31 ++++++ tools/releaseBuild/Image/dockerInstall.psm1 | 114 ++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 tools/releaseBuild/Image/DockerFile create mode 100644 tools/releaseBuild/Image/dockerInstall.psm1 diff --git a/tools/releaseBuild/Image/DockerFile b/tools/releaseBuild/Image/DockerFile new file mode 100644 index 000000000..35bfbcaa8 --- /dev/null +++ b/tools/releaseBuild/Image/DockerFile @@ -0,0 +1,31 @@ +# escape=` +#0.3.6 (no powershell 6) +# FROM microsoft/windowsservercore +FROM microsoft/dotnet-framework:4.7.1 +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, and platyPS +# Git installs to C:\Program Files\Git +# nuget installs to C:\ProgramData\chocolatey\bin\NuGet.exe +COPY dockerInstall.psm1 containerFiles/dockerInstall.psm1 +RUN Import-Module PackageManagement; ` + Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force; ` + Import-Module ./containerFiles/dockerInstall.psm1; ` + Install-ChocolateyPackage -PackageName git -Executable git.exe; ` + Install-ChocolateyPackage -PackageName nuget.commandline -Executable nuget.exe -Cleanup; ` + Install-Module -Force -Name platyPS; ` + Invoke-WebRequest -Uri https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.ps1 -outfile C:/dotnet-install.ps1; ` + C:/dotnet-install.ps1 -Channel Release -Version 2.1.4; ` + Add-Path C:/Users/ContainerAdministrator/AppData/Local/Microsoft/dotnet; + +RUN Import-Module ./containerFiles/dockerInstall.psm1; ` + git clone https://Github.com/PowerShell/PSScriptAnalyzer; ` + Install-ChocolateyPackage -PackageName dotnet4.5; + +RUN Import-Module ./containerFiles/dockerInstall.psm1; ` + Install-ChocolateyPackage -PackageName netfx-4.5.1-devpack; + +ENTRYPOINT ["C:\\windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-command"] + diff --git a/tools/releaseBuild/Image/dockerInstall.psm1 b/tools/releaseBuild/Image/dockerInstall.psm1 new file mode 100644 index 000000000..24d1235d6 --- /dev/null +++ b/tools/releaseBuild/Image/dockerInstall.psm1 @@ -0,0 +1,114 @@ +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 + } + + # 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" + } + + $exePath = Split-Path -Path $exeSource + Add-Path -path $exePath + } + + if($Cleanup.IsPresent) + { + Remove-Folder -Folder "$env:temp\chocolatey" + } +} + +function Add-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 + $env:Path += ";$newPath" + } + 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 d5a830ff19749d250521080b1f270fbf19cc9719 Mon Sep 17 00:00:00 2001 From: Jim Truher Date: Tue, 24 Apr 2018 16:30:28 -0700 Subject: [PATCH 2/4] Added scripts for VSTS build Updated docker file and releasemaker module --- Utils/ReleaseMaker.psm1 | 4 +- tools/releaseBuild/Image/DockerFile | 5 +- tools/releaseBuild/Image/buildPSSA.ps1 | 4 ++ tools/releaseBuild/build.json | 15 +++++ tools/releaseBuild/signing.xml | 30 ++++++++++ tools/releaseBuild/updateSigning.ps1 | 37 +++++++++++++ tools/releaseBuild/vstsbuild.ps1 | 77 ++++++++++++++++++++++++++ 7 files changed, 169 insertions(+), 3 deletions(-) create mode 100644 tools/releaseBuild/Image/buildPSSA.ps1 create mode 100644 tools/releaseBuild/build.json create mode 100644 tools/releaseBuild/signing.xml create mode 100644 tools/releaseBuild/updateSigning.ps1 create mode 100644 tools/releaseBuild/vstsbuild.ps1 diff --git a/Utils/ReleaseMaker.psm1 b/Utils/ReleaseMaker.psm1 index 3c0d244b4..a5079e454 100644 --- a/Utils/ReleaseMaker.psm1 +++ b/Utils/ReleaseMaker.psm1 @@ -92,7 +92,7 @@ function New-ReleaseBuild Push-Location $solutionPath try { - remove-item out/ -recurse -force + if ( test-path out ) { remove-item out/ -recurse -force } .\buildCoreClr.ps1 -Framework net451 -Configuration Release -Build .\buildCoreClr.ps1 -Framework net451 -Configuration PSV3Release -Build .\buildCoreClr.ps1 -Framework netstandard2.0 -Configuration Release -Build @@ -196,4 +196,4 @@ function Set-ContentUtf8NoBom { } Export-ModuleMember -Function New-Release -Export-ModuleMember -Function New-ReleaseBuild \ No newline at end of file +Export-ModuleMember -Function New-ReleaseBuild diff --git a/tools/releaseBuild/Image/DockerFile b/tools/releaseBuild/Image/DockerFile index 35bfbcaa8..a5d59dc2a 100644 --- a/tools/releaseBuild/Image/DockerFile +++ b/tools/releaseBuild/Image/DockerFile @@ -10,6 +10,7 @@ SHELL ["C:\\windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-comma # Git installs to C:\Program Files\Git # nuget installs to C:\ProgramData\chocolatey\bin\NuGet.exe COPY dockerInstall.psm1 containerFiles/dockerInstall.psm1 + RUN Import-Module PackageManagement; ` Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force; ` Import-Module ./containerFiles/dockerInstall.psm1; ` @@ -21,11 +22,13 @@ RUN Import-Module PackageManagement; ` Add-Path C:/Users/ContainerAdministrator/AppData/Local/Microsoft/dotnet; RUN Import-Module ./containerFiles/dockerInstall.psm1; ` - git clone https://Github.com/PowerShell/PSScriptAnalyzer; ` +# git clone https://Github.com/PowerShell/PSScriptAnalyzer; ` Install-ChocolateyPackage -PackageName dotnet4.5; RUN Import-Module ./containerFiles/dockerInstall.psm1; ` Install-ChocolateyPackage -PackageName netfx-4.5.1-devpack; +COPY buildPSSA.ps1 containerFiles/buildPSSA.ps1 + ENTRYPOINT ["C:\\windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-command"] diff --git a/tools/releaseBuild/Image/buildPSSA.ps1 b/tools/releaseBuild/Image/buildPSSA.ps1 new file mode 100644 index 000000000..bb60eb2b5 --- /dev/null +++ b/tools/releaseBuild/Image/buildPSSA.ps1 @@ -0,0 +1,4 @@ +push-location C:/PSScriptAnalyzer +import-module C:/PSScriptAnalyzer/Utils/ReleaseMaker.psm1 +New-ReleaseBuild +Copy-Item -Recurse C:/PSScriptAnalyzer/out C:/ diff --git a/tools/releaseBuild/build.json b/tools/releaseBuild/build.json new file mode 100644 index 000000000..8d46f2e33 --- /dev/null +++ b/tools/releaseBuild/build.json @@ -0,0 +1,15 @@ +{ + "Windows": { + "Name": "win7-x64", + "RepoDestinationPath": "C:\\PSScriptAnalyzer", + "BuildCommand": "C:\\containerFiles\\buildPSSA.ps1", + "DockerFile": ".\\tools\\releaseBuild\\Image\\DockerFile", + "DockerImageName": "pssa", + "BinaryBucket": "release", + "PublishAsFolder": true, + "AdditionalContextFiles" : [ + ".\\tools\\releaseBuild\\Image\\buildPSSA.ps1", + ".\\tools\\releaseBuild\\Image\\dockerInstall.psm1" + ] + } +} diff --git a/tools/releaseBuild/signing.xml b/tools/releaseBuild/signing.xml new file mode 100644 index 000000000..6595f3e1e --- /dev/null +++ b/tools/releaseBuild/signing.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/releaseBuild/updateSigning.ps1 b/tools/releaseBuild/updateSigning.ps1 new file mode 100644 index 000000000..62f06c4f5 --- /dev/null +++ b/tools/releaseBuild/updateSigning.ps1 @@ -0,0 +1,37 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +param( + [string] $SigningXmlPath = (Join-Path -Path $PSScriptRoot -ChildPath 'signing.xml') +) +# Script for use in VSTS to update signing.xml + +# Parse the signing xml +$signingXml = [xml](Get-Content $signingXmlPath) + +# Get any variables to updating 'signType' in the XML +# Define a varabile named `SignType' in VSTS to updating that signing type +# Example: $env:AuthenticodeSignType='newvalue' +# will cause all files with the 'Authenticode' signtype to be updated with the 'newvalue' signtype +$signTypes = @{} +Get-ChildItem -Path env:/*SignType | ForEach-Object -Process { + $signType = $_.Name.ToUpperInvariant().Replace('SIGNTYPE','') + Write-Host "Found SigningType $signType with value $($_.value)" + $signTypes[$signType] = $_.Value +} + +# examine each job in the xml +$signingXml.SignConfigXML.job | ForEach-Object -Process { + # examine each file in the job + $_.file | ForEach-Object -Process { + # if the sign type is one of the variables we found, update it to the new value + $signType = $_.SignType.ToUpperInvariant() + if($signTypes.ContainsKey($signType)) + { + $newSignType = $signTypes[$signType] + Write-Host "Updating $($_.src) to $newSignType" + $_.signType = $newSignType + } + } +} + +$signingXml.Save($signingXmlPath) diff --git a/tools/releaseBuild/vstsbuild.ps1 b/tools/releaseBuild/vstsbuild.ps1 new file mode 100644 index 000000000..f7fa8b49b --- /dev/null +++ b/tools/releaseBuild/vstsbuild.ps1 @@ -0,0 +1,77 @@ +[cmdletbinding()] +param( + [Parameter(Mandatory=$true,Position=0)] + [ValidatePattern("^v\d+\.\d+\.\d+(-\w+(\.\d+)?)?$")] + [string]$ReleaseTag +) + +Begin +{ + $ErrorActionPreference = 'Stop' + + $gitBinFullPath = (Get-Command -Name git -CommandType Application).Path | Select-Object -First 1 + if ( ! $gitBinFullPath ) + { + throw "Git is missing! Install from 'https://git-scm.com/download/win'" + } + + # clone the release tools + $releaseToolsDirName = "PSRelease" + $releaseToolsLocation = Join-Path -Path $PSScriptRoot -ChildPath PSRelease + if ( Test-Path $releaseToolsLocation ) + { + Remove-Item -Force -Recurse -Path $releaseToolsLocation + } + & $gitBinFullPath clone -b master --quiet https://github.com/PowerShell/${releaseToolsDirName}.git $releaseToolsLocation + Import-Module "$releaseToolsLocation/vstsBuild" -Force + Import-Module "$releaseToolsLocation/dockerBasedBuild" -Force +} + +End { + + $AdditionalFiles = .{ + Join-Path $PSScriptRoot -child "Image/buildPSSA.ps1" + Join-Path $PSScriptRoot -child "Image/dockerInstall.psm1" + } + $buildPackageName = $null + + # defined if building in VSTS + if($env:BUILD_STAGINGDIRECTORY) + { + # Use artifact staging if running in VSTS + $destFolder = $env:BUILD_STAGINGDIRECTORY + } + else + { + # Use temp as destination if not running in VSTS + $destFolder = $env:temp + } + + $resolvedRepoRoot = (Resolve-Path (Join-Path -Path $PSScriptRoot -ChildPath "../../")).Path + + try + { + Write-Verbose "Starting build at $resolvedRepoRoot ..." -Verbose + Clear-VstsTaskState + + $buildParameters = @{ + ReleaseTag = $ReleaseTag + } + $buildArgs = @{ + RepoPath = $resolvedRepoRoot + BuildJsonPath = './tools/releaseBuild/build.json' + Parameters = $buildParameters + AdditionalFiles = $AdditionalFiles + Name = "win7-x64" + } + Invoke-Build @buildArgs + } + catch + { + Write-VstsError -Error $_ + } + finally{ + Write-VstsTaskState + exit 0 + } +} From 82ebc03d9731f9117869714014db22b7a651dc08 Mon Sep 17 00:00:00 2001 From: James Truher Date: Tue, 8 May 2018 14:13:55 -0700 Subject: [PATCH 3/4] Change vsts build script to be able to put built module anywhere based on _DockerVolume_ Remove a comment --- tools/releaseBuild/Image/DockerFile | 1 - tools/releaseBuild/Image/buildPSSA.ps1 | 3 ++- tools/releaseBuild/build.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/releaseBuild/Image/DockerFile b/tools/releaseBuild/Image/DockerFile index a5d59dc2a..d75542750 100644 --- a/tools/releaseBuild/Image/DockerFile +++ b/tools/releaseBuild/Image/DockerFile @@ -1,6 +1,5 @@ # escape=` #0.3.6 (no powershell 6) -# FROM microsoft/windowsservercore FROM microsoft/dotnet-framework:4.7.1 LABEL maintainer='PowerShell Team ' LABEL description="This Dockerfile for Windows Server Core with git installed via chocolatey." diff --git a/tools/releaseBuild/Image/buildPSSA.ps1 b/tools/releaseBuild/Image/buildPSSA.ps1 index bb60eb2b5..631aedb98 100644 --- a/tools/releaseBuild/Image/buildPSSA.ps1 +++ b/tools/releaseBuild/Image/buildPSSA.ps1 @@ -1,4 +1,5 @@ +param ( [string]$target ) push-location C:/PSScriptAnalyzer import-module C:/PSScriptAnalyzer/Utils/ReleaseMaker.psm1 New-ReleaseBuild -Copy-Item -Recurse C:/PSScriptAnalyzer/out C:/ +Copy-Item -Recurse C:/PSScriptAnalyzer/out/* ${target} diff --git a/tools/releaseBuild/build.json b/tools/releaseBuild/build.json index 8d46f2e33..731a9da91 100644 --- a/tools/releaseBuild/build.json +++ b/tools/releaseBuild/build.json @@ -2,7 +2,7 @@ "Windows": { "Name": "win7-x64", "RepoDestinationPath": "C:\\PSScriptAnalyzer", - "BuildCommand": "C:\\containerFiles\\buildPSSA.ps1", + "BuildCommand": "C:\\containerFiles\\buildPSSA.ps1 -target _DockerVolume_", "DockerFile": ".\\tools\\releaseBuild\\Image\\DockerFile", "DockerImageName": "pssa", "BinaryBucket": "release", From db5dffb9465f11bfaf056b37a475444ddb01304a Mon Sep 17 00:00:00 2001 From: Jim Truher Date: Tue, 8 May 2018 15:52:41 -0700 Subject: [PATCH 4/4] Revert "Change vsts build script to be able to put built module anywhere based on _DockerVolume_" This reverts commit 82ebc03d9731f9117869714014db22b7a651dc08. --- tools/releaseBuild/Image/DockerFile | 1 + tools/releaseBuild/Image/buildPSSA.ps1 | 3 +-- tools/releaseBuild/build.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/releaseBuild/Image/DockerFile b/tools/releaseBuild/Image/DockerFile index d75542750..a5d59dc2a 100644 --- a/tools/releaseBuild/Image/DockerFile +++ b/tools/releaseBuild/Image/DockerFile @@ -1,5 +1,6 @@ # escape=` #0.3.6 (no powershell 6) +# FROM microsoft/windowsservercore FROM microsoft/dotnet-framework:4.7.1 LABEL maintainer='PowerShell Team ' LABEL description="This Dockerfile for Windows Server Core with git installed via chocolatey." diff --git a/tools/releaseBuild/Image/buildPSSA.ps1 b/tools/releaseBuild/Image/buildPSSA.ps1 index 631aedb98..bb60eb2b5 100644 --- a/tools/releaseBuild/Image/buildPSSA.ps1 +++ b/tools/releaseBuild/Image/buildPSSA.ps1 @@ -1,5 +1,4 @@ -param ( [string]$target ) push-location C:/PSScriptAnalyzer import-module C:/PSScriptAnalyzer/Utils/ReleaseMaker.psm1 New-ReleaseBuild -Copy-Item -Recurse C:/PSScriptAnalyzer/out/* ${target} +Copy-Item -Recurse C:/PSScriptAnalyzer/out C:/ diff --git a/tools/releaseBuild/build.json b/tools/releaseBuild/build.json index 731a9da91..8d46f2e33 100644 --- a/tools/releaseBuild/build.json +++ b/tools/releaseBuild/build.json @@ -2,7 +2,7 @@ "Windows": { "Name": "win7-x64", "RepoDestinationPath": "C:\\PSScriptAnalyzer", - "BuildCommand": "C:\\containerFiles\\buildPSSA.ps1 -target _DockerVolume_", + "BuildCommand": "C:\\containerFiles\\buildPSSA.ps1", "DockerFile": ".\\tools\\releaseBuild\\Image\\DockerFile", "DockerImageName": "pssa", "BinaryBucket": "release",