Add docker-compose exec command.
This commit is contained in:
@@ -45,7 +45,7 @@ trait DockerServicesTrait
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getCommand()
|
||||
public function getCommand()
|
||||
{
|
||||
// Append the services to the end of the command.
|
||||
return parent::getCommand() . ' ' . implode(' ', $this->services);
|
||||
|
||||
@@ -4,13 +4,14 @@ namespace Droath\RoboDockerCompose\Task;
|
||||
|
||||
use Droath\RoboDockerCompose\ExecutableArguments;
|
||||
use Robo\Common\ExecOneCommand;
|
||||
use Robo\Contract\CommandInterface;
|
||||
use Robo\Exception\TaskException;
|
||||
use Robo\Task\BaseTask;
|
||||
|
||||
/**
|
||||
* Docker compose base class.
|
||||
*/
|
||||
abstract class Base extends BaseTask
|
||||
abstract class Base extends BaseTask implements CommandInterface
|
||||
{
|
||||
use ExecOneCommand;
|
||||
use ExecutableArguments;
|
||||
@@ -128,7 +129,7 @@ abstract class Base extends BaseTask
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getCommand()
|
||||
public function getCommand()
|
||||
{
|
||||
return "{$this->executable} {$this->executableArgs} {$this->action} {$this->arguments}";
|
||||
}
|
||||
|
||||
153
src/Task/Execute.php
Normal file
153
src/Task/Execute.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
namespace Droath\RoboDockerCompose\Task;
|
||||
|
||||
use Robo\Contract\CommandInterface;
|
||||
|
||||
/**
|
||||
* Docker compose execute command.
|
||||
*/
|
||||
class Execute extends Base
|
||||
{
|
||||
/**
|
||||
* Execute command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $command;
|
||||
|
||||
/**
|
||||
* Execute container.
|
||||
*
|
||||
* @var string.
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $action = 'exec';
|
||||
|
||||
/**
|
||||
* Set docker container.
|
||||
*
|
||||
* @param $container
|
||||
* The container name.
|
||||
* @return $this
|
||||
*/
|
||||
public function setContainer($container)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set execute command.
|
||||
*
|
||||
* @param string|CommandInterface $command
|
||||
* The command to execute.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function exec($command)
|
||||
{
|
||||
if ($command instanceof CommandInterface) {
|
||||
$command = $command->getCommand();
|
||||
}
|
||||
$this->command = $command;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run command in the background.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function detachedMode()
|
||||
{
|
||||
$this->arg('-d');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give extended privileges to the process.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function privileged()
|
||||
{
|
||||
$this->option('privileged');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the command as this user.
|
||||
*
|
||||
* @param $user
|
||||
* The user on which to run the command under.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function user($user)
|
||||
{
|
||||
$this->option('user', $user);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable pseudo-tty allocation.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function disablePseudoTty()
|
||||
{
|
||||
$this->arg('-T');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Index of the container.
|
||||
*
|
||||
* @param $index
|
||||
* The container index.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function index($index)
|
||||
{
|
||||
$this->option('index', $index);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set environment variables
|
||||
*
|
||||
* @param $key
|
||||
* The environment key.
|
||||
* @param $value
|
||||
* The environment value.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function envVariable($key, $value)
|
||||
{
|
||||
$this->option('env', "{$key}={$value}");
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCommand()
|
||||
{
|
||||
return parent::getCommand() . "{$this->container} {$this->command}";
|
||||
}
|
||||
}
|
||||
@@ -46,4 +46,13 @@ trait loadTasks
|
||||
{
|
||||
return $this->task(Restart::class, $pathToDockerCompose);
|
||||
}
|
||||
|
||||
/**
|
||||
* Docker compose execute task.
|
||||
*/
|
||||
protected function taskDockerComposeExecute($pathToDockerCompose = null)
|
||||
{
|
||||
return $this->task(Execute::class, $pathToDockerCompose);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user