rocketeers / rocketeer

Send your projects up in the clouds
http://rocketeer.autopergamene.eu/
MIT License
2.66k stars 217 forks source link

Allow for Silent runForCurrentRelease() Calls #764

Open brianfreytag opened 6 years ago

brianfreytag commented 6 years ago

Currently, when you have a task run for the current release ($task->runForCurrentRelease('xyz')) it will ALWAYS output the response from the command.

This becomes a problem when I want to do some "behind-the-scenes" variable building using these commands. For example, I am utilizing rocketeer to deploy my application to an AWS bastion server that then goes ahead and uploads the bundle to S3 for AWS CodeDeploy.

$task->command->info('Generate Deployment Bundle');
$task->runForCurrentRelease('aws deploy push --application-name ' . $appName . ' --s3-location s3://ledms-deploy/' . $bundleName);
Outputs: To run this deployment do x,y,z,etc.

$deploymentId = json_decode($task->runForCurrentRelease('aws deploy create-deployment --application-name ' . $appName . ' --deployment-group-name ' . $deployGroup . ' --deployment-config-name CodeDeployDefault.OneAtATime --s3-location bucket=ledms-deploy,bundleType=zip,key=' . $bundleName), true)['deploymentId'];
Outputs: { 'deploymentId': 'd-D394jadsf98' }

$task->command->info('Deploying to Instances');
do {
    $deployment = json_decode($task->runForCurrentRelease('aws deploy get-deployment --deployment-id ' . $deploymentId, true), true);
Outputs: {
    "deploymentInfo": {
        "applicationName": "WordPress_App",
        "status": "Succeeded",
        "deploymentOverview": {
            "Failed": 0,
            "InProgress": 0,
            "Skipped": 0,
            "Succeeded": 1,
            "Pending": 0
        },
        "deploymentConfigName": "CodeDeployDefault.OneAtATime",
        "creator": "user",
                "description": "My WordPress app deployment",
                "revision": {
          "revisionType": "S3",
          "s3Location":  {
            "bundleType": "zip",
            "eTag": "\"dd56cfd59d434b8e768f9d77fEXAMPLE\"",
            "bucket": "CodeDeployDemoBucket",
            "key": "WordPressApp.zip"
                      }
        },
        "deploymentId": "d-USUAELQEX",
        "deploymentGroupName": "WordPress_DG",
                "createTime": 1409764576.589,
        "completeTime": 1409764596.101,
                "ignoreApplicationStopFailures": false
    }
}

    $status = $deployment['deploymentInfo']['status'];

     echo $status . "...\n";
     Outputs: InProgress...(Succeeded,Failed,etc)

      if ($status === 'Failed') {
          $task->halt('The AWS Deployment Failed!');
      }

       sleep(10);
} while (!in_array($status, ['Failed', 'Succeeded']));

So if it takes 5 minutes for the deployment to complete, that huge json block shows every single time.

I suggest we add the ability to pass a (false by default) $silent parameter into $task->runForCurrentRelease() that will then go through and finally add $this->run($command, true). I will be submitting a PR for this shortly.