예제 #1
0
        async Task LoadAllApps()
        {
            using (var response = await _client.GetAsync(
                       $"/subscriptions/{_config.Subscription}/resourceGroups/{_config.ResourceGroup}/providers/Microsoft.Web/sites?api-version=2016-03-01"))
            {
                response.EnsureSuccessStatusCode();

                var allApps = await response.Content.ReadAsAsync <dynamic>();

                // Delete any app we find that has been used before
                var allDeleteTasks = new List <Task>();

                JObject appsInUse = GetInUseAppNames();

                foreach (var appProps in allApps.value)
                {
                    BaseApp app;
                    string  appName = appProps.properties.name;
                    if (appName.StartsWith("Linux"))
                    {
                        app = new LinuxApp(_client, _config, Logger, appProps.properties);
                    }
                    else
                    {
                        app = new WindowsApp(_client, _config, Logger, appProps.properties);
                    }

                    if (appsInUse[appName] != null)
                    {
                        allDeleteTasks.Add(app.Delete());
                    }
                    else
                    {
                        if (app is LinuxApp)
                        {
                            _allFreeApps[Language.Ruby].Enqueue(app);
                        }
                        else
                        {
                            _allFreeApps[Language.Node].Enqueue(app);
                        }
                    }
                }

                await Task.WhenAll(allDeleteTasks);

                if (File.Exists(InUseFilePath))
                {
                    File.Delete(InUseFilePath);
                }
            }
        }
예제 #2
0
        public static async Task <BaseApp> CreateApp(HttpClient client, MyConfig config, ILogger <AppManager> logger, string appName)
        {
            using (var response = await client.PutAsJsonAsync(
                       $"/subscriptions/{config.Subscription}/resourceGroups/{config.ResourceGroup}/providers/Microsoft.Web/sites/{appName}?api-version=2016-03-01",
                       new
            {
                location = config.Region,
                properties = new
                {
                    siteConfig = new
                    {
                        appSettings = new[]
                        {
                            new
                            {
                                name = "DOCKER_CUSTOM_IMAGE_NAME",
                                value = config.DockerImageName
                            },
                            new
                            {
                                name = "DOCKER_REGISTRY_SERVER_URL",
                                value = config.DockerServerURL
                            },
                            new
                            {
                                name = "DOCKER_REGISTRY_SERVER_USERNAME",
                                value = config.DockerRegistryUserName
                            },
                            new
                            {
                                name = "DOCKER_REGISTRY_SERVER_PASSWORD",
                                value = config.DockerRegistryPassword
                            }
                        },
                        appCommandLine = "",
                        linuxFxVersion = $"DOCKER|{config.DockerImageName}"
                    },
                    serverFarmId = config.ServerFarmId,
                }
            }))
            {
                response.EnsureSuccessStatusCode();

                var json = await response.Content.ReadAsAsync <dynamic>();

                var app = new LinuxApp(client, config, logger, json.properties);

                await app.CompleteCreation();

                return(app);
            }
        }
예제 #3
0
        async Task CreateNewAppsIfNeededFor(Language language, int freeAppQueueSize)
        {
            var neededApps = freeAppQueueSize - _allFreeApps[language].Count;

            var newAppTasks = new List <Task <BaseApp> >();

            for (int i = 0; i < neededApps; i++)
            {
                newAppTasks.Add(language == Language.Ruby
                    ? LinuxApp.CreateApp(_client, _config, Logger, "Linuxfunclite-" + Guid.NewGuid())
                    : WindowsApp.CreateApp(_client, _config, Logger, "funclite-" + Environment.TickCount + "-" + Guid.NewGuid()));
            }

            foreach (var app in await Task.WhenAll(newAppTasks))
            {
                _allFreeApps[language].Enqueue(app);
            }
        }