Skip to content

Commit

Permalink
Docker compose v2 (#75)
Browse files Browse the repository at this point in the history
* support docker compose v2

* move option underneath docker-compose so its clearer, update doco

* phpcs fix
  • Loading branch information
jon-nunan authored Dec 23, 2023
1 parent ee3bf69 commit d7d023d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 4.2.2 - 2023/Jul/4

* Allow Docker Compose v2

### 4.2.1 - 2022/Oct/18

* Allow site-alias ^4
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -78,7 +79,12 @@ 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.service` is the exact name of the service as it appears in docker-compos.yml
`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
```

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

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', '');
if ($project && (strpos($options, '-p') === false || strpos($options, '--project') === false)) {
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 d7d023d

Please sign in to comment.