Skip to content
This repository was archived by the owner on Oct 18, 2018. It is now read-only.

Commit aa91b80

Browse files
author
Nate McMaster
committed
Add script used to deploy blobs to Azure storage
1 parent c3989f8 commit aa91b80

File tree

4 files changed

+153
-2
lines changed

4 files changed

+153
-2
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ node_modules
2222
.deps
2323
global.json
2424
msbuild.ProjectImports.zip
25+
.dotnet/
26+
.tools/

build/RuntimeStoreInstaller.targets

+5-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
<TimestampFreeLinuxRSArchive>$(TimestampFreeRSArchivePrefix)linux-x64.patch.tar.gz</TimestampFreeLinuxRSArchive>
3232
</PropertyGroup>
3333

34-
<Target Name="BuildInstallers" DependsOnTargets="GenerateTargzs;GenerateRpms;GenerateDebs;GenerateRelabledInstallers" />
34+
<Target Name="BuildInstallers" DependsOnTargets="GenerateRuntimeVersionFile;GenerateTargzs;GenerateRpms;GenerateDebs;GenerateRelabledInstallers" />
35+
36+
<Target Name="GenerateRuntimeVersionFile">
37+
<WriteLinesToFile File="$(_InstallersOutputDir)runtime.version" Lines="$(MicrosoftNETCoreApp20PackageVersion)" Overwrite="true" />
38+
</Target>
3539

3640
<Target Name="_EnsureInstallerPrerequisites">
3741
<MakeDir Directories="$(_InstallersOutputDir)" />

scripts/UploadBlobs.ps1

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<#
2+
.SYNOPSIS
3+
Deploys a build to an Azure blob store
4+
5+
.PARAMETER AccountName
6+
The account name for the Azure account
7+
8+
.PARAMETER AccountKey
9+
The account key for the Azure account
10+
11+
.PARAMETER BuildNumber
12+
The build number of the current build
13+
14+
.PARAMETER BaseFeedUrl
15+
The base URI of the package feed (may be different than blobBaseUrl for private-only blobs)
16+
17+
.PARAMETER ContainerName
18+
The container name. Defaults to 'dotnet'
19+
20+
.PARAMETER ArtifactsPath
21+
The path to the build outputs
22+
#>
23+
[CmdletBinding(SupportsShouldProcess = $true)]
24+
param(
25+
[Parameter(Mandatory = $true)]
26+
$AccountName,
27+
[Parameter(Mandatory = $true)]
28+
$AccountKey,
29+
[Parameter(Mandatory = $true)]
30+
$BuildNumber,
31+
[Parameter(Mandatory = $true)]
32+
$ArtifactsPath,
33+
$BaseBlobFeedUrl,
34+
$ContainerName = 'dotnet'
35+
)
36+
37+
$ErrorActionPreference = 'Stop'
38+
Set-StrictMode -Version 1
39+
40+
Import-Module -Scope Local "$PSScriptRoot/common.psm1"
41+
42+
if (!(Get-Command 'az' -ErrorAction Ignore)) {
43+
Write-Error 'Missing required command: az. Please install the Azure CLI and ensure it is available on PATH.'
44+
}
45+
46+
$repoRoot = Resolve-Path "$PSScriptRoot/.."
47+
48+
$sleetVersion = '2.3.25'
49+
$sleet = "$repoRoot/.tools/sleet.$sleetVersion/tools/sleet.exe"
50+
51+
if (-not (Test-Path $sleet)) {
52+
mkdir "$repoRoot/.tools/sleet.$sleetVersion" -ErrorAction Ignore | Out-Null
53+
$installScriptPath = "$repoRoot/.dotnet/dotnet-install.ps1"
54+
Invoke-WebRequest -UseBasicParsing -OutFile "$repoRoot/.tools/sleet.$sleetVersion.zip" https://www.nuget.org/api/v2/package/Sleet/$sleetVersion
55+
Expand-Archive "$repoRoot/.tools/sleet.$sleetVersion.zip" -DestinationPath "$repoRoot/.tools/sleet.$sleetVersion"
56+
}
57+
58+
[xml] $versionProps = Get-Content "$repoRoot/version.props"
59+
$props = $versionProps.Project.PropertyGroup
60+
$VersionPrefix = "$($props.AspNetCoreMajorVersion).$($props.AspNetCoreMinorVersion).$($props.AspNetCorePatchVersion)"
61+
62+
$blobFolder = "$ContainerName/aspnetcore/store/$VersionPrefix-$BuildNumber"
63+
$packagesFolder = "$blobFolder/packages/"
64+
65+
$blobBaseUrl = "https://$AccountName.blob.core.windows.net/$blobFolder"
66+
$packageBlobUrl = "https://$AccountName.blob.core.windows.net/$packagesFolder"
67+
68+
if (-not $BaseBlobFeedUrl) {
69+
$BaseBlobFeedUrl = "https://$AccountName.blob.core.windows.net/$packagesFolder"
70+
}
71+
72+
$packageGlobPath = "$ArtifactsPath/packages/**/*.nupkg"
73+
$globs = (
74+
@{
75+
basePath = "$ArtifactsPath/lzma"
76+
pattern = "*"
77+
destination = $blobFolder
78+
},
79+
@{
80+
basePath = "$ArtifactsPath/installers"
81+
pattern = "*"
82+
destination = $blobFolder
83+
})
84+
85+
$sleetConfigObj = @{
86+
sources = @(
87+
@{
88+
name = "feed"
89+
type = "azure"
90+
path = $packageBlobUrl
91+
baseURI = $BaseBlobFeedUrl
92+
container = $ContainerName
93+
connectionString = "DefaultEndpointsProtocol=https;AccountName=$AccountName;AccountKey=$AccountKey"
94+
})
95+
}
96+
97+
$sleetConfig = "$repoRoot/.tools/sleet.json"
98+
$sleetConfigObj | ConvertTo-Json | Set-Content -Path $sleetConfig -Encoding Ascii
99+
if ($PSCmdlet.ShouldProcess("Initialize remote feed in $packageBlobUrl")) {
100+
Invoke-Block { & $sleet init --config $sleetConfig --verbose }
101+
}
102+
103+
Get-ChildItem -Recurse $packageGlobPath `
104+
| split-path -parent `
105+
| select -Unique `
106+
| % {
107+
if ($PSCmdlet.ShouldProcess("Push packages in $_ to $packageBlobUrl")) {
108+
Invoke-Block { & $sleet push --verbose --config $sleetConfig --source feed --force $_ }
109+
}
110+
}
111+
112+
[string[]] $otherArgs = @()
113+
114+
if ($VerbosePreference) {
115+
$otherArgs += '--verbose'
116+
}
117+
118+
if ($WhatIfPreference) {
119+
$otherArgs += '--dryrun'
120+
}
121+
122+
$globs | ForEach-Object {
123+
$pattern = $_.pattern
124+
$basePath = $_.basePath
125+
$destination = $_.destination
126+
if (!(Get-ChildItem -Recurse "$basePath/$pattern" -ErrorAction Ignore)) {
127+
Write-Warning "Expected files in $basePath/$pattern but found none"
128+
}
129+
130+
Invoke-Block { & az storage blob upload-batch `
131+
--account-name $AccountName `
132+
--account-key $AccountKey `
133+
--verbose `
134+
--pattern $pattern `
135+
--destination $destination.TrimEnd('/') `
136+
--source $basePath `
137+
--no-progress `
138+
@otherArgs
139+
}
140+
}
141+
142+
Write-Host -f green "Done!"

scripts/common.psm1

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ function Invoke-Block([scriptblock]$cmd) {
1515
# - $?: did the powershell script block throw an error
1616
# - $lastexitcode: did a windows command executed by the script block end in error
1717
if ((-not $?) -or ($lastexitcode -ne 0)) {
18-
Write-Warning $error[0]
18+
if ($error -ne $null)
19+
{
20+
Write-Warning $error[0]
21+
}
1922
throw "Command failed to execute: $cmd"
2023
}
2124
}

0 commit comments

Comments
 (0)