Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AL-1672] - env:deploy now uses the --note option when initializing test/live #1965

Merged
merged 7 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. This projec
## MASTER
### Fixed
- Fixed `site:org:list` so that it no longer ends without returning anything. (#1964)
- Fixed `env:deploy` so the `--note` option is used when initializing the test or live environments. (#1965)
- "Deploy from Terminus" is the default message used by `env:deploy` when initializing the test or live environments. (#1965)

## 2.0.0 - 2019-02-20
### Added
Expand Down
5 changes: 3 additions & 2 deletions src/Commands/Env/DeployCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function deploy(
) {
list($site, $env) = $this->getUnfrozenSiteEnv($site_env, 'dev');

$annotation = $options['note'];
if ($env->isInitialized()) {
if (!$env->hasDeployableCode()) {
$this->log()->notice('There is nothing to deploy.');
Expand All @@ -58,7 +59,7 @@ public function deploy(
$params = [
'updatedb' => (integer)$options['updatedb'],
'clear_cache' => (integer)$options['cc'],
'annotation' => $options['note'],
'annotation' => $annotation,
];
if ($env->id == 'test' && isset($options['sync-content']) && $options['sync-content']) {
$live_env = 'live';
Expand All @@ -72,7 +73,7 @@ public function deploy(
}
$workflow = $env->deploy($params);
} else {
$workflow = $env->initializeBindings();
$workflow = $env->initializeBindings(compact('annotation'));
}
$this->processWorkflow($workflow);
$this->log()->notice($workflow->getMessage());
Expand Down
19 changes: 12 additions & 7 deletions src/Models/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,23 +655,28 @@ public function importFiles($url)
* content from previous environment (e.g. test clones dev content, live
* clones test content.)
*
* @param array $params Parameters for the environment-creation workflow
* string annotation Use to overwrite the default deploy message
* @return Workflow In-progress workflow
*/
public function initializeBindings()
public function initializeBindings(array $params = [])
{
if ($this->id == 'test') {
$from_env_id = 'dev';
} elseif ($this->id == 'live') {
$from_env_id = 'test';
}

$params = [
'annotation' => "Create the {$this->id} environment",
'clone_database' => ['from_environment' => $from_env_id,],
'clone_files' => ['from_environment' => $from_env_id,],
];
$parameters = array_merge(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so I'm getting my PHP right - annotation will be overridden in the $params if it exists, this first array is acting as the default?

Copy link
Contributor Author

@TeslaDethray TeslaDethray Mar 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. I had to look array_merge() up before using it, myself.

[
'annotation' => "Create the {$this->id} environment",
'clone_database' => ['from_environment' => $from_env_id,],
'clone_files' => ['from_environment' => $from_env_id,],
],
$params
);

return $this->getWorkflows()->create('create_environment', compact('params'));
return $this->getWorkflows()->create('create_environment', ['params' => $parameters,]);
}

/**
Expand Down
12 changes: 10 additions & 2 deletions tests/features/env-deploy.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,17 @@ Feature: Site Deployment
When I run "terminus env:deploy [[test_site_name]].test --note='Deploy test' --sync-content"
Then I should get: "There is nothing to deploy."

@vcr env-deploy-init.yml
@vcr env-deploy-init-with-message.yml
Scenario: Initializing test when it has not been previously initialized
When I run "terminus env:deploy [[test_site_name]].test --note='First deploy to live' --sync-content"
When I run "terminus env:deploy [[test_site_name]].test --note='Shes the one named Sailor Moon!' --sync-content"
Then I should get:
"""
Deploying code to "test", and cloning files from "live", and cloning database from "live"
"""

@vcr env-deploy-init.yml
Scenario: Initializing test when it has not been previously initialized and no note is provided
When I run "terminus env:deploy [[test_site_name]].test"
Then I should get:
"""
Deploying code to "test", and cloning files from "live", and cloning database from "live"
Expand Down
288 changes: 288 additions & 0 deletions tests/fixtures/env-deploy-init-with-message.yml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions tests/fixtures/env-deploy-init.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
absolute_url: ''
json: ''
Accept: null
body: '{"type":"create_environment","params":{"annotation":"Create the test environment","clone_database":{"from_environment":"dev"},"clone_files":{"from_environment":"dev"}}}'
body: '{"type":"create_environment","params":{"annotation":"Deploy from Terminus","clone_database":{"from_environment":"dev"},"clone_files":{"from_environment":"dev"}}}'
response:
status:
http_version: '1.1'
Expand All @@ -251,7 +251,7 @@
Cache-Control: no-cache
Pragma: no-cache
Vary: Accept-Encoding
body: '{"environment_id": "test", "user_id": "11111111-1111-1111-1111-111111111111", "keep_forever": true, "site_id": "11111111-1111-1111-1111-111111111111", "trace_id": "701dc0e0-697f-11e6-9ba8-733939e0aeaf", "params": {"clone_files": {"from_environment": "dev"}, "annotation": "Create the test environment", "clone_database": {"from_environment": "dev"}}, "task_ids": ["702b12f4-697f-11e6-af37-bc764e11227e", "702d30e8-697f-11e6-af37-bc764e11227e", "702e77fa-697f-11e6-af37-bc764e11227e", "702f812c-697f-11e6-af37-bc764e11227e", "70307f46-697f-11e6-af37-bc764e11227e", "70318df0-697f-11e6-af37-bc764e11227e", "70329cfe-697f-11e6-af37-bc764e11227e", "704327f4-697f-11e6-af37-bc764e11227e", "7044c00a-697f-11e6-af37-bc764e11227e"], "role": "owner", "type": "create_environment", "id": "7023046a-697f-11e6-af37-bc764e11227e", "key": "1471989600", "waiting_for_task_id": "702b12f4-697f-11e6-af37-bc764e11227e", "phase": "created", "queued_time": null, "run_time": null, "created_at": 1471990674.448497, "reason": "", "environment": "test", "final_task_id": null, "result": null, "total_time": null, "active_description": "Create environment \"test\"", "description": "Create environment \"test\"", "step": 1, "has_operation_log_output": false, "number_of_tasks": 9, "trace_log_url": "https://app.logz.io/#/dashboard/kibana?kibanaRoute=discover%3F_a%3D(query:(query_string:(analyze_wildcard:!t,query:%27trace_id:701dc0e0-697f-11e6-9ba8-733939e0aeaf%27)))%26_g%3D(refreshInterval:(display:Off,pause:!f,value:0),time:(from:%272016-08-23T22:12:54.448497Z%27,mode:quick,to:%27now%27))", "user": {"user_id": "11111111-1111-1111-1111-111111111111", "created_at": 1463779128, "destination_organization_id": null, "is_registered": true, "created_organization_id": "11111111-1111-1111-1111-111111111111", "password": "SCRUBBED", "email": "[email protected]"}, "user_email": "[email protected]", "waiting_for_task": {"allow_concurrent": true, "environment": "test", "fn_name": "queue_jenkins_task", "params": {"host": "localhost", "task_type": "converge_hostname", "job_id": "702b12f4-697f-11e6-af37-bc764e11227e", "hostname_id": "test-behat-tests.onebox.pantheon.io"}, "site_id": "11111111-1111-1111-1111-111111111111", "trace_id": "701dc0e0-697f-11e6-9ba8-733939e0aeaf", "workflow_id": "7023046a-697f-11e6-af37-bc764e11227e", "id": "702b12f4-697f-11e6-af37-bc764e11227e", "key": "1471989600", "responses": [], "queued_time": null, "host": "localhost", "result": null, "phase": "created", "created_at": 1471990674.501298, "run_time": null, "total_time": null, "reason": "", "error_details": "", "internal_reason": "", "trace_log_url": "https://app.logz.io/#/dashboard/kibana?kibanaRoute=discover%3F_a%3D(query:(query_string:(analyze_wildcard:!t,query:%27trace_id:701dc0e0-697f-11e6-9ba8-733939e0aeaf%27)))%26_g%3D(refreshInterval:(display:Off,pause:!f,value:0),time:(from:%272016-08-23T22:12:54.501298Z%27,mode:quick,to:%27now%27))", "type": "converge_hostname", "build_url": null, "messages": {}}}'
body: '{"environment_id": "test", "user_id": "11111111-1111-1111-1111-111111111111", "keep_forever": true, "site_id": "11111111-1111-1111-1111-111111111111", "trace_id": "701dc0e0-697f-11e6-9ba8-733939e0aeaf", "params": {"clone_files": {"from_environment": "dev"}, "annotation": "Deploy from Terminus", "clone_database": {"from_environment": "dev"}}, "task_ids": ["702b12f4-697f-11e6-af37-bc764e11227e", "702d30e8-697f-11e6-af37-bc764e11227e", "702e77fa-697f-11e6-af37-bc764e11227e", "702f812c-697f-11e6-af37-bc764e11227e", "70307f46-697f-11e6-af37-bc764e11227e", "70318df0-697f-11e6-af37-bc764e11227e", "70329cfe-697f-11e6-af37-bc764e11227e", "704327f4-697f-11e6-af37-bc764e11227e", "7044c00a-697f-11e6-af37-bc764e11227e"], "role": "owner", "type": "create_environment", "id": "7023046a-697f-11e6-af37-bc764e11227e", "key": "1471989600", "waiting_for_task_id": "702b12f4-697f-11e6-af37-bc764e11227e", "phase": "created", "queued_time": null, "run_time": null, "created_at": 1471990674.448497, "reason": "", "environment": "test", "final_task_id": null, "result": null, "total_time": null, "active_description": "Create environment \"test\"", "description": "Create environment \"test\"", "step": 1, "has_operation_log_output": false, "number_of_tasks": 9, "trace_log_url": "https://app.logz.io/#/dashboard/kibana?kibanaRoute=discover%3F_a%3D(query:(query_string:(analyze_wildcard:!t,query:%27trace_id:701dc0e0-697f-11e6-9ba8-733939e0aeaf%27)))%26_g%3D(refreshInterval:(display:Off,pause:!f,value:0),time:(from:%272016-08-23T22:12:54.448497Z%27,mode:quick,to:%27now%27))", "user": {"user_id": "11111111-1111-1111-1111-111111111111", "created_at": 1463779128, "destination_organization_id": null, "is_registered": true, "created_organization_id": "11111111-1111-1111-1111-111111111111", "password": "SCRUBBED", "email": "[email protected]"}, "user_email": "[email protected]", "waiting_for_task": {"allow_concurrent": true, "environment": "test", "fn_name": "queue_jenkins_task", "params": {"host": "localhost", "task_type": "converge_hostname", "job_id": "702b12f4-697f-11e6-af37-bc764e11227e", "hostname_id": "test-behat-tests.onebox.pantheon.io"}, "site_id": "11111111-1111-1111-1111-111111111111", "trace_id": "701dc0e0-697f-11e6-9ba8-733939e0aeaf", "workflow_id": "7023046a-697f-11e6-af37-bc764e11227e", "id": "702b12f4-697f-11e6-af37-bc764e11227e", "key": "1471989600", "responses": [], "queued_time": null, "host": "localhost", "result": null, "phase": "created", "created_at": 1471990674.501298, "run_time": null, "total_time": null, "reason": "", "error_details": "", "internal_reason": "", "trace_log_url": "https://app.logz.io/#/dashboard/kibana?kibanaRoute=discover%3F_a%3D(query:(query_string:(analyze_wildcard:!t,query:%27trace_id:701dc0e0-697f-11e6-9ba8-733939e0aeaf%27)))%26_g%3D(refreshInterval:(display:Off,pause:!f,value:0),time:(from:%272016-08-23T22:12:54.501298Z%27,mode:quick,to:%27now%27))", "type": "converge_hostname", "build_url": null, "messages": {}}}'
-
request:
method: GET
Expand Down Expand Up @@ -287,4 +287,4 @@
Pragma: no-cache
Vary: Accept-Encoding
Strict-Transport-Security: max-age=31536000
body: '{"environment_id": "test", "keep_forever": true, "params": {"clone_files": {"from_environment": "dev"}, "annotation": "Create the test environment", "clone_database": {"from_environment": "dev"}}, "role": "owner", "site_id": "11111111-1111-1111-1111-111111111111", "started_at": 1471990674.711835, "task_ids": ["702b12f4-697f-11e6-af37-bc764e11227e", "702d30e8-697f-11e6-af37-bc764e11227e", "702e77fa-697f-11e6-af37-bc764e11227e", "702f812c-697f-11e6-af37-bc764e11227e", "70307f46-697f-11e6-af37-bc764e11227e", "70318df0-697f-11e6-af37-bc764e11227e", "70329cfe-697f-11e6-af37-bc764e11227e", "704327f4-697f-11e6-af37-bc764e11227e", "7044c00a-697f-11e6-af37-bc764e11227e"], "trace_id": "701dc0e0-697f-11e6-9ba8-733939e0aeaf", "type": "create_environment", "user_id": "11111111-1111-1111-1111-111111111111", "id": "7023046a-697f-11e6-af37-bc764e11227e", "key": "11111111-1111-1111-1111-111111111111", "waiting_for_task_id": "702b12f4-697f-11e6-af37-bc764e11227e", "phase": "started", "queued_time": null, "run_time": null, "created_at": 1471990674.448497, "reason": "", "environment": "test", "final_task_id": null, "result": "succeeded", "total_time": null, "active_description": "Deploying code to \"test\", and cloning files from \"dev\", and cloning database from \"dev\"", "description": "Create environment \"test\"", "step": 1, "has_operation_log_output": false, "number_of_tasks": 9, "trace_log_url": "https://app.logz.io/#/dashboard/kibana?kibanaRoute=discover%3F_a%3D(query:(query_string:(analyze_wildcard:!t,query:%27trace_id:701dc0e0-697f-11e6-9ba8-733939e0aeaf%27)))%26_g%3D(refreshInterval:(display:Off,pause:!f,value:0),time:(from:%272016-08-23T22:12:54.448497Z%27,mode:quick,to:%27now%27))", "user": {"user_id": "11111111-1111-1111-1111-111111111111", "created_at": 1463779128, "destination_organization_id": null, "is_registered": true, "created_organization_id": "11111111-1111-1111-1111-111111111111", "password": "SCRUBBED", "email": "[email protected]"}, "user_email": "[email protected]", "waiting_for_task": {"allow_concurrent": true, "build": {"url": "job/converge_hostname/705/", "number": 705, "phase": "STARTED", "estimated_duration": 1153, "duration": 0, "full_url": "https://162.242.168.42:8090/jenkins/job/converge_hostname/705/"}, "environment": "test", "fn_name": "queue_jenkins_task", "params": {"host": "localhost", "task_type": "converge_hostname", "job_id": "702b12f4-697f-11e6-af37-bc764e11227e", "hostname_id": "test-behat-tests.onebox.pantheon.io"}, "queued_at": 1471990674.71195, "responses": [{"code": 201, "body": "Successfully queued converge_hostname", "error_details": "", "internal_reason": ""}], "site_id": "11111111-1111-1111-1111-111111111111", "started_at": 1471990675.946164, "trace_id": "701dc0e0-697f-11e6-9ba8-733939e0aeaf", "workflow_id": "7023046a-697f-11e6-af37-bc764e11227e", "id": "702b12f4-697f-11e6-af37-bc764e11227e", "key": "1471989600", "queued_time": 1.2342138290405273, "host": "localhost", "result": "succeeded", "phase": "started", "created_at": 1471990674.501298, "run_time": null, "total_time": null, "reason": "", "error_details": "", "internal_reason": "", "trace_log_url": "https://app.logz.io/#/dashboard/kibana?kibanaRoute=discover%3F_a%3D(query:(query_string:(analyze_wildcard:!t,query:%27trace_id:701dc0e0-697f-11e6-9ba8-733939e0aeaf%27)))%26_g%3D(refreshInterval:(display:Off,pause:!f,value:0),time:(from:%272016-08-23T22:12:54.501298Z%27,mode:quick,to:%27now%27))", "type": "converge_hostname", "build_url": "https://162.242.168.42:8090/jenkins/job/converge_hostname/705/", "messages": {"2016-08-23T22:17:56.403707": {"message": "Successfully queued converge_hostname", "level": "INFO"}}}}'
body: '{"environment_id": "test", "keep_forever": true, "params": {"clone_files": {"from_environment": "dev"}, "annotation": "Deploy from Terminus", "clone_database": {"from_environment": "dev"}}, "role": "owner", "site_id": "11111111-1111-1111-1111-111111111111", "started_at": 1471990674.711835, "task_ids": ["702b12f4-697f-11e6-af37-bc764e11227e", "702d30e8-697f-11e6-af37-bc764e11227e", "702e77fa-697f-11e6-af37-bc764e11227e", "702f812c-697f-11e6-af37-bc764e11227e", "70307f46-697f-11e6-af37-bc764e11227e", "70318df0-697f-11e6-af37-bc764e11227e", "70329cfe-697f-11e6-af37-bc764e11227e", "704327f4-697f-11e6-af37-bc764e11227e", "7044c00a-697f-11e6-af37-bc764e11227e"], "trace_id": "701dc0e0-697f-11e6-9ba8-733939e0aeaf", "type": "create_environment", "user_id": "11111111-1111-1111-1111-111111111111", "id": "7023046a-697f-11e6-af37-bc764e11227e", "key": "11111111-1111-1111-1111-111111111111", "waiting_for_task_id": "702b12f4-697f-11e6-af37-bc764e11227e", "phase": "started", "queued_time": null, "run_time": null, "created_at": 1471990674.448497, "reason": "", "environment": "test", "final_task_id": null, "result": "succeeded", "total_time": null, "active_description": "Deploying code to \"test\", and cloning files from \"dev\", and cloning database from \"dev\"", "description": "Create environment \"test\"", "step": 1, "has_operation_log_output": false, "number_of_tasks": 9, "trace_log_url": "https://app.logz.io/#/dashboard/kibana?kibanaRoute=discover%3F_a%3D(query:(query_string:(analyze_wildcard:!t,query:%27trace_id:701dc0e0-697f-11e6-9ba8-733939e0aeaf%27)))%26_g%3D(refreshInterval:(display:Off,pause:!f,value:0),time:(from:%272016-08-23T22:12:54.448497Z%27,mode:quick,to:%27now%27))", "user": {"user_id": "11111111-1111-1111-1111-111111111111", "created_at": 1463779128, "destination_organization_id": null, "is_registered": true, "created_organization_id": "11111111-1111-1111-1111-111111111111", "password": "SCRUBBED", "email": "[email protected]"}, "user_email": "[email protected]", "waiting_for_task": {"allow_concurrent": true, "build": {"url": "job/converge_hostname/705/", "number": 705, "phase": "STARTED", "estimated_duration": 1153, "duration": 0, "full_url": "https://162.242.168.42:8090/jenkins/job/converge_hostname/705/"}, "environment": "test", "fn_name": "queue_jenkins_task", "params": {"host": "localhost", "task_type": "converge_hostname", "job_id": "702b12f4-697f-11e6-af37-bc764e11227e", "hostname_id": "test-behat-tests.onebox.pantheon.io"}, "queued_at": 1471990674.71195, "responses": [{"code": 201, "body": "Successfully queued converge_hostname", "error_details": "", "internal_reason": ""}], "site_id": "11111111-1111-1111-1111-111111111111", "started_at": 1471990675.946164, "trace_id": "701dc0e0-697f-11e6-9ba8-733939e0aeaf", "workflow_id": "7023046a-697f-11e6-af37-bc764e11227e", "id": "702b12f4-697f-11e6-af37-bc764e11227e", "key": "1471989600", "queued_time": 1.2342138290405273, "host": "localhost", "result": "succeeded", "phase": "started", "created_at": 1471990674.501298, "run_time": null, "total_time": null, "reason": "", "error_details": "", "internal_reason": "", "trace_log_url": "https://app.logz.io/#/dashboard/kibana?kibanaRoute=discover%3F_a%3D(query:(query_string:(analyze_wildcard:!t,query:%27trace_id:701dc0e0-697f-11e6-9ba8-733939e0aeaf%27)))%26_g%3D(refreshInterval:(display:Off,pause:!f,value:0),time:(from:%272016-08-23T22:12:54.501298Z%27,mode:quick,to:%27now%27))", "type": "converge_hostname", "build_url": "https://162.242.168.42:8090/jenkins/job/converge_hostname/705/", "messages": {"2016-08-23T22:17:56.403707": {"message": "Successfully queued converge_hostname", "level": "INFO"}}}}'
28 changes: 24 additions & 4 deletions tests/unit_tests/Commands/Env/DeployCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,39 @@ public function testDeployLive()
}

/**
* Tests the env:deploy command when the environment is uninitialized
* Tests the env:deploy command when the environment is uninitialized and a deploy message is supplied
*/
public function testDeployUninitialized()
public function testDeployUninitializedWithMessage()
{
$this->environment->id = 'uninitialized';
$note = 'Never running from a real fight';

$this->environment->expects($this->once())
->method('isInitialized')
->willReturn(false);
$this->environment->expects($this->once())
->method('initializeBindings')
->willReturn($this->workflow)
->with();
->with(['annotation' => $note,])
->willReturn($this->workflow);

// Run the deploy.
$this->command->deploy("mysite.{$this->environment->id}", compact('note'));
}

/**
* Tests the env:deploy command when the environment is uninitialized and no deploy message is given
*/
public function testDeployUninitializedWithoutMessage()
{
$this->environment->id = 'uninitialized';

$this->environment->expects($this->once())
->method('isInitialized')
->willReturn(false);
$this->environment->expects($this->once())
->method('initializeBindings')
->with()
->willReturn($this->workflow);

// Run the deploy.
$this->command->deploy("mysite.{$this->environment->id}");
Expand Down
Loading