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

Adds setup:codespaces command #35

Open
wants to merge 10 commits into
base: 2.x
Choose a base branch
from
50 changes: 50 additions & 0 deletions src/Robo/Plugin/Commands/DevelopmentModeCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,54 @@ public function frontendDevDisable($siteDir = 'default', array $opts = ['yes|y'
->remove($this->devServicesPath)
->run();
}

/**
* Setup a site in GitHub Codespaces.
*
* @return \Robo\Result
* The result of the set of tasks.
*
* @throws \Robo\Exception\TaskException
*
*/
public function setupCodespaces(): Result
{
$this->io()->title('Symlinking file system.');
$docRootDir = Robo::config()->get('drupal_document_root') ?? 'web';
$codespaces_directory = getenv('PWD') . '/' . $docRootDir;
if (empty($codespaces_directory)) {
throw new TaskException($this, 'Codespaces directory is unavailable.');
}
$this->taskDeleteDir('/var/www/html')->run();
$result = $this->taskExec("ln -s $codespaces_directory /var/www/html")->run();

$this->io()->title('Start apache, forwarding port 80.');
$result = $this->taskExec('service apache2 start')->run();

$this->io()->title('Download database.');
$dbPath = $this->databaseDownload();
if (empty($dbPath)) {
throw new TaskException($this, 'Database download failed.');
}

$this->io()->section('Importing database.');
$result = $this->taskExec("zcat $dbPath | mysql -h db -u mariadb -pmariadb mariadb")->run();
$result = $this->taskExec('rm')->args($dbPath)->run();

$this->io()->section('Building theme.');
$result = $this->taskExec('composer robo theme:build')->run();
Copy link
Contributor

Choose a reason for hiding this comment

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

This and the db download line above will work for simple sites, but multi-sites will require some special cases. I am OK with merging this assuming we want to address that in a future update.

Copy link
Author

Choose a reason for hiding this comment

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

I can log a ticket about updating this to support multi-sites, as well as some other caveats that may need to be created to support running a multi-site in codespaces.


$this->io()->section('Drush deploy.');
$result = $this->taskExecStack()
->exec("vendor/bin/drush deploy --yes")
// Import the latest configuration again. This includes the latest
// configuration_split configuration. Importing this twice ensures that
// the latter command enables and disables modules based upon the most up
// to date configuration. Additional information and discussion can be
// found here:
// https://github.com/drush-ops/drush/issues/2449#issuecomment-708655673
->exec("drush config:import --yes")
->run();
return $result;
}
}