Skip to content

Commit 22d7430

Browse files
authored
Add Compress-SiteExtension.ps1 (#10793)
* Add Compress-SiteExtension.ps1 * Add log for copying JIT trace file * Add .jitmarker file
1 parent 5ef8f6c commit 22d7430

File tree

5 files changed

+119
-7
lines changed

5 files changed

+119
-7
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<#
2+
.SYNOPSIS
3+
Compresses the site extension.
4+
5+
.DESCRIPTION
6+
Takes in an unzipped site extension and produces a site extension.
7+
8+
.PARAMETER InputPath
9+
The path of the unzipped 'SiteExtension'. Leave null to scan for root in a child from here.
10+
11+
.PARAMETER OutputPath
12+
The path to produce the site extension to. Leave null to use current directory.
13+
14+
.PARAMETER JitFile
15+
[Array] The path of the JIT trace profiles to include in the site extension.
16+
17+
.PARAMETER Force
18+
[Switch] Include to overwrite existing files.
19+
20+
.INPUTS
21+
None. You can't pipe objects to Compress-SiteExtension.ps1.
22+
23+
.OUTPUTS
24+
None. Compress-SiteExtension.ps1 doesn't generate any output.
25+
#>
26+
27+
param (
28+
[string] $InputPath = $null,
29+
[string] $OutputPath = $null,
30+
[string[]] $JitFile = @(),
31+
[switch] $Force
32+
)
33+
34+
if (-not $InputPath)
35+
{
36+
$InputPath = (Get-ChildItem -Path . -Filter "extension.xml" -Recurse).Directory.FullName
37+
}
38+
39+
if (Test-Path (Join-Path $InputPath "WebJobs.Script.SiteExtension.csproj"))
40+
{
41+
Write-Error "This script should not be ran in the WebJobs.Script.SiteExtension project folder. Run this script in the root of the published site extension folder."
42+
exit 1
43+
}
44+
45+
if (-not (Join-Path $InputPath "extension.xml" | Test-Path))
46+
{
47+
Write-Error "Unable to find published site extension."
48+
exit 1
49+
}
50+
51+
if (-not $OutputPath)
52+
{
53+
$OutputPath = (Split-Path $InputPath -Leaf) + ".zip"
54+
}
55+
56+
if (Test-Path $OutputPath)
57+
{
58+
if ($Force)
59+
{
60+
Remove-Item -Path $OutputPath -Recurse -Force
61+
}
62+
else
63+
{
64+
Write-Error "OutputPath already exists. Use -Force to overwrite."
65+
exit 1
66+
}
67+
}
68+
69+
if ($JitFile)
70+
{
71+
$destinations = Get-ChildItem -Path $InputPath -Filter .jitmarker -Recurse
72+
$JitFile | ForEach-Object {
73+
$file = $_
74+
$destinations | ForEach-Object {
75+
Write-Host "Copying JIT trace file $file to $($_.Directory)"
76+
Copy-Item -Path $file -Destination $_.Directory -Force
77+
}
78+
}
79+
}
80+
81+
try
82+
{
83+
Compress-Archive -Path "$InputPath/*" -DestinationPath $OutputPath
84+
Write-Host "Published site extension to $OutputPath"
85+
}
86+
finally
87+
{
88+
# Cleanup JitTrace files
89+
if ($JitFile)
90+
{
91+
$JitFile | ForEach-Object {
92+
$file = Split-Path $_ -Leaf
93+
$destinations | ForEach-Object {
94+
Remove-Item -Path (Join-Path $_.Directory $file)
95+
}
96+
}
97+
}
98+
}

src/WebJobs.Script.SiteExtension/New-PrivateSiteExtension.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
[Switch] Include to overwrite existing files.
2222
2323
.INPUTS
24-
None. You can't pipe objects to Update-Month.ps1.
24+
None. You can't pipe objects to New-PrivateSiteExtension.ps1.
2525
2626
.OUTPUTS
27-
None. Update-Month.ps1 doesn't generate any output.
27+
None. New-PrivateSiteExtension.ps1 doesn't generate any output.
2828
#>
2929

3030
param (

src/WebJobs.Script.SiteExtension/readme.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ By default the outputs will not be zipped. To the zip the final outputs, add `-p
2323

2424
The output site extension can be found at `{repo_root}/out/pub/WebJobs.Script.SiteExtension/{config}_win`. When using `-p:ZipAfterPublish=true`, the zipped package is found at `{repo_root}/out/pkg/{config}`
2525

26+
# Site Extension
27+
28+
A compressed site extension can be produced one of two ways:
29+
30+
1. Publish with `-p:ZipAfterPublish=true`. The zipped package will then be found at `{repo_root}/out/pkg/{config}`
31+
2. If published without zipping, navigate to `{repo_root}/out/pub/WebJobs.Script.SiteExtension/{config}_win` and run `Compress-SiteExtension.ps1`
32+
1. jit trace files can also be inserted at time of compression with this method.
33+
34+
``` powershell
35+
# Produces the .zip site extension by default
36+
./Compress-SiteExtension.ps1
37+
38+
# Produce the zip, inserting JIT trace files beforehand.
39+
./Compress-SiteExtension.ps1 -JitTrace "path/to/file.jittrace", "path/to/file2.jittrace"
40+
```
41+
2642
## Private Site Extension
2743

2844
Private site extension (PSE) is not generated as part of building this project. To get a private site extension, navigate to the [publish output](#outputs) and run `New-PrivateSiteExtension.ps1`
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file is used to mark the location for .jittrace file insertion

src/WebJobs.Script.WebHost/WebJobs.Script.WebHost.csproj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,13 @@
3030
<None Remove="PreJIT\linux.coldstart.jittrace" />
3131
<None Remove="Resources\app_offline.htm" />
3232
<None Remove="Resources\Functions\WarmUp\run.csx" />
33-
<None Remove="PreJIT\coldstart.jittrace" />
33+
<None Update="PreJIT\.jitmarker" CopyToOutputDirectory="PreserveNewest" />
3434
</ItemGroup>
3535
<ItemGroup>
3636
<Content Include="applicationHost.xdt">
3737
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
3838
</Content>
39-
<Content Include="PreJIT\coldstart.jittrace">
40-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
41-
</Content>
42-
<Content Include="PreJIT\linux.coldstart.jittrace">
39+
<Content Include="PreJIT\*.jittrace">
4340
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
4441
</Content>
4542
</ItemGroup>

0 commit comments

Comments
 (0)