private RunContext(ApplicationContext applicationContext, string action, ReleasesConfig releasesConfig, FeatureConfigCollection featuresConfig, TaskDefinitionConfigCollection taskDefinitionsConfig, TaskManager taskManager, ReleaseConfig activeRelease, EnvironmentConfig activeEnvironment, bool dryRun)
 {
     mApplicationContext = applicationContext;
     mAction = action;
     mReleasesConfig = releasesConfig;
     mFeaturesConfig = featuresConfig;
     mTaskDefinitionsConfig = taskDefinitionsConfig;
     mTaskManager = taskManager;
     mActiveRelease = activeRelease;
     mActiveEnvironment = activeEnvironment;
     mDryRun = dryRun;
 }
        public override void Run(ApplicationContext appContext, IEnumerable<string> args)
        {
            string release = null;
            string env = null;
            var dryRun = false;
            var resume = false;
            var noCache = appContext.UserConfig.Cache.Disabled;
            var noBeeps = false;

            var p = new OptionSet
            {
                { "r=|release=", "Select which release to use, instead of the default.", v => release = v },
                { "e=|env=|environment=", "Select which environment to use, instead of the default.", v => env = v },
                { "n|dry-run", "Don't actually run actions, just print what would be done and exit.", v => dryRun = v != null },
                { "s|resume", "Resume a failed deploy, if possible.", v => resume = v != null },
                { "C|no-cache", "Disable cache.", v => noCache = v != null },
                { "B|no-beeps", "Disable buzzer.", v => noBeeps = v != null }
            };

            var extra = Parse(p, args,
                CommandConstants.Deploy,
                "[OPTIONS]+");
            if (extra == null)
                return;

            var runContext = RunContext.Create(appContext, CommandConstants.Deploy, release, env, dryRun);
            RunCore(DeployContext.Create(runContext, resume, noCache, noBeeps));
        }
        public override void Run(ApplicationContext appContext, IEnumerable<string> args)
        {
            string release = null;
            string env = null;
            var dryRun = false;

            var p = new OptionSet
            {
                { "r=|release=", "Select which release to use, instead of the default.", v => release = v },
                { "e=|env=|environment=", "Select which environment to use, instead of the default.", v => env = v },
                { "n|dry-run", "Don't actually run actions, just print what would be done and exit.", v => dryRun = v != null }
            };

            var extra = Parse(p, args,
                CommandConstants.Run,
                "<ACTION> [OPTIONS]+");
            if (extra == null)
                return;

            if (extra.Count != 1)
                return;

            var runContext = RunContext.Create(appContext, extra[0], release, env, dryRun);
            RunCore(runContext);
        }
 private VariableReplacer(ApplicationContext context, FeatureConfig feature, TaskConfig task, Dictionary<string, string> replacements)
 {
     mContext = context;
     mFeature = feature;
     mTask = task;
     mReplacements = replacements;
 }
        public override void Run(ApplicationContext appContext, IEnumerable<string> args)
        {
            var p = new OptionSet();
            var extra = Parse(p, args,
                CommandConstants.Help,
                "[COMMAND]");

            if (extra == null || extra.Count == 0)
            {
                Console.WriteLine("Usage: dbbm <COMMAND> [OPTIONS]+");
                Console.WriteLine();
                Console.WriteLine("Available commands:");
                Console.WriteLine();

                var maxLen = mCommands.Max(x => x.Key.Length);
                foreach (var cmd in mCommands)
                {
                    Console.WriteLine("{0}{1} - {2}", new string(' ', maxLen - cmd.Key.Length + 2), cmd.Key, cmd.Value.Description);
                }
            }
            else
            {
                DbbmCommand cmd;
                if (!mCommands.TryGetValue(extra[0], out cmd))
                    throw new SoftFailureException(string.Format("Unknown command {0}", extra[0]));

                cmd.Run(appContext, new[] { extra[0], "--help" });
            }
        }
        public override void Run(ApplicationContext appContext, IEnumerable<string> args)
        {
            var dryRun = false;
            var p = new OptionSet
            {
                { "n|dry-run", "Don't actually run actions, just print what would be done and exit.", v => dryRun = v != null }
            };

            var extra = Parse(p, args,
                CommandConstants.GarbageCollect,
                "[OPTIONS]+");
            if (extra == null)
                return;

            RunCore(new GarbageCollectContext(appContext.UserConfig.Cache, dryRun, appContext.Log));
        }
        public Application()
        {
            mSubCommands = new Dictionary<string, DbbmCommand>
            {
                { CommandConstants.Deploy, new DbbmDeployCommand() },
                { CommandConstants.Run, new DbbmRunCommand() },
                { CommandConstants.GarbageCollect, new DbbmGarbageCollectCommand() }
            };
            mSubCommands.Add(CommandConstants.Help, new DbbmHelpCommand(mSubCommands));

            var projectRoot = DiscoverProjectRoot();
            var projectConfig = ProjectConfig.LoadFromJson(Path.Combine(projectRoot, FileConstants.ProjectFileName));
            var userConfig = UserConfig.LoadFromJson(Path.Combine(projectRoot, FileConstants.UserFileName));

            mApplicationContext = new ApplicationContext(projectRoot, projectConfig, userConfig, new ConsoleLog());
        }
        private static Dictionary<string, string> BuildInitialReplacements(ApplicationContext context, FeatureConfig feature, TaskConfig task)
        {
            var result = new Dictionary<string, string>();

            result["projectRoot"] = context.ProjectRoot;
            result["f:name"] = feature.Name;
            result["f:baseDirectory"] = feature.BaseDirectory;

            foreach (var kvp in context.UserConfig.EnvironmentVariables)
            {
                result[string.Format("e:{0}", kvp.Key)] = kvp.Value;
            }

            foreach (var kvp in task.Parameters)
            {
                result[kvp.Key] = kvp.Value;
            }

            return result;
        }
 public VariableReplacer(ApplicationContext context, FeatureConfig feature, TaskConfig task)
     : this(context, feature, task, BuildInitialReplacements(context, feature, task))
 {
 }
Beispiel #10
0
        public static RunContext Create(ApplicationContext applicationContext, string action, string release, string env, bool dryRun)
        {
            var releasesFile = Path.Combine(applicationContext.ProjectRoot, applicationContext.ProjectConfig.Releases);
            var releases = ReleasesConfig.LoadFromJson(releasesFile);

            var featuresFiles = FileUtils.ExpandGlob(Path.Combine(applicationContext.ProjectRoot, applicationContext.ProjectConfig.Features));
            var features = FeatureConfigCollection.LoadFromMultipleJsons(featuresFiles);

            var tasksFiles = FileUtils.ExpandGlob(Path.Combine(applicationContext.ProjectRoot, applicationContext.ProjectConfig.Tasks));
            var tasks = TaskDefinitionConfigCollection.LoadFromMultipleJsons(tasksFiles);

            if (string.IsNullOrWhiteSpace(release))
                release = applicationContext.UserConfig.ActiveRelease ?? releases.DefaultRelease;
            if (string.IsNullOrWhiteSpace(env))
                env = applicationContext.UserConfig.EnvironmentVariables.GetOrDefault(EnvironmentConstants.Environment, EnvironmentConstants.DefaultEnvironment);

            ReleaseConfig activeRelease;
            if (!releases.Releases.TryGet(release, out activeRelease))
                throw new SoftFailureException(string.Format("Cannot find Release '{0}'", release));

            EnvironmentConfig activeEnvironment;
            if (!applicationContext.ProjectConfig.Environments.TryGet(env, out activeEnvironment))
                throw new SoftFailureException(string.Format("Cannot find Environment '{0}'", env));

            var taskManager = new TaskManager(tasks);

            return new RunContext(applicationContext, action, releases, features, tasks, taskManager, activeRelease, activeEnvironment, dryRun);
        }
 public abstract void Run(ApplicationContext appContext, IEnumerable<string> args);