Esempio n. 1
0
 public function __construct($project_id, $options = null)
 {
     parent::__construct($options);
     $this->setName('deploymentSetup');
     $servers_map = new GD_Model_ServersMapper();
     $servers = $servers_map->getServersByProject($project_id);
     if (!is_array($servers) || count($servers) == 0) {
         throw new GD_Exception("There are no servers configured for this project.");
     }
     $server_id = new Zend_Form_Element_Select('serverId');
     $server_id->setLabel(_r('Server'))->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
     foreach ($servers as $server) {
         $server_id->addMultiOption($server->getId(), $server->getDisplayName());
     }
     $from_revision = new Zend_Form_Element_Text('fromRevision');
     $from_revision->setLabel(_r('Current revision'))->setRequired(false)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty')->setAttrib('readonly', 'readonly')->setAttrib('disabled', 'disabled');
     $to_revision = new Zend_Form_Element_Text('toRevision');
     $to_revision->setLabel(_r('Deploy revision or tag'))->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty')->setDescription('<a href="javascript:;" onclick="getLatestRevision();">Click to get latest revision</a><span id="get_latest_revision_status"></span>');
     $comment = new Zend_Form_Element_Text('comment');
     $comment->setLabel(_r('Comment (optional)'))->setRequired(false)->addFilter('StripTags')->addFilter('StringTrim');
     $submitRun = new Zend_Form_Element_Image('submitRun');
     $submitRun->setImage('/images/buttons/small/deploy.png');
     $submitRun->class = "processing_btn size_small";
     $submitPreview = new Zend_Form_Element_Image('submitPreview');
     $submitPreview->setImage('/images/buttons/small/inverted/preview.png');
     $submitPreview->class = "preview processing_btn size_small";
     $this->addElements(array($server_id, $from_revision, $to_revision, $comment, $submitRun, $submitPreview));
 }
Esempio n. 2
0
 public function editAction()
 {
     $this->view->headTitle('Configuration Management');
     $this->view->headLink()->appendStylesheet("/css/template/form.css");
     $this->view->headLink()->appendStylesheet("/css/pages/configs_edit.css");
     $projects = new GD_Model_ProjectsMapper();
     $project_slug = $this->_getParam("project");
     if ($project_slug != "") {
         $project = $projects->getProjectBySlug($project_slug);
     }
     $this->view->project = $project;
     $configs_map = new GD_Model_ConfigsMapper();
     $config = new GD_Model_Config();
     $config_id = $this->_getParam("id");
     $configs_servers_map = new GD_Model_ConfigsServersMapper();
     $config_server_ids = array();
     $servers_map = new GD_Model_ServersMapper();
     $servers = $servers_map->getServersByProject($project->getId());
     $this->view->servers = $servers;
     $user = GD_Auth_Database::GetLoggedInUser();
     if ($config_id > 0) {
         $configs_map->find($config_id, $config);
         $config_servers = $configs_servers_map->getAllServersForConfig($config->getId());
         foreach ($config_servers as $cs) {
             $config_server_ids[] = $cs->getServersId();
         }
     } else {
         $config->setProjectsId($project->getId());
         $config->setDateAdded(date("Y-m-d H:i:s"));
         $config->setAddedUsersId($user->getId());
         foreach ($servers as $server) {
             $config_server_ids[] = $server->getId();
         }
     }
     $this->view->config_server_ids = $config_server_ids;
     if ($this->getRequest()->isPost()) {
         // First save the config file itself
         $config->setFilename($this->_getParam("filename", ""));
         $config->setContent($this->_getParam("configContent", ""));
         $config->setUpdatedUsersId($user->getId());
         $configs_map->save($config);
         // Then loop through the config_servers and update
         $configs_servers_map->deleteAllServersForConfig($config->getId());
         $add_to_servers = $this->_getParam("servers", array());
         foreach ($add_to_servers as $server_id) {
             $cs = new GD_Model_ConfigServer();
             $cs->setConfigsId($config->getId());
             $cs->setServersId($server_id);
             $configs_servers_map->save($cs);
         }
         $this->_redirect($this->getFrontController()->getBaseUrl() . "/project/" . $this->_getParam("project") . "/configs");
     } else {
         $this->view->config = $config;
     }
 }
 /**
  * Implement this by setting $obj values (e.g. $obj->setId($row->Id) from a DB row
  * @param GD_Model_ConfigServer $obj
  * @param Zend_Db_Table_Row_Abstract $row
  */
 protected function populateObjectFromRow(&$obj, Zend_Db_Table_Row_Abstract $row)
 {
     $obj->setId($row->id)->setServersId($row->servers_id)->setConfigsId($row->configs_id);
     $s_map = new GD_Model_ServersMapper();
     $server = new GD_Model_Server();
     $s_map->populateObjectFromRow($server, $row->findParentRow('GD_Model_DbTable_Servers'));
     $obj->setServer($server);
     $c_map = new GD_Model_ConfigsMapper();
     $config = new GD_Model_Config();
     $c_map->populateObjectFromRow($config, $row->findParentRow('GD_Model_DbTable_Configs'));
     $obj->setConfig($config);
 }
Esempio n. 4
0
 /**
  * Implement this by setting $obj values (e.g. $obj->setId($row->Id) from a DB row
  * @param GD_Model_Deployment $obj
  * @param Zend_Db_Table_Row_Abstract $row
  */
 protected function populateObjectFromRow(&$obj, Zend_Db_Table_Row_Abstract $row)
 {
     $obj->setId($row->id)->setUsersId($row->users_id)->setProjectsId($row->projects_id)->setWhen($row->when)->setServersId($row->servers_id)->setFromRevision($row->from_revision)->setToRevision($row->to_revision)->setComment($row->comment)->setDeploymentStatusesId($row->deployment_statuses_id);
     $u_map = new GD_Model_UsersMapper();
     $user = new GD_Model_User();
     $u_map->populateObjectFromRow($user, $row->findParentRow('GD_Model_DbTable_Users'));
     $obj->setUser($user);
     $p_map = new GD_Model_ProjectsMapper();
     $project = new GD_Model_Project();
     $p_map->populateObjectFromRow($project, $row->findParentRow('GD_Model_DbTable_Projects'));
     $obj->setProject($project);
     $s_map = new GD_Model_ServersMapper();
     $server = new GD_Model_Server();
     $s_map->populateObjectFromRow($server, $row->findParentRow('GD_Model_DbTable_Servers'));
     $obj->setServer($server);
     $ds_map = new GD_Model_DeploymentStatusesMapper();
     $deployment_status = new GD_Model_DeploymentStatus();
     $ds_map->populateObjectFromRow($deployment_status, $row->findParentRow('GD_Model_DbTable_DeploymentStatuses'));
     $obj->setDeploymentStatus($deployment_status);
 }
Esempio n. 5
0
 public function deleteAction()
 {
     $project_slug = $this->_getParam("project");
     $servers = new GD_Model_ServersMapper();
     $server = new GD_Model_Server();
     $server_id = $this->_request->getParam('id', 0);
     if ($server_id > 0) {
         $servers->find($server_id, $server);
         $servers->delete($server);
         $this->_redirect($this->getFrontController()->getBaseUrl() . "/project/" . $project_slug . "/settings");
     } else {
         throw new Zend_Exception("Server id was not specified");
     }
 }
Esempio n. 6
0
 public function executeDeploymentStartAction()
 {
     // session_start blocks other requests, so close the session for the
     // status AJAX request to work
     Zend_Session::writeClose();
     ob_start();
     GD_Debug::StartDeploymentLog($this->_getParam("id"));
     GD_Debug::Log("Setting time limit... ", GD_Debug::DEBUG_BASIC, false);
     set_time_limit(0);
     GD_Debug::Log("done.", GD_Debug::DEBUG_BASIC, true, false);
     // Project information
     GD_Debug::Log("Loading project... ", GD_Debug::DEBUG_BASIC, false);
     $projects = new GD_Model_ProjectsMapper();
     $project_slug = $this->_getParam("project");
     if ($project_slug != "") {
         $project = $projects->getProjectBySlug($project_slug);
     }
     if (is_null($project)) {
         throw new GD_Exception("Project '{$project_slug}' was not set up.");
     }
     GD_Debug::Log("done.", GD_Debug::DEBUG_BASIC, true, false);
     // Deployment information
     GD_Debug::Log("Loading deployment information... ", GD_Debug::DEBUG_BASIC, false);
     $deployments = new GD_Model_DeploymentsMapper();
     $deployment = new GD_Model_Deployment();
     $deployments->find($this->_getParam('id'), $deployment);
     GD_Debug::Log("done.", GD_Debug::DEBUG_BASIC, true, false);
     // Server information
     GD_Debug::Log("Loading server information... ", GD_Debug::DEBUG_BASIC, false);
     $servers = new GD_Model_ServersMapper();
     $server = new GD_Model_Server();
     $servers->find($deployment->getServersId(), $server);
     GD_Debug::Log("done.", GD_Debug::DEBUG_BASIC, true, false);
     // Update the deployment status to show we're now running
     GD_Debug::Log("Updating deployment status to running... ", GD_Debug::DEBUG_BASIC, false);
     $deployment->setDeploymentStatusesId(2);
     // Running
     $deployments->save($deployment);
     GD_Debug::Log("done.", GD_Debug::DEBUG_BASIC, true, false);
     // Perform a git pull to check we're up to date
     $git = GD_Git::FromProject($project);
     $git->gitPull();
     // File list to action
     GD_Debug::Log("Getting file list... ", GD_Debug::DEBUG_BASIC, false);
     $deployment_files = new GD_Model_DeploymentFilesMapper();
     $deployment_files_statuses = new GD_Model_DeploymentFileStatusesMapper();
     $file_list = $deployment_files->getDeploymentFilesByDeployment($deployment->getId());
     GD_Debug::Log("done.", GD_Debug::DEBUG_BASIC, true, false);
     // Check out the revision we want to upload from
     GD_Debug::Log("Checking out revision {$deployment->getToRevision()}... ", GD_Debug::DEBUG_BASIC, false);
     $previous_ref = $git->getCurrentBranch(true);
     $res = $git->gitCheckout($deployment->getToRevision());
     if (!$res) {
         GD_Debug::Log("FAILED.", GD_Debug::DEBUG_BASIC, true, false);
     } else {
         GD_Debug::Log("done.", GD_Debug::DEBUG_BASIC, true, false);
     }
     $errors = false;
     // Do the upload
     GD_Debug::Log("Actioning files now.", GD_Debug::DEBUG_BASIC);
     $ftp = GD_Ftp::FromServer($server);
     try {
         $ftp->connect();
     } catch (GD_Exception $ex) {
         GD_Debug::Log("FTP Connect failed: {$ex->getMessage()}", GD_Debug::DEBUG_BASIC);
     }
     $config_map = new GD_Model_ConfigsMapper();
     foreach ($file_list as $file) {
         GD_Debug::Log("Actioning '{$file->getDetails()}'... ", GD_Debug::DEBUG_BASIC, false);
         $file->setDeploymentFileStatusesId($deployment_files_statuses->getDeploymentFileStatusByCode('IN_PROGRESS')->getId());
         $deployment_files->save($file);
         $matches = array();
         $is_config_file = preg_match('/^!CFG!(\\d+)!(.*)$/', $file->getDetails(), $matches);
         try {
             if ($is_config_file == 1) {
                 // Configuration file - store in temp dir from DB then upload
                 $tmpfile = tempnam(sys_get_temp_dir(), 'gdcfg');
                 $config = new GD_Model_Config();
                 $config_map->find($matches[1], $config);
                 file_put_contents($tmpfile, $config->getContent());
                 GD_Debug::Log(" >> to '{$matches[2]}'", GD_Debug::DEBUG_BASIC, false, false);
                 $ftp->upload($tmpfile, $matches[2]);
             } else {
                 // Regular file - upload as normal
                 switch ($file->getDeploymentFileAction()->getGitStatus()) {
                     case 'A':
                     case 'M':
                         $ftp->upload($git->getGitDir() . $file->getDetails(), $file->getDetails());
                         break;
                     case 'D':
                         $ftp->delete($file->getDetails());
                         break;
                     default:
                         throw GD_Exception("Warning, unhandled action: '" . $file->getDeploymentFileAction()->getGitStatus() . "' ({$file->getDetails()}");
                         break;
                 }
             }
             $file->setDeploymentFileStatusesId($deployment_files_statuses->getDeploymentFileStatusByCode('COMPLETE')->getId());
             GD_Debug::Log("done.", GD_Debug::DEBUG_BASIC, true, false);
         } catch (GD_Exception $ex) {
             // Only fail the whole deployment if we're not a delete action
             if ($file->getDeploymentFileAction()->getGitStatus() != 'D') {
                 $errors = true;
             }
             $file->setDeploymentFileStatusesId($deployment_files_statuses->getDeploymentFileStatusByCode('FAILED')->getId());
             GD_Debug::Log("FAILED [" . $ex->getMessage() . "].", GD_Debug::DEBUG_BASIC, true, false);
         }
         $deployment_files->save($file);
     }
     // Revert to previous revision
     GD_Debug::Log("Checking out revision {$previous_ref}... ", GD_Debug::DEBUG_BASIC, false);
     $res = $git->gitCheckout($previous_ref);
     if (!$res) {
         GD_Debug::Log("FAILED.", GD_Debug::DEBUG_BASIC, true, false);
     } else {
         GD_Debug::Log("done.", GD_Debug::DEBUG_BASIC, true, false);
     }
     GD_Debug::Log("Setting deployment status " . ($errors ? "[errors]" : "[success]") . "... ", GD_Debug::DEBUG_BASIC, false);
     if ($errors) {
         $deployment->setDeploymentStatusesId(4);
         // Failed
         $deployments->save($deployment);
     } else {
         $deployment->setDeploymentStatusesId(3);
         // Complete
         $deployments->save($deployment);
     }
     GD_Debug::Log("done.", GD_Debug::DEBUG_BASIC, true, false);
     GD_Debug::Log("All finished.", GD_Debug::DEBUG_BASIC);
     $buf = ob_get_contents();
     if ($buf) {
         GD_Debug::Log("Extra content:\n\n{$buf}", GD_Debug::DEBUG_BASIC);
     }
     GD_Debug::EndDeploymentLog();
     ob_end_clean();
     flush();
     die;
 }
 public function deleteAction()
 {
     $projects = new GD_Model_ProjectsMapper();
     $project_slug = $this->_getParam("project");
     $project = $projects->getProjectBySlug($project_slug);
     // Initialise the mapper objects we'll need
     $deploymentsMapper = new GD_Model_DeploymentsMapper();
     $deploymentFilesMapper = new GD_Model_DeploymentFilesMapper();
     $serversMapper = new GD_Model_ServersMapper();
     // Delete the deployments associated with the project.
     $deployments = $deploymentsMapper->getDeploymentsByProject($project->getId());
     foreach ($deployments as $deployment) {
         // Delete the files associated with the project.
         $deploymentFiles = $deploymentFilesMapper->getDeploymentFilesByDeployment($deployment->getId());
         foreach ($deploymentFiles as $deploymentFile) {
             $deploymentFilesMapper->delete($deploymentFile);
         }
         // Delete deployment.
         $deploymentsMapper->delete($deployment);
     }
     // Delete the servers associated with the project.
     $servers = $serversMapper->getServersByProject($project->getId());
     foreach ($servers as $server) {
         $serversMapper->delete($server);
     }
     // Delete the project's git repo.
     $git = new GD_Git($project);
     $git->deleteRepository();
     // Delete the project
     $projects->delete($project);
     $this->_redirect($this->getFrontController()->getBaseUrl() . "/home");
 }