Esempio n. 1
0
        //[FunctionName("TimerPython")]
        public static async System.Threading.Tasks.Task RunAsync([TimerTrigger("0 8 * * *")] TimerInfo myTimer, ILogger log)
        {
            TelemetryClient telemetry = new TelemetryClient();

            telemetry.TrackEvent("TimerPython started");

            try
            {
                SecretsUtils secretsUtils = new SecretsUtils();
                await secretsUtils.GetSecrets();

                DockerhubUtils dockerhubUtils = new DockerhubUtils();

                List <String> newTags = await dockerhubUtils.PollDockerhubRepos("https://registry.hub.docker.com/v2/repositories/oryxprod",
                                                                                new Regex("^python-[0-9]+\\.[0-9]+$", RegexOptions.Compiled | RegexOptions.IgnoreCase),
                                                                                new Regex("^(?!.*latest).*$", RegexOptions.Compiled | RegexOptions.IgnoreCase),
                                                                                DateTime.Now.AddDays(-1));

                log.LogInformation(String.Format("Python: {0} tags found {1}", newTags.Count, String.Join(", ", newTags)));
                telemetry.TrackEvent(String.Format("Python: {0} tags found {1}", newTags.Count, String.Join(", ", newTags)));
                foreach (String t in newTags)
                {
                    try
                    {
                        List <String> tag = new List <String> {
                            String.Format("oryxprod/{0}", t)
                        };
                        HttpClient client = new HttpClient();
                        String     url    = String.Format("https://appsvcbuildfunc.azurewebsites.net/api/HttpPythonPipeline?code={0}", secretsUtils._appsvcbuildfuncMaster);
                        String     body   = "{\"newTags\": " + JsonConvert.SerializeObject(tag) + "}";
                        client.Timeout = new TimeSpan(3, 0, 0);

                        HttpResponseMessage response = await client.PostAsync(url, new StringContent(body));

                        String result = await response.Content.ReadAsStringAsync();

                        if (response.StatusCode == HttpStatusCode.OK)
                        {
                            log.LogInformation(result);
                            telemetry.TrackEvent(result);
                        }
                        else
                        {
                            log.LogInformation(response.ToString());
                            telemetry.TrackEvent(response.ToString());
                        }
                    }
                    catch (Exception ex)
                    {
                        log.LogInformation(ex.ToString());
                        telemetry.TrackException(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                log.LogInformation(ex.ToString());
                telemetry.TrackException(ex);
            }
        }
Esempio n. 2
0
        //[FunctionName("TimerRuby")]
        public static async System.Threading.Tasks.Task RunAsync([TimerTrigger("0 8 * * *")] TimerInfo myTimer, ILogger log)
        {
            TelemetryClient telemetry = new TelemetryClient();

            telemetry.TrackEvent("TimerRuby started");

            try
            {
                SecretsUtils secretsUtils = new SecretsUtils();
                await secretsUtils.GetSecrets();

                DockerhubUtils dockerhubUtils = new DockerhubUtils();

                List <String> newTags = new List <string> {
                    "ruby:2.3.8", "ruby:2.4.5", "ruby:2.5.5", "ruby:2.6.2"
                };

                log.LogInformation(String.Format("Ruby: {0} tags found {1}", newTags.Count, String.Join(", ", newTags)));
                telemetry.TrackEvent(String.Format("Ruby: {0} tags found {1}", newTags.Count, String.Join(", ", newTags)));
                foreach (String t in newTags)
                {
                    try
                    {
                        List <String> tag = new List <String> {
                            t
                        };
                        HttpClient client = new HttpClient();
                        String     url    = String.Format("https://appsvcbuildfunc.azurewebsites.net/api/HttpRubyPipeline?code={0}", secretsUtils._appsvcbuildfuncMaster);
                        String     body   = "{\"newTags\": " + JsonConvert.SerializeObject(tag) + "}";
                        client.Timeout = new TimeSpan(3, 0, 0);

                        HttpResponseMessage response = await client.PostAsync(url, new StringContent(body));

                        String result = await response.Content.ReadAsStringAsync();

                        if (response.StatusCode == HttpStatusCode.OK)
                        {
                            log.LogInformation(result);
                            telemetry.TrackEvent(result);
                        }
                        else
                        {
                            log.LogInformation(response.ToString());
                            telemetry.TrackEvent(response.ToString());
                        }
                    }
                    catch (Exception ex)
                    {
                        log.LogInformation(ex.ToString());
                        telemetry.TrackException(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                log.LogInformation(ex.ToString());
                telemetry.TrackException(ex);
            }
        }
        public static async System.Threading.Tasks.Task InitUtils(ILogger log)
        {
            _emailLog     = new StringBuilder();
            _secretsUtils = new SecretsUtils();
            await _secretsUtils.GetSecrets();

            _mailUtils      = new MailUtils(new SendGridClient(_secretsUtils._sendGridApiKey), "Python");
            _dockerhubUtils = new DockerhubUtils();
            _githubUtils    = new GitHubUtils(_secretsUtils._gitToken);
            _pipelineUtils  = new PipelineUtils(
                new ContainerRegistryManagementClient(_secretsUtils._credentials),
                new WebSiteManagementClient(_secretsUtils._credentials),
                _secretsUtils._subId
                );

            _log                 = log;
            _mailUtils._log      = log;
            _dockerhubUtils._log = log;
            _githubUtils._log    = log;
            _pipelineUtils._log  = log;
        }