Mercurial > hg > cmmr2012-drupal-site
comparison vendor/consolidation/site-process/src/Transport/DockerComposeTransport.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
1 <?php | |
2 | |
3 namespace Consolidation\SiteProcess\Transport; | |
4 | |
5 use Consolidation\SiteProcess\SiteProcess; | |
6 use Consolidation\SiteAlias\SiteAliasInterface; | |
7 use Consolidation\SiteProcess\Util\Shell; | |
8 use Consolidation\Config\ConfigInterface; | |
9 | |
10 /** | |
11 * DockerComposeTransport knows how to wrap a command such that it executes | |
12 * on a Docker Compose service. | |
13 */ | |
14 class DockerComposeTransport implements TransportInterface | |
15 { | |
16 protected $tty; | |
17 protected $siteAlias; | |
18 protected $cd_remote; | |
19 | |
20 public function __construct(SiteAliasInterface $siteAlias) | |
21 { | |
22 $this->siteAlias = $siteAlias; | |
23 } | |
24 | |
25 /** | |
26 * @inheritdoc | |
27 */ | |
28 public function configure(SiteProcess $process) | |
29 { | |
30 $this->tty = $process->isTty(); | |
31 } | |
32 | |
33 /** | |
34 * @inheritdoc | |
35 */ | |
36 public function wrap($args) | |
37 { | |
38 $transport = $this->getTransport(); | |
39 $transportOptions = $this->getTransportOptions(); | |
40 $commandToExecute = $this->getCommandToExecute($args); | |
41 | |
42 return array_merge( | |
43 $transport, | |
44 $transportOptions, | |
45 $commandToExecute | |
46 ); | |
47 } | |
48 | |
49 /** | |
50 * @inheritdoc | |
51 */ | |
52 public function addChdir($cd, $args) | |
53 { | |
54 $this->cd_remote = $cd; | |
55 return $args; | |
56 } | |
57 | |
58 /** | |
59 * getTransport returns the transport along with the docker-compose | |
60 * project in case it is defined. | |
61 */ | |
62 protected function getTransport() | |
63 { | |
64 $transport = ['docker-compose']; | |
65 $project = $this->siteAlias->get('docker.project', ''); | |
66 $options = $this->siteAlias->get('docker.compose.options', ''); | |
67 if ($project && (strpos($options, '-p') === false || strpos($options, '--project') === false)) { | |
68 $transport = array_merge($transport, ['-p', $project]); | |
69 } | |
70 if ($options) { | |
71 $transport[] = Shell::preEscaped($options); | |
72 } | |
73 return array_merge($transport, ['exec']); | |
74 } | |
75 | |
76 /** | |
77 * getTransportOptions returns the transport options for the tranport | |
78 * mechanism itself | |
79 */ | |
80 protected function getTransportOptions() | |
81 { | |
82 $transportOptions = [ | |
83 $this->siteAlias->get('docker.service', ''), | |
84 ]; | |
85 if ($options = $this->siteAlias->get('docker.exec.options', '')) { | |
86 array_unshift($transportOptions, Shell::preEscaped($options)); | |
87 } | |
88 if (!$this->tty) { | |
89 array_unshift($transportOptions, '-T'); | |
90 } | |
91 if ($this->cd_remote) { | |
92 $transportOptions = array_merge(['--workdir', $this->cd_remote], $transportOptions); | |
93 } | |
94 return array_filter($transportOptions); | |
95 } | |
96 | |
97 /** | |
98 * getCommandToExecute processes the arguments for the command to | |
99 * be executed such that they are appropriate for the transport mechanism. | |
100 * | |
101 * Nothing to do for this transport. | |
102 */ | |
103 protected function getCommandToExecute($args) | |
104 { | |
105 return $args; | |
106 } | |
107 } |