Inheritance: extends ViewableData
 /**
  * Create a deployment strategy.
  *
  * @param DNEnvironment $environment
  * @param array $options
  *
  * @return DeploymentStrategy
  */
 public function planDeploy(DNEnvironment $environment, $options)
 {
     $strategy = new DeploymentStrategy($environment, $options);
     $currentBuild = $environment->CurrentBuild();
     $currentSha = $currentBuild ? $currentBuild->SHA : '-';
     if ($currentSha !== $options['sha']) {
         $strategy->setChange('Code version', $currentSha, $options['sha']);
     }
     $strategy->setActionTitle('Confirm deployment');
     $strategy->setActionCode('fast');
     $strategy->setEstimatedTime('2');
     return $strategy;
 }
 /**
  * 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
     $strategy = new DeploymentStrategy($environment, array('sha' => $pipeline->SHA));
     $deployment = $strategy->createDeployment();
     $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;
 }
Esempio n. 3
0
 /**
  * Deployment form submission handler.
  *
  * Initiate a DNDeployment record and redirect to it for status polling
  *
  * @param SS_HTTPRequest $request
  *
  * @return SS_HTTPResponse
  * @throws ValidationException
  * @throws null
  */
 public function startDeploy(SS_HTTPRequest $request)
 {
     // Ensure the CSRF Token is correct
     if (!$this->checkCsrfToken($request)) {
         // CSRF token didn't match
         return $this->httpError(400, 'Bad Request');
     }
     // Performs canView permission check by limiting visible projects
     $project = $this->getCurrentProject();
     if (!$project) {
         return $this->project404Response();
     }
     // Performs canView permission check by limiting visible projects
     $environment = $this->getCurrentEnvironment($project);
     if (!$environment) {
         return $this->environment404Response();
     }
     // Initiate the deployment
     // The extension point should pass in: Project, Environment, SelectRelease, buildName
     $this->extend('doDeploy', $project, $environment, $buildName, $data);
     // Start the deployment based on the approved strategy.
     $strategy = new DeploymentStrategy($environment);
     $strategy->fromArray($request->requestVar('strategy'));
     $deployment = $strategy->createDeployment();
     $deployment->start();
     return json_encode(array('url' => Director::absoluteBaseURL() . $deployment->Link()), JSON_PRETTY_PRINT);
 }
Esempio n. 4
0
 /**
  * Start a resque job for this deployment
  *
  * @return string Resque token
  */
 protected function enqueueDeployment()
 {
     $environment = $this->Environment();
     $project = $environment->Project();
     $log = $this->log();
     $args = array('environmentName' => $environment->Name, 'repository' => $project->getLocalCVSPath(), 'logfile' => $this->logfile(), 'projectName' => $project->Name, 'env' => $project->getProcessEnv(), 'deploymentID' => $this->ID);
     $strategy = new DeploymentStrategy($environment);
     $strategy->fromJSON($this->Strategy);
     // Inject options.
     $args = array_merge($args, $strategy->getOptions());
     // Make sure we use the SHA as it was written into this DNDeployment.
     $args['sha'] = $this->SHA;
     if (!$this->DeployerID) {
         $this->DeployerID = Member::currentUserID();
     }
     if ($this->DeployerID) {
         $deployer = $this->Deployer();
         $message = sprintf('Deploy to %s initiated by %s (%s), with IP address %s', $environment->getFullName(), $deployer->getName(), $deployer->Email, Controller::curr()->getRequest()->getIP());
         $log->write($message);
     }
     return Resque::enqueue('deploy', 'DeployJob', $args, true);
 }
Esempio n. 5
0
 /**
  * @return DeploymentStrategy
  */
 public function getDeploymentStrategy()
 {
     $environment = $this->Environment();
     $strategy = new DeploymentStrategy($environment);
     $strategy->fromJSON($this->Strategy);
     return $strategy;
 }
 /**
  * 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
     $strategy = new DeploymentStrategy($pipeline->Environment(), array('sha' => $pipeline->SHA, 'leaveMaintenancePage' => $this->doRestoreDB()));
     $deployment = $strategy->createDeployment();
     $deployment->DeployerID = $pipeline->AuthorID;
     $deployment->write();
     $deployment->start();
     $this->RollbackDeploymentID = $deployment->ID;
     $this->write();
     return true;
 }
Esempio n. 7
0
 /**
  * Deployment form submission handler.
  *
  * @deprecated 2.0.0 - moved to DeployDispatcher
  *
  * Initiate a DNDeployment record and redirect to it for status polling
  *
  * @param \SS_HTTPRequest $request
  *
  * @return SS_HTTPResponse
  * @throws ValidationException
  * @throws null
  */
 public function startDeploy(\SS_HTTPRequest $request)
 {
     $token = SecurityToken::inst();
     // Ensure the submitted token has a value
     $submittedToken = $request->postVar(\Dispatcher::SECURITY_TOKEN_NAME);
     if (!$submittedToken) {
         return false;
     }
     // Do the actual check.
     $check = $token->check($submittedToken);
     // Ensure the CSRF Token is correct
     if (!$check) {
         // CSRF token didn't match
         return $this->httpError(400, 'Bad Request');
     }
     // Performs canView permission check by limiting visible projects
     $project = $this->getCurrentProject();
     if (!$project) {
         return $this->project404Response();
     }
     // Performs canView permission check by limiting visible projects
     $environment = $this->getCurrentEnvironment($project);
     if (!$environment) {
         return $this->environment404Response();
     }
     // Initiate the deployment
     // The extension point should pass in: Project, Environment, SelectRelease, buildName
     $this->extend('doDeploy', $project, $environment, $buildName, $data);
     // Start the deployment based on the approved strategy.
     $strategy = new DeploymentStrategy($environment);
     $strategy->fromArray($request->requestVar('strategy'));
     $deployment = $strategy->createDeployment();
     // Bypass approval by going straight to Queued.
     $deployment->getMachine()->apply(DNDeployment::TR_QUEUE);
     return json_encode(['url' => Director::absoluteBaseURL() . $deployment->Link()], JSON_PRETTY_PRINT);
 }
Esempio n. 8
0
 /**
  *
  * @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);
     }
     $strategy = new DeploymentStrategy($this->record, array('sha' => $reqBody['release']));
     $deploy = $strategy->createDeployment();
     $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;
 }