Skip to content

Commit

Permalink
Partway through tidy-up of Acquia and Deploy classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
typhonius committed Mar 21, 2020
1 parent 4e54206 commit 08bb805
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 177 deletions.
76 changes: 1 addition & 75 deletions src/Commands/AcquiaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,8 @@ protected function waitForNotification($response)
$progress->setEmptyBarCharacter('<fg=red>⚬</>');
$progress->setProgressCharacter('<fg=green>➤</>');
$progress->setFormat("<fg=white;bg=cyan> %message:-45s%</>\n%elapsed:6s% [%bar%] %percent:3s%%");

$progress->start();
$progress->setMessage('Looking up notification');
$progress->start();

$notificationAdapter = new Notifications($this->cloudapi);

Expand Down Expand Up @@ -348,79 +347,6 @@ protected function backupDb($uuid, EnvironmentResponse $environment, DatabaseRes
$this->waitForNotification($response);
}

/**
* @param string $uuid
* @param EnvironmentResponse $environmentFrom
* @param EnvironmentResponse $environmentTo
*/
protected function copyFiles($uuid, EnvironmentResponse $environmentFrom, EnvironmentResponse $environmentTo)
{
// Copy files from prod to non-prod.
$environmentAdapter = new Environments($this->cloudapi);
$this->say(sprintf('Moving files from %s to %s', $environmentFrom->label, $environmentTo->label));
$response = $environmentAdapter->copyFiles($environmentFrom->uuid, $environmentTo->uuid);
$this->waitForNotification($response);
}

/**
* @param string $uuid
* @param EnvironmentResponse $environmentFrom
* @param EnvironmentResponse $environmentTo
*/
protected function acquiaDeployEnvToEnv(
$uuid,
EnvironmentResponse $environmentFrom,
EnvironmentResponse $environmentTo
) {
$this->backupAllEnvironmentDbs($uuid, $environmentTo);
$this->say(
sprintf(
'Deploying code from the %s environment to the %s environment',
$environmentFrom->label,
$environmentTo->label
)
);

$code = new Code($this->cloudapi);
$response = $code->deploy($environmentFrom->uuid, $environmentTo->uuid);
$this->waitForNotification($response);
}

/**
* @param string $uuid
* @param EnvironmentResponse $environment
* @param string $branch
*/
protected function acquiaDeployEnv($uuid, EnvironmentResponse $environment, $branch)
{
$this->backupAllEnvironmentDbs($uuid, $environment);
$this->say(sprintf('Deploying %s to the %s environment', $branch, $environment->label));

$code = new Code($this->cloudapi);
$response = $code->switch($environment->uuid, $branch);
$this->waitForNotification($response);
}

/**
* @param string $uuid
* @param EnvironmentResponse $environment
*/
protected function acquiaPurgeVarnishForEnvironment($uuid, EnvironmentResponse $environment)
{
$domainAdapter = new Domains($this->cloudapi);
$domains = $domainAdapter->getAll($environment->uuid);

$domainsList = array_map(function ($domain) {
$this->say(sprintf('Purging varnish cache for %s', $domain->hostname));
return $domain->hostname;
}, $domains->getArrayCopy());


$domainAdapter = new Domains($this->cloudapi);
$response = $domainAdapter->purge($environment->uuid, $domainsList);
$this->waitForNotification($response);
}

protected function setTableStyles()
{
$tableStyle = new TableStyle();
Expand Down
171 changes: 69 additions & 102 deletions src/Commands/DeployCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,112 +10,79 @@
*/
class DeployCommand extends AcquiaCommand
{
/**
* Runs a deployment of a branch/tag and config/db update to the production environment.
*
* @param string $uuid
* @param string $branch
*
* @command prod:deploy
*/
public function acquiaDeployProd($uuid, $branch)
{
$this->yell('WARNING: DEPLOYING TO PROD');
if ($this->confirm('Are you sure you want to deploy to prod?')) {
$environment = $this->getEnvironmentFromEnvironmentName($uuid, 'prod');
$this->acquiaDeployEnv($uuid, $environment, $branch);
}
}
// /**
// * Runs a deployment of a branch/tag and config/db update to the production environment.
// *
// * @param string $uuid
// * @param string $branch
// *
// * @command prod:deploy
// */
// public function acquiaDeployProd($uuid, $branch)
// {
// $this->yell('WARNING: DEPLOYING TO PROD');
// if ($this->confirm('Are you sure you want to deploy to prod?')) {
// $environment = $this->getEnvironmentFromEnvironmentName($uuid, 'prod');
// $this->acquiaDeployEnv($uuid, $environment, $branch);
// }
// }

/**
* Runs a deployment of a branch/tag and config/db update to a non-production environment.
*
* @param string $uuid
* @param EnvironmentResponse $environment
* @param string $branch
* @throws \Exception
*
* @command preprod:deploy
*/
public function acquiaDeployPreProd($uuid, $environment, $branch)
{
if ($environment->name == 'prod') {
throw new \Exception('Use the prod:deploy command for the production environment.');
}
// /**
// * Runs a deployment of a branch/tag and config/db update to a non-production environment.
// *
// * @param string $uuid
// * @param EnvironmentResponse $environment
// * @param string $branch
// * @throws \Exception
// *
// * @command preprod:deploy
// */
// public function acquiaDeployPreProd($uuid, $environment, $branch)
// {
// if ($environment->name == 'prod') {
// throw new \Exception('Use the prod:deploy command for the production environment.');
// }

$this->acquiaDeployEnv($uuid, $environment, $branch);
}
// $this->acquiaDeployEnv($uuid, $environment, $branch);
// }

/**
* Runs a deployment of code from an environment to a non-production environment.
*
* @param string $uuid
* @param EnvironmentResponse $environmentFrom
* @param EnvironmentResponse $environmentTo
* @throws \Exception
*
* @command preprod:deployfromenv
*/
public function acquiaDeployPreProdFromEnv($uuid, $environmentFrom, $environmentTo)
{
if ($environmentTo->name == 'prod') {
throw new \Exception('Use the prod:deployfromenv command for the production environment.');
}
// /**
// * Runs a deployment of code from an environment to a non-production environment.
// *
// * @param string $uuid
// * @param EnvironmentResponse $environmentFrom
// * @param EnvironmentResponse $environmentTo
// * @throws \Exception
// *
// * @command preprod:deployfromenv
// */
// public function acquiaDeployPreProdFromEnv($uuid, $environmentFrom, $environmentTo)
// {
// if ($environmentTo->name == 'prod') {
// throw new \Exception('Use the prod:deployfromenv command for the production environment.');
// }

$this->acquiaDeployEnvToEnv($uuid, $environmentFrom, $environmentTo);
}
// $this->acquiaDeployEnvToEnv($uuid, $environmentFrom, $environmentTo);
// }

/**
* Prepares a non-production environment for deployment by copying the database and files from another environment.
*
* @param string $uuid
* @param EnvironmentResponse $environmentFrom
* @param EnvironmentResponse $environmentTo
* @throws \Exception
*
* @command preprod:prepare
*/
public function acquiaPreparePreProd($uuid, $environmentFrom, $environmentTo)
{
if ($environmentTo->name == 'prod') {
throw new \Exception('Use the db:backup and files:copy commands for the production environment.');
}
// /**
// * Prepares a non-production environment for deployment
// * by copying the database and files from another environment.
// *
// * @param string $uuid
// * @param EnvironmentResponse $environmentFrom
// * @param EnvironmentResponse $environmentTo
// * @throws \Exception
// *
// * @command preprod:prepare
// */
// public function acquiaPreparePreProd($uuid, $environmentFrom, $environmentTo)
// {
// if ($environmentTo->name == 'prod') {
// throw new \Exception('Use the db:backup and files:copy commands for the production environment.');
// }

$this->backupAndMoveDbs($uuid, $environmentFrom, $environmentTo);
$this->copyFiles($uuid, $environmentFrom, $environmentTo);
}

/**
* Clears varnish cache for all domains in specific a specific pre-production environment.
*
* @param string $uuid
* @param EnvironmentResponse $environment
* @throws \Exception
*
* @command preprod:purgevarnish
*/
public function acquiaPurgeVarnish($uuid, $environment)
{
if ($environment->name == 'prod') {
throw new \Exception('Use the prod:purgevarnish command for the production environment.');
}

$this->acquiaPurgeVarnishForEnvironment($uuid, $environment);
}

/**
* Clears varnish cache for all domains the production environment.
*
* @param string $uuid
*
* @command prod:purgevarnish
*/
public function acquiaPurgeVarnishProd($uuid)
{
$this->yell('WARNING: CLEARNING PROD VARNISH CACHE CAN RESULT IN REDUCTION IN PERFORMANCE');
if ($this->confirm('Are you sure you want to clear prod varnish cache?')) {
$environment = $this->getEnvironmentFromEnvironmentName($uuid, 'prod');
$this->acquiaPurgeVarnishForEnvironment($uuid, $environment);
}
}
// $this->backupAndMoveDbs($uuid, $environmentFrom, $environmentTo);
// $this->copyFiles($uuid, $environmentFrom, $environmentTo);
// }
}

0 comments on commit 08bb805

Please sign in to comment.