Exemplo n.º 1
0
        protected override void ProcessRecord()
        {
            ReturnStatus         status    = new ReturnStatus();
            ApplicationContainer container = new ApplicationContainer(WithAppUuid, WithContainerUuid, null, WithAppName,
                                                                      WithContainerName, WithNamespace, null, null, null);

            try
            {
                RubyHash options = new RubyHash();
                options["deployment_id"] = DeploymentId;
                status.Output            = container.Activate(options);
                status.ExitCode          = 0;
            }
            catch (Exception ex)
            {
                Logger.Error("Error running oo-activate command: {0} - {1}", ex.Message, ex.StackTrace);
                status.Output   = ex.ToString();
                status.ExitCode = 1;
            }
            this.WriteObject(status);
        }
Exemplo n.º 2
0
        public ReturnStatus Execute()
        {
            ReturnStatus status = new ReturnStatus();

            try
            {
                ApplicationContainer container = new ApplicationContainer(WithAppUuid, WithContainerUuid, null, WithAppName,
                                                                          WithContainerName, WithNamespace, null, null, null);

                RubyHash options = new RubyHash();
                options["deployment_id"] = WithDeploymentId;
                status.Output            = container.Activate(options);
                status.ExitCode          = 0;
            }
            catch (Exception ex)
            {
                Logger.Error("Error running oo-activate command: {0} - {1}", ex.Message, ex.StackTrace);
                status.Output   = ex.ToString();
                status.ExitCode = 1;
            }
            return(status);
        }
Exemplo n.º 3
0
        public ReturnStatus Execute()
        {
            Logger.Debug("Running gear command: '{0}'", Environment.CommandLine);

            ReturnStatus status = new ReturnStatus();

            try
            {
                string appUuid  = Environment.GetEnvironmentVariable("OPENSHIFT_APP_UUID");
                string gearUuid = Environment.GetEnvironmentVariable("OPENSHIFT_GEAR_UUID");
                string appName  = Environment.GetEnvironmentVariable("OPENSHIFT_APP_NAME");
                string gearName = Environment.GetEnvironmentVariable("OPENSHIFT_GEAR_NAME");
                string nmSpace  = Environment.GetEnvironmentVariable("OPENSHIFT_NAMESPACE");

                NodeConfig config  = new NodeConfig();
                EtcUser    etcUser = new Etc(config).GetPwanam(gearUuid);

                container = new ApplicationContainer(appUuid, gearUuid, etcUser, appName, gearName, nmSpace, null, null, null);
                repo      = new ApplicationRepository(container);

                if (Prereceive)
                {
                    Dictionary <string, object> options = new Dictionary <string, object>();
                    options["init"]            = Init;
                    options["hotDeploy"]       = true;
                    options["forceCleanBuild"] = true;
                    options["ref"]             = container.DetermineDeploymentRef();
                    container.PreReceive(options);
                }
                else if (Postreceive)
                {
                    RubyHash options = new RubyHash();
                    options["init"]             = Init;
                    options["all"]              = true;
                    options["reportDeployment"] = true;
                    options["ref"]              = container.DetermineDeploymentRef();
                    container.PostReceive(options);
                }
                else if (Build)
                {
                    string ciRepoPath = Path.Combine(Environment.GetEnvironmentVariable("OPENSHIFT_REPO_DIR"), ".git");
                    string repoDir    = null;
                    if (Directory.Exists(ciRepoPath))
                    {
                        repoDir = ciRepoPath;
                    }
                    repo = new ApplicationRepository(this.container, repoDir);
                    string gitRef  = null;
                    bool   archive = false;
                    if (repoDir == null)
                    {
                        gitRef  = this.container.DetermineDeploymentRef(this.RefId);
                        archive = true;
                    }
                    else
                    {
                        gitRef = Environment.GetEnvironmentVariable("GIT_BRANCH");
                    }
                    if (!ValidGitRef(gitRef))
                    {
                        throw new Exception(string.Format("Git ref {0} is invalid", gitRef));
                    }
                    if (archive)
                    {
                        repo.Archive(Environment.GetEnvironmentVariable("OPENSHIFT_REPO_DIR"), gitRef);
                    }

                    RubyHash options = new RubyHash();
                    options["ref"]               = gitRef;
                    options["hot_deploy"]        = repo.FileExists(HOT_DEPLOY_MARKER, gitRef);
                    options["force_clean_build"] = repo.FileExists(FORCE_CLEAN_BUILD_MARKER, gitRef);
                    options["git_repo"]          = repo;

                    Console.WriteLine(container.Build(options));
                }
                else if (Prepare)
                {
                    throw new NotImplementedException();
                }
                else if (Deploy)
                {
                    if (Environment.GetEnvironmentVariable("OPENSHIFT_DEPLOYMENT_TYPE") == "binary")
                    {
                        throw new Exception("OPENSHIFT_DEPLOYMENT_TYPE is 'binary' - git-based deployments are disabled.");
                    }
                    string refToDeploy = container.DetermineDeploymentRef(this.DeployRefId);
                    if (!ValidGitRef(refToDeploy))
                    {
                        throw new Exception("Git ref " + refToDeploy + " is not valid");
                    }
                    RubyHash options = new RubyHash();
                    options["hot_deploy"]        = this.HotDeploy;
                    options["force_clean_build"] = this.ForceCleanBuild;
                    options["ref"] = this.DeployRefId;
                    options["report_deployments"] = true;
                    options["all"] = true;
                    container.Deploy(options);
                }
                else if (Activate)
                {
                    status.Output = container.Activate(new RubyHash
                    {
                        { "deployment_id", this.DeploymentId },
                        { "post_install", this.PostInstall.ToBool() },
                        { "all", this.All.ToBool() },
                        { "rotate", this.Rotation && !this.NoRotation },
                        { "report_deployments", true },
                        { "out", !this.AsJson.ToBool() }
                    });
                }
                status.ExitCode = 0;
            }
            catch (Exception ex)
            {
                Logger.Error("Error running gear command: {0} - {1}", ex.Message, ex.StackTrace);
                status.Output   = string.Format("{0}", ex.Message, ex.StackTrace);
                status.ExitCode = 255;
            }

            return(status);
        }
Exemplo n.º 4
0
        protected override void ProcessRecord()
        {
            Logger.Debug("Running gear command: '{0}'", Environment.CommandLine);

            ReturnStatus status = new ReturnStatus();

            try
            {
                string appUuid  = Environment.GetEnvironmentVariable("OPENSHIFT_APP_UUID");
                string gearUuid = Environment.GetEnvironmentVariable("OPENSHIFT_GEAR_UUID");
                string appName  = Environment.GetEnvironmentVariable("OPENSHIFT_APP_NAME");
                string gearName = Environment.GetEnvironmentVariable("OPENSHIFT_GEAR_NAME");
                string nmSpace  = Environment.GetEnvironmentVariable("OPENSHIFT_NAMESPACE");

                NodeConfig config  = new NodeConfig();
                EtcUser    etcUser = new Etc(config).GetPwanam(gearUuid);

                container = new ApplicationContainer(appUuid, gearUuid, etcUser, appName, gearName, nmSpace, null, null, null);
                repo      = new ApplicationRepository(container);

                if (Prereceive)
                {
                    Dictionary <string, object> options = new Dictionary <string, object>();
                    options["init"]            = Init;
                    options["hotDeploy"]       = true;
                    options["forceCleanBuild"] = true;
                    options["ref"]             = container.DetermineDeploymentRef();
                    container.PreReceive(options);
                }
                else if (Postreceive)
                {
                    RubyHash options = new RubyHash();
                    options["init"]             = Init;
                    options["all"]              = true;
                    options["reportDeployment"] = true;
                    options["ref"]              = container.DetermineDeploymentRef();
                    container.PostReceive(options);
                }
                else if (Build)
                {
                    throw new NotImplementedException();
                }
                else if (Prepare)
                {
                    throw new NotImplementedException();
                }
                else if (Deploy)
                {
                    if (Environment.GetEnvironmentVariable("OPENSHIFT_DEPLOYMENT_TYPE") == "binary")
                    {
                        throw new Exception("OPENSHIFT_DEPLOYMENT_TYPE is 'binary' - git-based deployments are disabled.");
                    }
                    string refToDeploy = container.DetermineDeploymentRef(this.DeployRefId);
                    if (!ValidGitRef(refToDeploy))
                    {
                        throw new Exception("Git ref " + refToDeploy + " is not valid");
                    }
                    RubyHash options = new RubyHash();
                    options["hot_deploy"]        = this.HotDeploy;
                    options["force_clean_build"] = this.ForceCleanBuild;
                    options["ref"] = this.DeployRefId;
                    options["report_deployments"] = true;
                    options["all"] = true;
                    container.Deploy(options);
                }
                else if (Activate)
                {
                    status.Output = container.Activate(new RubyHash
                    {
                        { "deployment_id", this.DeploymentId },
                        { "post_install", this.PostInstall.ToBool() },
                        { "all", this.All.ToBool() },
                        { "rotate", this.Rotation && !this.NoRotation },
                        { "report_deployments", true },
                        { "out", !this.AsJson.ToBool() }
                    });
                }
                status.ExitCode = 0;
            }
            catch (Exception ex)
            {
                Logger.Error("Error running gear command: {0} - {1}", ex.Message, ex.StackTrace);
                status.Output   = string.Format("{0}", ex.Message, ex.StackTrace);
                status.ExitCode = 255;
            }
            this.WriteObject(status);
        }