/** * Begin a new deployment * * @return boolean */ protected function startRevertDeploy() { $this->Status = 'Started'; $this->Doing = 'Deployment'; $this->log("{$this->Title} starting revert deployment"); // Skip deployment for dry run if ($this->Pipeline()->DryRun) { $this->log("[Skipped] Create DNDeployment"); $this->write(); return true; } // Get old deployment from pipeline $pipeline = $this->Pipeline(); $previous = $pipeline->PreviousDeployment(); if (empty($previous) || empty($previous->SHA)) { $this->log("No available SHA for {$this->Title}"); $this->markFailed(); return false; } // Initialise deployment $deployment = DNDeployment::create(); // Leave the maintenance page up if we are restoring the DB $deployment->LeaveMaintenacePage = $this->doRestoreDB(); $deployment->EnvironmentID = $pipeline->EnvironmentID; $deployment->SHA = $previous->SHA; $deployment->DeployerID = $pipeline->AuthorID; $deployment->write(); $deployment->start(); $this->RollbackDeploymentID = $deployment->ID; $this->write(); return true; }
/** * Makes the dummy deployment step * * @return Pipeline */ public function getDummyPipeline($restoreDB = true) { // Get default backups $previous = DNDeployment::create(); $previous->write(); $current = DNDeployment::create(); $current->write(); $snapshot = DNDataTransfer::create(); $snapshot->write(); // Setup default pipeline $pipeline = $this->objFromFixture('Pipeline', 'testpipesmoketest'); $pipeline->Config = serialize(array('RollbackStep1' => array('Class' => 'RollbackStep', 'RestoreDB' => $restoreDB, 'MaxDuration' => '3600'))); $pipeline->PreviousDeploymentID = $previous->ID; $pipeline->CurrentDeploymentID = $current->ID; $pipeline->PreviousSnapshotID = $snapshot->ID; $pipeline->write(); return $pipeline; }
/** * Begin a new deployment * * @return boolean */ protected function startDeploy() { $this->Status = 'Started'; $this->Doing = 'Deployment'; $this->log("{$this->Title} starting deployment"); // Check environment and SHA $pipeline = $this->Pipeline(); $environment = $pipeline->Environment(); if (empty($environment) || !$environment->exists()) { $this->log("No available environment for {$this->Title}"); $this->markFailed(); return false; } if (empty($pipeline->SHA)) { $this->log("No available SHA for {$this->Title}"); $this->markFailed(); return false; } // Skip deployment for dry run if ($this->Pipeline()->DryRun) { $this->log("[Skipped] Create DNDeployment for SHA " . $pipeline->SHA); $this->write(); return true; } // Initialise deployment $deployment = DNDeployment::create(); $deployment->EnvironmentID = $environment->ID; $deployment->SHA = $pipeline->SHA; $previousStep = $pipeline->findPreviousStep(); $deployment->DeployerID = $previousStep && $previousStep->ResponderID ? $previousStep->ResponderID : $pipeline->AuthorID; $deployment->write(); $deployment->start(); $pipeline->CurrentDeploymentID = $deployment->ID; $pipeline->write(); $this->write(); return true; }
/** * * @return SS_HTTPResponse */ protected function createDeploy() { if (!$this->record->canDeploy($this->getMember())) { return $this->message('You are not authorized to do that on this environment', 403); } $reqBody = $this->getRequestBody(); if ($reqBody === null) { return $this->message('the request body did not contain a valid JSON object.', 400); } if (empty($reqBody['release'])) { return $this->message('deploy requires a {"release": "sha1"} in the body of the request.', 400); } $deploy = DNDeployment::create(); $deploy->EnvironmentID = $this->record->ID; $deploy->SHA = $reqBody['release']; $deploy->write(); $deploy->start(); $location = Director::absoluteBaseURL() . $this->Link() . '/deploy/' . $deploy->ID; $output = array('message' => 'Deploy queued as job ' . $deploy->ResqueToken, 'href' => $location); $response = $this->getAPIResponse($output); $response->setStatusCode(201); $response->addHeader('Location', $location); return $response; }
/** * @return DNDeployment */ public function createDeployment() { $deployment = \DNDeployment::create(); $deployment->EnvironmentID = $this->environment->ID; $deployment->SHA = $this->getOption('sha'); $deployment->RefType = $this->getOption('ref_type'); $deployment->RefName = $this->getOption('ref_name'); $deployment->Summary = $this->getOption('summary'); $deployment->Title = $this->getOption('title'); $deployment->Strategy = $this->toJSON(); $deployment->DeployerID = \Member::currentUserID(); $deployment->write(); // re-get and return the deployment so we have the correct state return \DNDeployment::get()->byId($deployment->ID); }
/** * @return DNDeployment */ public function createDeployment() { $deployment = DNDeployment::create(); $deployment->EnvironmentID = $this->environment->ID; // Pull out the SHA from the options so we can make it queryable. $deployment->SHA = $this->getOption('sha'); $deployment->Strategy = $this->toJSON(); $deployment->write(); return $deployment; }
/** * Provide rollback-able pipeline on the verge of failing. */ public function getFailingPipeline() { // Get default backups $previous = DNDeployment::create(); $previous->SHA = '9f0a012e97715b1871n41gk30f34268u12a0029q'; $previous->write(); $current = DNDeployment::create(); $current->write(); $snapshot = DNDataTransfer::create(); $snapshot->write(); $pipeline = $this->objFromFixture('Pipeline', 'FailingPipe'); $pipeline->Config = serialize(array('RollbackStep1' => array('Class' => 'RollbackStep', 'RestoreDB' => false, 'MaxDuration' => '3600'), 'RollbackStep2' => array('Class' => 'SmokeTestPipelineStep', 'MaxDuration' => '3600'))); $pipeline->PreviousDeploymentID = $previous->ID; $pipeline->CurrentDeploymentID = $current->ID; $pipeline->PreviousSnapshotID = $snapshot->ID; $pipeline->write(); return $pipeline; }
/** * Deployment form submission handler. * * Initiate a DNDeployment record and redirect to it for status polling * * @param array $data * @param DeployForm $form * @return \SS_HTTPResponse */ public function doDeploy($data, $form) { $buildName = $form->getSelectedBuild($data); // Performs canView permission check by limiting visible projects $project = $this->getCurrentProject(); if (!$project) { return new SS_HTTPResponse("Project '" . Convert::raw2xml($this->getRequest()->latestParam('Project')) . "' not found.", 404); } // Performs canView permission check by limiting visible projects $environment = $this->getCurrentEnvironment($project); if (!$environment) { return new SS_HTTPResponse("Environment '" . Convert::raw2xml($this->getRequest()->latestParam('Environment')) . "' not found.", 404); } // Initiate the deployment // The extension point should pass in: Project, Environment, SelectRelease, buildName $this->extend('doDeploy', $project, $environment, $buildName, $data); $sha = $project->DNBuildList()->byName($buildName); $deployment = DNDeployment::create(); $deployment->EnvironmentID = $environment->ID; $deployment->SHA = $sha->FullName(); $deployment->write(); $deployment->start(); return $this->redirect($deployment->Link()); }