Example #1
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());
        }
        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();
        }
Example #3
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());
        }