Skip to content

Commit

Permalink
Allow to explicitly specify the transport to use for a site-alias
Browse files Browse the repository at this point in the history
  • Loading branch information
ceesgeene committed Dec 5, 2022
1 parent 49ec2b9 commit 1e51630
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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.

Expand All @@ -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
Expand Down Expand Up @@ -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`


Expand Down
24 changes: 15 additions & 9 deletions src/ProcessManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/SiteProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1e51630

Please sign in to comment.