コード例 #1
0
        public void PostReceive(RubyHash options)
        {
            Logger.Debug("Running post receive for gear {0}", this.Uuid);

            Dictionary <string, string> gearEnv = Environ.ForGear(this.ContainerDir);

            string repoDir = Path.Combine(this.ContainerDir, "app-root", "runtime", "repo");

            Directory.CreateDirectory(repoDir);

            ApplicationRepository applicationRepository = new ApplicationRepository(this);

            applicationRepository.Archive(repoDir, options["ref"]);

            options["deployment_datetime"] = this.LatestDeploymentDateTime();

            Build(options);

            Logger.Debug("Running post receive - prepare for gear {0}", this.Uuid);
            Prepare(options);

            Logger.Debug("Running post receive - distribute for gear {0}", this.Uuid);
            Distribute(options);

            Logger.Debug("Running post receive - activate for gear {0}", this.Uuid);
            Activate(options);
        }
コード例 #2
0
        public string PostConfigure(string cartName, string templateGitUrl = null)
        {
            Logger.Debug("Running PostConfigure for '{0}' with cart '{1}' and git url '{2}'", this.Uuid, cartName, templateGitUrl);

            StringBuilder output    = new StringBuilder();
            Manifest      cartridge = this.Cartridge.GetCartridge(cartName);

            bool performInitialBuild = !Git.EmptyCloneSpec(templateGitUrl) && (cartridge.InstallBuildRequired || !string.IsNullOrEmpty(templateGitUrl)) && cartridge.Buildable;

            if (performInitialBuild)
            {
                Logger.Info("Performing initial build");
                try
                {
                    RunProcessInContainerContext(this.ContainerDir, "gear prereceive --init");
                    RunProcessInContainerContext(this.ContainerDir, "gear postreceive --init");
                }
                catch (Exception ex)
                {
                    // TODO: vladi: implement exception handling for initial build
                }
            }
            else if (cartridge.Deployable)
            {
                string             deploymentDatetime = LatestDeploymentDateTime();
                DeploymentMetadata deploymentMetadata = DeploymentMetadataFor(deploymentDatetime);
                if (deploymentMetadata.Activations.Count == 0)
                {
                    Prepare(new RubyHash()
                    {
                        { "deployment_datetime", deploymentDatetime }
                    });
                    deploymentMetadata.Load();
                    ApplicationRepository applicationRepository = new ApplicationRepository(this);
                    string gitRef         = "master";
                    string gitSha1        = applicationRepository.GetSha1(gitRef);
                    string deploymentsDir = Path.Combine(this.ContainerDir, "app-deployments");
                    SetRWPermissions(deploymentsDir);
                    // TODO: reset_permission_R(deployments_dir)

                    deploymentMetadata.RecordActivation();
                    deploymentMetadata.Save();

                    UpdateCurrentDeploymentDateTimeSymlink(deploymentDatetime);

                    FixHomeDir();
                }
            }

            output.AppendLine(this.Cartridge.PostConfigure(cartName));

            if (performInitialBuild)
            {
                // TODO: grep build log
            }

            return(output.ToString());
        }
コード例 #3
0
        private string PopulateGearRepo(string cartName, string softwareVersion, string templateGitUrl)
        {
            ApplicationRepository repo = new ApplicationRepository(this.container);

            if (string.IsNullOrEmpty(templateGitUrl))
            {
                repo.PopulateFromCartridge(cartName);
            }
            else
            {
                repo.PopulateFromUrl(cartName, templateGitUrl);
            }
            if (repo.Exists())
            {
                repo.Archive(Path.Combine(this.container.ContainerDir, "app-root", "runtime", "repo"), "master");
            }

            var prison = Prison.Prison.LoadPrisonNoAttach(PrisonIdConverter.Generate(this.container.Uuid));

            // TODO (vladi): make sure there isn't a more elegant way to deal with SQL Server Instances
            if (cartName == "mssql" && softwareVersion == "2008")
            {
                Uhuru.Prison.MsSqlInstanceTool.ConfigureMsSqlInstanceRegistry(prison, "MSSQL10_50", "MSSQLSERVER");
                CreateSQLServerInstanceDatabases(cartName, prison, "MSSQL10_50", "MSSQLSERVER");
                ChangeConfigControl(cartName, softwareVersion, "MSSQL10_50");
            }
            else if (cartName == "mssql" && softwareVersion == "2012")
            {
                Uhuru.Prison.MsSqlInstanceTool.ConfigureMsSqlInstanceRegistry(prison, "MSSQL11", "MSSQLSERVER2012");
                CreateSQLServerInstanceDatabases(cartName, prison, "MSSQL11", "MSSQLSERVER2012");
                ChangeConfigControl(cartName, softwareVersion, "MSSQL11");
            }

            Logger.Debug("Setting permisions to home dir gear {0}, prison user {1}", this.container.Uuid, prison.User.Username);
            LinuxFiles.TakeOwnershipOfGearHome(this.container.ContainerDir, prison.User.Username);

            string gitDir = Path.Combine(this.container.ContainerDir, "git", "template", ".git");

            Logger.Debug("Setting permisions to git dir {0}, prison user {1}", gitDir, prison.User.Username);
            if (Directory.Exists(gitDir))
            {
                LinuxFiles.TakeOwnership(gitDir, prison.User.Username);
            }

            Logger.Debug("Setting permisions to git dir {0}, prison user {1}", repo.RepositoryPath, prison.User.Username);
            LinuxFiles.TakeOwnership(repo.RepositoryPath, prison.User.Username);

            return(string.Empty);
        }
コード例 #4
0
        private string PopulateGearRepo(string cartName, string templateGitUrl)
        {
            ApplicationRepository repo = new ApplicationRepository(this.container);

            if (string.IsNullOrEmpty(templateGitUrl))
            {
                repo.PopulateFromCartridge(cartName);
            }
            else
            {
                repo.PopulateFromUrl(cartName, templateGitUrl);
            }
            if (repo.Exists())
            {
                repo.Archive(Path.Combine(this.container.ContainerDir, "app-root", "runtime", "repo"), "master");
            }

            var prison = Prison.Prison.LoadPrisonNoAttach(Guid.Parse(this.container.Uuid.PadLeft(32, '0')));

            // TODO (vladi): make sure there isn't a more elegant way to deal with SQL Server Instances
            if (cartName == "mssql")
            {
                CreateSQLServerInstanceDatabases(cartName, prison);
            }

            Logger.Debug("Setting permisions to home dir gear {0}, prison user {1}", this.container.Uuid, prison.User.Username);
            LinuxFiles.TakeOwnershipOfGearHome(this.container.ContainerDir, prison.User.Username);

            string gitDir = Path.Combine(this.container.ContainerDir, "git", "template", ".git");

            Logger.Debug("Setting permisions to git dir {0}, prison user {1}", gitDir, prison.User.Username);
            if (Directory.Exists(gitDir))
            {
                LinuxFiles.TakeOwnership(gitDir, prison.User.Username);
            }

            Logger.Debug("Setting permisions to git dir {0}, prison user {1}", repo.RepositoryPath, prison.User.Username);
            LinuxFiles.TakeOwnership(repo.RepositoryPath, prison.User.Username);

            return(string.Empty);
        }
コード例 #5
0
ファイル: Gear.cs プロジェクト: JANCARLO123/openshift.net
        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;
        }
コード例 #6
0
        private string PopulateGearRepo(string cartName, string templateGitUrl)
        {
            ApplicationRepository repo = new ApplicationRepository(this.container);
            if (string.IsNullOrEmpty(templateGitUrl))
            {
                repo.PopulateFromCartridge(cartName);
            }
            else
            {
                repo.PopulateFromUrl(cartName, templateGitUrl);
            }
            if (repo.Exists())
            {
                repo.Archive(Path.Combine(this.container.ContainerDir, "app-root", "runtime", "repo"), "master");
            }

            var prison = Prison.Prison.LoadPrisonNoAttach(Guid.Parse(this.container.Uuid.PadLeft(32, '0')));

            // TODO (vladi): make sure there isn't a more elegant way to deal with SQL Server Instances
            if (cartName == "mssql")
            {
                Uhuru.Prison.MsSqlInstanceTool.ConfigureMsSqlInstanceRegistry(prison, "MSSQL10_50", "MSSQLSERVER");
                CreateSQLServerInstanceDatabases(cartName, prison, "MSSQL10_50", "MSSQLSERVER");
            }

            if (cartName == "mssql2012")
            {
                Uhuru.Prison.MsSqlInstanceTool.ConfigureMsSqlInstanceRegistry(prison, "MSSQL11", "MSSQLSERVER2012");
                CreateSQLServerInstanceDatabases(cartName, prison, "MSSQL11", "MSSQLSERVER2012");
            }

            Logger.Debug("Setting permisions to home dir gear {0}, prison user {1}", this.container.Uuid, prison.User.Username);
            LinuxFiles.TakeOwnershipOfGearHome(this.container.ContainerDir, prison.User.Username);

            string gitDir = Path.Combine(this.container.ContainerDir, "git", "template", ".git");
            Logger.Debug("Setting permisions to git dir {0}, prison user {1}", gitDir, prison.User.Username);
            if (Directory.Exists(gitDir))
            {
                LinuxFiles.TakeOwnership(gitDir, prison.User.Username);
            }

            Logger.Debug("Setting permisions to git dir {0}, prison user {1}", repo.RepositoryPath, prison.User.Username);
            LinuxFiles.TakeOwnership(repo.RepositoryPath, prison.User.Username);

            return string.Empty;
        }
コード例 #7
0
        public void PostReceive(RubyHash options)
        {
            Logger.Debug("Running post receive for gear {0}", this.Uuid);

            Dictionary<string, string> gearEnv = Environ.ForGear(this.ContainerDir);
            
            string repoDir = Path.Combine(this.ContainerDir, "app-root", "runtime", "repo");

            Directory.CreateDirectory(repoDir);

            ApplicationRepository applicationRepository = new ApplicationRepository(this);
            applicationRepository.Archive(repoDir, options["ref"]);

            options["deployment_datetime"] = this.LatestDeploymentDateTime();

            Build(options);

            Logger.Debug("Running post receive - prepare for gear {0}", this.Uuid);
            Prepare(options);

            Logger.Debug("Running post receive - distribute for gear {0}", this.Uuid);
            Distribute(options);

            Logger.Debug("Running post receive - activate for gear {0}", this.Uuid);
            Activate(options);
        }
コード例 #8
0
        public string PostConfigure(string cartName, string templateGitUrl = null)
        {
            Logger.Debug("Running PostConfigure for '{0}' with cart '{1}' and git url '{2}'", this.Uuid, cartName, templateGitUrl);

            StringBuilder output = new StringBuilder();
            Manifest cartridge = this.Cartridge.GetCartridge(cartName);

            bool performInitialBuild = !Git.EmptyCloneSpec(templateGitUrl) && (cartridge.InstallBuildRequired || !string.IsNullOrEmpty(templateGitUrl)) && cartridge.Buildable;

            if (performInitialBuild)
            {
                Logger.Info("Performing initial build");
                try
                {
                    RunProcessInContainerContext(this.ContainerDir, "gear prereceive --init");
                    RunProcessInContainerContext(this.ContainerDir, "gear postreceive --init");                   
                }
                catch (Exception ex)
                {
                    // TODO: vladi: implement exception handling for initial build
                }
            }
            else if (cartridge.Deployable)
            {
                string deploymentDatetime = LatestDeploymentDateTime();
                DeploymentMetadata deploymentMetadata = DeploymentMetadataFor(deploymentDatetime);
                if (deploymentMetadata.Activations.Count == 0)
                {
                    Prepare(new RubyHash() { { "deployment_datetime", deploymentDatetime } });
                    deploymentMetadata.Load();
                    ApplicationRepository applicationRepository = new ApplicationRepository(this);
                    string gitRef = "master";
                    string gitSha1 = applicationRepository.GetSha1(gitRef);
                    string deploymentsDir = Path.Combine(this.ContainerDir, "app-deployments");
                    SetRWPermissions(deploymentsDir);
                    // TODO: reset_permission_R(deployments_dir)

                    deploymentMetadata.RecordActivation();
                    deploymentMetadata.Save();

                    UpdateCurrentDeploymentDateTimeSymlink(deploymentDatetime);
                    
                    FixHomeDir();
                }
            }

            output.AppendLine(this.Cartridge.PostConfigure(cartName));

            if (performInitialBuild)
            {
                // TODO: grep build log
            }

            return output.ToString();
        }
コード例 #9
0
        public string Build(RubyHash options)
        {
            this.State.Value(Runtime.State.BUILDING);
            string             deploymentDateTime = options["deployment_datetime"] != null ? options["deployment_datetime"] : LatestDeploymentDateTime();
            DeploymentMetadata deploymentMetadata = DeploymentMetadataFor(deploymentDateTime);

            if (!options.ContainsKey("deployment_datetime"))
            {
                // this will execute if coming from a CI builder, since it doesn't
                // specify :deployment_datetime in the options hash
                ApplicationRepository applicationRepository = options["git_repo"];
                string gitRef  = options["ref"];
                string gitSha1 = applicationRepository.GetSha1(gitRef);
                deploymentMetadata.GitSha          = gitSha1;
                deploymentMetadata.GitRef          = gitRef;
                deploymentMetadata.HotDeploy       = options["hot_deploy"];
                deploymentMetadata.ForceCleanBuild = options["force_clean_build"];
                deploymentMetadata.Save();
            }

            StringBuilder buffer = new StringBuilder();

            if (deploymentMetadata.ForceCleanBuild)
            {
                buffer.AppendLine("Force clean build enabled - cleaning dependencies");

                CleanRuntimeDirs(new RubyHash()
                {
                    { "dependencies", true }, { "build_dependencies", true }
                });

                this.Cartridge.EachCartridge(delegate(Manifest cartridge) {
                    this.Cartridge.CreateDependencyDirectories(cartridge);
                });
            }

            buffer.AppendLine(string.Format("Building git ref {0}, commit {1}", deploymentMetadata.GitRef, deploymentMetadata.GitSha));

            Dictionary <string, string> env = Environ.ForGear(this.ContainerDir);
            int deploymentsToKeep           = DeploymentsToKeep(env);

            try
            {
                Manifest primaryCartridge = this.Cartridge.GetPrimaryCartridge();
                buffer.AppendLine(this.Cartridge.DoControl("update-configuration", primaryCartridge, new RubyHash()
                {
                    { "pre_action_hooks_enabled", false }, { "post_action_hooks_enabled", false }
                }));
                buffer.AppendLine(this.Cartridge.DoControl("pre-build", primaryCartridge, new RubyHash()
                {
                    { "pre_action_hooks_enabled", false }, { "post_action_hooks_enabled", false }
                }));
                buffer.AppendLine(this.Cartridge.DoControl("build", primaryCartridge, new RubyHash()
                {
                    { "pre_action_hooks_enabled", false }, { "post_action_hooks_enabled", false }
                }));
            }
            catch (Exception ex)
            {
                buffer.AppendLine("Encountered a failure during build: " + ex.ToString());
                if (deploymentsToKeep > 1)
                {
                    buffer.AppendLine("Restarting application");
                    buffer.AppendLine(StartGear(new RubyHash()
                    {
                        { "user_initiated", true }, { "hot_deploy", deploymentMetadata.HotDeploy }
                    }));
                }
                throw ex;
            }

            return(buffer.ToString());
        }