Merge pull request #3669 from eerhardt/publish

Fixing up build publishing to be more organized
This commit is contained in:
Eric Erhardt 2016-06-21 23:50:38 -05:00 committed by GitHub
commit 5b2615766b
3 changed files with 138 additions and 163 deletions

View file

@ -182,7 +182,7 @@ namespace Microsoft.DotNet.Cli.Build
c.BuildContext.Get<string>("CombinedFrameworkHostCompressedFile"); c.BuildContext.Get<string>("CombinedFrameworkHostCompressedFile");
AzurePublisher.DownloadFile( AzurePublisher.DownloadFile(
AzurePublisher.CalculateArchiveBlob( CalculateArchiveBlob(
combinedSharedHostAndFrameworkArchiveBuildContextFile, combinedSharedHostAndFrameworkArchiveBuildContextFile,
sharedFrameworkChannel, sharedFrameworkChannel,
sharedFrameworkVersion), sharedFrameworkVersion),
@ -231,7 +231,7 @@ namespace Microsoft.DotNet.Cli.Build
Mkdirp(Path.GetDirectoryName(sharedFrameworkInstallerDestinationFile)); Mkdirp(Path.GetDirectoryName(sharedFrameworkInstallerDestinationFile));
AzurePublisher.DownloadFile( AzurePublisher.DownloadFile(
AzurePublisher.CalculateInstallerBlob( CalculateInstallerBlob(
sharedFrameworkInstallerDestinationFile, sharedFrameworkInstallerDestinationFile,
sharedFrameworkChannel, sharedFrameworkChannel,
sharedFrameworkVersion), sharedFrameworkVersion),
@ -246,7 +246,7 @@ namespace Microsoft.DotNet.Cli.Build
Mkdirp(Path.GetDirectoryName(sharedHostInstallerDestinationFile)); Mkdirp(Path.GetDirectoryName(sharedHostInstallerDestinationFile));
AzurePublisher.DownloadFile( AzurePublisher.DownloadFile(
AzurePublisher.CalculateInstallerBlob( CalculateInstallerBlob(
sharedHostInstallerDestinationFile, sharedHostInstallerDestinationFile,
sharedHostChannel, sharedHostChannel,
hostVersion), hostVersion),
@ -261,7 +261,7 @@ namespace Microsoft.DotNet.Cli.Build
Mkdirp(Path.GetDirectoryName(hostFxrInstallerDestinationFile)); Mkdirp(Path.GetDirectoryName(hostFxrInstallerDestinationFile));
AzurePublisher.DownloadFile( AzurePublisher.DownloadFile(
AzurePublisher.CalculateInstallerBlob( CalculateInstallerBlob(
hostFxrInstallerDestinationFile, hostFxrInstallerDestinationFile,
hostFxrChannel, hostFxrChannel,
hostFxrVersion), hostFxrVersion),
@ -548,7 +548,18 @@ cmake is required to build the native host 'corehost'";
{ {
c.BuildContext[contextPrefix + "InstallerFile"] = Path.Combine(Dirs.Packages, installer); c.BuildContext[contextPrefix + "InstallerFile"] = Path.Combine(Dirs.Packages, installer);
} }
}
// The following CalculateBlob methods are temporary until the core-setup repo up-takes the new Azure Publish layout and
// CLI consumes newer Shared FX versions.
private static string CalculateArchiveBlob(string archiveFile, string channel, string version)
{
return $"{channel}/Binaries/{version}/{Path.GetFileName(archiveFile)}";
}
private static string CalculateInstallerBlob(string installerFile, string channel, string version)
{
return $"{channel}/Installers/{version}/{Path.GetFileName(installerFile)}";
} }
} }
} }

View file

@ -15,6 +15,8 @@ namespace Microsoft.DotNet.Cli.Build
private static string Channel { get; set; } private static string Channel { get; set; }
private static string CommitHash { get; set; }
private static string CliNuGetVersion { get; set; } private static string CliNuGetVersion { get; set; }
private static string SharedFrameworkNugetVersion { get; set; } private static string SharedFrameworkNugetVersion { get; set; }
@ -28,11 +30,13 @@ namespace Microsoft.DotNet.Cli.Build
CliNuGetVersion = c.BuildContext.Get<BuildVersion>("BuildVersion").NuGetVersion; CliNuGetVersion = c.BuildContext.Get<BuildVersion>("BuildVersion").NuGetVersion;
SharedFrameworkNugetVersion = CliDependencyVersions.SharedFrameworkVersion; SharedFrameworkNugetVersion = CliDependencyVersions.SharedFrameworkVersion;
Channel = c.BuildContext.Get<string>("Channel"); Channel = c.BuildContext.Get<string>("Channel");
CommitHash = c.BuildContext.Get<string>("CommitHash");
return c.Success(); return c.Success();
} }
[Target(nameof(PrepareTargets.Init), [Target(
nameof(PrepareTargets.Init),
nameof(PublishTargets.InitPublish), nameof(PublishTargets.InitPublish),
nameof(PublishTargets.PublishArtifacts), nameof(PublishTargets.PublishArtifacts),
nameof(PublishTargets.FinalizeBuild))] nameof(PublishTargets.FinalizeBuild))]
@ -47,9 +51,9 @@ namespace Microsoft.DotNet.Cli.Build
{ {
if (CheckIfAllBuildsHavePublished()) if (CheckIfAllBuildsHavePublished())
{ {
string targetContainer = $"{Channel}/Binaries/Latest/"; string targetContainer = $"{AzurePublisher.Product.Sdk}/{Channel}/";
string targetVersionFile = $"{targetContainer}{CliNuGetVersion}"; string targetVersionFile = $"{targetContainer}{CommitHash}";
string semaphoreBlob = $"{Channel}/Binaries/publishSemaphore"; string semaphoreBlob = $"{targetContainer}/publishSemaphore";
AzurePublisherTool.CreateBlobIfNotExists(semaphoreBlob); AzurePublisherTool.CreateBlobIfNotExists(semaphoreBlob);
string leaseId = AzurePublisherTool.AcquireLeaseOnBlob(semaphoreBlob); string leaseId = AzurePublisherTool.AcquireLeaseOnBlob(semaphoreBlob);
@ -63,11 +67,10 @@ namespace Microsoft.DotNet.Cli.Build
} }
else else
{ {
Regex versionFileRegex = new Regex(@"(?<version>\d\.\d\.\d)-(?<release>.*)?"); Regex versionFileRegex = new Regex(@"(?<CommitHash>[\w\d]{40})");
// Delete old version files // Delete old version files
AzurePublisherTool.ListBlobs($"{targetContainer}") AzurePublisherTool.ListBlobs(targetContainer)
.Select(s => s.Replace("/dotnet/", ""))
.Where(s => versionFileRegex.IsMatch(s)) .Where(s => versionFileRegex.IsMatch(s))
.ToList() .ToList()
.ForEach(f => AzurePublisherTool.TryDeleteBlob(f)); .ForEach(f => AzurePublisherTool.TryDeleteBlob(f));
@ -78,32 +81,10 @@ namespace Microsoft.DotNet.Cli.Build
try try
{ {
// Copy the latest CLI bits CopyBlobsToLatest(targetContainer);
CopyBlobs($"{Channel}/Binaries/{CliNuGetVersion}/", targetContainer);
// Copy the latest installer files
CopyBlobs($"{Channel}/Installers/{CliNuGetVersion}/", $"{Channel}/Installers/Latest/");
// Generate the CLI and SDK Version text files
List<string> versionFiles = new List<string>()
{
"win.x86.version",
"win.x64.version",
"ubuntu.x64.version",
"ubuntu.16.04.x64.version",
"rhel.x64.version",
"osx.x64.version",
"debian.x64.version",
"centos.x64.version",
"fedora.23.x64.version",
"opensuse.13.2.x64.version"
};
string cliVersion = Utils.GetCliVersionFileContent(c); string cliVersion = Utils.GetCliVersionFileContent(c);
foreach (string version in versionFiles) AzurePublisherTool.PublishStringToBlob($"{targetContainer}/latest.version", cliVersion);
{
AzurePublisherTool.PublishStringToBlob($"{Channel}/dnvm/latest.{version}", cliVersion);
}
UpdateVersionsRepo(c); UpdateVersionsRepo(c);
} }
@ -116,16 +97,15 @@ namespace Microsoft.DotNet.Cli.Build
return c.Success(); return c.Success();
} }
private static void CopyBlobs(string sourceFolder, string destinationFolder) private static void CopyBlobsToLatest(string destinationFolder)
{ {
foreach (string blob in AzurePublisherTool.ListBlobs(sourceFolder)) foreach (string blob in AzurePublisherTool.ListBlobs(AzurePublisher.Product.Sdk, CliNuGetVersion))
{ {
string source = blob.Replace("/dotnet/", "");
string targetName = Path.GetFileName(blob) string targetName = Path.GetFileName(blob)
.Replace(CliNuGetVersion, "latest"); .Replace(CliNuGetVersion, "latest");
string target = $"{destinationFolder}{targetName}"; string target = $"{destinationFolder}{targetName}";
AzurePublisherTool.CopyBlob(source, target); AzurePublisherTool.CopyBlob(blob, target);
} }
} }
@ -145,35 +125,27 @@ namespace Microsoft.DotNet.Cli.Build
{ "openSUSE_13_2_x64", false } { "openSUSE_13_2_x64", false }
}; };
List<string> blobs = new List<string>(AzurePublisherTool.ListBlobs($"{Channel}/Binaries/{CliNuGetVersion}/"));
var versionBadgeName = $"{Monikers.GetBadgeMoniker()}"; var versionBadgeName = $"{Monikers.GetBadgeMoniker()}";
if (badges.ContainsKey(versionBadgeName) == false) if (!badges.ContainsKey(versionBadgeName))
{ {
throw new ArgumentException("A new OS build was added without adding the moniker to the {nameof(badges)} lookup"); throw new ArgumentException($"A new OS build '{versionBadgeName}' was added without adding the moniker to the {nameof(badges)} lookup");
} }
IEnumerable<string> blobs = AzurePublisherTool.ListBlobs(AzurePublisher.Product.Sdk, CliNuGetVersion);
foreach (string file in blobs) foreach (string file in blobs)
{ {
string name = Path.GetFileName(file); string name = Path.GetFileName(file);
string key = string.Empty;
foreach (string img in badges.Keys) foreach (string img in badges.Keys)
{ {
if ((name.StartsWith($"{img}")) && (name.EndsWith(".svg"))) if ((name.StartsWith($"{img}")) && (name.EndsWith(".svg")))
{ {
key = img; badges[img] = true;
break; break;
} }
} }
if (string.IsNullOrEmpty(key) == false)
{
badges[key] = true;
}
} }
return badges.Keys.All(key => badges[key]); return badges.Values.All(v => v);
} }
[Target( [Target(
@ -206,8 +178,8 @@ namespace Microsoft.DotNet.Cli.Build
public static BuildTargetResult PublishCliVersionBadge(BuildTargetContext c) public static BuildTargetResult PublishCliVersionBadge(BuildTargetContext c)
{ {
var versionBadge = c.BuildContext.Get<string>("VersionBadge"); var versionBadge = c.BuildContext.Get<string>("VersionBadge");
var versionBadgeBlob = $"{Channel}/Binaries/{CliNuGetVersion}/{Path.GetFileName(versionBadge)}"; UploadFile(versionBadge);
AzurePublisherTool.PublishFile(versionBadgeBlob, versionBadge);
return c.Success(); return c.Success();
} }
@ -215,10 +187,8 @@ namespace Microsoft.DotNet.Cli.Build
[BuildPlatforms(BuildPlatform.Ubuntu)] [BuildPlatforms(BuildPlatform.Ubuntu)]
public static BuildTargetResult PublishSdkInstallerFileToAzure(BuildTargetContext c) public static BuildTargetResult PublishSdkInstallerFileToAzure(BuildTargetContext c)
{ {
var version = CliNuGetVersion;
var installerFile = c.BuildContext.Get<string>("SdkInstallerFile"); var installerFile = c.BuildContext.Get<string>("SdkInstallerFile");
UploadFile(installerFile);
AzurePublisherTool.PublishInstallerFile(installerFile, Channel, version);
return c.Success(); return c.Success();
} }
@ -227,10 +197,8 @@ namespace Microsoft.DotNet.Cli.Build
[BuildPlatforms(BuildPlatform.Windows, BuildPlatform.OSX)] [BuildPlatforms(BuildPlatform.Windows, BuildPlatform.OSX)]
public static BuildTargetResult PublishCombinedFrameworkSDKHostInstallerFileToAzure(BuildTargetContext c) public static BuildTargetResult PublishCombinedFrameworkSDKHostInstallerFileToAzure(BuildTargetContext c)
{ {
var version = CliNuGetVersion;
var installerFile = c.BuildContext.Get<string>("CombinedFrameworkSDKHostInstallerFile"); var installerFile = c.BuildContext.Get<string>("CombinedFrameworkSDKHostInstallerFile");
UploadFile(installerFile);
AzurePublisherTool.PublishInstallerFile(installerFile, Channel, version);
return c.Success(); return c.Success();
} }
@ -239,10 +207,8 @@ namespace Microsoft.DotNet.Cli.Build
[BuildPlatforms(BuildPlatform.Windows)] [BuildPlatforms(BuildPlatform.Windows)]
public static BuildTargetResult PublishCombinedFrameworkSDKArchiveToAzure(BuildTargetContext c) public static BuildTargetResult PublishCombinedFrameworkSDKArchiveToAzure(BuildTargetContext c)
{ {
var version = CliNuGetVersion;
var archiveFile = c.BuildContext.Get<string>("CombinedFrameworkSDKCompressedFile"); var archiveFile = c.BuildContext.Get<string>("CombinedFrameworkSDKCompressedFile");
UploadFile(archiveFile);
AzurePublisherTool.PublishArchive(archiveFile, Channel, version);
return c.Success(); return c.Success();
} }
@ -250,10 +216,8 @@ namespace Microsoft.DotNet.Cli.Build
[Target] [Target]
public static BuildTargetResult PublishCombinedHostFrameworkSdkArchiveToAzure(BuildTargetContext c) public static BuildTargetResult PublishCombinedHostFrameworkSdkArchiveToAzure(BuildTargetContext c)
{ {
var version = CliNuGetVersion;
var archiveFile = c.BuildContext.Get<string>("CombinedFrameworkSDKHostCompressedFile"); var archiveFile = c.BuildContext.Get<string>("CombinedFrameworkSDKHostCompressedFile");
UploadFile(archiveFile);
AzurePublisherTool.PublishArchive(archiveFile, Channel, version);
return c.Success(); return c.Success();
} }
@ -261,10 +225,8 @@ namespace Microsoft.DotNet.Cli.Build
[Target] [Target]
public static BuildTargetResult PublishSDKSymbolsArchiveToAzure(BuildTargetContext c) public static BuildTargetResult PublishSDKSymbolsArchiveToAzure(BuildTargetContext c)
{ {
var version = CliNuGetVersion;
var archiveFile = c.BuildContext.Get<string>("SdkSymbolsCompressedFile"); var archiveFile = c.BuildContext.Get<string>("SdkSymbolsCompressedFile");
UploadFile(archiveFile);
AzurePublisherTool.PublishArchive(archiveFile, Channel, version);
return c.Success(); return c.Success();
} }
@ -277,7 +239,7 @@ namespace Microsoft.DotNet.Cli.Build
var packageName = CliMonikers.GetSdkDebianPackageName(c); var packageName = CliMonikers.GetSdkDebianPackageName(c);
var installerFile = c.BuildContext.Get<string>("SdkInstallerFile"); var installerFile = c.BuildContext.Get<string>("SdkInstallerFile");
var uploadUrl = AzurePublisherTool.CalculateInstallerUploadUrl(installerFile, Channel, version); var uploadUrl = AzurePublisher.CalculateUploadUrlForFile(installerFile, AzurePublisher.Product.Sdk, version);
DebRepoPublisherTool.PublishDebFileToDebianRepo( DebRepoPublisherTool.PublishDebFileToDebianRepo(
packageName, packageName,
@ -297,6 +259,11 @@ namespace Microsoft.DotNet.Cli.Build
VersionRepoUpdater repoUpdater = new VersionRepoUpdater(githubAuthToken); VersionRepoUpdater repoUpdater = new VersionRepoUpdater(githubAuthToken);
repoUpdater.UpdatePublishedVersions(nupkgFilePath, versionsRepoPath).Wait(); repoUpdater.UpdatePublishedVersions(nupkgFilePath, versionsRepoPath).Wait();
} }
private static string UploadFile(string file)
{
return AzurePublisherTool.UploadFile(file, AzurePublisher.Product.Sdk, CliNuGetVersion);
}
} }
} }

View file

@ -1,22 +1,28 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Text; using System.Threading;
using Microsoft.DotNet.Cli.Build.Framework; using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage; using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob; using Microsoft.WindowsAzure.Storage.Blob;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
using System.Threading.Tasks;
namespace Microsoft.DotNet.Cli.Build namespace Microsoft.DotNet.Cli.Build
{ {
public class AzurePublisher public class AzurePublisher
{ {
private static readonly string s_dotnetBlobRootUrl = "https://dotnetcli.blob.core.windows.net/dotnet/"; public enum Product
private static readonly string s_dotnetBlobContainerName = "dotnet"; {
SharedFramework,
Host,
HostFxr,
Sdk,
}
private const string s_dotnetBlobRootUrl = "https://dotnetcli.blob.core.windows.net/" + s_dotnetBlobContainerName;
private const string s_dotnetBlobContainerName = "dotnet";
private string _connectionString { get; set; } private string _connectionString { get; set; }
private CloudBlobContainer _blobContainer { get; set; } private CloudBlobContainer _blobContainer { get; set; }
@ -35,24 +41,13 @@ namespace Microsoft.DotNet.Cli.Build
return blobClient.GetContainerReference(s_dotnetBlobContainerName); return blobClient.GetContainerReference(s_dotnetBlobContainerName);
} }
public void PublishInstallerFile(string installerFile, string channel, string version) public string UploadFile(string file, Product product, string version)
{ {
var installerFileBlob = CalculateInstallerBlob(installerFile, channel, version); string url = CalculateUploadUrlForFile(file, product, version);
PublishFile(installerFileBlob, installerFile); CloudBlockBlob blob = _blobContainer.GetBlockBlobReference(url);
} blob.UploadFromFileAsync(file, FileMode.Open).Wait();
SetBlobPropertiesBasedOnFileType(blob);
public void PublishArchive(string archiveFile, string channel, string version) return url;
{
var archiveFileBlob = CalculateArchiveBlob(archiveFile, channel, version);
PublishFile(archiveFileBlob, archiveFile);
}
public void PublishFile(string blob, string file)
{
CloudBlockBlob blockBlob = _blobContainer.GetBlockBlobReference(blob);
blockBlob.UploadFromFileAsync(file, FileMode.Open).Wait();
SetBlobPropertiesBasedOnFileType(blockBlob);
} }
public void PublishStringToBlob(string blob, string content) public void PublishStringToBlob(string blob, string content)
@ -60,8 +55,7 @@ namespace Microsoft.DotNet.Cli.Build
CloudBlockBlob blockBlob = _blobContainer.GetBlockBlobReference(blob); CloudBlockBlob blockBlob = _blobContainer.GetBlockBlobReference(blob);
blockBlob.UploadTextAsync(content).Wait(); blockBlob.UploadTextAsync(content).Wait();
blockBlob.Properties.ContentType = "text/plain"; SetBlobPropertiesBasedOnFileType(blockBlob);
blockBlob.SetPropertiesAsync().Wait();
} }
public void CopyBlob(string sourceBlob, string targetBlob) public void CopyBlob(string sourceBlob, string targetBlob)
@ -90,26 +84,57 @@ namespace Microsoft.DotNet.Cli.Build
else if (Path.GetExtension(blockBlob.Uri.AbsolutePath.ToLower()) == ".version") else if (Path.GetExtension(blockBlob.Uri.AbsolutePath.ToLower()) == ".version")
{ {
blockBlob.Properties.ContentType = "text/plain"; blockBlob.Properties.ContentType = "text/plain";
blockBlob.Properties.CacheControl = "no-cache";
blockBlob.SetPropertiesAsync().Wait(); blockBlob.SetPropertiesAsync().Wait();
} }
} }
public IEnumerable<string> ListBlobs(Product product, string version)
{
string virtualDirectory = $"{product}/{version}";
return ListBlobs(virtualDirectory);
}
public IEnumerable<string> ListBlobs(string virtualDirectory) public IEnumerable<string> ListBlobs(string virtualDirectory)
{ {
CloudBlobDirectory blobDir = _blobContainer.GetDirectoryReference(virtualDirectory); CloudBlobDirectory blobDir = _blobContainer.GetDirectoryReference(virtualDirectory);
BlobContinuationToken continuationToken = new BlobContinuationToken(); BlobContinuationToken continuationToken = new BlobContinuationToken();
var blobFiles = blobDir.ListBlobsSegmentedAsync(continuationToken).Result; var blobFiles = blobDir.ListBlobsSegmentedAsync(continuationToken).Result;
return blobFiles.Results.Select(bf => bf.Uri.PathAndQuery); return blobFiles.Results.Select(bf => bf.Uri.PathAndQuery.Replace($"/{s_dotnetBlobContainerName}/", string.Empty));
} }
public string AcquireLeaseOnBlob(string blob) public string AcquireLeaseOnBlob(
string blob,
TimeSpan? maxWaitDefault = null,
TimeSpan? delayDefault = null)
{
TimeSpan maxWait = maxWaitDefault ?? TimeSpan.FromSeconds(120);
TimeSpan delay = delayDefault ?? TimeSpan.FromMilliseconds(500);
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
// This will throw an exception with HTTP code 409 when we cannot acquire the lease
// But we should block until we can get this lease, with a timeout (maxWaitSeconds)
while (stopWatch.ElapsedMilliseconds < maxWait.TotalMilliseconds)
{
try
{ {
CloudBlockBlob cloudBlob = _blobContainer.GetBlockBlobReference(blob); CloudBlockBlob cloudBlob = _blobContainer.GetBlockBlobReference(blob);
System.Threading.Tasks.Task<string> task = cloudBlob.AcquireLeaseAsync(TimeSpan.FromMinutes(1), null); Task<string> task = cloudBlob.AcquireLeaseAsync(TimeSpan.FromMinutes(1), null);
task.Wait(); task.Wait();
return task.Result; return task.Result;
} }
catch (Exception e)
{
Console.WriteLine($"Retrying lease acquisition on {blob}, {e.Message}");
Thread.Sleep(delay);
}
}
throw new Exception($"Unable to acquire lease on {blob}");
}
public void ReleaseLeaseOnBlob(string blob, string leaseId) public void ReleaseLeaseOnBlob(string blob, string leaseId)
{ {
@ -120,7 +145,7 @@ namespace Microsoft.DotNet.Cli.Build
public bool IsLatestSpecifiedVersion(string version) public bool IsLatestSpecifiedVersion(string version)
{ {
System.Threading.Tasks.Task<bool> task = _blobContainer.GetBlockBlobReference(version).ExistsAsync(); Task<bool> task = _blobContainer.GetBlockBlobReference(version).ExistsAsync();
task.Wait(); task.Wait();
return task.Result; return task.Result;
} }
@ -136,7 +161,7 @@ namespace Microsoft.DotNet.Cli.Build
public void CreateBlobIfNotExists(string path) public void CreateBlobIfNotExists(string path)
{ {
System.Threading.Tasks.Task<bool> task = _blobContainer.GetBlockBlobReference(path).ExistsAsync(); Task<bool> task = _blobContainer.GetBlockBlobReference(path).ExistsAsync();
task.Wait(); task.Wait();
if (!task.Result) if (!task.Result)
{ {
@ -164,29 +189,19 @@ namespace Microsoft.DotNet.Cli.Build
} }
} }
public void DeleteBlob(string path) private void DeleteBlob(string path)
{ {
_blobContainer.GetBlockBlobReference(path).DeleteAsync().Wait(); _blobContainer.GetBlockBlobReference(path).DeleteAsync().Wait();
} }
public string CalculateInstallerUploadUrl(string installerFile, string channel, string version) public static string CalculateUploadUrlForFile(string file, Product product, string version)
{ {
return $"{s_dotnetBlobRootUrl}{CalculateInstallerBlob(installerFile, channel, version)}"; return $"{s_dotnetBlobRootUrl}/{product}/{version}/{Path.GetFileName(file)}";
}
public static string CalculateInstallerBlob(string installerFile, string channel, string version)
{
return $"{channel}/Installers/{version}/{Path.GetFileName(installerFile)}";
}
public static string CalculateArchiveBlob(string archiveFile, string channel, string version)
{
return $"{channel}/Binaries/{version}/{Path.GetFileName(archiveFile)}";
} }
public static async Task DownloadFile(string blobFilePath, string localDownloadPath) public static async Task DownloadFile(string blobFilePath, string localDownloadPath)
{ {
var blobUrl = $"{s_dotnetBlobRootUrl}{blobFilePath}"; var blobUrl = $"{s_dotnetBlobRootUrl}/{blobFilePath}";
using (var client = new HttpClient()) using (var client = new HttpClient())
{ {
@ -204,23 +219,5 @@ namespace Microsoft.DotNet.Cli.Build
} }
} }
} }
public void DownloadFilesWithExtension(string blobVirtualDirectory, string fileExtension, string localDownloadPath)
{
CloudBlobDirectory blobDir = _blobContainer.GetDirectoryReference(blobVirtualDirectory);
BlobContinuationToken continuationToken = new BlobContinuationToken();
var blobFiles = blobDir.ListBlobsSegmentedAsync(continuationToken).Result;
foreach (var blobFile in blobFiles.Results.OfType<CloudBlockBlob>())
{
if (Path.GetExtension(blobFile.Uri.AbsoluteUri) == fileExtension)
{
string localBlobFile = Path.Combine(localDownloadPath, Path.GetFileName(blobFile.Uri.AbsoluteUri));
Console.WriteLine($"Downloading {blobFile.Uri.AbsoluteUri} to {localBlobFile}...");
blobFile.DownloadToFileAsync(localBlobFile, FileMode.Create).Wait();
}
}
}
} }
} }