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

DEVOPS-000 - Provisioning with blt command [automation] #343

Open
wants to merge 8 commits into
base: 4.x
Choose a base branch
from
Open
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
87 changes: 87 additions & 0 deletions blt/src/Blt/Plugin/Commands/GryphonCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Gryphon\Blt\Plugin\Commands;

use Acquia\Blt\Robo\BltTasks;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Yaml\Yaml;

/**
* Class GryphonCommands.
Expand Down Expand Up @@ -81,4 +83,89 @@ public function roleReport($role)
fclose($out);
}

/**
* Provisioning a site.
*
* @command gryphon:provision
* @description This is command to populate URLs by scafoliding the multisite and designating URLs on Acquia.
*/
public function provision($sitename): void {
if (empty($sitename)) {
$this->say('Sitename cannot be empty. Exiting');
return;
}

// Define environment types
$env_types = ['dev', 'test', 'prod'];

foreach ($env_types as $env_type) {
$sitename_env = $sitename . '-' . $env_type;

// Checks to see if domain name is in use.
if ($this->checkForARecord($sitename_env)) {
$this->say('A Record present in NetDB. Cannot proceed with provision until aliases released.');
}
//Outputs alias for NetDB.
$this->say('A Record not present. Site name is free to use.');
$this->say('Alias for NetDB: ' . $sitename_env);
$this->addDomainsToAcquia($sitename, $env_type, $sitename_env);
// $this->postMultiSiteInit($sitename);

}
}

/**
* @param $domain
*
* @return bool
*/
private function checkForARecord($domain): bool {
return !empty(dns_get_record($domain . '.stanford.edu', DNS_A));
}

/**
* Adds domains to Acquia
*
* @param $sitename_env
*
* @return void
*/
private function addDomainsToAcquia($sitename, $env_type, $sitename_env): void {
$condition = $this->ask("Do you want to add the domain to acquia? (yes/no)", "yes");

if (strtolower($condition) === 'yes') {
$this->say("Running the specific function...");
$this->gryphonAddDomain($env_type, $sitename_env . '.stanford.edu');
$this->addToBltYml($sitename);
$this->scaffoldingMultisite();
} else {
$this->say("Skipped running the specific function.");
}
}

private function scaffoldingMultisite(): void {
$gryphon = new GryphonHooksCommands();
$gryphon->postMultiSiteInit();
}

/**
* @return void
*
* @command gryphon:yaml
* @description This is command to show provision URLs.
*/
private function addToBltYml($sitename) {
$bltYAML = __DIR__ . "/../../../../blt.yml";

if (!file_exists($bltYAML)){
$this->say('No BLT yaml file to edit.');
return;
}

$yamlContentsBlt = Yaml::parseFile($bltYAML);
$yamlContentsBlt['multisites'][] = $sitename;
sort($yamlContentsBlt['multisites']);
$newMultisiteYaml = Yaml::dump($yamlContentsBlt, 10, 2);
$this->taskWriteToFile($bltYAML)->text($newMultisiteYaml)->run();
}
}
Loading