8000 Copy to static site instead of making blob public (#24269) · PowerShell/PowerShell@ba493b6 · GitHub
[go: up one dir, main page]

Skip to content

Commit ba493b6

Browse files
Copy to static site instead of making blob public (#24269)
1 parent b9c0127 commit ba493b6

File tree

3 files changed

+84
-60
lines changed

3 files changed

+84
-60
lines changed

.pipelines/templates/release-MakeBlobPublic.yml

+72-47
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
11
jobs:
22
- template: /.pipelines/templates/approvalJob.yml@self
33
parameters:
4-
displayName: Approve Blob Public
5-
jobName: ApproveBlobPublic
4+
displayName: Approve Copy release packages to PSInfra storage
5+
jobName: CopyReleaseBlobApproval
66
instructions: |
7-
Are you sure you want to make the blob public?
7+
Approval for Copy release packages to PSInfra storage
88
9-
- job: blobPublic
10-
displayName: Make Azure Blob Public
11-
dependsOn: ApproveBlobPublic
12-
condition: succeeded()
9+
- job: PSInfraReleaseBlobPublic
10+
displayName: Copy release to PSInfra storage
11+
dependsOn: CopyReleaseBlobApproval
1312
pool:
1413
type: windows
14+
1515
variables:
16-
- name: runCodesignValidationInjection
17-
value: false
18-
- name: NugetSecurityAnalysisWarningLevel
19-
value: none
20-
- name: DOTNET_SKIP_FIRST_TIME_EXPERIENCE
21-
value: 1
16+
- group: 'PSInfraStorage'
2217
- group: 'Azure Blob variable group'
2318
- name: ob_outputDirectory
2419
value: '$(Build.ArtifactStagingDirectory)/ONEBRANCH_ARTIFACT'
25-
- name: ob_sdl_codeSignValidation_enabled
26-
value: false
27-
- name: ob_sdl_binskim_enabled
28-
value: false
2920
- name: ob_sdl_tsa_configFile
3021
value: $(Build.SourcesDirectory)\PowerShell\.config\tsaoptions.json
3122
- name: ob_sdl_credscan_suppressionsFile
@@ -34,47 +25,81 @@ jobs:
3425
value: false
3526

3627
steps:
37-
- checkout: self
38-
clean: true
39-
env:
40-
ob_restore_phase: true # This ensures checkout is done at the beginning of the restore phase
28+
- checkout: self
29+
clean: true
30+
env:
31+
ob_restore_phase: true # This ensures checkout is done at the beginning of the restore phase
4132

42-
- template: /.pipelines/templates/SetVersionVariables.yml@self
43-
parameters:
44-
ReleaseTagVar: $(ReleaseTagVar)
45-
CreateJson: yes
46-
UseJson: no
33+
- template: /.pipelines/templates/SetVersionVariables.yml@self
34+
parameters:
35+
ReleaseTagVar: $(ReleaseTagVar)
36+
CreateJson: yes
37+
UseJson: no
4738

4839
- pwsh: |
4940
Get-ChildItem Env: | Out-String -width 9999 -Stream | write-Verbose -Verbose
5041
displayName: 'Capture Environment Variables'
5142
52-
- pwsh: |
53-
$azureRmModule = Get-InstalledModule AzureRM -ErrorAction SilentlyContinue -Verbose
54-
if ($azureRmModule) {
55-
Write-Host 'AzureRM module exists. Removing it'
56-
Uninstall-AzureRm
57-
Write-Host 'AzureRM module removed'
58-
}
59-
60-
Install-Module -Name Az.Storage -Force -AllowClobber -Scope CurrentUser -Verbose
61-
displayName: Remove AzRM modules
62-
63-
- task: AzureCLI@2
64-
displayName: 'Set blob permissions'
65-
inputs:
66-
azureSubscription: az-blob-cicd-infra
67-
scriptType: 'pscore'
68-
scriptLocation: 'inlineScript'
69-
inlineScript: |
70-
az storage container set-permission --account-name $(StorageAccount) --name $(azureVersion) --public-access blob
71-
az storage container set-permission --account-name $(StorageAccount) --name $(azureVersion)-gc --public-access blob
43+
- pwsh: |
44+
$azureRmModule = Get-InstalledModule AzureRM -ErrorAction SilentlyContinue -Verbose
45+
if ($azureRmModule) {
46+
Write-Host 'AzureRM module exists. Removing it'
47+
Uninstall-AzureRm
48+
Write-Host 'AzureRM module removed'
49+
}
50+
51+
Install-Module -Name Az.Storage -Force -AllowClobber -Scope CurrentUser -Verbose
52+
displayName: Remove AzRM modules
53+
54+
- task: AzurePowerShell@5
55+
displayName: Copy blobs to PSInfra storage
56+
inputs:
57+
azureSubscription: az-blob-cicd-infra
58+
scriptType: inlineScript
59+
azurePowerShellVersion: LatestVersion
60+
pwsh: true
61+
inline: |
62+
$sourceStorageAccountName = '$(StorageAccount)'
63+
$destinationStorageAccountName = '$(PSInfraStorageAccount)'
64+
$destinationContainerName = '$web'
65+
$destinationPrefix = 'install/$(ReleaseTagVar)'
66+
67+
$sourceContext = New-AzStorageContext -StorageAccountName $sourceStorageAccountName
68+
Write-Verbose -Verbose "Source context: $($sourceContext.BlobEndPoint)"
69+
70+
$destinationContext = New-AzStorageContext -StorageAccountName $destinationStorageAccountName
71+
Write-Verbose -Verbose "Destination context: $($destinationContext.BlobEndPoint)"
72+
73+
foreach ($sourceContainerName in '$(AzureVersion)', '$(AzureVersion)-gc') {
74+
$blobs = Get-AzStorageBlob -Context $sourceContext -Container $sourceContainerName
75+
76+
Write-Verbose -Verbose "Blobs found in $sourceContainerName"
77+
$blobs.Name | Write-Verbose -Verbose
78+
79+
Write-Verbose -Verbose "Copying blobs from $sourceContainerName to $destinationContainerName/$destinationPrefix"
80+
81+
foreach ($blob in $blobs) {
82+
$sourceBlobName = $blob.Name
83+
Write-Verbose -Verbose "sourceBlobName = $sourceBlobName"
84+
85+
$destinationBlobName = "$destinationPrefix/$sourceBlobName"
86+
Write-Verbose -Verbose "destinationBlobName = $destinationBlobName"
87+
$existingBlob = Get-AzStorageBlob -Blob $destinationBlobName -Container $destinationContainerName -Context $destinationContext -ErrorAction Ignore
88+
if ($existingBlob) {
89+
Write-Verbose -Verbose "Blob $destinationBlobName already exists in '$destinationStorageAccountName/$destinationContainerName', removing before copy."
90+
$existingBlob | Remove-AzStorageBlob -ErrorAction Stop -Verbose
91+
}
92+
93+
Copy-AzStorageBlob -SourceContext $sourceContext -DestinationContext $destinationContext -SrcContainer $sourceContainerName -SrcBlob $sourceBlobName -DestContainer $destinationContainerName -DestBlob $destinationBlobName -Force -Verbose -Confirm:$false
94+
}
95+
}
96+
7297
7398
- template: /.pipelines/templates/approvalJob.yml@self
7499
parameters:
75100
displayName: Approve Copy Global tool packages to PSInfra storage
76101
jobName: CopyBlobApproval
77-
dependsOnJob: blobPublic
102+
dependsOnJob: PSInfraReleaseBlobPublic
78103
instructions: |
79104
Approval for Copy global tool packages to PSInfra storage
80105

.pipelines/templates/release-upload-buildinfo.yml

+11-10
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ jobs:
4545
displayName: Download build info artifact
4646

4747
- pwsh: |
48-
Import-Module '$(Build.SourcesDirectory)/tools/ci.psm1'
48+
Import-Module '$(Build.SourcesDirectory)/PowerShell/tools/ci.psm1'
4949
$jsonFile = Get-Item "$ENV:PIPELINE_WORKSPACE/PSPackagesOfficial/BuildInfoJson/*.json"
5050
$fileName = Split-Path $jsonFile -Leaf
5151
5252
$dateTime = [datetime]::UtcNow
5353
$dateTime = [datetime]::new($dateTime.Ticks - ($dateTime.Ticks % [timespan]::TicksPerSecond), $dateTime.Kind)
5454
55-
$metadata = Get-Content ./tools/metadata.json | ConvertFrom-Json
55+
$metadata = Get-Content -LiteralPath '$(Build.SourcesDirectory)/PowerShell/tools/metadata.json' -ErrorAction Stop | ConvertFrom-Json
5656
$stableRelease = $metadata.StableRelease.Latest
5757
$ltsRelease = $metadata.LTSRelease.Latest
5858
@@ -118,29 +118,30 @@ jobs:
118118
azurePowerShellVersion: LatestVersion
119119
pwsh: true
120120
inline: |
121-
$containerName = "buildinfo"
122-
$storageAccount = '$(StorageAccount)'
121+
$containerName = '$web'
122+
$storageAccount = '$(PSInfraStorageAccount)'
123+
$prefix = "buildinfo"
123124
124125
$storageContext = New-AzStorageContext -StorageAccountName $storageAccount -UseConnectedAccount
125126
126127
if ($env:CopyMainBuildInfo -eq 'YES') {
127128
$jsonFile = "$env:BuildInfoJsonFile"
128129
$blobName = Get-Item $jsonFile | Split-Path -Leaf
129-
Write-Verbose -Verbose "Uploading $jsonFile to $containerName/$blobName"
130-
Set-AzStorageBlobContent -File $jsonFile -Container $containerName -Blob $blobName -Context $storageContext -Force
130+
Write-Verbose -Verbose "Uploading $jsonFile to $containerName/$prefix/$blobName"
131+
Set-AzStorageBlobContent -File $jsonFile -Container $containerName -Blob "$prefix/$blobName" -Context $storageContext -Force
131132
}
132133
133134
if ($env:CopyLTSBuildInfo -eq 'YES') {
134135
$jsonFile = "$env:LtsBuildInfoJsonFile"
135136
$blobName = Get-Item $jsonFile | Split-Path -Leaf
136-
Write-Verbose -Verbose "Uploading $jsonFile to $containerName/$blobName"
137-
Set-AzStorageBlobContent -File $jsonFile -Container $containerName -Blob $blobName -Context $storageContext -Force
137+
Write-Verbose -Verbose "Uploading $jsonFile to $containerName/$prefix/$blobName"
138+
Set-AzStorageBlobContent -File $jsonFile -Container $containerName -Blob "$prefix/$blobName" -Context $storageContext -Force
138139
}
139140
140141
if ($env:CopyVersionBuildInfo -eq 'YES') {
141142
$jsonFile = "$env:VersionBuildInfoJsonFile"
142143
$blobName = Get-Item $jsonFile | Split-Path -Leaf
143-
Write-Verbose -Verbose "Uploading $jsonFile to $containerName/$blobName"
144-
Set-AzStorageBlobContent -File $jsonFile -Container $containerName -Blob $blobName -Context $storageContext -Force
144+
Write-Verbose -Verbose "Uploading $jsonFile to $containerName/$prefix/$blobName"
145+
Set-AzStorageBlobContent -File $jsonFile -Container $containerName -Blob "$prefix/$blobName" -Context $storageContext -Force
145146
}
146147
condition: and(succeeded(), eq(variables['CopyMainBuildInfo'], 'YES'))

tools/install-powershell.ps1

+1-3
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ try {
268268
if ($Daily) {
269269
$metadata = Invoke-RestMethod 'https://aka.ms/pwsh-buildinfo-daily'
270270
$release = $metadata.ReleaseTag -replace '^v'
271-
$blobName = $metadata.BlobName
272271

273272
# Get version from currently installed PowerShell Daily if available.
274273
$pwshPath = if ($IsWinEnv) {Join-Path $Destination "pwsh.exe"} else {Join-Path $Destination "pwsh"}
@@ -297,8 +296,7 @@ try {
297296
throw "The OS architecture is '$architecture'. However, we currently only support daily package for x64."
298297
}
299298

300-
301-
$downloadURL = "https://pscoretestdata.blob.core.windows.net/${blobName}/${packageName}"
299+
$downloadURL = "https://powershellinfraartifacts-gkhedzdeaghdezhr.z01.azurefd.net/install/$($metadata.ReleaseTag)/$packageName"
302300
Write-Verbose "About to download package from '$downloadURL'" -Verbose
303301

304302
$packagePath = Join-Path -Path $tempDir -ChildPath $packageName

0 commit comments

Comments
 (0)
0