public async Task <DeployStatus> PerformServerSideBuild(Site functionApp, Func <Task <Stream> > zipFileFactory, Func <HttpClient, Task <DeployStatus> > deploymentStatusPollTask) { using (var handler = new ProgressMessageHandler(new HttpClientHandler())) using (var client = GetRemoteZipClient(new Uri($"https://{functionApp.ScmUri}"), handler)) using (var request = new HttpRequestMessage(HttpMethod.Post, new Uri( $"api/zipdeploy?isAsync=true&author={Environment.MachineName}", UriKind.Relative))) { ColoredConsole.WriteLine("Creating archive for current directory..."); request.Headers.IfMatch.Add(EntityTagHeaderValue.Any); (var content, var length) = CreateStreamContentZip(await zipFileFactory()); request.Content = content; HttpResponseMessage response = await PublishHelper.InvokeLongRunningRequest(client, handler, request, length, "Uploading"); await PublishHelper.CheckResponseStatusAsync(response, "Uploading archive..."); // Streaming deployment status for Linux Server Side Build DeployStatus status = await deploymentStatusPollTask(client); if (status == DeployStatus.Success) { ColoredConsole.WriteLine(Green("Remote build succeeded!")); } else if (status == DeployStatus.Failed) { throw new CliException("Remote build failed!"); } else if (status == DeployStatus.Unknown) { ColoredConsole.WriteLine(Yellow($"Failed to retrieve remote build status, please visit https://{functionApp.ScmUri}/api/deployments")); } return(status); } }
public async Task <DeployStatus> PerformServerSideBuild(Site functionApp, Func <Task <Stream> > zipFileFactory, Func <HttpClient, Task <DeployStatus> > deploymentStatusPollTask, bool attachRestrictedToken = true) { if (string.IsNullOrEmpty(functionApp.ScmUri)) { throw new CliException("Remote build is a new feature added to function apps. " + $"Your function app {functionApp.SiteName} does not support remote build as it was created before August 1st, 2019."); } using (var handler = new ProgressMessageHandler(new HttpClientHandler())) using (var client = GetRemoteZipClient(new Uri($"https://{functionApp.ScmUri}"), handler)) using (var request = new HttpRequestMessage(HttpMethod.Post, new Uri( $"api/zipdeploy?isAsync=true&author={Environment.MachineName}", UriKind.Relative))) { ColoredConsole.WriteLine("Creating archive for current directory..."); request.Headers.IfMatch.Add(EntityTagHeaderValue.Any); (var content, var length) = CreateStreamContentZip(await zipFileFactory()); request.Content = content; if (attachRestrictedToken) { // Attach x-ms-site-restricted-token for Linux Consumption remote build string restrictedToken = await KuduLiteDeploymentHelpers.GetRestrictedToken(functionApp, AccessToken, ManagementURL); request.Headers.Add("x-ms-site-restricted-token", restrictedToken); } HttpResponseMessage response = await PublishHelper.InvokeLongRunningRequest(client, handler, request, length, "Uploading"); await PublishHelper.CheckResponseStatusAsync(response, "Uploading archive..."); // Streaming deployment status for Linux Server Side Build DeployStatus status = await deploymentStatusPollTask(client); if (status == DeployStatus.Success) { ColoredConsole.WriteLine(Green("Remote build succeeded!")); } else if (status == DeployStatus.Failed) { throw new CliException("Remote build failed!"); } return(status); } }
public async Task PublishZipDeploy(Site functionApp, Func <Task <Stream> > zipFileFactory) { await RetryHelper.Retry(async() => { using (var handler = new ProgressMessageHandler(new HttpClientHandler())) using (var client = GetRemoteZipClient(new Uri($"https://{functionApp.ScmUri}"), handler)) using (var request = new HttpRequestMessage(HttpMethod.Post, new Uri("api/zipdeploy", UriKind.Relative))) { request.Headers.IfMatch.Add(EntityTagHeaderValue.Any); ColoredConsole.WriteLine("Creating archive for current directory..."); (var content, var length) = CreateStreamContentZip(await zipFileFactory()); request.Content = content; HttpResponseMessage response = await PublishHelper.InvokeLongRunningRequest(client, handler, request, length, "Uploading"); await PublishHelper.CheckResponseStatusAsync(response, "uploading archive"); ColoredConsole.WriteLine("Upload completed successfully."); } }, 2); }
public async Task <DeployStatus> PerformServerSideBuild(Site functionApp, Func <Task <Stream> > zipFileFactory, Func <HttpClient, Task <DeployStatus> > deploymentStatusPollTask) { if (string.IsNullOrEmpty(functionApp.ScmUri)) { throw new CliException($"Remote build is a new feature added to function apps.{Environment.NewLine}" + $"Your function app {functionApp.SiteName} does not support remote build as it was created before August 1st, 2019.{Environment.NewLine}" + $"Please use '--build local', '--build-native-deps' or manually enable remote build.{Environment.NewLine}" + $"For more information, please visit https://aka.ms/remotebuild"); } using (var handler = new ProgressMessageHandler(new HttpClientHandler())) using (var client = GetRemoteZipClient(new Uri($"https://{functionApp.ScmUri}"), handler)) using (var request = new HttpRequestMessage(HttpMethod.Post, new Uri( $"api/zipdeploy?isAsync=true&author={Environment.MachineName}", UriKind.Relative))) { ColoredConsole.WriteLine("Creating archive for current directory..."); request.Headers.IfMatch.Add(EntityTagHeaderValue.Any); (var content, var length) = CreateStreamContentZip(await zipFileFactory()); request.Content = content; HttpResponseMessage response = await PublishHelper.InvokeLongRunningRequest(client, handler, request, length, "Uploading"); await PublishHelper.CheckResponseStatusAsync(response, "Uploading archive..."); // Streaming deployment status for Linux Server Side Build DeployStatus status = await deploymentStatusPollTask(client); if (status == DeployStatus.Success) { ColoredConsole.WriteLine(Green("Remote build succeeded!")); } else if (status == DeployStatus.Failed) { throw new CliException("Remote build failed!"); } return(status); } }
public async Task <DeployStatus> PerformServerSideBuild(Site functionApp, Func <Task <Stream> > zipFileFactory) { using (var handler = new ProgressMessageHandler(new HttpClientHandler())) using (var client = GetRemoteZipClient(new Uri($"https://{functionApp.ScmUri}"), handler)) using (var request = new HttpRequestMessage(HttpMethod.Post, new Uri( $"api/zipdeploy?isAsync=true&author={Environment.MachineName}", UriKind.Relative))) { ColoredConsole.WriteLine("Creating archive for current directory..."); request.Headers.IfMatch.Add(EntityTagHeaderValue.Any); // Attach x-ms-site-restricted-token for Linux Consumption remote build string restrictedToken = await KuduLiteDeploymentHelpers.GetRestrictedToken(functionApp, AccessToken, ManagementURL); (var content, var length) = CreateStreamContentZip(await zipFileFactory()); request.Content = content; request.Headers.Add("x-ms-site-restricted-token", restrictedToken); HttpResponseMessage response = await PublishHelper.InvokeLongRunningRequest(client, handler, request, length, "Uploading"); await PublishHelper.CheckResponseStatusAsync(response, "uploading archive"); // Streaming deployment status for Linux Dynamic Server Side Build DeployStatus status = await KuduLiteDeploymentHelpers.WaitForServerSideBuild(client, functionApp, AccessToken, ManagementURL); if (status == DeployStatus.Success) { ColoredConsole.WriteLine(Green("Server side build succeeded!")); } else if (status == DeployStatus.Failed) { ColoredConsole.WriteLine(Red("Server side build failed!")); } return(status); } }