Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c3fee31737 | ||
|
|
8ff8ed66bf | ||
|
|
2800a55776 | ||
|
|
0bd195e5a9 | ||
|
|
0d799fca6c | ||
|
|
a5c405ec02 | ||
|
|
c3cc0c2e1f | ||
|
|
65893fc1a9 |
@@ -7,7 +7,7 @@ Run docker compose commands from the Robo task runner.
|
|||||||
First, you'll need to download the robo docker compose library using composer:
|
First, you'll need to download the robo docker compose library using composer:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
composer require droath/robo-docker-compose:~0.0.1
|
composer require --dev droath/robo-docker-compose
|
||||||
```
|
```
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
@@ -33,6 +33,10 @@ composer require droath/robo-docker-compose:~0.0.1
|
|||||||
The following commands have been implemented:
|
The following commands have been implemented:
|
||||||
|
|
||||||
- docker-compose up
|
- docker-compose up
|
||||||
|
- docker-compose ps
|
||||||
|
- docker-compose logs
|
||||||
|
- docker-compose pull
|
||||||
|
- docker-compose exec
|
||||||
- docker-compose down
|
- docker-compose down
|
||||||
- docker-compose start
|
- docker-compose start
|
||||||
- docker-compose restart
|
- docker-compose restart
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ trait DockerServicesTrait
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function getCommand()
|
public function getCommand()
|
||||||
{
|
{
|
||||||
// Append the services to the end of the command.
|
// Append the services to the end of the command.
|
||||||
return parent::getCommand() . ' ' . implode(' ', $this->services);
|
return parent::getCommand() . ' ' . implode(' ', $this->services);
|
||||||
|
|||||||
@@ -4,13 +4,14 @@ namespace Droath\RoboDockerCompose\Task;
|
|||||||
|
|
||||||
use Droath\RoboDockerCompose\ExecutableArguments;
|
use Droath\RoboDockerCompose\ExecutableArguments;
|
||||||
use Robo\Common\ExecOneCommand;
|
use Robo\Common\ExecOneCommand;
|
||||||
|
use Robo\Contract\CommandInterface;
|
||||||
use Robo\Exception\TaskException;
|
use Robo\Exception\TaskException;
|
||||||
use Robo\Task\BaseTask;
|
use Robo\Task\BaseTask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Docker compose base class.
|
* Docker compose base class.
|
||||||
*/
|
*/
|
||||||
abstract class Base extends BaseTask
|
abstract class Base extends BaseTask implements CommandInterface
|
||||||
{
|
{
|
||||||
use ExecOneCommand;
|
use ExecOneCommand;
|
||||||
use ExecutableArguments;
|
use ExecutableArguments;
|
||||||
@@ -128,7 +129,7 @@ abstract class Base extends BaseTask
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getCommand()
|
public function getCommand()
|
||||||
{
|
{
|
||||||
return "{$this->executable} {$this->executableArgs} {$this->action} {$this->arguments}";
|
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}";
|
||||||
|
}
|
||||||
|
}
|
||||||
77
src/Task/Logs.php
Normal file
77
src/Task/Logs.php
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Droath\RoboDockerCompose\Task;
|
||||||
|
|
||||||
|
use Droath\RoboDockerCompose\DockerServicesTrait;
|
||||||
|
use Robo\Exception\TaskException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the docker compose logs task.
|
||||||
|
*/
|
||||||
|
class Logs extends Base
|
||||||
|
{
|
||||||
|
use DockerServicesTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $action = 'logs';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produce monochrome output.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function noColor()
|
||||||
|
{
|
||||||
|
$this->option('no-color');
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Follow log output.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function follow()
|
||||||
|
{
|
||||||
|
$this->option('follow');
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show timestamps.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function timestamps()
|
||||||
|
{
|
||||||
|
$this->option('timestamps');
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of lines to show from the end of the logs for
|
||||||
|
* each container.
|
||||||
|
*
|
||||||
|
* @param string $value
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
* @throws TaskException
|
||||||
|
*/
|
||||||
|
public function tail($value = 'all')
|
||||||
|
{
|
||||||
|
if ($value !== 'all' && !is_numeric($value)) {
|
||||||
|
throw new TaskException(
|
||||||
|
__CLASS__,
|
||||||
|
'Provided argument value is invalid.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$this->option('tail', $value);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
59
src/Task/Ps.php
Normal file
59
src/Task/Ps.php
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Droath\RoboDockerCompose\Task;
|
||||||
|
|
||||||
|
use Droath\RoboDockerCompose\DockerServicesTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the docker composer ps command.
|
||||||
|
*/
|
||||||
|
class Ps extends Base
|
||||||
|
{
|
||||||
|
use DockerServicesTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $action = 'ps';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only display IDs.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function quiet()
|
||||||
|
{
|
||||||
|
$this->option('quiet');
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display services.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function services()
|
||||||
|
{
|
||||||
|
$this->option('services');
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter services by a property.
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* The filter property key.
|
||||||
|
* @param string $value
|
||||||
|
* The filter property value.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function filter($key, $value)
|
||||||
|
{
|
||||||
|
$this->option('filter', "{$key}={$value}");
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
66
src/Task/Pull.php
Normal file
66
src/Task/Pull.php
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Droath\RoboDockerCompose\Task;
|
||||||
|
|
||||||
|
use Droath\RoboDockerCompose\DockerServicesTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define Docker compose pull command.
|
||||||
|
*/
|
||||||
|
class Pull extends Base
|
||||||
|
{
|
||||||
|
use DockerServicesTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $action = 'pull';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pull what it can and ignores images with pull failures.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function ignoreFailures()
|
||||||
|
{
|
||||||
|
$this->option('ignore-pull-failures');
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pull multiple images in parallel.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function parallel()
|
||||||
|
{
|
||||||
|
$this->option('parallel');
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pull without printing progress information.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function quiet()
|
||||||
|
{
|
||||||
|
$this->option('quiet');
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Also pull services declared as dependencies.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function includeDeps()
|
||||||
|
{
|
||||||
|
$this->option('include-deps');
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,22 @@ trait loadTasks
|
|||||||
return $this->task(Up::class, $pathToDockerCompose);
|
return $this->task(Up::class, $pathToDockerCompose);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Docker compose ps task.
|
||||||
|
*/
|
||||||
|
protected function taskDockerComposePs($pathToDockerCompose = null)
|
||||||
|
{
|
||||||
|
return $this->task(Ps::class, $pathToDockerCompose);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Docker compose logs task.
|
||||||
|
*/
|
||||||
|
protected function taskDockerComposeLogs($pathToDockerCompose = null)
|
||||||
|
{
|
||||||
|
return $this->task(Logs::class, $pathToDockerCompose);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Docker compose down task.
|
* Docker compose down task.
|
||||||
*/
|
*/
|
||||||
@@ -31,6 +47,14 @@ trait loadTasks
|
|||||||
return $this->task(Pause::class, $pathToDockerCompose);
|
return $this->task(Pause::class, $pathToDockerCompose);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Docker compose pull task.
|
||||||
|
*/
|
||||||
|
protected function taskDockerComposePull($pathToDockerCompose = null)
|
||||||
|
{
|
||||||
|
return $this->task(Pull::class, $pathToDockerCompose);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Docker compose start task.
|
* Docker compose start task.
|
||||||
*/
|
*/
|
||||||
@@ -46,4 +70,12 @@ trait loadTasks
|
|||||||
{
|
{
|
||||||
return $this->task(Restart::class, $pathToDockerCompose);
|
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