Skip to content

Allow packaging from a zip package to allow for signing #5418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 13, 2017

Conversation

TravisEz13
Copy link
Member

  1. Include a serialized version of PSOptions in an includesymbols zip
  2. Add a function which will create a zip package from the expanded includesymbols zip and a folder of signed files
  3. add a function to restore an includesymbols zip as a build and populated PSOptions with the options
  4. update related files

@TravisEz13
Copy link
Member Author

rebased due to merge conflict

build.psm1 Outdated
@@ -742,6 +753,13 @@ function Get-PSOptions {
return $script:Options
}

function Set-PSOptions {
param(
$Options
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the argument passed in could be a PSObject, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

@@ -180,6 +180,7 @@ function Start-PSPackage {
# Zip symbols.zip to the root package
$zipSource = Join-Path $symbolsSource -ChildPath '*'
$zipPath = Join-Path -Path $Source -ChildPath 'symbols.zip'
$Script:Options | ConvertTo-Json -Depth 3 | Out-File -Encoding utf8 -FilePath (Join-Path -Path $source -ChildPath 'psoptions.json')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be careful about the entries PSModuleRestore and CrossGen when convert to/from json. Currnetly the values of these 2 are SwitchParameter values, which works fined with the comparison to bool. However, after convert from json, you will get a synthetic property named 'IsPresent' with a bool value, and the comparison to bool would behave differently. See the example:

> $p = New-PSOptions
> $s=  $p | ConvertTo-Json | ConvertFrom-Json
> if (-not $p.PSModuleRestore) { echo "ff" }
ff
> if (-not $s.PSModuleRestore) { echo "ff" } ## print nothing.

I suggest to not use the SwitchParameter value in the first place. Instead, use $CrossGen.IsPresent and $PSModuleRestore.IsPresent when setting the initial $options

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to suggested implementation

$windowsExecutablePath = (Join-Path $buildPath -ChildPath 'pwsh.exe')
$linuxExecutablePath = (Join-Path $buildPath -ChildPath 'pwsh')

Restore-PSModuleToBuild -PublishPath $buildPath
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain again why we need to restore modules again here? After restoring the modules, they only exist in the publish folder. We do signing and other compliance check using the files from the parent folder of publish so those restored modules won't affect any of that ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the first time modules are being restored. Restoring them during the initial build would add size to the files we are carrying around. It also ensures 100% that we do not sign 3rd party code, which not signing 3rd party code is a requirement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restoring them during the initial build would add size to the files we are carrying around.

This makes sense. My worry is that the package management cmdlet may fail when running Restore-PSModuleToBuild when working with myget. I see this failure often enough in our CI runs. Before this change, the build can fail fast if this happens, but after this change, the signing effort would be in vain in case this happens.

But this is not a blocking comment. Let's do this and see how it works.

remove-item -Path (Join-Path -Path $buildPath -ChildPath '*.zip') -Recurse

$windowsExecutablePath = (Join-Path $buildPath -ChildPath 'pwsh.exe')
$linuxExecutablePath = (Join-Path $buildPath -ChildPath 'pwsh')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why checking for Linux? We don't sign individual files for Linux so this function should never be used in a Linux build, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

[string] $destination = "$env:WORKSPACE",
[ValidateSet("win7-x64", "win81-x64", "win10-x64", "win7-x86")]

[ValidateSet("win7-x64", "win81-x64", "win10-x64", "win7-x86")]
[string]$Runtime = 'win10-x64',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I guess we should only accept win7-x64 and win7-x86 now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

"BuildCommand": "C:\\PowerShellPackage.ps1 -BuildZip _RepoDestinationPath_\\_BuildPackageName_ -location _RepoDestinationPath_ -destination _DockerVolume_ -Runtime win7-x64 -ReleaseTag _ReleaseTag_",
"BuildDockerOptions": [
"-m",
"3968m"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why do we want to limit the memory for the container?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is increasing the memory in the container on many machines. I cannot add comments in JSON. but the packaging script verifies that we have increased the memory to at least 2GB.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say a minimum of this value if I could but they don't have this option.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thanks!

@@ -1,7 +1,18 @@
[cmdletbinding(DefaultParameterSetName='default')]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no common parameters that can be used for the default set. It seems to me we should use Build as the default parameter set.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

@@ -74,7 +108,12 @@ End {
Import-Module "$location/dockerBasedBuild" -Force
Clear-VstsTaskState

Invoke-Build -RepoPath $resolvedRepoRoot -BuildJsonPath './tools/releaseBuild/build.json' -Name $Name -Parameters $PSBoundParameters
$buildParameters = @{
ReleaseTag = $ReleaseTag
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, you pass in $PSBoundParameters, so if -ReleaseTag is not specified, it won't be passed to Invoke-Build.
Now you always pass in ReleaseTag, and the value will be $null in case -ReleaseTag is not specified when calling this script. Will this cause any problems?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new hashtable I have has ReleaseTag

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this won't cause any issues. I've verified this previously.

@TravisEz13
Copy link
Member Author

TravisEz13 commented Nov 12, 2017

@daxian-dbw daxian-dbw merged commit 36fac11 into PowerShell:master Nov 13, 2017
@TravisEz13 TravisEz13 deleted the codesigning2 branch November 13, 2017 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants