in src/Cli/func/Helpers/AzureHelper.cs [573:630]
public static async Task<string> CreateFunctionAppOnContainerService(string accessToken, string managementURL, string subscriptionId, string resourceGroup, ContainerAppsFunctionPayload payload)
{
string hostName = string.Empty;
var url = new Uri($"{managementURL}/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Web/sites/{payload.Name}?api-version={ArmUriTemplates.FunctionAppOnContainerAppsApiVersion}");
ColoredConsole.WriteLine(Constants.FunctionAppDeploymentToContainerAppsMessage);
var response = await ArmClient.HttpInvoke(HttpMethod.Put, url, accessToken, payload);
if (!response.IsSuccessStatusCode)
{
string errorMessage;
try
{
var content = await response.Content.ReadAsStringAsync();
var errorResponse = JsonConvert.DeserializeObject<ContainerAppsFunctionDeployResponse>(content);
errorMessage = $"{Constants.FunctionAppFailedToDeployOnContainerAppsMessage} {(!string.IsNullOrWhiteSpace(errorResponse?.Message) ? $"Error: {errorResponse.Message}" : string.Empty)}";
}
catch (Exception)
{
errorMessage = Constants.FunctionAppFailedToDeployOnContainerAppsMessage;
}
throw new CliException(errorMessage);
}
var statusUrlHeader = response.Headers.GetValues("location").FirstOrDefault();
if (string.IsNullOrEmpty(statusUrlHeader))
{
throw new CliException(Constants.FunctionAppDeploymentToContainerAppsFailedMessage);
}
ColoredConsole.Write(Constants.FunctionAppDeploymentToContainerAppsStatusMessage);
var statusUrl = new Uri(statusUrlHeader);
int maxRetries = 12; // 12 * 5 seconds = 1 minute
for (int retry = 1; retry <= maxRetries; retry++)
{
var getResponse = await ArmClient.HttpInvoke(HttpMethod.Get, statusUrl, accessToken, payload);
if (getResponse.StatusCode != System.Net.HttpStatusCode.Accepted)
{
getResponse.EnsureSuccessStatusCode();
var content = await getResponse.Content.ReadAsStringAsync();
var deployResponse = JsonConvert.DeserializeObject<ContainerAppFunctonCreateResponse>(content);
hostName = deployResponse?.Properties?.DefaultHostName;
break;
}
if (retry == maxRetries)
{
throw new CliException("The creation of the function app could not be verified.");
}
// Waiting for 5 seconds before another request
await Task.Delay(TimeSpan.FromSeconds(5));
ColoredConsole.Write(".");
}
ColoredConsole.Write(Environment.NewLine);
ColoredConsole.WriteLine($"The functon app \"{payload.Name}\" was successfully deployed.");
return hostName;
}