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

Add host to DockerComposeTransport.php #85

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ docker-compose --project dockerComposeProjectName --file docker-compose.yml --pr

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

`docker.host` connects to a remote docker host. You can use ssh if you don't want to open the docker port. `host: ssh://user@host`

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

`docker.compose.version` defaults to `1`. Set to `2` to use the new syntax:
Expand Down
10 changes: 9 additions & 1 deletion src/Transport/DockerComposeTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,18 @@ public function addChdir($cd, $args)
protected function getTransport()
{
$version = $this->siteAlias->get('docker.compose.version', '1');
$host = $this->siteAlias->get('docker.host', '');
if ($version == 2) {
$transport = ['docker', 'compose'];
$transport = ['docker'];
if ($host != '') {
$transport[] = Shell::preEscaped('-H ' . $host);
}
$transport[] = 'compose';
} else {
$transport = ['docker-compose'];
if ($host != '') {
$transport[] = Shell::preEscaped('-H ' . $host);
}
}
$project = $this->siteAlias->get('docker.project', '');
$options = $this->siteAlias->get('docker.compose.options', '');
Expand Down
23 changes: 23 additions & 0 deletions tests/Transport/DockerComposeTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,29 @@ public function wrapTestValues()
]
],
],
[
'docker-compose -H ssh://user@dockerhost -p project1 exec -T drupal ls',
[
'docker' => [
'service' => 'drupal',
'host' => 'ssh://user@dockerhost',
'project' => 'project1',
]
],
],
[
'docker -H ssh://user@dockerhost compose -p project1 exec -T drupal ls',
[
'docker' => [
'service' => 'drupal',
'host' => 'ssh://user@dockerhost',
'project' => 'project1',
'compose' => [
'version' => '2',
],
]
],
],
];
}

Expand Down
Loading