Skip to content

Instantly share code, notes, and snippets.

@dustinleblanc
Created August 6, 2018 23:29
Show Gist options
  • Save dustinleblanc/f5aa553d702ade014b416dd6bfe31c2d to your computer and use it in GitHub Desktop.
Save dustinleblanc/f5aa553d702ade014b416dd6bfe31c2d to your computer and use it in GitHub Desktop.
Magic Robofile for Acquia sites
name: client
recipe: drupal7
config:
webroot: docroot
xdebug: true
php: '7.1'
via: nginx
services:
appserver:
composer:
consolidation/robo: "*"
boedah/robo-drush: "~3.0"
typhonius/acquia_cli: "*"
tooling:
robo:
service: appserver
acquiacli:
service: appserver
drush:
service: appserver
cmd: drush --uri=https://client.lndo.site
<?php
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFile extends \Robo\Tasks {
use Boedah\Robo\Task\Drush\loadTasks;
/**
* Path to Drush executable.
*/
protected $drushBin;
/**
* Path to Drupal root.
*/
protected $drupalRoot;
/**
* RoboFile constructor.
*/
public function __construct() {
$this->disable_prod = ['syslog'];
$this->enable_dev = ['stage_file_proxy', 'dblog', 'devel'];
$this->envs = [
'dev' => 'https://dev-acquia.client.com/',
'test' => 'https://stage-acquia.client.com/',
'prod' => 'https://www.client.com',
];
// Use Global Drush in Lando
$this->drushBin = '/usr/local/bin/drush';
// Use absolute Path inside Lando
$this->drupalRoot = '/app/docroot';
}
/**
* Synchronizes local development environment with a specified remote.
*
* @param $env
*
* @return \Robo\Result
* @throws \Robo\Exception\TaskException
*/
public function sync($env) {
if (!array_key_exists($env, $this->envs)) {
return Robo\Result::error($this, "I'm sorry but that environment is invalid");
}
$this->getDrushAliases();
if ($this->syncDb($env)->run()->wasSuccessful()) {
$this->disableProdModules();
$this->enableDevModules();
$this->buildDrushTask()
->exec("vset stage_file_proxy_origin {$this->getEnvUrl($env)}")
->run();
}
if ($this->ask("Should I run updates? (y/n) \n") === 'y') {
$this->runUpdates();
}
}
/**
* Run database updates and revert features.
*/
public function runUpdates() {
$this->buildDrushTask()
->maintenanceOn()
->updateDb()
->maintenanceOff()
->run();
}
/**
* @param $env
*
* @return $this
*/
private function syncDb($env) {
return $this->buildDrushTask()
->exec("sql-drop")
->exec("sql-sync @client.{$env} @self");
}
/**
* Builds a Drush task with common arguments.
*
* @return $this
* A DrushStack task to use in building a task.
*/
private function buildDrushTask() {
return $this->taskDrushStack($this->drushBin . ' --root=/app/docroot');
}
/**
* @return mixed
*/
public function disableProdModules() {
return $this->buildDrushTask()
->exec("dis {$this->getDisableProd()}")
->yes()
->run();
}
/**
* Get a list of modules to disable to pass to drush
*
* @return string
*/
private function getDisableProd() {
return implode(' ', $this->disable_prod);
}
/**
* @return mixed
*/
public function enableDevModules() {
return $this->buildDrushTask()
->exec("en {$this->getEnableDev()}")
->yes()
->run();
}
/**
* Get a list of modules to enable to pass to drush
*
* @return mixed
*/
private function getEnableDev() {
return implode(' ', $this->enable_dev);
}
/**
* @param $env
*
* @return mixed
*/
private function getEnvUrl($env) {
return $this->envs[$env];
}
protected function getDrushAliases() {
if (!file_exists('/var/www/.acquiacli/acquiacli.yml')) {
$this->_exec('acquiacli setup');
}
$this->_cleanDir('/tmp');
$this->_exec('acquiacli drush:aliases');
$finder = new Symfony\Component\Finder\Finder();
$aliases = $finder->in('/tmp')
->files()
->name('/AcquiaDrushAliases([0-9A-Za-z])\w+.tar.gz$/');
foreach ($aliases as $alias) {
$this->_exec("tar -C \$HOME -xf {$alias->getRealPath()}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment