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); }
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); }
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); }
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; }
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; }
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); }