internal static async Task <bool> DeployAciInstance(string templateFileName, string subscriptionId, string resourceGroupName, string aciName, string jobName)
        {
            try
            {
                if (await ShouldDeleteExistingInstance(templateFileName, subscriptionId, resourceGroupName, aciName))
                {
                    await DeleteAciInstance(subscriptionId, resourceGroupName, aciName);
                }
                var rgName               = resourceGroupName;
                var deploymentName       = jobName;
                var templateFileContents = File.ReadAllText(templateFileName);

                log.LogInformation($"Starting a deployment for ACI '{aciName}' for job: {deploymentName}");
                bool success = await ArmHelper.SubmitDeployment(subscriptionId, rgName, templateFileContents, "{}", deploymentName);

                log.LogInformation($"Completed ACI deployment: {deploymentName}. Waiting for identity assignment completion....");


                //Introduce a delay to see if that will help with what seems to be an issue with a timely managed identity assignment
                Thread.Sleep(10000);

                log.LogInformation("Completed ACI deployment");
                return(success);
            }
            catch (Exception ex)
            {
                log.LogError($"Unable to deploy ACI instance: {ex.Message}");
                return(false);
            }
        }
Beispiel #2
0
        internal static async Task <bool> DeployContainerApp(CommandLineArgs cmdLine)
        {
            try
            {
                // https://github.com/Azure-Samples/azure-samples-net-management/blob/master/samples/resources/deploy-using-arm-template/Program.cs
                var    rgName           = cmdLine.ContainerAppArgs.ResourceGroup;
                var    subId            = cmdLine.ContainerAppArgs.SubscriptionId;
                var    deploymentName   = cmdLine.JobName;
                string parametersString = GetParametersString(cmdLine);
                log.LogDebug($"ContainerApp parameters:{Environment.NewLine}{parametersString}");
                log.LogDebug(GetSecretsString(cmdLine));
                log.LogDebug(GetEnvironmentVariablesString(cmdLine));

                string templateString = GetTemplateFileContents(cmdLine);
                log.LogDebug($"ContainerApp template:{Environment.NewLine}{templateString}");
                log.LogInformation($"Starting a deployment for Container App 'sbm{deploymentName}' in environment '{cmdLine.ContainerAppArgs.EnvironmentName}'");
                bool success = await ArmHelper.SubmitDeployment(subId, rgName, templateString, parametersString, $"sbm{deploymentName}");

                if (success)
                {
                    //Introduce a delay to see if that will help with what seems to be an issue with a timely managed identity assignment
                    Thread.Sleep(10000);
                    log.LogInformation("Completed Container App deployment: " + deploymentName);
                }
                else
                {
                    log.LogError("Container App deployment failed. Unablet to proceed.");
                }
                return(success);
            }
            catch (Exception ex)
            {
                log.LogError($"Unable to deploy Container App instance: {ex.Message}");
                return(false);
            }
        }