diff --git a/README.md b/README.md index e07d8f2..bd8e701 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Site Process -A thin wrapper around the Symfony Process Component that allows applications to use the Site Alias library to specify the target for a remote call. +A thin wrapper around the Symfony Process Component that allows applications to use the Site Alias library to specify the target for a remote call. [![ci](https://github.com/consolidation/site-process/workflows/CI/badge.svg)](https://travis-ci.org/consolidation/site-process) [![scrutinizer](https://scrutinizer-ci.com/g/consolidation/site-process/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/consolidation/site-process/?branch=master) @@ -32,6 +32,18 @@ This is equivalent to: $process = $processManager->siteProcess($site_alias, ['git', '--untracked-files=no', 'status']); ``` ### Transports + +The transport for a site alias is automatically determined based on its config. The +transport can be specified explicitly using the `transport` property. + +Available transports: + +* ssh +* kubectl +* skpr +* docker-dompose +* vagrant + #### SSH Wraps a command so that it runs on a remote system via the ssh cli. @@ -41,7 +53,7 @@ local: host: localhost uri: http://localhost ssh: - options: -o PasswordAuthentication=no -i $HOME/.ssh/id_rsa + options: -o PasswordAuthentication=no -i $HOME/.ssh/id_rsa ``` ### Vagrant @@ -97,7 +109,7 @@ The test suite may be run locally by way of some simple composer scripts: | Run all tests | `composer test` | PHPUnit tests | `composer unit` | PHP linter | `composer lint` -| Code style | `composer cs` +| Code style | `composer cs` | Fix style errors | `composer cbf` diff --git a/src/ProcessManager.php b/src/ProcessManager.php index acfe12b..40ce98b 100644 --- a/src/ProcessManager.php +++ b/src/ProcessManager.php @@ -69,11 +69,11 @@ public static function createDefault() */ public static function addTransports(ProcessManager $processManager) { - $processManager->add(new SshTransportFactory()); - $processManager->add(new KubectlTransportFactory()); - $processManager->add(new SkprTransportFactory()); - $processManager->add(new DockerComposeTransportFactory()); - $processManager->add(new VagrantTransportFactory()); + $processManager->add(new SshTransportFactory(), 'ssh'); + $processManager->add(new KubectlTransportFactory(), 'kubectl'); + $processManager->add(new SkprTransportFactory(), 'skpr'); + $processManager->add(new DockerComposeTransportFactory(), 'docker-compose'); + $processManager->add(new VagrantTransportFactory(), 'vagrant'); return $processManager; } @@ -125,10 +125,15 @@ public function shell($command, $cwd = null, array $env = null, $input = null, $ /** * add a transport factory to our factory list * @param TransportFactoryInterface $factory + * @param string $name */ - public function add(TransportFactoryInterface $factory) + public function add(TransportFactoryInterface $factory, string $name = null) { - $this->transportFactories[] = $factory; + if ($name) { + $this->transportFactories[$name] = $factory; + } else { + $this->transportFactories[] = $factory; + } return $this; } @@ -170,8 +175,9 @@ public function getTransport(SiteAliasInterface $siteAlias) */ protected function getTransportFactory(SiteAliasInterface $siteAlias) { - foreach ($this->transportFactories as $factory) { - if ($factory->check($siteAlias)) { + $transport = $siteAlias->get('transport'); + foreach ($this->transportFactories as $key => $factory) { + if ((!$transport || $transport === $key) && $factory->check($siteAlias)) { return $factory; } } diff --git a/tests/SiteProcessTest.php b/tests/SiteProcessTest.php index a207d8e..b5b29de 100644 --- a/tests/SiteProcessTest.php +++ b/tests/SiteProcessTest.php @@ -136,6 +136,17 @@ public function siteProcessTestValues() NULL, ], + [ + "kubectl --namespace=vv exec --tty=false --stdin=false deploy/drupal -- ls -al /path1 /path2", + false, + false, + ['transport' => 'kubectl', 'host' => 'server.net', 'kubectl' => ['namespace' => 'vv', 'resource' => 'deploy/drupal']], + ['ls', '-al', '/path1', '/path2'], + [], + [], + NULL, + ], + [ "drush status '--fields=root,uri'", false,