Skip to content

Commit

Permalink
forward-port docker composer v2 support in 5.x branch. (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
hkorik committed Jul 10, 2024
1 parent 4632092 commit c7d8b4d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 5.4.1 - 2024/Jul/10

* Allow Docker Compose v2

### 5.4.0

* Support Symfony 7
Expand Down
12 changes: 9 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 @@ -41,7 +41,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 All @@ -65,6 +65,7 @@ local:
docker:
service: drupal
compose:
version: 1
options: --project dockerComposeProjectName --file docker-compose.yml --project-directory dockerComposeWorkDir
exec:
options: --user www-data
Expand All @@ -80,6 +81,11 @@ docker-compose --project dockerComposeProjectName --file docker-compose.yml --pr

`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:

```
docker compose --project dockerComposeProjectName --file docker-compose.yml --project-directory dockerComposeWorkDir exec --user www-data -T drupal
```
The default behaviour is to use `docker-compose exec` to invoke a command on a running container.
You can change this to use `docker-compose run` for containers which by default are not running, with the property `compose.command`.

Expand All @@ -97,7 +103,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
7 changes: 6 additions & 1 deletion src/Transport/DockerComposeTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ public function addChdir($cd, $args)
*/
protected function getTransport()
{
$transport = ['docker-compose'];
$version = $this->siteAlias->get('docker.compose.version', '1');
if ($version == 2) {
$transport = ['docker', 'compose'];
} else {
$transport = ['docker-compose'];
}
$project = $this->siteAlias->get('docker.project', '');
$options = $this->siteAlias->get('docker.compose.options', '');
$command = $this->siteAlias->get('docker.compose.command', 'exec');
Expand Down
22 changes: 22 additions & 0 deletions tests/Transport/DockerComposeTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ public function wrapTestValues()
]
],
],
[
'docker compose exec -T drupal ls',
[
'docker' => [
'service' => 'drupal',
'compose' => [
'version' => '2',
],
]
],
],
[
'docker-compose exec -T drupal ls',
[
'docker' => [
'service' => 'drupal',
'compose' => [
'version' => '1',
]
]
],
],
[
'docker-compose --project project2 --file myCompose.yml exec -T drupal ls',
[
Expand Down

0 comments on commit c7d8b4d

Please sign in to comment.