Remove Azure dependency from build
This commit is contained in:
parent
62224b3435
commit
b63fb1aaf8
3 changed files with 19 additions and 153 deletions
|
@ -12,7 +12,7 @@
|
||||||
<PackageReference Include="NETStandard.Library" Version="1.6.0" />
|
<PackageReference Include="NETStandard.Library" Version="1.6.0" />
|
||||||
<PackageReference Include="System.Diagnostics.Process" Version="4.1.0" />
|
<PackageReference Include="System.Diagnostics.Process" Version="4.1.0" />
|
||||||
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.1.0" />
|
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.1.0" />
|
||||||
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="1.0.1-beta-000933" />
|
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="2.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -9,9 +9,6 @@ using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.WindowsAzure.Storage;
|
|
||||||
using Microsoft.WindowsAzure.Storage.Auth;
|
|
||||||
using Microsoft.WindowsAzure.Storage.Blob;
|
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.Build
|
namespace Microsoft.DotNet.Cli.Build
|
||||||
{
|
{
|
||||||
|
@ -25,113 +22,44 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
Sdk,
|
Sdk,
|
||||||
}
|
}
|
||||||
|
|
||||||
private const string s_dotnetBlobContainerName = "dotnet";
|
public AzurePublisher(string containerName)
|
||||||
|
|
||||||
private string _connectionString { get; set; }
|
|
||||||
private string _containerName { get; set; }
|
|
||||||
private CloudBlobContainer _blobContainer { get; set; }
|
|
||||||
|
|
||||||
public AzurePublisher(string containerName = s_dotnetBlobContainerName)
|
|
||||||
{
|
{
|
||||||
_connectionString = EnvVars.EnsureVariable("CONNECTION_STRING").Trim('"');
|
throw new NotImplementedException();
|
||||||
_containerName = containerName;
|
|
||||||
_blobContainer = GetDotnetBlobContainer(_connectionString, containerName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AzurePublisher(string accountName, string accountKey, string containerName = s_dotnetBlobContainerName)
|
public AzurePublisher(string accountName, string accountKey, string containerName)
|
||||||
{
|
{
|
||||||
_containerName = containerName;
|
throw new NotImplementedException();
|
||||||
_blobContainer = GetDotnetBlobContainer(accountName, accountKey, containerName);
|
|
||||||
}
|
|
||||||
|
|
||||||
private CloudBlobContainer GetDotnetBlobContainer(string connectionString, string containerName)
|
|
||||||
{
|
|
||||||
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
|
|
||||||
|
|
||||||
return GetDotnetBlobContainer(storageAccount, containerName);
|
|
||||||
}
|
|
||||||
|
|
||||||
private CloudBlobContainer GetDotnetBlobContainer(string accountName, string accountKey, string containerName)
|
|
||||||
{
|
|
||||||
var storageCredentials = new StorageCredentials(accountName, accountKey);
|
|
||||||
var storageAccount = new CloudStorageAccount(storageCredentials, true);
|
|
||||||
return GetDotnetBlobContainer(storageAccount, containerName);
|
|
||||||
}
|
|
||||||
|
|
||||||
private CloudBlobContainer GetDotnetBlobContainer(CloudStorageAccount storageAccount, string containerName)
|
|
||||||
{
|
|
||||||
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
|
|
||||||
|
|
||||||
return blobClient.GetContainerReference(containerName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string UploadFile(string file, Product product, string version)
|
public string UploadFile(string file, Product product, string version)
|
||||||
{
|
{
|
||||||
string url = CalculateRelativePathForFile(file, product, version);
|
throw new NotImplementedException();
|
||||||
CloudBlockBlob blob = _blobContainer.GetBlockBlobReference(url);
|
|
||||||
blob.UploadFromFileAsync(file).Wait();
|
|
||||||
SetBlobPropertiesBasedOnFileType(blob);
|
|
||||||
return url;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PublishStringToBlob(string blob, string content)
|
public void PublishStringToBlob(string blob, string content)
|
||||||
{
|
{
|
||||||
CloudBlockBlob blockBlob = _blobContainer.GetBlockBlobReference(blob);
|
throw new NotImplementedException();
|
||||||
blockBlob.UploadTextAsync(content).Wait();
|
|
||||||
|
|
||||||
SetBlobPropertiesBasedOnFileType(blockBlob);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CopyBlob(string sourceBlob, string targetBlob)
|
public void CopyBlob(string sourceBlob, string targetBlob)
|
||||||
{
|
{
|
||||||
CloudBlockBlob source = _blobContainer.GetBlockBlobReference(sourceBlob);
|
throw new NotImplementedException();
|
||||||
CloudBlockBlob target = _blobContainer.GetBlockBlobReference(targetBlob);
|
|
||||||
|
|
||||||
// Create the empty blob
|
|
||||||
using (MemoryStream ms = new MemoryStream())
|
|
||||||
{
|
|
||||||
target.UploadFromStreamAsync(ms).Wait();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy actual blob data
|
|
||||||
target.StartCopyAsync(source).Wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetBlobPropertiesBasedOnFileType(string path)
|
public void SetBlobPropertiesBasedOnFileType(string path)
|
||||||
{
|
{
|
||||||
CloudBlockBlob blob = _blobContainer.GetBlockBlobReference(path);
|
throw new NotImplementedException();
|
||||||
SetBlobPropertiesBasedOnFileType(blob);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetBlobPropertiesBasedOnFileType(CloudBlockBlob blockBlob)
|
|
||||||
{
|
|
||||||
if (Path.GetExtension(blockBlob.Uri.AbsolutePath.ToLower()) == ".svg")
|
|
||||||
{
|
|
||||||
blockBlob.Properties.ContentType = "image/svg+xml";
|
|
||||||
blockBlob.Properties.CacheControl = "no-cache";
|
|
||||||
blockBlob.SetPropertiesAsync().Wait();
|
|
||||||
}
|
|
||||||
else if (Path.GetExtension(blockBlob.Uri.AbsolutePath.ToLower()) == ".version")
|
|
||||||
{
|
|
||||||
blockBlob.Properties.ContentType = "text/plain";
|
|
||||||
blockBlob.Properties.CacheControl = "no-cache";
|
|
||||||
blockBlob.SetPropertiesAsync().Wait();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<string> ListBlobs(Product product, string version)
|
public IEnumerable<string> ListBlobs(Product product, string version)
|
||||||
{
|
{
|
||||||
string virtualDirectory = $"{product}/{version}";
|
throw new NotImplementedException();
|
||||||
return ListBlobs(virtualDirectory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<string> ListBlobs(string virtualDirectory)
|
public IEnumerable<string> ListBlobs(string virtualDirectory)
|
||||||
{
|
{
|
||||||
CloudBlobDirectory blobDir = _blobContainer.GetDirectoryReference(virtualDirectory);
|
throw new NotImplementedException();
|
||||||
BlobContinuationToken continuationToken = new BlobContinuationToken();
|
|
||||||
|
|
||||||
var blobFiles = blobDir.ListBlobsSegmentedAsync(continuationToken).Result;
|
|
||||||
return blobFiles.Results.Select(bf => bf.Uri.PathAndQuery.Replace($"/{_containerName}/", string.Empty));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string AcquireLeaseOnBlob(
|
public string AcquireLeaseOnBlob(
|
||||||
|
@ -139,94 +67,32 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
TimeSpan? maxWaitDefault = null,
|
TimeSpan? maxWaitDefault = null,
|
||||||
TimeSpan? delayDefault = null)
|
TimeSpan? delayDefault = null)
|
||||||
{
|
{
|
||||||
TimeSpan maxWait = maxWaitDefault ?? TimeSpan.FromSeconds(120);
|
throw new NotImplementedException();
|
||||||
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);
|
|
||||||
Task<string> task = cloudBlob.AcquireLeaseAsync(TimeSpan.FromMinutes(1), null);
|
|
||||||
task.Wait();
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
CloudBlockBlob cloudBlob = _blobContainer.GetBlockBlobReference(blob);
|
throw new NotImplementedException();
|
||||||
AccessCondition ac = new AccessCondition() { LeaseId = leaseId };
|
|
||||||
cloudBlob.ReleaseLeaseAsync(ac).Wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsLatestSpecifiedVersion(string version)
|
public bool IsLatestSpecifiedVersion(string version)
|
||||||
{
|
{
|
||||||
Task<bool> task = _blobContainer.GetBlockBlobReference(version).ExistsAsync();
|
throw new NotImplementedException();
|
||||||
task.Wait();
|
|
||||||
return task.Result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DropLatestSpecifiedVersion(string version)
|
public void DropLatestSpecifiedVersion(string version)
|
||||||
{
|
{
|
||||||
CloudBlockBlob blob = _blobContainer.GetBlockBlobReference(version);
|
throw new NotImplementedException();
|
||||||
using (MemoryStream ms = new MemoryStream())
|
|
||||||
{
|
|
||||||
blob.UploadFromStreamAsync(ms).Wait();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CreateBlobIfNotExists(string path)
|
public void CreateBlobIfNotExists(string path)
|
||||||
{
|
{
|
||||||
Task<bool> task = _blobContainer.GetBlockBlobReference(path).ExistsAsync();
|
throw new NotImplementedException();
|
||||||
task.Wait();
|
|
||||||
if (!task.Result)
|
|
||||||
{
|
|
||||||
CloudBlockBlob blob = _blobContainer.GetBlockBlobReference(path);
|
|
||||||
using (MemoryStream ms = new MemoryStream())
|
|
||||||
{
|
|
||||||
blob.UploadFromStreamAsync(ms).Wait();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryDeleteBlob(string path)
|
public bool TryDeleteBlob(string path)
|
||||||
{
|
{
|
||||||
try
|
throw new NotImplementedException();
|
||||||
{
|
|
||||||
DeleteBlob(path);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Deleting blob {path} failed with \r\n{e.Message}");
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DeleteBlob(string path)
|
|
||||||
{
|
|
||||||
_blobContainer.GetBlockBlobReference(path).DeleteAsync().Wait();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string CalculateRelativePathForFile(string file, Product product, string version)
|
|
||||||
{
|
|
||||||
return $"{product}/{version}/{Path.GetFileName(file)}";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,13 +12,13 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
|
||||||
<PackageReference Include="NETStandard.Library" Version="1.6.0" />
|
<PackageReference Include="NETStandard.Library" Version="1.6.0" />
|
||||||
<PackageReference Include="System.Reflection.Metadata" Version="1.4.1-beta-24410-02" />
|
<PackageReference Include="System.Reflection.Metadata" Version="1.4.1-beta-24410-02" />
|
||||||
<PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.1.1" />
|
<PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.1.1" />
|
||||||
<PackageReference Include="System.Threading.Thread" Version="4.0.0" />
|
<PackageReference Include="System.Threading.Thread" Version="4.0.0" />
|
||||||
<PackageReference Include="System.Xml.XmlSerializer" Version="4.0.11" />
|
<PackageReference Include="System.Xml.XmlSerializer" Version="4.0.11" />
|
||||||
<PackageReference Include="WindowsAzure.Storage" Version="7.2.1" />
|
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="2.0.0" />
|
||||||
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="1.0.1-beta-000933" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue