Skip to content

Commit

Permalink
CLI passthru fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisnharvey committed Sep 18, 2020
1 parent a7c7938 commit f4f1325
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions containers/workspace/cli/app/Docker/Docker.php
Expand Up @@ -55,12 +55,12 @@ public function shell(string $container, ?string $shell = null, string $user = '

public function run(string $container, string $command, string $user = 'root')
{
return passthru("{$this->dockerComposePath} exec -u {$user} {$container} {$command}");
return $this->runCommand([$this->dockerComposePath, 'exec', '-u', $user, $container, $command], true, false);
}

public function getContainerId(string $container): string
{
$process = $this->runCommand($this->dockerComposePath, 'ps', '-q', $container);
$process = $this->runCommand([$this->dockerComposePath, 'ps', '-q', $container]);

return trim($process->getOutput());
}
Expand All @@ -80,34 +80,41 @@ public function containerPathToHostPath(string $path)

public function restart(string $container)
{
$this->runCommand($this->dockerComposePath, 'restart', $container);
$this->runCommand([$this->dockerComposePath, 'restart', $container]);
}

public function recreate(string $container)
{
$this->runCommand($this->dockerComposePath, 'up', '-d', $container);
$this->runCommand([$this->dockerComposePath, 'up', '-d', $container]);
}

public function stop(string $container)
{
$this->runCommand($this->dockerComposePath, 'stop', $container);
$this->runCommand([$this->dockerComposePath, 'stop', $container]);
}

public function copy(string $container, string $source, string $destination)
{
$id = $this->getContainerId($container);

$this->runCommand($this->dockerPath, 'cp', "{$id}:{$source}", $destination);
$this->runCommand([$this->dockerPath, 'cp', "{$id}:{$source}", $destination]);
}

public function getError(): string
{
return $this->error;
}

protected function runCommand(...$args)
protected function runCommand(array $args, bool $tty = false, bool $escape = true)
{
$process = new Process($args);
if ($escape) {
$process = new Process($args, $this->magicLampPath);
} else {
$process = Process::fromShellCommandline(implode(' ', $args), $this->magicLampPath);
}

$process->setTty($tty);
$process->setTimeout(null);

try {
$process->mustRun();
Expand Down

0 comments on commit f4f1325

Please sign in to comment.