Skip to content

Commit

Permalink
Allow passing the file to docker-compose.yml and any other docker-com…
Browse files Browse the repository at this point in the history
…pose arguments (#39)
  • Loading branch information
alexxed authored and greg-1-anderson committed Apr 4, 2019
1 parent 2c1fd13 commit 4849ce2
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

### 2.0.2 -
* When the transport is Docker, allow setting any docker-compose flags in the alias file

### 2.0.1 - 2019/Apr/2

* Do not format output in RealTimeOutput
Expand Down
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,49 @@ This is equivalent to:
```
$process = $processManager->siteProcess($site_alias, ['git', '--untracked-files=no', 'status']);
```
### Transports
#### SSH
Wraps a command so that it runs on a remote system via the ssh cli.

Example:
```yaml
local:
host: localhost
uri: http://localhost
ssh:
options: -o PasswordAuthentication=no -i $HOME/.ssh/id_rsa

```
#### Docker Compose
Wraps a command so that it runs on a remote system via docker-compose.

Example:
```yaml
local:
host: localhost
uri: http://localhost
docker:
service: drupal
compose:
options: --project dockerComposeProjectName --file docker-compose.yml --project-directory dockerComposeWorkDir
exec:
options: --user www-data

```

The above would execute commands prefixed with:
```
docker-compose --project dockerComposeProjectName --file docker-compose.yml --project-directory dockerComposeWorkDir exec --user www-data -T drupal
```

`docker.project` and `compose.options --project` do the same thing, docker.project existed before options.

`docker.service` is the exact name of the service as it appears in docker-compos.yml

Check the [docker-compose](https://docs.docker.com/compose/reference/overview/) manual for all available options.

#### Local
Runs the command on the local system.

## Symfony 4

Expand Down
7 changes: 6 additions & 1 deletion src/Transport/DockerComposeTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,14 @@ public function addChdir($cd, $args)
protected function getTransport()
{
$transport = ['docker-compose'];
if ($project = $this->siteAlias->get('docker.project', '')) {
$project = $this->siteAlias->get('docker.project', '');
$options = $this->siteAlias->get('docker.compose.options', '');
if ($project && (strpos($options, '-p') === false || strpos($options, '--project') === false)) {
$transport = array_merge($transport, ['-p', $project]);
}
if ($options) {
$transport[] = Shell::preEscaped($options);
}
return array_merge($transport, ['exec']);
}

Expand Down
74 changes: 74 additions & 0 deletions tests/Transport/DockerComposeTransportTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Consolidation\SiteProcess;

use Consolidation\SiteProcess\Transport\DockerComposeTransport;
use PHPUnit\Framework\TestCase;
use Consolidation\SiteAlias\SiteAlias;

class DockerComposeTransportTest extends TestCase
{
/**
* Data provider for testWrap.
*/
public function wrapTestValues()
{
return [
[
'docker-compose --project project --project-directory projectDir --file myCompose.yml exec -T --user root drupal ls',
[
'docker' => [
'service' => 'drupal',
'compose' => [
'options' => '--project project --project-directory projectDir --file myCompose.yml'
],
'exec' => ['options' => '--user root']
]
],
],
[
'docker-compose exec -T drupal ls',
[
'docker' => [
'service' => 'drupal',
]
],
],
[
'docker-compose --project project2 --file myCompose.yml exec -T drupal ls',
[
'docker' => [
'service' => 'drupal',
'project' => 'project1',
'compose' => [
'options' => '--project project2 --file myCompose.yml'
]
]
],
],
[
'docker-compose -p project1 --file myCompose.yml exec -T drupal ls',
[
'docker' => [
'service' => 'drupal',
'project' => 'project1',
'compose' => [
'options' => '--file myCompose.yml'
]
]
],
],
];
}

/**
* @dataProvider wrapTestValues
*/
public function testWrap($expected, $siteAliasData)
{
$siteAlias = new SiteAlias($siteAliasData, '@alias.dev');
$dockerTransport = new DockerComposeTransport($siteAlias);
$actual = $dockerTransport->wrap(['ls']);
$this->assertEquals($expected, implode(' ', $actual));
}
}

0 comments on commit 4849ce2

Please sign in to comment.