public static async Task Run([TimerTrigger("0 0 * * * 0")] TimerInfo myTimer, ILogger log) { // clean up blimp app every sunday secretsUtils = new SecretsUtils(); await secretsUtils.GetSecrets(); pipelineUtils = new PipelineUtils( new ContainerRegistryManagementClient(secretsUtils._credentials), new WebSiteManagementClient(secretsUtils._credentials), secretsUtils._subId ); resourceGroupName = "blimprg"; webClient = new WebSiteManagementClient(secretsUtils._credentials) { SubscriptionId = secretsUtils._subId }; DeleteApps("blimp-dotnetcore-plan"); DeleteApps("blimp-node-plan"); DeleteApps("blimp-php-plan"); DeleteApps("blimp-python-plan"); DeleteApps("blimp-ruby-plan"); DeleteImages("blimpacr", "dotnetcore"); DeleteImages("blimpacr", "node"); DeleteImages("blimpacr", "php"); DeleteImages("blimpacr", "python"); DeleteImages("blimpacr", "ruby"); }
private static async void cleanupACRStack(String stack) { SecretsUtils secretsUtils = new SecretsUtils(); await secretsUtils.GetSecrets(); PipelineUtils pipelineUtils = new PipelineUtils( new ContainerRegistryManagementClient(secretsUtils._credentials), new WebSiteManagementClient(secretsUtils._credentials), secretsUtils._subId); var client = new RestClient(String.Format("https://blimpacr.azurecr.io/v2/{0}/tags/list", stack)); var request = new RestRequest(Method.GET); request.AddHeader("Host", "blimpacr.azurecr.io"); request.AddHeader("Cache-Control", "no-cache"); String token = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes( String.Format("{0}:{1}", "blimpacr", secretsUtils._acrPassword))); request.AddHeader("Authorization", String.Format("Basic {0}", token)); // add logic for next page // or just run again IRestResponse response = client.Execute(request); var json = JsonConvert.DeserializeObject <dynamic>(response.Content.ToString()); var tags = json.tags; foreach (String t in tags) { if (t.Contains("2019")) { Console.WriteLine(String.Format("{0}:{1}", stack, t)); pipelineUtils.DeleteImage("blimpacr", stack, t, "blimpacr", secretsUtils._acrPassword); } } }
public static async Task <string> updateStack([ActivityTrigger] UpdateBaseImageRequest request, ILogger log) { SecretsUtils _secretsUtils = new SecretsUtils(); await _secretsUtils.GetSecrets(); GitHubUtils _githubUtils = new GitHubUtils(_secretsUtils._gitToken); String timeStamp = DateTime.Now.ToString("yyyyMMddHHmmss"); String random = new Random().Next(0, 9999).ToString(); String prname = String.Format("blimp{0}{1}", timeStamp, random); String parent = String.Format("D:\\local\\Temp\\blimp{0}{1}", timeStamp, random); String repoUrl = String.Format("https://github.com/Azure-App-Service/{0}-template.git", request.stack); String repoName = String.Format("{0}-template", request.stack); _githubUtils.CreateDir(parent); String localTemplateRepoPath = String.Format("{0}\\{1}", parent, repoName); _githubUtils.Clone(repoUrl, localTemplateRepoPath, "dev"); _githubUtils.Checkout(localTemplateRepoPath, prname); // edit the configs await updateConfig(String.Format("{0}\\{1}", localTemplateRepoPath, "blessedImageConfig-dev.json"), request.NewBaseImage); await updateConfig(String.Format("{0}\\{1}", localTemplateRepoPath, "blessedImageConfig-master.json"), request.NewBaseImage); await updateConfig(String.Format("{0}\\{1}", localTemplateRepoPath, "blessedImageConfig-temp.json"), request.NewBaseImage); await updateConfig(String.Format("{0}\\{1}", localTemplateRepoPath, "blessedImageConfig-save.json"), request.NewBaseImage); _githubUtils.Stage(localTemplateRepoPath, "*"); _githubUtils.CommitAndPush(localTemplateRepoPath, prname, String.Format("[blimp] new base image {0}", request.NewBaseImage)); String pullRequestURL = String.Format("https://api.github.com/repos/{0}/{1}-template/pulls?access_token={2}", "azure-app-service", request.stack, _secretsUtils._gitToken); String body = "{ " + "\"title\": " + JsonConvert.SerializeObject("[blimp] Update Base Image") + ", " + "\"body\": " + JsonConvert.SerializeObject("[blimp] auto generated Update Base Image") + ", " + "\"head\": " + JsonConvert.SerializeObject("azure-app-service:" + prname) + ", " + "\"base\": " + JsonConvert.SerializeObject("dev") + "}"; HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("patricklee2"); HttpResponseMessage response = null; response = await httpClient.PostAsync(pullRequestURL, new StringContent(body)); // fails on empty commits String result = await response.Content.ReadAsStringAsync(); System.Console.WriteLine(response.ToString()); System.Console.WriteLine(result); //if (response.StatusCode == HttpStatusCode.UnprocessableEntity) //{ // System.Console.WriteLine("Unable to make PR due to no differnce"); //} _githubUtils.gitDispose(localTemplateRepoPath); _githubUtils.Delete(parent); return(""); }