|
1 |
| -param ( |
2 |
| - [string]$buildNumber = "0", |
3 |
| - [string]$suffix = "", |
4 |
| - [ValidateSet("6", "8", "")][string]$minorVersionPrefix = "", |
5 |
| - [string]$hashesForHardlinksFile = "hashesForHardlinks.txt" |
6 |
| -) |
7 |
| - |
8 |
| -Import-Module "$PSScriptRoot\Get-AzureFunctionsVersion.psm1" -Force |
9 |
| -$rootDir = Split-Path -Parent $PSScriptRoot |
10 |
| -$outDir = "$rootDir\out" |
11 |
| -$publishDir = "$outDir\pub\WebJobs.Script.WebHost" |
12 |
| - |
13 |
| -$extensionVersion = Get-AzureFunctionsVersion $buildNumber $suffix $minorVersionPrefix |
14 |
| -Write-Host "Site extension version: $extensionVersion" |
15 |
| - |
16 |
| -function ZipContent([string] $sourceDirectory, [string] $target) { |
17 |
| - $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() |
18 |
| - |
19 |
| - Write-Host "======================================" |
20 |
| - Write-Host "Zipping $sourceDirectory into $target" |
21 |
| - |
22 |
| - if (Test-Path $target) { |
23 |
| - Remove-Item $target |
24 |
| - } |
25 |
| - |
26 |
| - Add-Type -assembly "system.io.compression.filesystem" |
27 |
| - [IO.Compression.ZipFile]::CreateFromDirectory($sourceDirectory, $target) |
28 |
| - |
29 |
| - Write-Host "Done zipping $target. Elapsed: $($stopwatch.Elapsed)" |
30 |
| - Write-Host "======================================" |
31 |
| - Write-Host "" |
32 |
| -} |
33 |
| - |
34 |
| -function BuildRuntime([string] $targetRid, [bool] $isSelfContained) { |
35 |
| - $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() |
36 |
| - |
37 |
| - $publishTarget = "$publishDir\release_$targetRid" |
38 |
| - $projectPath = "$rootDir\src\WebJobs.Script.WebHost\WebJobs.Script.WebHost.csproj" |
39 |
| - if (-not (Test-Path $projectPath)) |
40 |
| - { |
41 |
| - throw "Project path '$projectPath' does not exist." |
42 |
| - } |
43 |
| - |
44 |
| - $cmd = "publish", $projectPath , "-r", "$targetRid", "--self-contained", "$isSelfContained", "-v", "m", "-c", "Release", "-p:IsPackable=false", "-p:BuildNumber=$buildNumber", "-p:MinorVersionPrefix=$minorVersionPrefix" |
45 |
| - |
46 |
| - Write-Host "======================================" |
47 |
| - Write-Host "Building $targetRid" |
48 |
| - Write-Host " Self-Contained: $isSelfContained" |
49 |
| - Write-Host " Publish Directory: $publishTarget" |
50 |
| - Write-Host "" |
51 |
| - Write-Host "dotnet $cmd" |
52 |
| - Write-Host "" |
53 |
| - |
54 |
| - & dotnet $cmd |
55 |
| - |
56 |
| - if ($LASTEXITCODE -ne 0) |
57 |
| - { |
58 |
| - exit $LASTEXITCODE |
59 |
| - } |
60 |
| - |
61 |
| - Write-Host "" |
62 |
| - $symbols = Get-ChildItem -Path $publishTarget -Filter *.pdb |
63 |
| - $symbols += Get-ChildItem -Path "$publishTarget\workers\dotnet-isolated\*" -Include "*.pdb", "*.dbg" -Recurse |
64 |
| - Write-Host "Zipping symbols: $($symbols.Count) symbols found" |
65 |
| - |
66 |
| - $symbolsPath = "$publishDir\Symbols" |
67 |
| - if (!(Test-Path -PathType Container $symbolsPath)) { |
68 |
| - New-Item -ItemType Directory -Path $symbolsPath | Out-Null |
69 |
| - } |
70 |
| - |
71 |
| - $symbols | Compress-Archive -DestinationPath "$symbolsPath\Functions.Symbols.$extensionVersion.$targetRid.zip" | Out-Null |
72 |
| - $symbols | Remove-Item | Out-Null |
73 |
| - |
74 |
| - Write-Host "" |
75 |
| - CleanOutput $publishTarget |
76 |
| - Write-Host "" |
77 |
| - Write-Host "Done building $targetRid. Elapsed: $($stopwatch.Elapsed)" |
78 |
| - Write-Host "======================================" |
79 |
| - Write-Host "" |
80 |
| -} |
81 |
| - |
82 |
| -function GetFolderSizeInMb([string] $rootPath) { |
83 |
| - return [math]::Round((Get-ChildItem $rootPath -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum / 1Mb, 2) |
84 |
| -} |
85 |
| - |
86 |
| -function CleanOutput([string] $rootPath) { |
87 |
| - Write-Host "Cleaning build output under $rootPath" |
88 |
| - Write-Host " Current size: $(GetFolderSizeInMb $rootPath) Mb" |
89 |
| - |
90 |
| - Write-Host " Removing any linux and osx runtimes" |
91 |
| - Remove-Item -Recurse -Force "$privateSiteExtensionPath\$bitness\runtimes\linux" -ErrorAction SilentlyContinue |
92 |
| - Remove-Item -Recurse -Force "$privateSiteExtensionPath\$bitness\runtimes\osx" -ErrorAction SilentlyContinue |
93 |
| - |
94 |
| - Write-Host " Removing python worker" |
95 |
| - Remove-Item -Recurse -Force "$rootPath\workers\python" -ErrorAction SilentlyContinue |
96 |
| - |
97 |
| - $keepRuntimes = @('win', 'win-x86', 'win10-x86', 'win-x64', 'win10-x64') |
98 |
| - Write-Host " Removing all powershell runtimes except $keepRuntimes" |
99 |
| - Get-ChildItem "$rootPath\workers\powershell" -Directory -ErrorAction SilentlyContinue | |
100 |
| - ForEach-Object { Get-ChildItem "$($_.FullName)\runtimes" -Directory -Exclude $keepRuntimes } | |
101 |
| - Remove-Item -Recurse -Force -ErrorAction SilentlyContinue |
102 |
| - |
103 |
| - Write-Host " Removing FunctionsNetHost(linux executable) and dependencies from dotnet-isolated worker" |
104 |
| - $dotnetIsolatedBinPath = Join-Path $rootPath "workers\dotnet-isolated\bin" |
105 |
| - if (Test-Path $dotnetIsolatedBinPath) { |
106 |
| - Remove-Item -Path (Join-Path $dotnetIsolatedBinPath "FunctionsNetHost") -ErrorAction SilentlyContinue |
107 |
| - Get-ChildItem -Path $dotnetIsolatedBinPath -Filter "*.so" | Remove-Item -ErrorAction SilentlyContinue |
108 |
| - } |
109 |
| - |
110 |
| - Write-Host " Current size: $(GetFolderSizeInMb $rootPath) Mb" |
111 |
| -} |
112 |
| - |
113 |
| -function CreateSiteExtensions() { |
114 |
| - $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() |
115 |
| - $siteExtensionPath = "$publishDir\temp_extension" |
116 |
| - |
117 |
| - if (Test-Path $siteExtensionPath) { |
118 |
| - Write-Host " Existing site extension path found. Deleting." |
119 |
| - Remove-Item $siteExtensionPath -Recurse -Force | Out-Null |
120 |
| - } |
121 |
| - |
122 |
| - # The official site extension needs to be nested inside a folder with its version. |
123 |
| - # Not using the suffix (eg: '-ci') here as it may not work correctly in a private stamp |
124 |
| - $officialSiteExtensionPath = "$siteExtensionPath\$extensionVersion" |
125 |
| - |
126 |
| - Write-Host "======================================" |
127 |
| - Write-Host "Copying build to temp directory to prepare for zipping official site extension." |
128 |
| - Copy-Item -Path $publishDir\release_win-x86\ -Destination $officialSiteExtensionPath\32bit -Force -Recurse > $null |
129 |
| - Copy-Item -Path $publishDir\release_win-x64 -Destination $officialSiteExtensionPath\64bit -Force -Recurse > $null |
130 |
| - Copy-Item -Path $officialSiteExtensionPath\32bit\applicationHost.xdt -Destination $officialSiteExtensionPath -Force > $null |
131 |
| - Write-Host " Deleting workers directory: $officialSiteExtensionPath\32bit\workers" |
132 |
| - Remove-Item -Recurse -Force "$officialSiteExtensionPath\32bit\workers" -ErrorAction SilentlyContinue |
133 |
| - Write-Host " Moving workers directory: $officialSiteExtensionPath\64bit\workers to $officialSiteExtensionPath\workers" |
134 |
| - Move-Item -Path "$officialSiteExtensionPath\64bit\workers" -Destination "$officialSiteExtensionPath\workers" |
135 |
| - |
136 |
| - # This goes in the root dir |
137 |
| - Copy-Item $rootDir\src\WebJobs.Script.WebHost\extension.xml $siteExtensionPath > $null |
138 |
| - |
139 |
| - Write-Host "Done copying. Elapsed: $($stopwatch.Elapsed)" |
140 |
| - Write-Host "======================================" |
141 |
| - Write-Host "" |
142 |
| - |
143 |
| - Write-Host "======================================" |
144 |
| - Write-Host "Generating hashes for hard links" |
145 |
| - WriteHashesFile $siteExtensionPath/$extensionVersion |
146 |
| - Write-Host "Done generating hashes for hard links into $siteExtensionPath/$extensionVersion" |
147 |
| - Write-Host "======================================" |
148 |
| - Write-Host |
149 |
| - |
150 |
| - $zipOutput = "$publishDir\SiteExtension" |
151 |
| - $hashesForHardLinksPath = "$siteExtensionPath\$extensionVersion\$hashesForHardlinksFile" |
152 |
| - New-Item -Itemtype directory -path $zipOutput -Force > $null |
153 |
| - if ($minorVersionPrefix -eq "") { |
154 |
| - ZipContent $siteExtensionPath "$zipOutput\Functions.$extensionVersion.zip" |
155 |
| - } elseif ($minorVersionPrefix -eq "8") { |
156 |
| - Write-Host "======================================" |
157 |
| - # Only the "Functions" site extension supports hard links |
158 |
| - Write-Host "MinorVersionPrefix is '8'. Removing $hashesForHardLinksPath before zipping." |
159 |
| - Remove-Item -Force "$hashesForHardLinksPath" -ErrorAction Stop |
160 |
| - # The .NET 8 host doesn't require any workers. Doing this to save space. |
161 |
| - Write-Host "Removing workers before zipping." |
162 |
| - # The host requires that this folder exists and it cannot be empty |
163 |
| - Remove-Item -Recurse -Force "$siteExtensionPath\$extensionVersion\workers" -ErrorAction Stop |
164 |
| - New-Item -Path "$siteExtensionPath\$extensionVersion" -Name "workers" -ItemType Directory -ErrorAction Stop | Out-Null |
165 |
| - Set-Content -Force -Path "$siteExtensionPath\$extensionVersion\workers\this_folder_intentionally_empty.txt" -Value ".NET 8 builds do not have workers. However, this folder must contain at least one file." -ErrorAction Stop |
166 |
| - Write-Host "======================================" |
167 |
| - Write-Host |
168 |
| - ZipContent $siteExtensionPath "$zipOutput\FunctionsInProc8.$extensionVersion.zip" |
169 |
| - } elseif ($minorVersionPrefix -eq "6") { |
170 |
| - # Only the "Functions" site extension supports hard links |
171 |
| - Write-Host "======================================" |
172 |
| - Write-Host "MinorVersionPrefix is '6'. Removing $hashesForHardLinksPath before zipping." |
173 |
| - Remove-Item -Force "$hashesForHardLinksPath" -ErrorAction Stop |
174 |
| - Write-Host "======================================" |
175 |
| - Write-Host |
176 |
| - ZipContent $siteExtensionPath "$zipOutput\FunctionsInProc.$extensionVersion.zip" |
177 |
| - } |
178 |
| - |
179 |
| - Remove-Item $siteExtensionPath -Recurse -Force > $null |
180 |
| - |
181 |
| - Write-Host "======================================" |
182 |
| - $stopwatch.Reset() |
183 |
| - Write-Host "Copying build to temp directory to prepare for zipping private site extension." |
184 |
| - Copy-Item -Path $publishDir\release_win-x86\ -Destination $siteExtensionPath\SiteExtensions\Functions\32bit -Force -Recurse > $null |
185 |
| - Copy-Item -Path $siteExtensionPath\SiteExtensions\Functions\32bit\applicationHost.xdt -Destination $siteExtensionPath\SiteExtensions\Functions -Force > $null |
186 |
| - Write-Host "Done copying. Elapsed: $($stopwatch.Elapsed)" |
187 |
| - Write-Host "======================================" |
188 |
| - Write-Host "" |
189 |
| - |
190 |
| - $zipOutput = "$publishDir\PrivateSiteExtension" |
191 |
| - New-Item -Itemtype directory -path $zipOutput -Force > $null |
192 |
| - ZipContent $siteExtensionPath "$zipOutput\Functions.Private.$extensionVersion.win-x32.inproc.zip" |
193 |
| - |
194 |
| - Remove-Item $siteExtensionPath -Recurse -Force > $null |
195 |
| -} |
196 |
| - |
197 |
| -function WriteHashesFile([string] $directoryPath) { |
198 |
| - New-Item -Path "$directoryPath/../temp_hashes" -ItemType Directory | Out-Null |
199 |
| - $temp_current = (Get-Location) |
200 |
| - Set-Location $directoryPath |
201 |
| - Get-ChildItem -Recurse $directoryPath | Where-Object { $_.PsIsContainer -eq $false } | Foreach-Object { "Hash:" + [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes((Get-FileHash -Algorithm MD5 $_.FullName).Hash)) + " FileName:" + (Resolve-Path -Relative -Path $_.FullName) } | Out-File -FilePath "$directoryPath\..\temp_hashes\$hashesForHardlinksFile" |
202 |
| - Move-Item -Path "$directoryPath/../temp_hashes/$hashesForHardlinksFile" -Destination "$directoryPath" -Force |
203 |
| - Set-Location $temp_current |
204 |
| - Remove-Item "$directoryPath/../temp_hashes" -Recurse -Force > $null |
205 |
| -} |
206 |
| - |
207 |
| -Write-Host "Output directory: $publishDir" |
208 |
| -if (Test-Path $publishDir) { |
209 |
| - Write-Host " Existing build output found. Deleting." |
210 |
| - Remove-Item $publishDir -Recurse -Force -ErrorAction Stop |
211 |
| -} |
212 |
| - |
213 |
| -Write-Host "Extensions version: $extensionVersion" |
214 |
| -Write-Host "" |
215 |
| - |
216 |
| -BuildRuntime "win-x86" |
217 |
| -BuildRuntime "win-x64" |
218 |
| - |
219 |
| -CreateSiteExtensions |
| 1 | +Write-Error "This script is no longer used. Instead, publish src/WebJobs.Script.SiteExtension/WebJobs.Script.SiteExtension.proj directly." |
0 commit comments