Skip to content

Commit

Permalink
During deploy, ensure only Live content can be cloned to Test
Browse files Browse the repository at this point in the history
  • Loading branch information
bensheldon committed Aug 11, 2015
1 parent 92ae6dd commit 0ad0a59
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 29 deletions.
18 changes: 5 additions & 13 deletions php/Terminus/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,21 +388,13 @@ private function element_as_database($element) {
}

/**
* Deploys the given environment
* Deploys the Test or Live environment)
*
* @param [array] $args Arguments for deployment
* [string] $args['from'] Environment from which to deploy
* [string] $args['annotation'] Commit message
* @return [array] Data from the request
* @param [array] $params Parameters for the deploy workflow
*
* @return [workflow] workflow response
*/
public function deploy($args) {
$default_params = array(
'annotation' => 'Terminus deploy',
'clone_database' => array('from_environment' => 'dev'),
'clone_files' => array('from_environment' => 'dev'),
);
$params = array_merge($default_params, $args);

public function deploy($params) {
$workflow = $this->site->workflows->create('deploy', array(
'environment' => $this->id,
'params' => $params
Expand Down
5 changes: 0 additions & 5 deletions php/Terminus/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,6 @@ public function removeInstrument() {
return $workflow;
}

/**
* Returns the environment's name
*
}
/**
* Create a multidev environment
*/
Expand Down
22 changes: 13 additions & 9 deletions php/commands/site.php
Original file line number Diff line number Diff line change
Expand Up @@ -781,10 +781,13 @@ public function delete_env($args, $assoc_args) {
* : Site to deploy from
*
* [--env=<env>]
* : Environment to deploy to
* : Environment to be deployed (Test or Live)
*
* [--clone-live-content]
* : If deploying test, copy content from Live
*
* [--from=<env>]
* : Environment to deploy from
* : [deprecated] Environment to deploy from (non-functional)
*
* [--cc]
* : Clear cache after deploy?
Expand All @@ -803,11 +806,9 @@ public function deploy($args, $assoc_args) {
'env',
'Choose environment to deploy'
));
$from = Input::env(
$assoc_args,
'from',
'Choose environment you want to deploy from'
);

$clone_live_content = ($env->id == 'test' && isset($assoc_args['clone-live-content']));

if(!isset($assoc_args['note'])) {
$annotation = Terminus::prompt(
'Custom note for the deploy log',
Expand All @@ -824,10 +825,13 @@ public function deploy($args, $assoc_args) {
'updatedb' => $updatedb,
'clear_cache' => $cc,
'annotation' => $annotation,
'clone_database' => array('from_environment' => $from),
'clone_files' => array('from_environment' => $from),
);

if ($clone_live_content) {
$params['clone_database'] = array('from_environment' => 'live');
$params['clone_files'] = array('from_environment' => 'live');
}

$workflow = $env->deploy($params);
$workflow->wait();

Expand Down
2 changes: 1 addition & 1 deletion tests/features/deploy.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ Feature: Deploy
@vcr site-deploy
Given I am authenticated
And a site named "[[test_site_name]]"
When I run "terminus site deploy --site=[[test_site_name]] --from=dev --env=test --note='Deploy test'"
When I run "terminus site deploy --site=[[test_site_name]] --env=test --clone-live-content --note='Deploy test'"
Then I should get "Woot! Code deployed to test"
2 changes: 1 addition & 1 deletion tests/fixtures/site-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
User-Agent: 'Terminus/1.0.0 (php_version=5.5.26&script=boot-fs.php)'
Cookie: 'X-Pantheon-Session=25069e79-eae7-4d41-8925-1f728a114cb8:50d069c4-3ae4-11e5-97ba-bc764e117665:XdwFVyCuTDtq4km6jNjnT'
Content-type: application/json
body: '{"type":"deploy","params":{"annotation":"Deploy test","clone_database":{"from_environment":"dev"},"clone_files":{"from_environment":"dev"},"updatedb":0,"clear_cache":0}}'
body: '{"type":"deploy","params":{"updatedb":0,"clear_cache":0,"annotation":"Deploy test","clone_database":{"from_environment":"live"},"clone_files":{"from_environment":"live"}}}'
response:
status:
http_version: '1.1'
Expand Down

0 comments on commit 0ad0a59

Please sign in to comment.