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

Commit

Permalink
Add script used to deploy blobs to Azure storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate McMaster committed Jun 13, 2018
1 parent c3989f8 commit aa91b80
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ node_modules
.deps
global.json
msbuild.ProjectImports.zip
.dotnet/
.tools/
6 changes: 5 additions & 1 deletion build/RuntimeStoreInstaller.targets
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
<TimestampFreeLinuxRSArchive>$(TimestampFreeRSArchivePrefix)linux-x64.patch.tar.gz</TimestampFreeLinuxRSArchive>
</PropertyGroup>

<Target Name="BuildInstallers" DependsOnTargets="GenerateTargzs;GenerateRpms;GenerateDebs;GenerateRelabledInstallers" />
<Target Name="BuildInstallers" DependsOnTargets="GenerateRuntimeVersionFile;GenerateTargzs;GenerateRpms;GenerateDebs;GenerateRelabledInstallers" />

<Target Name="GenerateRuntimeVersionFile">
<WriteLinesToFile File="$(_InstallersOutputDir)runtime.version" Lines="$(MicrosoftNETCoreApp20PackageVersion)" Overwrite="true" />
</Target>

<Target Name="_EnsureInstallerPrerequisites">
<MakeDir Directories="$(_InstallersOutputDir)" />
Expand Down
142 changes: 142 additions & 0 deletions scripts/UploadBlobs.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<#
.SYNOPSIS
Deploys a build to an Azure blob store
.PARAMETER AccountName
The account name for the Azure account
.PARAMETER AccountKey
The account key for the Azure account
.PARAMETER BuildNumber
The build number of the current build
.PARAMETER BaseFeedUrl
The base URI of the package feed (may be different than blobBaseUrl for private-only blobs)
.PARAMETER ContainerName
The container name. Defaults to 'dotnet'
.PARAMETER ArtifactsPath
The path to the build outputs
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory = $true)]
$AccountName,
[Parameter(Mandatory = $true)]
$AccountKey,
[Parameter(Mandatory = $true)]
$BuildNumber,
[Parameter(Mandatory = $true)]
$ArtifactsPath,
$BaseBlobFeedUrl,
$ContainerName = 'dotnet'
)

$ErrorActionPreference = 'Stop'
Set-StrictMode -Version 1

Import-Module -Scope Local "$PSScriptRoot/common.psm1"

if (!(Get-Command 'az' -ErrorAction Ignore)) {
Write-Error 'Missing required command: az. Please install the Azure CLI and ensure it is available on PATH.'
}

$repoRoot = Resolve-Path "$PSScriptRoot/.."

$sleetVersion = '2.3.25'
$sleet = "$repoRoot/.tools/sleet.$sleetVersion/tools/sleet.exe"

if (-not (Test-Path $sleet)) {
mkdir "$repoRoot/.tools/sleet.$sleetVersion" -ErrorAction Ignore | Out-Null
$installScriptPath = "$repoRoot/.dotnet/dotnet-install.ps1"
Invoke-WebRequest -UseBasicParsing -OutFile "$repoRoot/.tools/sleet.$sleetVersion.zip" https://www.nuget.org/api/v2/package/Sleet/$sleetVersion
Expand-Archive "$repoRoot/.tools/sleet.$sleetVersion.zip" -DestinationPath "$repoRoot/.tools/sleet.$sleetVersion"
}

[xml] $versionProps = Get-Content "$repoRoot/version.props"
$props = $versionProps.Project.PropertyGroup
$VersionPrefix = "$($props.AspNetCoreMajorVersion).$($props.AspNetCoreMinorVersion).$($props.AspNetCorePatchVersion)"

$blobFolder = "$ContainerName/aspnetcore/store/$VersionPrefix-$BuildNumber"
$packagesFolder = "$blobFolder/packages/"

$blobBaseUrl = "https://$AccountName.blob.core.windows.net/$blobFolder"
$packageBlobUrl = "https://$AccountName.blob.core.windows.net/$packagesFolder"

if (-not $BaseBlobFeedUrl) {
$BaseBlobFeedUrl = "https://$AccountName.blob.core.windows.net/$packagesFolder"
}

$packageGlobPath = "$ArtifactsPath/packages/**/*.nupkg"
$globs = (
@{
basePath = "$ArtifactsPath/lzma"
pattern = "*"
destination = $blobFolder
},
@{
basePath = "$ArtifactsPath/installers"
pattern = "*"
destination = $blobFolder
})

$sleetConfigObj = @{
sources = @(
@{
name = "feed"
type = "azure"
path = $packageBlobUrl
baseURI = $BaseBlobFeedUrl
container = $ContainerName
connectionString = "DefaultEndpointsProtocol=https;AccountName=$AccountName;AccountKey=$AccountKey"
})
}

$sleetConfig = "$repoRoot/.tools/sleet.json"
$sleetConfigObj | ConvertTo-Json | Set-Content -Path $sleetConfig -Encoding Ascii
if ($PSCmdlet.ShouldProcess("Initialize remote feed in $packageBlobUrl")) {
Invoke-Block { & $sleet init --config $sleetConfig --verbose }
}

Get-ChildItem -Recurse $packageGlobPath `
| split-path -parent `
| select -Unique `
| % {
if ($PSCmdlet.ShouldProcess("Push packages in $_ to $packageBlobUrl")) {
Invoke-Block { & $sleet push --verbose --config $sleetConfig --source feed --force $_ }
}
}

[string[]] $otherArgs = @()

if ($VerbosePreference) {
$otherArgs += '--verbose'
}

if ($WhatIfPreference) {
$otherArgs += '--dryrun'
}

$globs | ForEach-Object {
$pattern = $_.pattern
$basePath = $_.basePath
$destination = $_.destination
if (!(Get-ChildItem -Recurse "$basePath/$pattern" -ErrorAction Ignore)) {
Write-Warning "Expected files in $basePath/$pattern but found none"
}

Invoke-Block { & az storage blob upload-batch `
--account-name $AccountName `
--account-key $AccountKey `
--verbose `
--pattern $pattern `
--destination $destination.TrimEnd('/') `
--source $basePath `
--no-progress `
@otherArgs
}
}

Write-Host -f green "Done!"
5 changes: 4 additions & 1 deletion scripts/common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ function Invoke-Block([scriptblock]$cmd) {
# - $?: did the powershell script block throw an error
# - $lastexitcode: did a windows command executed by the script block end in error
if ((-not $?) -or ($lastexitcode -ne 0)) {
Write-Warning $error[0]
if ($error -ne $null)
{
Write-Warning $error[0]
}
throw "Command failed to execute: $cmd"
}
}
Expand Down

0 comments on commit aa91b80

Please sign in to comment.