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

Forward-port docker compose v2 support to main (5.x) #79

Merged
merged 1 commit into from
Jul 10, 2024
Merged
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
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
Loading