Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Generalize Container/Host Task execution location logic #29

Open
jameswilson opened this issue Aug 16, 2018 · 2 comments
Open

Generalize Container/Host Task execution location logic #29

jameswilson opened this issue Aug 16, 2018 · 2 comments

Comments

@jameswilson
Copy link
Member

Refactor the “where to execute this task?” logic out from Spark\Robo\Plugin\Commands\DrushCommand so that any Robo command inside spark can leverage it. This is a blocker for the GDPR dump sanitization task.

One approach would amount to moving the "isContainer" variable up to Spark\Robo\Tasks, and changing how the task execution code works in Tasks to take the container name and "isContaner" logic into account.

Here is how we're current using isContainer:

if ($this->isContainer) {
$this->say('🚢 Running inside the PHP container');
$this->taskDockerComposeExecute()
->file($this->dockerComposeFile)
->projectName($this->config->get('name'))
->setContainer(' php')
->exec($command)
->disablePseudoTty()
->run();
}
else {
$this->say('💻 Running locally');
$this->taskExec($command)->run();
}

Another challenge will be figuring out how to generalize certain caveats, like the execution directory, which appears to be different when inside the container versus outside. In this snippet we are changing both the webroot location as well as the path to the command binary drush when inside the container.

private function prepare() {
$this->isContainer = $this->containerExists('php');
if ($this->isContainer) {
$this->drush = '../vendor/bin/drush';
$this->webRoot = '.';
}
else {
$this->drush = $this->workDir . '/vendor/bin/drush';
}
$this->commandBase = sprintf('%s --root=%s', $this->drush, $this->webRoot);
}

/cc @balintk @brants

@jameswilson
Copy link
Member Author

jameswilson commented Aug 16, 2018

Would it make sense to have a general way for Command files to override or instantiate their own default container name where their tasks should be run?

@jameswilson
Copy link
Member Author

Eg the DrushCommand.php constructor would set $this->container = 'php'; the DbCommand.php constructor would set $this->container = 'db';

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant