Merge branch 'rel/1.0.0' of https://github.com/dotnet/cli into cli-sdk-stages
This commit is contained in:
commit
de8b326872
12 changed files with 179 additions and 63 deletions
|
@ -1,12 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using Microsoft.DotNet.Cli.Build.Framework;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
using Microsoft.WindowsAzure;
|
||||
using Microsoft.WindowsAzure.Storage;
|
||||
using Microsoft.WindowsAzure.Storage.Auth;
|
||||
using Microsoft.WindowsAzure.Storage.Blob;
|
||||
|
||||
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
|
||||
|
@ -36,7 +33,8 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
|
||||
[Target(nameof(PrepareTargets.Init),
|
||||
nameof(PublishTargets.InitPublish),
|
||||
nameof(PublishTargets.PublishArtifacts))]
|
||||
nameof(PublishTargets.PublishArtifacts),
|
||||
nameof(PublishTargets.TriggerDockerHubBuilds))]
|
||||
[Environment("PUBLISH_TO_AZURE_BLOB", "1", "true")] // This is set by CI systems
|
||||
public static BuildTargetResult Publish(BuildTargetContext c)
|
||||
{
|
||||
|
@ -107,6 +105,45 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
return c.Success();
|
||||
}
|
||||
|
||||
[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();
|
||||
}
|
||||
|
||||
private static string GenerateUploadJsonFile(string packageName, string version, string uploadUrl)
|
||||
{
|
||||
var repoID = Environment.GetEnvironmentVariable("REPO_ID");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue