public ElasticBeanStalkDeploymentTest()
        {
            var filePath = Path.Combine("ConfigFileDeployment", "TestFiles", "UnitTestFiles", "ElasticBeanStalkConfigFile.json");
            var userDeploymentSettings = UserDeploymentSettings.ReadSettings(filePath);

            _userDeploymentSettings = userDeploymentSettings;
        }
        public async Task PerformDeployment()
        {
            // Deploy
            var projectPath    = _testAppManager.GetProjectPath(Path.Combine("testapps", "WebAppWithDockerFile", "WebAppWithDockerFile.csproj"));
            var configFilePath = Path.Combine(Directory.GetParent(projectPath).FullName, "ECSFargateConfigFile.json");

            ConfigFileHelper.ReplacePlaceholders(configFilePath);

            var userDeploymentSettings = UserDeploymentSettings.ReadSettings(configFilePath);

            _stackName   = userDeploymentSettings.StackName;
            _clusterName = userDeploymentSettings.LeafOptionSettingItems["ECSCluster.NewClusterName"];

            var deployArgs = new[] { "deploy", "--project-path", projectPath, "--apply", configFilePath, "--silent" };
            await _app.Run(deployArgs);

            // Verify application is deployed and running
            Assert.Equal(StackStatus.CREATE_COMPLETE, await _cloudFormationHelper.GetStackStatus(_stackName));

            var cluster = await _ecsHelper.GetCluster(_clusterName);

            Assert.Equal("ACTIVE", cluster.Status);
            Assert.Equal(cluster.ClusterName, _clusterName);

            var deployStdOut = _interactiveService.StdOutReader.ReadAllLines();

            var applicationUrl = deployStdOut.First(line => line.Trim().StartsWith("Endpoint:"))
                                 .Split(" ")[1]
                                 .Trim();

            // URL could take few more minutes to come live, therefore, we want to wait and keep trying for a specified timeout
            await _httpHelper.WaitUntilSuccessStatusCode(applicationUrl, TimeSpan.FromSeconds(5), TimeSpan.FromMinutes(5));

            // list
            var listArgs = new[] { "list-deployments" };
            await _app.Run(listArgs);

            // Verify stack exists in list of deployments
            var listDeployStdOut = _interactiveService.StdOutReader.ReadAllLines();

            Assert.Contains(listDeployStdOut, (deployment) => _stackName.Equals(deployment));

            // Arrange input for delete
            await _interactiveService.StdInWriter.WriteAsync("y"); // Confirm delete

            await _interactiveService.StdInWriter.FlushAsync();

            var deleteArgs = new[] { "delete-deployment", _stackName };

            // Delete
            await _app.Run(deleteArgs);

            // Verify application is deleted
            Assert.True(await _cloudFormationHelper.IsStackDeleted(_stackName), $"{_stackName} still exists.");
        }
Exemplo n.º 3
0
        /// <summary>
        /// This method is used to set the values for Option Setting Items when a deployment is being performed using a user specifed config file.
        /// </summary>
        /// <param name="recommendation">The selected recommendation settings used for deployment <see cref="Recommendation"/></param>
        /// <param name="userDeploymentSettings">The deserialized object from the user provided config file. <see cref="UserDeploymentSettings"/></param>
        private void ConfigureDeploymentFromConfigFile(Recommendation recommendation, UserDeploymentSettings userDeploymentSettings)
        {
            foreach (var entry in userDeploymentSettings.LeafOptionSettingItems)
            {
                var optionSettingJsonPath = entry.Key;
                var optionSettingValue    = entry.Value;

                var optionSetting = recommendation.GetOptionSetting(optionSettingJsonPath);

                if (!recommendation.IsExistingCloudApplication || optionSetting.Updatable)
                {
                    object settingValue;
                    try
                    {
                        switch (optionSetting.Type)
                        {
                        case OptionSettingValueType.String:
                            settingValue = optionSettingValue;
                            break;

                        case OptionSettingValueType.Int:
                            settingValue = int.Parse(optionSettingValue);
                            break;

                        case OptionSettingValueType.Bool:
                            settingValue = bool.Parse(optionSettingValue);
                            break;

                        case OptionSettingValueType.Double:
                            settingValue = double.Parse(optionSettingValue);
                            break;

                        default:
                            throw new InvalidOverrideValueException($"Invalid value {optionSettingValue} for option setting item {optionSettingJsonPath}");
                        }
                    }
                    catch (Exception)
                    {
                        throw new InvalidOverrideValueException($"Invalid value {optionSettingValue} for option setting item {optionSettingJsonPath}");
                    }

                    optionSetting.SetValueOverride(settingValue);

                    SetDeploymentBundleOptionSetting(recommendation, optionSetting.Id, settingValue);
                }
            }

            var validatorFailedResults =
                recommendation.Recipe
                .BuildValidators()
                .Select(validator => validator.Validate(recommendation.Recipe, _session))
                .Where(x => !x.IsValid)
                .ToList();

            if (!validatorFailedResults.Any())
            {
                // validation successful
                // deployment configured
                return;
            }

            var errorMessage = "The deployment configuration needs to be adjusted before it can be deployed:" + Environment.NewLine;

            foreach (var result in validatorFailedResults)
            {
                errorMessage += result.ValidationFailedMessage + Environment.NewLine;
            }
            throw new InvalidUserDeploymentSettingsException(errorMessage.Trim());
        }