Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6bce2a0a58 | ||
|
|
14b153d73e | ||
|
|
b36011de1e | ||
|
|
c3fee31737 | ||
|
|
8ff8ed66bf | ||
|
|
2800a55776 | ||
|
|
9e35a8ab4d | ||
|
|
1a94e483fe | ||
|
|
abd26b2b0a | ||
|
|
18eea076d7 | ||
|
|
0bd195e5a9 | ||
|
|
0d799fca6c | ||
|
|
a5c405ec02 | ||
|
|
c3cc0c2e1f | ||
|
|
65893fc1a9 | ||
|
|
c2242c4b93 | ||
|
|
463daf3a2d | ||
|
|
761f956826 | ||
|
|
01740ee9e4 | ||
|
|
ce1360c733 | ||
|
|
4697d956fa |
16
README.md
16
README.md
@@ -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:
|
||||
|
||||
```bash
|
||||
composer require droath/robo-docker-compose:~0.0.1
|
||||
composer require --dev droath/robo-docker-compose
|
||||
```
|
||||
|
||||
### Example
|
||||
@@ -32,8 +32,18 @@ composer require droath/robo-docker-compose:~0.0.1
|
||||
|
||||
The following commands have been implemented:
|
||||
|
||||
- docker-compose up
|
||||
- docker-compose down
|
||||
- docker-compose up - [Command Options](https://docs.docker.com/compose/reference/up)
|
||||
- docker-compose ps - [Command Options](https://docs.docker.com/compose/reference/ps)
|
||||
- docker-compose run - [Command Options](https://docs.docker.com/compose/reference/run)
|
||||
- docker-compose logs - [Command Options](https://docs.docker.com/compose/reference/logs)
|
||||
- docker-compose pull - [Command Options](https://docs.docker.com/compose/reference/pull)
|
||||
- docker-compose exec - [Command Options](https://docs.docker.com/compose/reference/exec)
|
||||
- docker-compose down - [Command Options](https://docs.docker.com/compose/reference/down)
|
||||
- docker-compose build - [Command Options](https://docs.docker.com/compose/reference/build)
|
||||
- docker-compose start - [Command Options](https://docs.docker.com/compose/reference/start)
|
||||
- docker-compose restart - [Command Options](https://docs.docker.com/compose/reference/restart)
|
||||
- docker-compose pause - [Command Options](https://docs.docker.com/compose/reference/pause)
|
||||
|
||||
|
||||
I'll be adding the rests of the docker-compose commands shortly. Or if you want
|
||||
to create a PR with additional commands that would be much appreciated.
|
||||
|
||||
66
src/DockerCommandTrait.php
Normal file
66
src/DockerCommandTrait.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Droath\RoboDockerCompose;
|
||||
|
||||
use Robo\Contract\CommandInterface;
|
||||
|
||||
/**
|
||||
* Define the docker command trait.
|
||||
*/
|
||||
trait DockerCommandTrait
|
||||
{
|
||||
/**
|
||||
* Execute command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $command;
|
||||
|
||||
/**
|
||||
* Execute container.
|
||||
*
|
||||
* @var string.
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* Set docker container.
|
||||
*
|
||||
* @param $container
|
||||
* The container name.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setContainer($container)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set docker command.
|
||||
*
|
||||
* @param string|CommandInterface $command
|
||||
* The command to execute.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCommand($command)
|
||||
{
|
||||
if ($command instanceof CommandInterface) {
|
||||
$command = $command->getCommand();
|
||||
}
|
||||
$this->command = $command;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCommand()
|
||||
{
|
||||
return parent::getCommand() . " {$this->container} {$this->command}";
|
||||
}
|
||||
}
|
||||
53
src/DockerServicesTrait.php
Executable file
53
src/DockerServicesTrait.php
Executable file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Droath\RoboDockerCompose;
|
||||
|
||||
/**
|
||||
* Define docker services trait.
|
||||
*/
|
||||
trait DockerServicesTrait
|
||||
{
|
||||
/**
|
||||
* Docker compose services.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $services = [];
|
||||
|
||||
/**
|
||||
* Add docker composer service.
|
||||
*
|
||||
* @param string $service
|
||||
* The docker services.
|
||||
*/
|
||||
public function setService($service)
|
||||
{
|
||||
$this->services[] = $service;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add docker composer services.
|
||||
*
|
||||
* @param array $services
|
||||
* An array of services.
|
||||
*/
|
||||
public function setServices(array $services)
|
||||
{
|
||||
foreach ($services as $service) {
|
||||
$this->setService($service);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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}";
|
||||
}
|
||||
|
||||
95
src/Task/Build.php
Executable file
95
src/Task/Build.php
Executable file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace Droath\RoboDockerCompose\Task;
|
||||
|
||||
use Droath\RoboDockerCompose\DockerServicesTrait;
|
||||
|
||||
/**
|
||||
* Define docker compose build command.
|
||||
*/
|
||||
class Build extends Base
|
||||
{
|
||||
use DockerServicesTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $action = 'build';
|
||||
|
||||
/**
|
||||
* Compress the build context using gzip.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function compress()
|
||||
{
|
||||
$this->option('compress');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Always remove intermediate containers.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function forceRm()
|
||||
{
|
||||
$this->option('force-rm');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not use cache when building the image.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function noCache()
|
||||
{
|
||||
$this->option('no-cache');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Always attempt to pull a newer version of the image.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function pull()
|
||||
{
|
||||
$this->option('pull');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets memory limit for the build container.
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function memory($value)
|
||||
{
|
||||
$this->option('memory', $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set build-time variables for services.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function buildArg($key, $value)
|
||||
{
|
||||
$this->option('build-arg', "{$key}={$value}");
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
116
src/Task/Execute.php
Normal file
116
src/Task/Execute.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace Droath\RoboDockerCompose\Task;
|
||||
|
||||
use Droath\RoboDockerCompose\DockerCommandTrait;
|
||||
|
||||
/**
|
||||
* Docker compose execute command.
|
||||
*/
|
||||
class Execute extends Base
|
||||
{
|
||||
use DockerCommandTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $action = 'exec';
|
||||
|
||||
/**
|
||||
* Set execute command.
|
||||
*
|
||||
* @param string|CommandInterface $command
|
||||
* The command to execute.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function exec($command)
|
||||
{
|
||||
$this->setCommand($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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
18
src/Task/Pause.php
Executable file
18
src/Task/Pause.php
Executable file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Droath\RoboDockerCompose\Task;
|
||||
|
||||
use Droath\RoboDockerCompose\DockerServicesTrait;
|
||||
|
||||
/**
|
||||
* Define docker compose pause command.
|
||||
*/
|
||||
class Pause extends Base
|
||||
{
|
||||
use DockerServicesTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $action = 'pause';
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
33
src/Task/Restart.php
Executable file
33
src/Task/Restart.php
Executable file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Droath\RoboDockerCompose\Task;
|
||||
|
||||
use Droath\RoboDockerCompose\DockerServicesTrait;
|
||||
|
||||
/**
|
||||
* Define docker compose restart command.
|
||||
*/
|
||||
class Restart extends Base
|
||||
{
|
||||
use DockerServicesTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $action = 'restart';
|
||||
|
||||
/**
|
||||
* Specify a shutdown timeout in seconds.
|
||||
*
|
||||
* @param int $timeout
|
||||
* The timeout in seconds.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function timeout($timeout = 10)
|
||||
{
|
||||
$this->option('timeout', $timeout);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
218
src/Task/Run.php
Normal file
218
src/Task/Run.php
Normal file
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
|
||||
namespace Droath\RoboDockerCompose\Task;
|
||||
|
||||
use Droath\RoboDockerCompose\DockerCommandTrait;
|
||||
|
||||
/**
|
||||
* Docker compose run command.
|
||||
*/
|
||||
class Run extends Base
|
||||
{
|
||||
use DockerCommandTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $action = 'run';
|
||||
|
||||
/**
|
||||
* Run container in the background.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function detach()
|
||||
{
|
||||
$this->option('detach');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign a name to the container.
|
||||
*
|
||||
* @param $value
|
||||
* The container name.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function name($value)
|
||||
{
|
||||
$this->option('name', $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the entrypoint of the image.
|
||||
*
|
||||
* @param $cmd
|
||||
* The entrypoint command.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function entrypoint($cmd)
|
||||
{
|
||||
$this->option('entrypoint', $cmd);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an environment variable.
|
||||
*
|
||||
* @param $key
|
||||
* The environment key.
|
||||
* @param $value
|
||||
* The environment value.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function envVar($key, $value)
|
||||
{
|
||||
$this->option('-e', "{$key}={$value}");
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or override a label.
|
||||
*
|
||||
* @param $key
|
||||
* The label key.
|
||||
* @param $value
|
||||
* The label value.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function label($key, $value)
|
||||
{
|
||||
$this->option('label', "{$key}={$value}");
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run as specified username or uid.
|
||||
*
|
||||
* @param $user
|
||||
* The username or uid.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function user($user)
|
||||
{
|
||||
$this->option('user', $user);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't start linked services.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function noDeps()
|
||||
{
|
||||
$this->option('no-deps');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove container after run.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
$this->option('rm');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish a container's port(s) to the host.
|
||||
*
|
||||
* @param $host
|
||||
* The host post.
|
||||
* @param $container
|
||||
* The container port.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function publish($host, $container)
|
||||
{
|
||||
$this->option('publish', "{$host}:{$container}");
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run command with the service's ports enabled and mapped
|
||||
* to the host.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function servicePorts()
|
||||
{
|
||||
$this->option('service-ports');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the service's network aliases in the network(s) the
|
||||
* container connects to.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function useAliases()
|
||||
{
|
||||
$this->option('use-aliases');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind mount a volume.
|
||||
*
|
||||
* @param $volume
|
||||
* The volume to mount.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function volume($volume)
|
||||
{
|
||||
$this->option('volume', $volume);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable pseudo-tty allocation.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function disablePseudoTty()
|
||||
{
|
||||
$this->option('-T');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Working directory inside the container.
|
||||
*
|
||||
* @param $workdir
|
||||
* The directory which to run the command under.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setWorkDir($workdir)
|
||||
{
|
||||
$this->option('workdir', $workdir, '=');
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
18
src/Task/Start.php
Executable file
18
src/Task/Start.php
Executable file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Droath\RoboDockerCompose\Task;
|
||||
|
||||
use Droath\RoboDockerCompose\DockerServicesTrait;
|
||||
|
||||
/**
|
||||
* Define docker compose start command.
|
||||
*/
|
||||
class Start extends Base
|
||||
{
|
||||
use DockerServicesTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $action = 'start';
|
||||
}
|
||||
47
src/Task/Up.php
Normal file → Executable file
47
src/Task/Up.php
Normal file → Executable file
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Droath\RoboDockerCompose\Task;
|
||||
|
||||
use Droath\RoboDockerCompose\DockerServicesTrait;
|
||||
use Robo\Exception\TaskException;
|
||||
|
||||
/**
|
||||
@@ -9,18 +10,13 @@ use Robo\Exception\TaskException;
|
||||
*/
|
||||
class Up extends Base
|
||||
{
|
||||
use DockerServicesTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $action = 'up';
|
||||
|
||||
/**
|
||||
* Docker compose services.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $services = [];
|
||||
|
||||
/**
|
||||
* Command detached mode.
|
||||
*
|
||||
@@ -28,34 +24,6 @@ class Up extends Base
|
||||
*/
|
||||
protected $detachedMode = false;
|
||||
|
||||
/**
|
||||
* Add docker composer service.
|
||||
*
|
||||
* @param string $service
|
||||
* The docker services.
|
||||
*/
|
||||
public function setService($service)
|
||||
{
|
||||
$this->services[] = $service;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add docker composer services.
|
||||
*
|
||||
* @param array $services
|
||||
* An array of services.
|
||||
*/
|
||||
public function setServices(array $services)
|
||||
{
|
||||
foreach ($services as $service) {
|
||||
$this->setService($service);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run containers in the background.
|
||||
*/
|
||||
@@ -147,15 +115,6 @@ class Up extends Base
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getCommand()
|
||||
{
|
||||
// Append the services to the end of the command.
|
||||
return parent::getCommand() . ' ' . implode(' ', $this->services);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set command detached mode.
|
||||
*/
|
||||
|
||||
74
src/Task/loadTasks.php
Normal file → Executable file
74
src/Task/loadTasks.php
Normal file → Executable file
@@ -16,10 +16,82 @@ trait loadTasks
|
||||
}
|
||||
|
||||
/**
|
||||
* Docker compose up task.
|
||||
* 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.
|
||||
*/
|
||||
protected function taskDockerComposeDown($pathToDockerCompose = null)
|
||||
{
|
||||
return $this->task(Down::class, $pathToDockerCompose);
|
||||
}
|
||||
|
||||
/**
|
||||
* Docker compose pause task.
|
||||
*/
|
||||
protected function taskDockerComposePause($pathToDockerCompose = null)
|
||||
{
|
||||
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.
|
||||
*/
|
||||
protected function taskDockerComposeStart($pathToDockerCompose = null)
|
||||
{
|
||||
return $this->task(Start::class, $pathToDockerCompose);
|
||||
}
|
||||
|
||||
/**
|
||||
* Docker compose restart task.
|
||||
*/
|
||||
protected function taskDockerComposeRestart($pathToDockerCompose = null)
|
||||
{
|
||||
return $this->task(Restart::class, $pathToDockerCompose);
|
||||
}
|
||||
|
||||
/**
|
||||
* Docker compose execute task.
|
||||
*/
|
||||
protected function taskDockerComposeExecute($pathToDockerCompose = null)
|
||||
{
|
||||
return $this->task(Execute::class, $pathToDockerCompose);
|
||||
}
|
||||
|
||||
/**
|
||||
* Docker compose run task.
|
||||
*/
|
||||
protected function taskDockerComposeRun($pathToDockerCompose = null)
|
||||
{
|
||||
return $this->task(Run::class, $pathToDockerCompose);
|
||||
}
|
||||
|
||||
/**
|
||||
* Docker compose build task.
|
||||
*/
|
||||
protected function taskDockerComposeBuild($pathToDockerCompose = null)
|
||||
{
|
||||
return $this->task(Build::class, $pathToDockerCompose);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user