Skip to content

Commit

Permalink
Add Compress-SiteExtension.ps1 (#10793)
Browse files Browse the repository at this point in the history
* Add Compress-SiteExtension.ps1

* Add log for copying JIT trace file

* Add .jitmarker file
  • Loading branch information
jviau authored Feb 5, 2025
1 parent 5ef8f6c commit 22d7430
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 7 deletions.
98 changes: 98 additions & 0 deletions src/WebJobs.Script.SiteExtension/Compress-SiteExtension.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<#
.SYNOPSIS
Compresses the site extension.
.DESCRIPTION
Takes in an unzipped site extension and produces a site extension.
.PARAMETER InputPath
The path of the unzipped 'SiteExtension'. Leave null to scan for root in a child from here.
.PARAMETER OutputPath
The path to produce the site extension to. Leave null to use current directory.
.PARAMETER JitFile
[Array] The path of the JIT trace profiles to include in the site extension.
.PARAMETER Force
[Switch] Include to overwrite existing files.
.INPUTS
None. You can't pipe objects to Compress-SiteExtension.ps1.
.OUTPUTS
None. Compress-SiteExtension.ps1 doesn't generate any output.
#>

param (
[string] $InputPath = $null,
[string] $OutputPath = $null,
[string[]] $JitFile = @(),
[switch] $Force
)

if (-not $InputPath)
{
$InputPath = (Get-ChildItem -Path . -Filter "extension.xml" -Recurse).Directory.FullName
}

if (Test-Path (Join-Path $InputPath "WebJobs.Script.SiteExtension.csproj"))
{
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."
exit 1
}

if (-not (Join-Path $InputPath "extension.xml" | Test-Path))
{
Write-Error "Unable to find published site extension."
exit 1
}

if (-not $OutputPath)
{
$OutputPath = (Split-Path $InputPath -Leaf) + ".zip"
}

if (Test-Path $OutputPath)
{
if ($Force)
{
Remove-Item -Path $OutputPath -Recurse -Force
}
else
{
Write-Error "OutputPath already exists. Use -Force to overwrite."
exit 1
}
}

if ($JitFile)
{
$destinations = Get-ChildItem -Path $InputPath -Filter .jitmarker -Recurse
$JitFile | ForEach-Object {
$file = $_
$destinations | ForEach-Object {
Write-Host "Copying JIT trace file $file to $($_.Directory)"
Copy-Item -Path $file -Destination $_.Directory -Force
}
}
}

try
{
Compress-Archive -Path "$InputPath/*" -DestinationPath $OutputPath
Write-Host "Published site extension to $OutputPath"
}
finally
{
# Cleanup JitTrace files
if ($JitFile)
{
$JitFile | ForEach-Object {
$file = Split-Path $_ -Leaf
$destinations | ForEach-Object {
Remove-Item -Path (Join-Path $_.Directory $file)
}
}
}
}
4 changes: 2 additions & 2 deletions src/WebJobs.Script.SiteExtension/New-PrivateSiteExtension.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
[Switch] Include to overwrite existing files.
.INPUTS
None. You can't pipe objects to Update-Month.ps1.
None. You can't pipe objects to New-PrivateSiteExtension.ps1.
.OUTPUTS
None. Update-Month.ps1 doesn't generate any output.
None. New-PrivateSiteExtension.ps1 doesn't generate any output.
#>

param (
Expand Down
16 changes: 16 additions & 0 deletions src/WebJobs.Script.SiteExtension/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ By default the outputs will not be zipped. To the zip the final outputs, add `-p

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}`

# Site Extension

A compressed site extension can be produced one of two ways:

1. Publish with `-p:ZipAfterPublish=true`. The zipped package will then be found at `{repo_root}/out/pkg/{config}`
2. If published without zipping, navigate to `{repo_root}/out/pub/WebJobs.Script.SiteExtension/{config}_win` and run `Compress-SiteExtension.ps1`
1. jit trace files can also be inserted at time of compression with this method.

``` powershell
# Produces the .zip site extension by default
./Compress-SiteExtension.ps1
# Produce the zip, inserting JIT trace files beforehand.
./Compress-SiteExtension.ps1 -JitTrace "path/to/file.jittrace", "path/to/file2.jittrace"
```

## Private Site Extension

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`
Expand Down
1 change: 1 addition & 0 deletions src/WebJobs.Script.WebHost/PreJIT/.jitmarker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file is used to mark the location for .jittrace file insertion
7 changes: 2 additions & 5 deletions src/WebJobs.Script.WebHost/WebJobs.Script.WebHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@
<None Remove="PreJIT\linux.coldstart.jittrace" />
<None Remove="Resources\app_offline.htm" />
<None Remove="Resources\Functions\WarmUp\run.csx" />
<None Remove="PreJIT\coldstart.jittrace" />
<None Update="PreJIT\.jitmarker" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<Content Include="applicationHost.xdt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="PreJIT\coldstart.jittrace">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="PreJIT\linux.coldstart.jittrace">
<Content Include="PreJIT\*.jittrace">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
Expand Down

0 comments on commit 22d7430

Please sign in to comment.