2016-02-15 18:07:39 +00:00
|
|
|
|
using System;
|
2016-02-12 18:11:30 +00:00
|
|
|
|
using System.IO;
|
2016-03-16 21:39:02 +00:00
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Text;
|
2016-02-15 18:07:39 +00:00
|
|
|
|
using Microsoft.DotNet.Cli.Build.Framework;
|
2016-03-07 20:20:50 +00:00
|
|
|
|
using Microsoft.WindowsAzure.Storage;
|
|
|
|
|
using Microsoft.WindowsAzure.Storage.Blob;
|
2016-02-12 18:11:30 +00:00
|
|
|
|
|
|
|
|
|
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli.Build
|
|
|
|
|
{
|
|
|
|
|
public static class PublishTargets
|
|
|
|
|
{
|
2016-03-07 20:20:50 +00:00
|
|
|
|
private static CloudBlobContainer BlobContainer { get; set; }
|
|
|
|
|
|
2016-03-07 22:52:41 +00:00
|
|
|
|
private static string Channel { get; set; }
|
2016-03-07 20:20:50 +00:00
|
|
|
|
|
|
|
|
|
private static string Version { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Target]
|
|
|
|
|
public static BuildTargetResult InitPublish(BuildTargetContext c)
|
|
|
|
|
{
|
|
|
|
|
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("CONNECTION_STRING").Trim('"'));
|
|
|
|
|
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
|
|
|
|
|
BlobContainer = blobClient.GetContainerReference("dotnet");
|
|
|
|
|
|
|
|
|
|
Version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
|
2016-03-07 22:52:41 +00:00
|
|
|
|
Channel = c.BuildContext.Get<string>("Channel");
|
2016-03-07 20:20:50 +00:00
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Target(nameof(PrepareTargets.Init),
|
|
|
|
|
nameof(PublishTargets.InitPublish),
|
2016-03-16 21:39:02 +00:00
|
|
|
|
nameof(PublishTargets.PublishArtifacts),
|
|
|
|
|
nameof(PublishTargets.TriggerDockerHubBuilds))]
|
2016-03-07 22:52:41 +00:00
|
|
|
|
[Environment("PUBLISH_TO_AZURE_BLOB", "1", "true")] // This is set by CI systems
|
2016-02-12 18:11:30 +00:00
|
|
|
|
public static BuildTargetResult Publish(BuildTargetContext c)
|
|
|
|
|
{
|
2016-03-07 20:20:50 +00:00
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
2016-02-16 19:39:17 +00:00
|
|
|
|
|
2016-03-07 20:20:50 +00:00
|
|
|
|
[Target(nameof(PublishTargets.PublishVersionBadge),
|
|
|
|
|
nameof(PublishTargets.PublishCompressedFile),
|
2016-03-08 21:39:41 +00:00
|
|
|
|
nameof(PublishTargets.PublishSdkInstallerFile),
|
2016-03-15 18:55:56 +00:00
|
|
|
|
nameof(PublishTargets.PublishDebFileToDebianRepo),
|
2016-03-14 23:44:52 +00:00
|
|
|
|
nameof(PublishTargets.PublishSharedFrameworkCompressedFile),
|
|
|
|
|
nameof(PublishTargets.PublishSharedHostCompressedFile),
|
2016-03-16 00:41:42 +00:00
|
|
|
|
nameof(PublishTargets.PublishCombinedFrameworkSDKHostFile),
|
|
|
|
|
nameof(PublishTargets.PublishCombinedFrameworkHostFile),
|
2016-03-07 20:20:50 +00:00
|
|
|
|
nameof(PublishTargets.PublishLatestVersionTextFile))]
|
|
|
|
|
public static BuildTargetResult PublishArtifacts(BuildTargetContext c)
|
|
|
|
|
{
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
2016-02-12 18:11:30 +00:00
|
|
|
|
|
2016-03-07 20:20:50 +00:00
|
|
|
|
[Target]
|
|
|
|
|
public static BuildTargetResult PublishVersionBadge(BuildTargetContext c)
|
|
|
|
|
{
|
|
|
|
|
var versionBadge = c.BuildContext.Get<string>("VersionBadge");
|
|
|
|
|
var latestVersionBadgeBlob = $"{Channel}/Binaries/Latest/{Path.GetFileName(versionBadge)}";
|
|
|
|
|
var versionBadgeBlob = $"{Channel}/Binaries/{Version}/{Path.GetFileName(versionBadge)}";
|
2016-02-12 18:11:30 +00:00
|
|
|
|
|
2016-03-07 20:20:50 +00:00
|
|
|
|
PublishFileAzure(versionBadgeBlob, versionBadge);
|
|
|
|
|
PublishFileAzure(latestVersionBadgeBlob, versionBadge);
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Target]
|
|
|
|
|
public static BuildTargetResult PublishCompressedFile(BuildTargetContext c)
|
|
|
|
|
{
|
2016-03-08 21:39:41 +00:00
|
|
|
|
var compressedFile = c.BuildContext.Get<string>("SdkCompressedFile");
|
2016-03-07 20:20:50 +00:00
|
|
|
|
var compressedFileBlob = $"{Channel}/Binaries/{Version}/{Path.GetFileName(compressedFile)}";
|
|
|
|
|
var latestCompressedFile = compressedFile.Replace(Version, "latest");
|
|
|
|
|
var latestCompressedFileBlob = $"{Channel}/Binaries/Latest/{Path.GetFileName(latestCompressedFile)}";
|
|
|
|
|
|
|
|
|
|
PublishFileAzure(compressedFileBlob, compressedFile);
|
|
|
|
|
PublishFileAzure(latestCompressedFileBlob, compressedFile);
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Target]
|
|
|
|
|
[BuildPlatforms(BuildPlatform.Windows, BuildPlatform.OSX, BuildPlatform.Ubuntu)]
|
2016-03-08 21:39:41 +00:00
|
|
|
|
public static BuildTargetResult PublishSdkInstallerFile(BuildTargetContext c)
|
2016-03-07 20:20:50 +00:00
|
|
|
|
{
|
2016-03-08 21:39:41 +00:00
|
|
|
|
var installerFile = c.BuildContext.Get<string>("SdkInstallerFile");
|
2016-03-07 20:20:50 +00:00
|
|
|
|
var installerFileBlob = $"{Channel}/Installers/{Version}/{Path.GetFileName(installerFile)}";
|
|
|
|
|
var latestInstallerFile = installerFile.Replace(Version, "latest");
|
|
|
|
|
var latestInstallerFileBlob = $"{Channel}/Installers/Latest/{Path.GetFileName(latestInstallerFile)}";
|
|
|
|
|
|
|
|
|
|
PublishFileAzure(installerFileBlob, installerFile);
|
|
|
|
|
PublishFileAzure(latestInstallerFileBlob, installerFile);
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Target]
|
|
|
|
|
public static BuildTargetResult PublishLatestVersionTextFile(BuildTargetContext c)
|
|
|
|
|
{
|
|
|
|
|
var osname = Monikers.GetOSShortName();
|
|
|
|
|
var latestVersionBlob = $"{Channel}/dnvm/latest.{osname}.{CurrentArchitecture.Current}.version";
|
|
|
|
|
var latestVersionFile = Path.Combine(Dirs.Stage2, ".version");
|
|
|
|
|
|
|
|
|
|
PublishFileAzure(latestVersionBlob, latestVersionFile);
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-08 21:39:41 +00:00
|
|
|
|
[Target(nameof(PublishSdkInstallerFile))]
|
2016-03-08 23:33:18 +00:00
|
|
|
|
[BuildPlatforms(BuildPlatform.Ubuntu)]
|
|
|
|
|
public static BuildTargetResult PublishDebFileToDebianRepo(BuildTargetContext c)
|
|
|
|
|
{
|
|
|
|
|
var packageName = Monikers.GetDebianPackageName(c);
|
2016-03-08 21:39:41 +00:00
|
|
|
|
var installerFile = c.BuildContext.Get<string>("SdkInstallerFile");
|
2016-03-16 21:39:02 +00:00
|
|
|
|
var uploadUrl = $"https://dotnetcli.blob.core.windows.net/dotnet/{Channel}/Installers/{Version}/{Path.GetFileName(installerFile)}";
|
2016-03-08 23:33:18 +00:00
|
|
|
|
var uploadJson = GenerateUploadJsonFile(packageName, Version, uploadUrl);
|
|
|
|
|
|
|
|
|
|
Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "publish", "repoapi_client.sh"), "-addpkg", uploadJson)
|
|
|
|
|
.Execute()
|
|
|
|
|
.EnsureSuccessful();
|
|
|
|
|
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-16 21:39:02 +00:00
|
|
|
|
[Target]
|
|
|
|
|
[Environment("DOCKER_HUB_REPO")]
|
|
|
|
|
[Environment("DOCKER_HUB_TRIGGER_TOKEN")]
|
|
|
|
|
public static BuildTargetResult TriggerDockerHubBuilds(BuildTargetContext c)
|
|
|
|
|
{
|
|
|
|
|
string dockerHubRepo = Environment.GetEnvironmentVariable("DOCKER_HUB_REPO");
|
|
|
|
|
string dockerHubTriggerToken = Environment.GetEnvironmentVariable("DOCKER_HUB_TRIGGER_TOKEN");
|
|
|
|
|
|
|
|
|
|
Uri baseDockerHubUri = new Uri("https://registry.hub.docker.com/u/");
|
|
|
|
|
Uri dockerHubTriggerUri;
|
|
|
|
|
if (!Uri.TryCreate(baseDockerHubUri, $"{dockerHubRepo}/trigger/{dockerHubTriggerToken}/", out dockerHubTriggerUri))
|
|
|
|
|
{
|
|
|
|
|
return c.Failed("Invalid DOCKER_HUB_REPO and/or DOCKER_HUB_TRIGGER_TOKEN");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.Info($"Triggering automated DockerHub builds for {dockerHubRepo}");
|
|
|
|
|
using (HttpClient client = new HttpClient())
|
|
|
|
|
{
|
|
|
|
|
StringContent requestContent = new StringContent("{\"build\": true}", Encoding.UTF8, "application/json");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
HttpResponseMessage response = client.PostAsync(dockerHubTriggerUri, requestContent).Result;
|
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sb.AppendLine($"HTTP request to {dockerHubTriggerUri.ToString()} was unsuccessful.");
|
|
|
|
|
sb.AppendLine($"Response status code: {response.StatusCode}. Reason phrase: {response.ReasonPhrase}.");
|
|
|
|
|
sb.Append($"Respone content: {response.Content.ReadAsStringAsync().Result}");
|
|
|
|
|
return c.Failed(sb.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (AggregateException e)
|
|
|
|
|
{
|
|
|
|
|
return c.Failed($"HTTP request to {dockerHubTriggerUri.ToString()} failed. {e.ToString()}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-08 23:33:18 +00:00
|
|
|
|
private static string GenerateUploadJsonFile(string packageName, string version, string uploadUrl)
|
|
|
|
|
{
|
|
|
|
|
var repoID = Environment.GetEnvironmentVariable("REPO_ID");
|
|
|
|
|
var uploadJson = Path.Combine(Dirs.Packages, "package_upload.json");
|
|
|
|
|
File.Delete(uploadJson);
|
|
|
|
|
|
|
|
|
|
using (var fileStream = File.Create(uploadJson))
|
|
|
|
|
{
|
|
|
|
|
using (StreamWriter sw = new StreamWriter(fileStream))
|
|
|
|
|
{
|
2016-03-16 21:39:02 +00:00
|
|
|
|
sw.WriteLine("{");
|
|
|
|
|
sw.WriteLine($" \"name\":\"{packageName}\",");
|
|
|
|
|
sw.WriteLine($" \"version\":\"{version}\",");
|
|
|
|
|
sw.WriteLine($" \"repositoryId\":\"{repoID}\",");
|
|
|
|
|
sw.WriteLine($" \"sourceUrl\":\"{uploadUrl}\"");
|
|
|
|
|
sw.WriteLine("}");
|
2016-03-08 23:33:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return uploadJson;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-15 01:46:56 +00:00
|
|
|
|
[Target]
|
2016-03-14 23:44:52 +00:00
|
|
|
|
public static BuildTargetResult PublishSharedFrameworkCompressedFile(BuildTargetContext c)
|
|
|
|
|
{
|
|
|
|
|
var compressedFile = c.BuildContext.Get<string>("SharedFrameworkCompressedFile");
|
|
|
|
|
var compressedFileBlob = $"{Channel}/Binaries/{Version}/{Path.GetFileName(compressedFile)}";
|
|
|
|
|
var latestCompressedFile = compressedFile.Replace(Version, "latest");
|
|
|
|
|
var latestCompressedFileBlob = $"{Channel}/Binaries/Latest/{Path.GetFileName(latestCompressedFile)}";
|
|
|
|
|
|
|
|
|
|
PublishFileAzure(compressedFileBlob, compressedFile);
|
|
|
|
|
PublishFileAzure(latestCompressedFileBlob, compressedFile);
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-15 01:46:56 +00:00
|
|
|
|
[Target]
|
2016-03-14 23:44:52 +00:00
|
|
|
|
public static BuildTargetResult PublishSharedHostCompressedFile(BuildTargetContext c)
|
|
|
|
|
{
|
|
|
|
|
var compressedFile = c.BuildContext.Get<string>("SharedHostCompressedFile");
|
|
|
|
|
var compressedFileBlob = $"{Channel}/Binaries/{Version}/{Path.GetFileName(compressedFile)}";
|
|
|
|
|
var latestCompressedFile = compressedFile.Replace(Version, "latest");
|
|
|
|
|
var latestCompressedFileBlob = $"{Channel}/Binaries/Latest/{Path.GetFileName(latestCompressedFile)}";
|
|
|
|
|
|
2016-03-16 00:41:42 +00:00
|
|
|
|
PublishFileAzure(compressedFileBlob, compressedFile);
|
|
|
|
|
PublishFileAzure(latestCompressedFileBlob, compressedFile);
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Target]
|
|
|
|
|
public static BuildTargetResult PublishCombinedFrameworkSDKHostFile(BuildTargetContext c)
|
|
|
|
|
{
|
|
|
|
|
var compressedFile = c.BuildContext.Get<string>("CombinedFrameworkSDKHostCompressedFile");
|
|
|
|
|
var compressedFileBlob = $"{Channel}/Binaries/{Version}/{Path.GetFileName(compressedFile)}";
|
|
|
|
|
var latestCompressedFile = compressedFile.Replace(Version, "latest");
|
|
|
|
|
var latestCompressedFileBlob = $"{Channel}/Binaries/Latest/{Path.GetFileName(latestCompressedFile)}";
|
|
|
|
|
|
|
|
|
|
PublishFileAzure(compressedFileBlob, compressedFile);
|
|
|
|
|
PublishFileAzure(latestCompressedFileBlob, compressedFile);
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Target]
|
|
|
|
|
public static BuildTargetResult PublishCombinedFrameworkHostFile(BuildTargetContext c)
|
|
|
|
|
{
|
|
|
|
|
var compressedFile = c.BuildContext.Get<string>("CombinedFrameworkHostCompressedFile");
|
|
|
|
|
var compressedFileBlob = $"{Channel}/Binaries/{Version}/{Path.GetFileName(compressedFile)}";
|
|
|
|
|
var latestCompressedFile = compressedFile.Replace(Version, "latest");
|
|
|
|
|
var latestCompressedFileBlob = $"{Channel}/Binaries/Latest/{Path.GetFileName(latestCompressedFile)}";
|
|
|
|
|
|
2016-03-14 23:44:52 +00:00
|
|
|
|
PublishFileAzure(compressedFileBlob, compressedFile);
|
|
|
|
|
PublishFileAzure(latestCompressedFileBlob, compressedFile);
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-07 20:20:50 +00:00
|
|
|
|
private static BuildTargetResult PublishFile(BuildTargetContext c, string file)
|
|
|
|
|
{
|
|
|
|
|
var env = PackageTargets.GetCommonEnvVars(c);
|
|
|
|
|
Cmd("powershell", "-NoProfile", "-NoLogo",
|
|
|
|
|
Path.Combine(Dirs.RepoRoot, "scripts", "publish", "publish.ps1"), file)
|
2016-02-12 18:11:30 +00:00
|
|
|
|
.Environment(env)
|
|
|
|
|
.Execute()
|
|
|
|
|
.EnsureSuccessful();
|
2016-03-07 20:20:50 +00:00
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void PublishFileAzure(string blob, string file)
|
|
|
|
|
{
|
|
|
|
|
CloudBlockBlob blockBlob = BlobContainer.GetBlockBlobReference(blob);
|
2016-03-10 18:23:52 +00:00
|
|
|
|
blockBlob.UploadFromFileAsync(file, FileMode.Open).Wait();
|
|
|
|
|
|
|
|
|
|
if (Path.GetExtension(blockBlob.Uri.AbsolutePath.ToLower()) == ".svg")
|
2016-02-12 18:11:30 +00:00
|
|
|
|
{
|
2016-03-10 18:23:52 +00:00
|
|
|
|
blockBlob.Properties.ContentType = "image/svg+xml";
|
2016-03-11 00:03:43 +00:00
|
|
|
|
blockBlob.Properties.CacheControl = "no-cache";
|
2016-03-10 18:23:52 +00:00
|
|
|
|
blockBlob.SetPropertiesAsync().Wait();
|
2016-02-12 18:11:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|